1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[InstCombine] (-NSW x) s< x --> x s> 0 (PR39480)

Name: (-x) s< x  -->  x > 0
%neg_x = sub nsw i8 0, %x ; %x must not be INT_MIN
%r = icmp slt i8 %neg_x, %x
  =>
%r = icmp sgt i8 %x, 0

https://rise4fun.com/Alive/3IXb

https://bugs.llvm.org/show_bug.cgi?id=39480
This commit is contained in:
Roman Lebedev 2020-08-06 11:10:38 +03:00
parent 0e688c47d3
commit 08ee2e8233
2 changed files with 6 additions and 2 deletions

View File

@ -3738,6 +3738,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
NewRHS = Constant::getNullValue(X->getType());
break;
case ICmpInst::ICMP_SLT:
NewPred = ICmpInst::ICMP_SGT;
NewRHS = Constant::getNullValue(X->getType());
break;
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_NE:
NewPred = Pred;

View File

@ -51,8 +51,7 @@ define i1 @t1(i8 %x) {
define i1 @t2(i8 %x) {
; CHECK-LABEL: @t2(
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[NEG_X]], [[X]]
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%neg_x = sub nsw i8 0, %x