[InstCombine] reduce test-for-overflow of shifted value
authorTian Zhou <tianzhou93@gmail.com>
Mon, 5 Sep 2022 13:50:40 +0000 (09:50 -0400)
committerSanjay Patel <spatel@rotateright.com>
Mon, 5 Sep 2022 13:51:51 +0000 (09:51 -0400)
commit8fa432be4f749c4ab0ee452d8f7c4337d67861a1
treee15aa15e6f0cb3f27c6354ded99409e566049a17
parent5db8d6fd2bd6db3cdc6290b538f054ca0833d763
[InstCombine] reduce test-for-overflow of shifted value

Fixes #57338.

The added code makes the following transformations:

For unsigned predicates / eq / ne:
icmp pred (x << 1), x --> icmp getSignedPredicate(pred) x, 0
icmp pred x, (x << 1) --> icmp getSignedPredicate(pred) 0, x

Some examples:
https://alive2.llvm.org/ce/z/ckn4cj
https://alive2.llvm.org/ce/z/h-4bAQ

Differential Revision: https://reviews.llvm.org/D132888
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-shl-1-overflow.ll