summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-27 08:32:52 +0000
committerChris Lattner <sabre@nondot.org>2009-11-27 08:32:52 +0000
commita650f770d4cfc9aabacddf41851d23c55f23cb8c (patch)
treeb6475a0965fda40ed9c38889fc8309fa9d784e45 /lib
parent616613d7a4ddc7cefce53b2bfe3fdcdec6b032c2 (diff)
downloadllvm-a650f770d4cfc9aabacddf41851d23c55f23cb8c.tar.gz
llvm-a650f770d4cfc9aabacddf41851d23c55f23cb8c.tar.bz2
llvm-a650f770d4cfc9aabacddf41851d23c55f23cb8c.tar.xz
limit the recursion depth of GetLinearExpression. This
fixes a crash analyzing consumer-lame, which had an "%X = add %X, 1" in unreachable code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90000 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/ValueTracking.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index f6a492f767..3e6af58aa9 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -955,8 +955,15 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
/// have IntegerType. Note that this looks through extends, so the high bits
/// may not be represented in the result.
static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
- const TargetData *TD) {
+ const TargetData *TD, unsigned Depth) {
assert(isa<IntegerType>(V->getType()) && "Not an integer value");
+
+ // Limit our recursion depth.
+ if (Depth == 6) {
+ Scale = 1;
+ Offset = 0;
+ return V;
+ }
if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(V)) {
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
@@ -969,16 +976,16 @@ static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
break;
// FALL THROUGH.
case Instruction::Add:
- V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD);
+ V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD, Depth+1);
Offset += RHSC->getValue();
return V;
case Instruction::Mul:
- V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD);
+ V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD, Depth+1);
Offset *= RHSC->getValue();
Scale *= RHSC->getValue();
return V;
case Instruction::Shl:
- V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD);
+ V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, TD, Depth+1);
Offset <<= RHSC->getValue().getLimitedValue();
Scale <<= RHSC->getValue().getLimitedValue();
return V;
@@ -994,7 +1001,7 @@ static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
unsigned SmallWidth = CastOp->getType()->getPrimitiveSizeInBits();
Scale.trunc(SmallWidth);
Offset.trunc(SmallWidth);
- Value *Result = GetLinearExpression(CastOp, Scale, Offset, TD);
+ Value *Result = GetLinearExpression(CastOp, Scale, Offset, TD, Depth+1);
Scale.zext(OldWidth);
Offset.zext(OldWidth);
return Result;
@@ -1088,7 +1095,7 @@ const Value *llvm::DecomposeGEPExpression(const Value *V, int64_t &BaseOffs,
// Use GetLinearExpression to decompose the index into a C1*V+C2 form.
unsigned Width = cast<IntegerType>(Index->getType())->getBitWidth();
APInt IndexScale(Width, 0), IndexOffset(Width, 0);
- Index = GetLinearExpression(Index, IndexScale, IndexOffset, TD);
+ Index = GetLinearExpression(Index, IndexScale, IndexOffset, TD, 0);
// The GEP index scale ("Scale") scales C1*V+C2, yielding (C1*V+C2)*Scale.
// This gives us an aggregate computation of (C1*Scale)*V + C2*Scale.