Skip to content

Commit 0e1241a

Browse files
committed
[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 uge i8 %neg_x, %x => %r = icmp sge i8 %x, 0 https://rise4fun.com/Alive/LLHd https://bugs.llvm.org/show_bug.cgi?id=39480
1 parent 16c642f commit 0e1241a

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
@@ -3753,6 +3753,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
37533753
NewRHS = Constant::getNullValue(X->getType());
37543754
break;
37553755

3756+
case ICmpInst::ICMP_UGE:
3757+
NewPred = ICmpInst::ICMP_SGE;
3758+
NewRHS = Constant::getNullValue(X->getType());
3759+
break;
3760+
37563761
case ICmpInst::ICMP_EQ:
37573762
case ICmpInst::ICMP_NE:
37583763
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
@@ -81,8 +81,7 @@ define i1 @t4(i8 %x) {
8181

8282
define i1 @t5(i8 %x) {
8383
; CHECK-LABEL: @t5(
84-
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
85-
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[NEG_X]], [[X]]
84+
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
8685
; CHECK-NEXT: ret i1 [[CMP]]
8786
;
8887
%neg_x = sub nsw i8 0, %x

0 commit comments

Comments
 (0)