From: Roman Lebedev Date: Thu, 6 Aug 2020 08:07:17 +0000 (+0300) Subject: [InstCombine] (-NSW x) s>= x --> x s<= 0 (PR39480) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=388520765157f1ce7e48e49179dc58781ae61f56;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index ce75a36..13dacd4 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 a2e39f1..0a557a8 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