Skip to content

Commit

Permalink
[InstCombine] (-NSW x) u<= x --> x s<=0 (PR39480)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LebedevRI committed Aug 6, 2020
1 parent 132be1f commit 1413576
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
NewRHS = Constant::getNullValue(X->getType());
break;

case ICmpInst::ICMP_ULE:
NewPred = ICmpInst::ICMP_SLE;
NewRHS = Constant::getNullValue(X->getType());
break;

case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_NE:
NewPred = Pred;
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/InstCombine/cmp-x-vs-neg-x.ll
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ define i1 @t6(i8 %x) {

define i1 @t7(i8 %x) {
; CHECK-LABEL: @t7(
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[NEG_X]], [[X]]
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 1
; CHECK-NEXT: ret i1 [[CMP]]
;
%neg_x = sub nsw i8 0, %x
Expand Down

0 comments on commit 1413576

Please sign in to comment.