[llvm] 3885207 - [InstCombine] (-NSW x) s>= x --> x s<= 0 (PR39480)

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 01:51:45 PDT 2020


Author: Roman Lebedev
Date: 2020-08-06T11:50:34+03:00
New Revision: 388520765157f1ce7e48e49179dc58781ae61f56

URL: https://github.com/llvm/llvm-project/commit/388520765157f1ce7e48e49179dc58781ae61f56
DIFF: https://github.com/llvm/llvm-project/commit/388520765157f1ce7e48e49179dc58781ae61f56.diff

LOG: [InstCombine] (-NSW x) s>= x  --> x s<= 0  (PR39480)

Name: (-x) s>= x  -->  x s<= 0
%neg_x = sub nsw i8 0, %x ; %x must not be INT_MIN
%r = icmp sge i8 %neg_x, %x
  =>
%r = icmp sle i8 %x, 0

https://rise4fun.com/Alive/Hdip

https://bugs.llvm.org/show_bug.cgi?id=39480

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index ce75a360de9d..13dacd4b0bf3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3733,6 +3733,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
     NewRHS = Constant::getNullValue(X->getType());
     break;
 
+  case ICmpInst::ICMP_SGE:
+    NewPred = ICmpInst::ICMP_SLE;
+    NewRHS = Constant::getNullValue(X->getType());
+    break;
+
   case ICmpInst::ICMP_EQ:
   case ICmpInst::ICMP_NE:
     NewPred = Pred;

diff  --git a/llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll b/llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll
index a2e39f1637d8..0a557a81fa0d 100644
--- a/llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll
+++ b/llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll
@@ -41,8 +41,7 @@ define i1 @t0_extrause(i8 %x) {
 
 define i1 @t1(i8 %x) {
 ; CHECK-LABEL: @t1(
-; CHECK-NEXT:    [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
-; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i8 [[NEG_X]], [[X]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1
 ; CHECK-NEXT:    ret i1 [[CMP]]
 ;
   %neg_x = sub nsw i8 0, %x


        


More information about the llvm-commits mailing list