Skip to content

Commit 1413576

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 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
1 parent 132be1f commit 1413576

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
@@ -3763,6 +3763,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
37633763
NewRHS = Constant::getNullValue(X->getType());
37643764
break;
37653765

3766+
case ICmpInst::ICMP_ULE:
3767+
NewPred = ICmpInst::ICMP_SLE;
3768+
NewRHS = Constant::getNullValue(X->getType());
3769+
break;
3770+
37663771
case ICmpInst::ICMP_EQ:
37673772
case ICmpInst::ICMP_NE:
37683773
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
@@ -101,8 +101,7 @@ define i1 @t6(i8 %x) {
101101

102102
define i1 @t7(i8 %x) {
103103
; CHECK-LABEL: @t7(
104-
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
105-
; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[NEG_X]], [[X]]
104+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1
106105
; CHECK-NEXT: ret i1 [[CMP]]
107106
;
108107
%neg_x = sub nsw i8 0, %x

0 commit comments

Comments
 (0)