Skip to content

Commit 59387c0

Browse files
committed
[InstCombine] (-NSW x) s<= x --> x s>= 0 (PR39480)
Name: (-x) s<= x --> x >= 0 %neg_x = sub nsw i8 0, %x ; %x must not be INT_MIN %r = icmp sle i8 %neg_x, %x => %r = icmp sge i8 %x, 0 https://rise4fun.com/Alive/91k https://bugs.llvm.org/show_bug.cgi?id=39480
1 parent 01a6c4b commit 59387c0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
37433743
NewRHS = Constant::getNullValue(X->getType());
37443744
break;
37453745

3746+
case ICmpInst::ICMP_SLE:
3747+
NewPred = ICmpInst::ICMP_SGE;
3748+
NewRHS = Constant::getNullValue(X->getType());
3749+
break;
3750+
37463751
case ICmpInst::ICMP_EQ:
37473752
case ICmpInst::ICMP_NE:
37483753
NewPred = Pred;

llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ define i1 @t2(i8 %x) {
6161

6262
define i1 @t3(i8 %x) {
6363
; CHECK-LABEL: @t3(
64-
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
65-
; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[NEG_X]], [[X]]
64+
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
6665
; CHECK-NEXT: ret i1 [[CMP]]
6766
;
6867
%neg_x = sub nsw i8 0, %x

0 commit comments

Comments
 (0)