]> granicus.if.org Git - llvm/commit
[InstCombine] fold cmp+select using select operand equivalence
authorSanjay Patel <spatel@rotateright.com>
Fri, 2 Aug 2019 17:39:32 +0000 (17:39 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 2 Aug 2019 17:39:32 +0000 (17:39 +0000)
commite2d5f7a219146fea8618567881c0bacc467f4850
treee3b6b21bb19752b8d5dda12ae3b42f658faf5702
parent59e60377ac39f41650dcf0424f66686d9d625abb
[InstCombine] fold cmp+select using select operand equivalence

As discussed in PR42696:
https://bugs.llvm.org/show_bug.cgi?id=42696
...but won't help that case yet.

We have an odd situation where a select operand equivalence fold was
implemented in InstSimplify when it could have been done more generally
in InstCombine if we allow dropping of {nsw,nuw,exact} from a binop operand.

Here's an example:
https://rise4fun.com/Alive/Xplr

  %cmp = icmp eq i32 %x, 2147483647
  %add = add nsw i32 %x, 1
  %sel = select i1 %cmp, i32 -2147483648, i32 %add
  =>
  %sel = add i32 %x, 1

I've left the InstSimplify code in place for now, but my guess is that we'd
prefer to remove that as a follow-up to save on code duplication and
compile-time.

Differential Revision: https://reviews.llvm.org/D65576

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367695 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/InstructionSimplify.cpp
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/select-bitext-bitwise-ops.ll
test/Transforms/InstCombine/select-obo-peo-ops.ll
test/Transforms/InstCombine/select.ll