]> granicus.if.org Git - llvm/commit
[InstCombine] fold icmp sgt/slt (add nsw X, C2), C --> icmp sgt/slt X, (C - C2)
authorSanjay Patel <spatel@rotateright.com>
Sun, 12 Feb 2017 16:40:30 +0000 (16:40 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 12 Feb 2017 16:40:30 +0000 (16:40 +0000)
commit095a0b49b30207ede8dc79012d2080b7776f2c8b
treeffecd1aae8d16c6434585f16978e7bce18e18e49
parent38d869aaef048651993ef2beaae1d49916b61ff7
[InstCombine] fold icmp sgt/slt (add nsw X, C2), C --> icmp sgt/slt X, (C - C2)

I found one special case of this transform for 'slt 0', so I removed that and added the general transform.

Alive code to check correctness:

Name: slt_no_overflow
Pre: WillNotOverflowSignedSub(C1, C2)
%a = add nsw i8 %x, C2
%b = icmp slt %a, C1
  =>
%b = icmp slt %x, C1 - C2

Name: sgt_no_overflow
Pre: WillNotOverflowSignedSub(C1, C2)
%a = add nsw i8 %x, C2
%b = icmp sgt %a, C1
  =>
%b = icmp sgt %x, C1 - C2

http://rise4fun.com/Alive/MH

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294898 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp-add.ll