[llvm-commits] [llvm] r53443 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-07-10-CastSextBool.ll
Chris Lattner
sabre at nondot.org
Thu Jul 10 21:09:09 PDT 2008
Author: lattner
Date: Thu Jul 10 23:09:09 2008
New Revision: 53443
URL: http://llvm.org/viewvc/llvm-project?rev=53443&view=rev
Log:
Fix a bogus optimization: folding (slt (zext i1 A to i32), 1) -> (slt i1 A, true)
This cause a regression in InstCombine/JavaCompare, which was doing the right
thing on accident. To handle the missed case, generalize the comparisons based
on masked bits a little bit to handle comparisons against the max value. For
example, we can now xform (slt i32 (and X, 4), 4) -> (setne i32 (and X, 4), 4)
Added:
llvm/trunk/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=53443&r1=53442&r2=53443&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Thu Jul 10 23:09:09 2008
@@ -5230,7 +5230,7 @@
// See if we are doing a comparison between a constant and an instruction that
// can be folded into the comparison.
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
- Value *A, *B;
+ Value *A, *B;
// (icmp ne/eq (sub A B) 0) -> (icmp ne/eq A, B)
if (I.isEquality() && CI->isNullValue() &&
@@ -5396,6 +5396,8 @@
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (Min.sgt(RHSVal))
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
+ if (Max == RHSVal) // A <s MAX -> A != MAX
+ return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
break;
case ICmpInst::ICMP_SGT:
if (Min.sgt(RHSVal))
@@ -6300,12 +6302,11 @@
// %B = icmp ugt short %X, 1330
// because %A may have negative value.
//
- // However, it is OK if SrcTy is bool (See cast-set.ll testcase)
- // OR operation is EQ/NE.
- if (isSignedExt == isSignedCmp || SrcTy == Type::Int1Ty || ICI.isEquality())
+ // However, we allow this when the compare is EQ/NE, because they are
+ // signless.
+ if (isSignedExt == isSignedCmp || ICI.isEquality())
return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
- else
- return 0;
+ return 0;
}
// The re-extended constant changed so the constant cannot be represented
@@ -6343,17 +6344,15 @@
// Finally, return the value computed.
if (ICI.getPredicate() == ICmpInst::ICMP_ULT ||
- ICI.getPredicate() == ICmpInst::ICMP_SLT) {
+ ICI.getPredicate() == ICmpInst::ICMP_SLT)
return ReplaceInstUsesWith(ICI, Result);
- } else {
- assert((ICI.getPredicate()==ICmpInst::ICMP_UGT ||
- ICI.getPredicate()==ICmpInst::ICMP_SGT) &&
- "ICmp should be folded!");
- if (Constant *CI = dyn_cast<Constant>(Result))
- return ReplaceInstUsesWith(ICI, ConstantExpr::getNot(CI));
- else
- return BinaryOperator::CreateNot(Result);
- }
+
+ assert((ICI.getPredicate()==ICmpInst::ICMP_UGT ||
+ ICI.getPredicate()==ICmpInst::ICMP_SGT) &&
+ "ICmp should be folded!");
+ if (Constant *CI = dyn_cast<Constant>(Result))
+ return ReplaceInstUsesWith(ICI, ConstantExpr::getNot(CI));
+ return BinaryOperator::CreateNot(Result);
}
Instruction *InstCombiner::visitShl(BinaryOperator &I) {
Added: llvm/trunk/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll?rev=53443&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-07-10-CastSextBool.ll Thu Jul 10 23:09:09 2008
@@ -0,0 +1,8 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {%C = xor i1 %A, true}
+; PR2539
+
+define i1 @test(i1 %A) {
+ %B = zext i1 %A to i32
+ %C = icmp slt i32 %B, 1
+ ret i1 %C
+}
More information about the llvm-commits
mailing list