[llvm-commits] [llvm] r70051 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Transforms/IndVarSimplify/avoid-i0.ll
Dan Gohman
gohman at apple.com
Sat Apr 25 10:05:40 PDT 2009
Author: djg
Date: Sat Apr 25 12:05:40 2009
New Revision: 70051
URL: http://llvm.org/viewvc/llvm-project?rev=70051&view=rev
Log:
Handle ands with 0 and shifts by 0 correctly. These aren't
common, but indvars shouldn't crash on them. This fixes PR4054.
Added:
llvm/trunk/test/Transforms/IndVarSimplify/avoid-i0.ll
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=70051&r1=70050&r2=70051&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sat Apr 25 12:05:40 2009
@@ -1754,6 +1754,8 @@
// For an expression like x&255 that merely masks off the high bits,
// use zext(trunc(x)) as the SCEV expression.
if (ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1))) {
+ if (CI->isNullValue())
+ return getSCEV(U->getOperand(1));
const APInt &A = CI->getValue();
unsigned Ones = A.countTrailingOnes();
if (APIntOps::isMask(Ones, A))
@@ -1818,10 +1820,15 @@
if (Instruction *L = dyn_cast<Instruction>(U->getOperand(0)))
if (L->getOpcode() == Instruction::Shl &&
L->getOperand(1) == U->getOperand(1)) {
- uint64_t Amt = getTypeSizeInBits(U->getType()) - CI->getZExtValue();
+ unsigned BitWidth = getTypeSizeInBits(U->getType());
+ uint64_t Amt = BitWidth - CI->getZExtValue();
+ if (Amt == BitWidth)
+ return getSCEV(L->getOperand(0)); // shift by zero --> noop
+ if (Amt > BitWidth)
+ return getIntegerSCEV(0, U->getType()); // value is undefined
return
getSignExtendExpr(getTruncateExpr(getSCEV(L->getOperand(0)),
- IntegerType::get(Amt)),
+ IntegerType::get(Amt)),
U->getType());
}
break;
Added: llvm/trunk/test/Transforms/IndVarSimplify/avoid-i0.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/avoid-i0.ll?rev=70051&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/avoid-i0.ll (added)
+++ llvm/trunk/test/Transforms/IndVarSimplify/avoid-i0.ll Sat Apr 25 12:05:40 2009
@@ -0,0 +1,23 @@
+; RUN: llvm-as < %s | opt -indvars
+; PR4054
+
+; Don't treat an and with 0 as a mask (trunc+zext).
+
+define i32 @int80(i8 signext %p_71) nounwind {
+entry:
+ br label %bb
+
+bb: ; preds = %bb6, %entry
+ %p_71_addr.0 = phi i8 [ %p_71, %entry ], [ %0, %bb6 ] ; <i8> [#uses=0]
+ br i1 false, label %bb4, label %bb1
+
+bb1: ; preds = %bb
+ ret i32 0
+
+bb4: ; preds = %bb4, %bb
+ br i1 false, label %bb6, label %bb4
+
+bb6: ; preds = %bb4
+ %0 = and i8 0, 0 ; <i8> [#uses=1]
+ br label %bb
+}
More information about the llvm-commits
mailing list