Skip to content

Commit 16c642f

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 ugt i8 %neg_x, %x => %r = icmp sgt i8 %x, 0 https://rise4fun.com/Alive/Raea https://bugs.llvm.org/show_bug.cgi?id=39480
1 parent 59387c0 commit 16c642f

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
@@ -3748,6 +3748,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
37483748
NewRHS = Constant::getNullValue(X->getType());
37493749
break;
37503750

3751+
case ICmpInst::ICMP_UGT:
3752+
NewPred = ICmpInst::ICMP_SGT;
3753+
NewRHS = Constant::getNullValue(X->getType());
3754+
break;
3755+
37513756
case ICmpInst::ICMP_EQ:
37523757
case ICmpInst::ICMP_NE:
37533758
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
@@ -71,8 +71,7 @@ define i1 @t3(i8 %x) {
7171

7272
define i1 @t4(i8 %x) {
7373
; CHECK-LABEL: @t4(
74-
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
75-
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NEG_X]], [[X]]
74+
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0
7675
; CHECK-NEXT: ret i1 [[CMP]]
7776
;
7877
%neg_x = sub nsw i8 0, %x

0 commit comments

Comments
 (0)