[llvm] r186229 - Fix logic error optimizing "icmp pred (urem X, Y), Y" where pred is signed.
Nick Lewycky
nicholas at mxc.ca
Fri Jul 12 16:42:57 PDT 2013
Author: nicholas
Date: Fri Jul 12 18:42:57 2013
New Revision: 186229
URL: http://llvm.org/viewvc/llvm-project?rev=186229&view=rev
Log:
Fix logic error optimizing "icmp pred (urem X, Y), Y" where pred is signed.
Fixes PR16605.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/compare.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=186229&r1=186228&r2=186229&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Fri Jul 12 18:42:57 2013
@@ -2246,6 +2246,7 @@ static Value *SimplifyICmpInst(unsigned
}
}
+ // icmp pred (urem X, Y), Y
if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) {
bool KnownNonNegative, KnownNegative;
switch (Pred) {
@@ -2253,7 +2254,7 @@ static Value *SimplifyICmpInst(unsigned
break;
case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_SGE:
- ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.TD);
+ ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.TD);
if (!KnownNonNegative)
break;
// fall-through
@@ -2263,7 +2264,7 @@ static Value *SimplifyICmpInst(unsigned
return getFalse(ITy);
case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_SLE:
- ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.TD);
+ ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.TD);
if (!KnownNonNegative)
break;
// fall-through
@@ -2273,6 +2274,8 @@ static Value *SimplifyICmpInst(unsigned
return getTrue(ITy);
}
}
+
+ // icmp pred X, (urem Y, X)
if (RBO && match(RBO, m_URem(m_Value(), m_Specific(LHS)))) {
bool KnownNonNegative, KnownNegative;
switch (Pred) {
@@ -2280,7 +2283,7 @@ static Value *SimplifyICmpInst(unsigned
break;
case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_SGE:
- ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.TD);
+ ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.TD);
if (!KnownNonNegative)
break;
// fall-through
@@ -2290,7 +2293,7 @@ static Value *SimplifyICmpInst(unsigned
return getTrue(ITy);
case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_SLE:
- ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.TD);
+ ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.TD);
if (!KnownNonNegative)
break;
// fall-through
Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=186229&r1=186228&r2=186229&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Fri Jul 12 18:42:57 2013
@@ -480,7 +480,7 @@ define i1 @urem5(i16 %X, i32 %Y) {
%B = urem i32 %A, %Y
%C = icmp slt i32 %B, %Y
ret i1 %C
-; CHECK: ret i1 true
+; CHECK-NOT: ret i1 true
}
define i1 @urem6(i32 %X, i32 %Y) {
@@ -491,6 +491,14 @@ define i1 @urem6(i32 %X, i32 %Y) {
; CHECK: ret i1 true
}
+define i1 @urem7(i32 %X) {
+; CHECK: @urem7
+ %A = urem i32 1, %X
+ %B = icmp sgt i32 %A, %X
+ ret i1 %B
+; CHECK-NOT: ret i1 false
+}
+
define i1 @srem1(i32 %X) {
; CHECK: @srem1
%A = srem i32 %X, -5
More information about the llvm-commits
mailing list