Move LSR's private isZero function to a public SCEV member

function, and make use of it in several places.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52463 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-06-18 16:23:07 +00:00
parent a9c0f2b03f
commit cfeb6a4506
4 changed files with 24 additions and 27 deletions

View File

@ -81,6 +81,10 @@ namespace llvm {
///
uint32_t getBitWidth() const;
/// isZero - Return true if the expression is a constant zero.
///
bool isZero() const;
/// replaceSymbolicValuesWithConcrete - If this SCEV internally references
/// the symbolic value "Sym", construct and return a new SCEV that produces
/// the same value, but which uses the concrete value Conc instead of the

View File

@ -132,6 +132,12 @@ uint32_t SCEV::getBitWidth() const {
return 0;
}
bool SCEV::isZero() const {
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
return SC->getValue()->isZero();
return false;
}
SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
@ -1136,11 +1142,10 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
const Loop *L) {
if (Operands.size() == 1) return Operands[0];
if (SCEVConstant *StepC = dyn_cast<SCEVConstant>(Operands.back()))
if (StepC->getValue()->isZero()) {
Operands.pop_back();
return getAddRecExpr(Operands, L); // { X,+,0 } --> X
}
if (Operands.back()->isZero()) {
Operands.pop_back();
return getAddRecExpr(Operands, L); // { X,+,0 } --> X
}
SCEVAddRecExpr *&Result =
(*SCEVAddRecExprs)[std::make_pair(L, std::vector<SCEV*>(Operands.begin(),
@ -2583,9 +2588,8 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToZero(SCEV *V, const Loop *L) {
// value at this index. When solving for "X*X != 5", for example, we
// should not accept a root of 2.
SCEVHandle Val = AddRec->evaluateAtIteration(R1, SE);
if (SCEVConstant *EvalVal = dyn_cast<SCEVConstant>(Val))
if (EvalVal->getValue()->isZero())
return R1; // We found a quadratic root!
if (Val->isZero())
return R1; // We found a quadratic root!
}
}
}

View File

@ -126,8 +126,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
assert(Ty->isInteger() && "Cannot expand fp recurrences yet!");
// {X,+,F} --> X + {0,+,F}
if (!isa<SCEVConstant>(S->getStart()) ||
!cast<SCEVConstant>(S->getStart())->getValue()->isZero()) {
if (!S->getStart()->isZero()) {
Value *Start = expand(S->getStart());
std::vector<SCEVHandle> NewOps(S->op_begin(), S->op_end());
NewOps[0] = SE.getIntegerSCEV(0, Ty);

View File

@ -586,9 +586,8 @@ 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())
return Rewriter.expandCodeFor(NewBase, BaseInsertPt);
if (Imm->isZero())
return Rewriter.expandCodeFor(NewBase, BaseInsertPt);
Value *Base = Rewriter.expandCodeFor(NewBase, BaseInsertPt);
@ -891,8 +890,7 @@ static void SeparateSubExprs(std::vector<SCEVHandle> &SubExprs,
SeparateSubExprs(SubExprs, SARE->getOperand(0), SE);
}
} else if (!isa<SCEVConstant>(Expr) ||
!cast<SCEVConstant>(Expr)->getValue()->isZero()) {
} else if (!Expr->isZero()) {
// Do not add zero.
SubExprs.push_back(Expr);
}
@ -979,14 +977,6 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses,
return Result;
}
/// isZero - returns true if the scalar evolution expression is zero.
///
static bool isZero(const SCEVHandle &V) {
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
return SC->getValue()->isZero();
return false;
}
/// ValidStride - Check whether the given Scale is valid for all loads and
/// stores in UsersToProcess.
///
@ -1009,7 +999,7 @@ bool LoopStrengthReduce::ValidStride(bool HasBaseReg,
TargetLowering::AddrMode AM;
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(UsersToProcess[i].Imm))
AM.BaseOffs = SC->getValue()->getSExtValue();
AM.HasBaseReg = HasBaseReg || !isZero(UsersToProcess[i].Base);
AM.HasBaseReg = HasBaseReg || !UsersToProcess[i].Base->isZero();
AM.Scale = Scale;
// If load[imm+r*scale] is illegal, bail out.
@ -1069,7 +1059,7 @@ unsigned LoopStrengthReduce::CheckForIVReuse(bool HasBaseReg,
IE = SI->second.IVs.end(); II != IE; ++II)
// FIXME: Only handle base == 0 for now.
// Only reuse previous IV if it would not require a type conversion.
if (isZero(II->Base) &&
if (II->Base->isZero() &&
!RequiresTypeConversion(II->Base->getType(), Ty)) {
IV = *II;
return Scale;
@ -1233,7 +1223,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
// their value in a register and add it in for each use. This will take up
// a register operand, which potentially restricts what stride values are
// valid.
bool HaveCommonExprs = !isZero(CommonExprs);
bool HaveCommonExprs = !CommonExprs->isZero();
// If all uses are addresses, check if it is possible to reuse an IV with a
// stride that is a factor of this stride. And that the multiple is a number
@ -1629,7 +1619,7 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
// Avoid rewriting the compare instruction with an iv of new stride
// if it's likely the new stride uses will be rewritten using the
if (AllUsesAreAddresses &&
ValidStride(!isZero(CommonExprs), Scale, UsersToProcess)) {
ValidStride(!CommonExprs->isZero(), Scale, UsersToProcess)) {
NewCmpVal = CmpVal;
continue;
}