summaryrefslogtreecommitdiffstats
path: root/lib/Analysis
diff options
context:
space:
mode:
authorZhou Sheng <zhousheng00@gmail.com>2007-04-07 17:40:57 +0000
committerZhou Sheng <zhousheng00@gmail.com>2007-04-07 17:40:57 +0000
commitfdc1e16dcf358cd5e0ff1cf36735630854a268e4 (patch)
tree3e1b27ffba5a7f48461de414a1783436d1ed479f /lib/Analysis
parent8342836d70e94361a88d431a68a6da0ae0a9e219 (diff)
downloadexternal_llvm-fdc1e16dcf358cd5e0ff1cf36735630854a268e4.zip
external_llvm-fdc1e16dcf358cd5e0ff1cf36735630854a268e4.tar.gz
external_llvm-fdc1e16dcf358cd5e0ff1cf36735630854a268e4.tar.bz2
Make APInt variables do the computation stuffs instead of
ConstantExpr::getXX if possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35738 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index d9256c9..48b0d6d 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -602,7 +602,8 @@ SCEVHandle SCEVAddExpr::get(std::vector<SCEVHandle> &Ops) {
assert(Idx < Ops.size());
while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
// We found two constants, fold them together!
- Constant *Fold = ConstantExpr::getAdd(LHSC->getValue(), RHSC->getValue());
+ Constant *Fold = ConstantInt::get(LHSC->getValue()->getValue() +
+ RHSC->getValue()->getValue());
if (ConstantInt *CI = dyn_cast<ConstantInt>(Fold)) {
Ops[0] = SCEVConstant::get(CI);
Ops.erase(Ops.begin()+1); // Erase the folded element
@@ -839,7 +840,8 @@ SCEVHandle SCEVMulExpr::get(std::vector<SCEVHandle> &Ops) {
++Idx;
while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
// We found two constants, fold them together!
- Constant *Fold = ConstantExpr::getMul(LHSC->getValue(), RHSC->getValue());
+ Constant *Fold = ConstantInt::get(LHSC->getValue()->getValue() *
+ RHSC->getValue()->getValue());
if (ConstantInt *CI = dyn_cast<ConstantInt>(Fold)) {
Ops[0] = SCEVConstant::get(CI);
Ops.erase(Ops.begin()+1); // Erase the folded element
@@ -1412,10 +1414,9 @@ SCEVHandle ScalarEvolutionsImpl::createSCEV(Value *V) {
// optimizations will transparently handle this case.
if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
SCEVHandle LHS = getSCEV(I->getOperand(0));
- APInt CommonFact = GetConstantFactor(LHS);
+ APInt CommonFact(GetConstantFactor(LHS));
assert(!CommonFact.isMinValue() &&
"Common factor should at least be 1!");
- CommonFact.zextOrTrunc(CI->getValue().getBitWidth());
if (CommonFact.ugt(CI->getValue())) {
// If the LHS is a multiple that is larger than the RHS, use +.
return SCEVAddExpr::get(LHS,
@@ -1436,8 +1437,9 @@ SCEVHandle ScalarEvolutionsImpl::createSCEV(Value *V) {
case Instruction::Shl:
// Turn shift left of a constant amount into a multiply.
if (ConstantInt *SA = dyn_cast<ConstantInt>(I->getOperand(1))) {
- Constant *X = ConstantInt::get(V->getType(), 1);
- X = ConstantExpr::getShl(X, SA);
+ uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
+ Constant *X = ConstantInt::get(
+ APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth)));
return SCEVMulExpr::get(getSCEV(I->getOperand(0)), getSCEV(X));
}
break;
@@ -2428,9 +2430,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
R1->getValue());
if (Range.contains(R1Val->getValue())) {
// The next iteration must be out of the range...
- Constant *NextVal =
- ConstantExpr::getAdd(R1->getValue(),
- ConstantInt::get(R1->getType(), 1));
+ Constant *NextVal = ConstantInt::get(R1->getValue()->getValue()+1);
R1Val = EvaluateConstantChrecAtConstant(this, NextVal);
if (!Range.contains(R1Val->getValue()))
@@ -2440,9 +2440,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// If R1 was not in the range, then it is a good return value. Make
// sure that R1-1 WAS in the range though, just in case.
- Constant *NextVal =
- ConstantExpr::getSub(R1->getValue(),
- ConstantInt::get(R1->getType(), 1));
+ Constant *NextVal = ConstantInt::get(R1->getValue()->getValue()-1);
R1Val = EvaluateConstantChrecAtConstant(this, NextVal);
if (Range.contains(R1Val->getValue()))
return R1;
@@ -2457,7 +2455,6 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// incredibly important, we will be able to simplify the exit test a lot, and
// we are almost guaranteed to get a trip count in this case.
ConstantInt *TestVal = ConstantInt::get(getType(), 0);
- ConstantInt *One = ConstantInt::get(getType(), 1);
ConstantInt *EndVal = TestVal; // Stop when we wrap around.
do {
++NumBruteForceEvaluations;
@@ -2470,7 +2467,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
return SCEVConstant::get(TestVal);
// Increment to test the next index.
- TestVal = cast<ConstantInt>(ConstantExpr::getAdd(TestVal, One));
+ TestVal = ConstantInt::get(TestVal->getValue()+1);
} while (TestVal != EndVal);
return new SCEVCouldNotCompute();