[llvm] r303105 - [InstCombine] restrict icmp fold with 2 sdiv exact operands (PR32949)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 12:27:53 PDT 2017
Author: spatel
Date: Mon May 15 14:27:53 2017
New Revision: 303105
URL: http://llvm.org/viewvc/llvm-project?rev=303105&view=rev
Log:
[InstCombine] restrict icmp fold with 2 sdiv exact operands (PR32949)
This is the InstCombine counterpart to D32954.
I added some comments about the code duplication in:
rL302436
Alive-based verification:
http://rise4fun.com/Alive/dPw
This is a 2nd fix for the problem reported in:
https://bugs.llvm.org/show_bug.cgi?id=32949
Differential Revision: https://reviews.llvm.org/D32970
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=303105&r1=303104&r2=303105&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Mon May 15 14:27:53 2017
@@ -3068,16 +3068,23 @@ Instruction *InstCombiner::foldICmpBinOp
}
}
break;
+
case Instruction::UDiv:
case Instruction::LShr:
- if (I.isSigned())
+ if (I.isSigned() || !BO0->isExact() || !BO1->isExact())
break;
- LLVM_FALLTHROUGH;
+ return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0));
+
case Instruction::SDiv:
+ if (!I.isEquality() || !BO0->isExact() || !BO1->isExact())
+ break;
+ return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0));
+
case Instruction::AShr:
if (!BO0->isExact() || !BO1->isExact())
break;
return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0));
+
case Instruction::Shl: {
bool NUW = BO0->hasNoUnsignedWrap() && BO1->hasNoUnsignedWrap();
bool NSW = BO0->hasNoSignedWrap() && BO1->hasNoSignedWrap();
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=303105&r1=303104&r2=303105&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Mon May 15 14:27:53 2017
@@ -695,11 +695,13 @@ define i1 @test48(i32 %X, i32 %Y, i32 %Z
ret i1 %C
}
-; FIXME: The above transform only works for equality predicates.
+; The above transform only works for equality predicates.
define i1 @PR32949(i32 %X, i32 %Y, i32 %Z) {
; CHECK-LABEL: @PR32949(
-; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 %X, %Y
+; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 %X, %Z
+; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 %Y, %Z
+; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[A]], [[B]]
; CHECK-NEXT: ret i1 [[C]]
;
%A = sdiv exact i32 %X, %Z
More information about the llvm-commits
mailing list