summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-02 00:31:39 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-02 00:31:39 +0000
commit513d0f25ed9b719841c4c9f18e0f22e2ffd426b4 (patch)
tree1dcae4d05902cdff8977f0d3fa5271235a6f9f47 /lib/Transforms/Scalar/LoopStrengthReduce.cpp
parentcae5754619433aed7be74abbf1c0551a82d369cb (diff)
downloadllvm-513d0f25ed9b719841c4c9f18e0f22e2ffd426b4.tar.gz
llvm-513d0f25ed9b719841c4c9f18e0f22e2ffd426b4.tar.bz2
llvm-513d0f25ed9b719841c4c9f18e0f22e2ffd426b4.tar.xz
Reverse a premature commital.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34822 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 1a1ea7a72b..e97921237f 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -540,7 +540,7 @@ Value *BasedUser::InsertCodeForBaseAtPosition(const SCEVHandle &NewBase,
// If there is no immediate value, skip the next part.
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Imm))
- if (SC->getValue()->isZero())
+ if (SC->getValue()->isNullValue())
return Rewriter.expandCodeFor(NewBase, BaseInsertPt,
OperandValToReplace->getType());
@@ -779,7 +779,7 @@ static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,
SeparateSubExprs(SubExprs, SARE->getOperand(0));
}
} else if (!isa<SCEVConstant>(Expr) ||
- !cast<SCEVConstant>(Expr)->getValue()->isZero()) {
+ !cast<SCEVConstant>(Expr)->getValue()->isNullValue()) {
// Do not add zero.
SubExprs.push_back(Expr);
}
@@ -869,7 +869,7 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) {
///
static bool isZero(SCEVHandle &V) {
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
- return SC->getValue()->isZero();
+ return SC->getValue()->getZExtValue() == 0;
return false;
}
@@ -883,18 +883,17 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride,
if (!TLI) return 0;
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) {
- const APInt &SInt = SC->getValue()->getValue();
- if (SInt == 1)
- return 0;
+ int64_t SInt = SC->getValue()->getSExtValue();
+ if (SInt == 1) return 0;
for (TargetLowering::legal_am_scale_iterator
I = TLI->legal_am_scale_begin(), E = TLI->legal_am_scale_end();
I != E; ++I) {
- APInt Scale(SInt.getBitWidth(), *I);
- if (SInt.abs().ult(Scale) || SInt.srem(Scale) != 0)
+ unsigned Scale = *I;
+ if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0)
continue;
std::map<SCEVHandle, IVsOfOneStride>::iterator SI =
- IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt.sdiv(Scale)));
+ IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy));
if (SI == IVsByStride.end())
continue;
for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(),
@@ -903,7 +902,7 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride,
// Only reuse previous IV if it would not require a type conversion.
if (isZero(II->Base) && II->Base->getType() == Ty) {
IV = *II;
- return Scale.getZExtValue();
+ return Scale;
}
}
}
@@ -1149,14 +1148,14 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
// are reusing an IV, it has not been used to initialize the PHI node.
// Add it to the expression used to rewrite the uses.
if (!isa<ConstantInt>(CommonBaseV) ||
- !cast<ConstantInt>(CommonBaseV)->isZero())
+ !cast<ConstantInt>(CommonBaseV)->isNullValue())
RewriteExpr = SCEVAddExpr::get(RewriteExpr,
SCEVUnknown::get(CommonBaseV));
}
// Now that we know what we need to do, insert code before User for the
// immediate and any loop-variant expressions.
- if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isZero())
+ if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isNullValue())
// Add BaseV to the PHI value if needed.
RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV));
@@ -1258,17 +1257,14 @@ namespace {
SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS);
SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);
if (LHSC && RHSC) {
- APInt LV(LHSC->getValue()->getValue());
- APInt RV(RHSC->getValue()->getValue());
- uint32_t MaxWidth = std::max(LV.getBitWidth(), RV.getBitWidth());
- LV.sextOrTrunc(MaxWidth);
- RV.sextOrTrunc(MaxWidth);
- APInt ALV(LV.abs());
- APInt ARV(RV.abs());
+ int64_t LV = LHSC->getValue()->getSExtValue();
+ int64_t RV = RHSC->getValue()->getSExtValue();
+ uint64_t ALV = (LV < 0) ? -LV : LV;
+ uint64_t ARV = (RV < 0) ? -RV : RV;
if (ALV == ARV)
- return LV.sgt(RV);
+ return LV > RV;
else
- return ALV.ult(ARV);
+ return ALV < ARV;
}
return (LHSC && !RHSC);
}