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

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


Author: Roman Lebedev
Date: 2020-08-06T11:50:36+03:00
New Revision: 141357663e671636392c9973025ea723f423a9c4

URL: https://github.com/llvm/llvm-project/commit/141357663e671636392c9973025ea723f423a9c4
DIFF: https://github.com/llvm/llvm-project/commit/141357663e671636392c9973025ea723f423a9c4.diff

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

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

https://rise4fun.com/Alive/V22

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 78dd5f04facc..66977cc3fce8 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3763,6 +3763,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
     NewRHS = Constant::getNullValue(X->getType());
     break;
 
+  case ICmpInst::ICMP_ULE:
+    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 d0bbccda2d78..cd5446112cdf 100644
--- a/llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll
+++ b/llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll
@@ -101,8 +101,7 @@ define i1 @t6(i8 %x) {
 
 define i1 @t7(i8 %x) {
 ; CHECK-LABEL: @t7(
-; CHECK-NEXT:    [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ule 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