Skip to content

Commit 132be1f

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 ult i8 %neg_x, %x => %r = icmp slt i8 %x, 0 https://rise4fun.com/Alive/zSuf https://bugs.llvm.org/show_bug.cgi?id=39480
1 parent 0e1241a commit 132be1f

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
@@ -3758,6 +3758,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
37583758
NewRHS = Constant::getNullValue(X->getType());
37593759
break;
37603760

3761+
case ICmpInst::ICMP_ULT:
3762+
NewPred = ICmpInst::ICMP_SLT;
3763+
NewRHS = Constant::getNullValue(X->getType());
3764+
break;
3765+
37613766
case ICmpInst::ICMP_EQ:
37623767
case ICmpInst::ICMP_NE:
37633768
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
@@ -91,8 +91,7 @@ define i1 @t5(i8 %x) {
9191

9292
define i1 @t6(i8 %x) {
9393
; CHECK-LABEL: @t6(
94-
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
95-
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[NEG_X]], [[X]]
94+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
9695
; CHECK-NEXT: ret i1 [[CMP]]
9796
;
9897
%neg_x = sub nsw i8 0, %x

0 commit comments

Comments
 (0)