summaryrefslogtreecommitdiff
path: root/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-04 01:25:35 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-04 01:25:35 +0000
commit0797605204a0726a2f3f726ae4431445b5d40ca9 (patch)
tree333f72d181efacab9263708c982f605663f3cea2 /lib/Analysis/ScalarEvolution.cpp
parent9caed5440d59dac4b388152fe8b993dc0491e5e9 (diff)
downloadllvm-0797605204a0726a2f3f726ae4431445b5d40ca9.tar.gz
llvm-0797605204a0726a2f3f726ae4431445b5d40ca9.tar.bz2
llvm-0797605204a0726a2f3f726ae4431445b5d40ca9.tar.xz
Guard further against APInt operations with operands of unequal bit width.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34897 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index d2eca4adeb..051631e80d 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -1354,16 +1354,22 @@ static APInt GetConstantFactor(SCEVHandle S) {
// The result is the min of all operands.
APInt Res = GetConstantFactor(A->getOperand(0));
for (unsigned i = 1, e = A->getNumOperands();
- i != e && Res.ugt(APInt(Res.getBitWidth(),1)); ++i)
- Res = APIntOps::umin(Res, GetConstantFactor(A->getOperand(i)));
+ i != e && Res.ugt(APInt(Res.getBitWidth(),1)); ++i) {
+ APInt Tmp(GetConstantFactor(A->getOperand(i)));
+ Tmp.zextOrTrunc(Res.getBitWidth());
+ Res = APIntOps::umin(Res, Tmp);
+ }
return Res;
}
if (SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
// The result is the product of all the operands.
APInt Res = GetConstantFactor(M->getOperand(0));
- for (unsigned i = 1, e = M->getNumOperands(); i != e; ++i)
- Res *= GetConstantFactor(M->getOperand(i));
+ for (unsigned i = 1, e = M->getNumOperands(); i != e; ++i) {
+ APInt Tmp(GetConstantFactor(M->getOperand(i)));
+ Tmp.zextOrTrunc(Res.getBitWidth());
+ Res *= Tmp;
+ }
return Res;
}
@@ -1375,6 +1381,7 @@ static APInt GetConstantFactor(SCEVHandle S) {
if (Start == 1)
return APInt(A->getBitWidth(),1);
APInt Stride = GetConstantFactor(A->getOperand(1));
+ Start.zextOrTrunc(Stride.getBitWidth());
return APIntOps::GreatestCommonDivisor(Start, Stride);
}
}