mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Constify a bunch of SCEV-using code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70919 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7d04e4a7c0
commit
622ed671b9
@ -650,25 +650,25 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op,
|
||||
"This is not a conversion to a SCEVable type!");
|
||||
Ty = getEffectiveSCEVType(Ty);
|
||||
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
|
||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
|
||||
return getUnknown(
|
||||
ConstantExpr::getTrunc(SC->getValue(), Ty));
|
||||
|
||||
// trunc(trunc(x)) --> trunc(x)
|
||||
if (SCEVTruncateExpr *ST = dyn_cast<SCEVTruncateExpr>(Op))
|
||||
if (const SCEVTruncateExpr *ST = dyn_cast<SCEVTruncateExpr>(Op))
|
||||
return getTruncateExpr(ST->getOperand(), Ty);
|
||||
|
||||
// trunc(sext(x)) --> sext(x) if widening or trunc(x) if narrowing
|
||||
if (SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
|
||||
if (const SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
|
||||
return getTruncateOrSignExtend(SS->getOperand(), Ty);
|
||||
|
||||
// trunc(zext(x)) --> zext(x) if widening or trunc(x) if narrowing
|
||||
if (SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
|
||||
if (const SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
|
||||
return getTruncateOrZeroExtend(SZ->getOperand(), Ty);
|
||||
|
||||
// If the input value is a chrec scev made out of constants, truncate
|
||||
// all of the constants.
|
||||
if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
|
||||
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(Op)) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
for (unsigned i = 0, e = AddRec->getNumOperands(); i != e; ++i)
|
||||
// FIXME: This should allow truncation of other expression types!
|
||||
@ -693,7 +693,7 @@ SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op,
|
||||
"This is not a conversion to a SCEVable type!");
|
||||
Ty = getEffectiveSCEVType(Ty);
|
||||
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
|
||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
|
||||
const Type *IntTy = getEffectiveSCEVType(Ty);
|
||||
Constant *C = ConstantExpr::getZExt(SC->getValue(), IntTy);
|
||||
if (IntTy != Ty) C = ConstantExpr::getIntToPtr(C, Ty);
|
||||
@ -701,14 +701,14 @@ SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op,
|
||||
}
|
||||
|
||||
// zext(zext(x)) --> zext(x)
|
||||
if (SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
|
||||
if (const SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
|
||||
return getZeroExtendExpr(SZ->getOperand(), Ty);
|
||||
|
||||
// If the input value is a chrec scev, and we can prove that the value
|
||||
// did not overflow the old, smaller, value, we can zero extend all of the
|
||||
// operands (often constants). This allows analysis of something like
|
||||
// this: for (unsigned char X = 0; X < 100; ++X) { int Y = X; }
|
||||
if (SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
|
||||
if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
|
||||
if (AR->isAffine()) {
|
||||
// Check whether the backedge-taken count is SCEVCouldNotCompute.
|
||||
// Note that this serves two purposes: It filters out loops that are
|
||||
@ -778,7 +778,7 @@ SCEVHandle ScalarEvolution::getSignExtendExpr(const SCEVHandle &Op,
|
||||
"This is not a conversion to a SCEVable type!");
|
||||
Ty = getEffectiveSCEVType(Ty);
|
||||
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
|
||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
|
||||
const Type *IntTy = getEffectiveSCEVType(Ty);
|
||||
Constant *C = ConstantExpr::getSExt(SC->getValue(), IntTy);
|
||||
if (IntTy != Ty) C = ConstantExpr::getIntToPtr(C, Ty);
|
||||
@ -786,14 +786,14 @@ SCEVHandle ScalarEvolution::getSignExtendExpr(const SCEVHandle &Op,
|
||||
}
|
||||
|
||||
// sext(sext(x)) --> sext(x)
|
||||
if (SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
|
||||
if (const SCEVSignExtendExpr *SS = dyn_cast<SCEVSignExtendExpr>(Op))
|
||||
return getSignExtendExpr(SS->getOperand(), Ty);
|
||||
|
||||
// If the input value is a chrec scev, and we can prove that the value
|
||||
// did not overflow the old, smaller, value, we can sign extend all of the
|
||||
// operands (often constants). This allows analysis of something like
|
||||
// this: for (signed char X = 0; X < 100; ++X) { int Y = X; }
|
||||
if (SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
|
||||
if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Op))
|
||||
if (AR->isAffine()) {
|
||||
// Check whether the backedge-taken count is SCEVCouldNotCompute.
|
||||
// Note that this serves two purposes: It filters out loops that are
|
||||
@ -850,10 +850,10 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
||||
|
||||
// If there are any constants, fold them together.
|
||||
unsigned Idx = 0;
|
||||
if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
++Idx;
|
||||
assert(Idx < Ops.size());
|
||||
while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() +
|
||||
RHSC->getValue()->getValue());
|
||||
@ -896,7 +896,7 @@ SCEVHandle ScalarEvolution::getAddExpr(std::vector<SCEVHandle> &Ops) {
|
||||
// If there are add operands they would be next.
|
||||
if (Idx < Ops.size()) {
|
||||
bool DeletedAdd = false;
|
||||
while (SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[Idx])) {
|
||||
while (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[Idx])) {
|
||||
// If we have an add, expand the add operands onto the end of the operands
|
||||
// list.
|
||||
Ops.insert(Ops.end(), Add->op_begin(), Add->op_end());
|
||||
@ -1075,11 +1075,11 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
||||
|
||||
// If there are any constants, fold them together.
|
||||
unsigned Idx = 0;
|
||||
if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
|
||||
// C1*(C2+V) -> C1*C2 + C1*V
|
||||
if (Ops.size() == 2)
|
||||
if (SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[1]))
|
||||
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[1]))
|
||||
if (Add->getNumOperands() == 2 &&
|
||||
isa<SCEVConstant>(Add->getOperand(0)))
|
||||
return getAddExpr(getMulExpr(LHSC, Add->getOperand(0)),
|
||||
@ -1087,7 +1087,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
||||
|
||||
|
||||
++Idx;
|
||||
while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = ConstantInt::get(LHSC->getValue()->getValue() *
|
||||
RHSC->getValue()->getValue());
|
||||
@ -1117,7 +1117,7 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
||||
// If there are mul operands inline them all into this expression.
|
||||
if (Idx < Ops.size()) {
|
||||
bool DeletedMul = false;
|
||||
while (SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(Ops[Idx])) {
|
||||
while (const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(Ops[Idx])) {
|
||||
// If we have an mul, expand the mul operands onto the end of the operands
|
||||
// list.
|
||||
Ops.insert(Ops.end(), Mul->op_begin(), Mul->op_end());
|
||||
@ -1225,11 +1225,11 @@ SCEVHandle ScalarEvolution::getMulExpr(std::vector<SCEVHandle> &Ops) {
|
||||
}
|
||||
|
||||
SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) {
|
||||
if (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS)) {
|
||||
if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS)) {
|
||||
if (RHSC->getValue()->equalsInt(1))
|
||||
return LHS; // X udiv 1 --> x
|
||||
|
||||
if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS)) {
|
||||
if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS)) {
|
||||
Constant *LHSCV = LHSC->getValue();
|
||||
Constant *RHSCV = RHSC->getValue();
|
||||
return getUnknown(ConstantExpr::getUDiv(LHSCV, RHSCV));
|
||||
@ -1250,7 +1250,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(const SCEVHandle &Start,
|
||||
const SCEVHandle &Step, const Loop *L) {
|
||||
std::vector<SCEVHandle> Operands;
|
||||
Operands.push_back(Start);
|
||||
if (SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
|
||||
if (const SCEVAddRecExpr *StepChrec = dyn_cast<SCEVAddRecExpr>(Step))
|
||||
if (StepChrec->getLoop() == L) {
|
||||
Operands.insert(Operands.end(), StepChrec->op_begin(),
|
||||
StepChrec->op_end());
|
||||
@ -1273,7 +1273,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(std::vector<SCEVHandle> &Operands,
|
||||
}
|
||||
|
||||
// Canonicalize nested AddRecs in by nesting them in order of loop depth.
|
||||
if (SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
|
||||
if (const SCEVAddRecExpr *NestedAR = dyn_cast<SCEVAddRecExpr>(Operands[0])) {
|
||||
const Loop* NestedLoop = NestedAR->getLoop();
|
||||
if (L->getLoopDepth() < NestedLoop->getLoopDepth()) {
|
||||
std::vector<SCEVHandle> NestedOperands(NestedAR->op_begin(),
|
||||
@ -1309,10 +1309,10 @@ SCEVHandle ScalarEvolution::getSMaxExpr(std::vector<SCEVHandle> Ops) {
|
||||
|
||||
// If there are any constants, fold them together.
|
||||
unsigned Idx = 0;
|
||||
if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
++Idx;
|
||||
assert(Idx < Ops.size());
|
||||
while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = ConstantInt::get(
|
||||
APIntOps::smax(LHSC->getValue()->getValue(),
|
||||
@ -1340,7 +1340,7 @@ SCEVHandle ScalarEvolution::getSMaxExpr(std::vector<SCEVHandle> Ops) {
|
||||
// onto our operand list, and recurse to simplify.
|
||||
if (Idx < Ops.size()) {
|
||||
bool DeletedSMax = false;
|
||||
while (SCEVSMaxExpr *SMax = dyn_cast<SCEVSMaxExpr>(Ops[Idx])) {
|
||||
while (const SCEVSMaxExpr *SMax = dyn_cast<SCEVSMaxExpr>(Ops[Idx])) {
|
||||
Ops.insert(Ops.end(), SMax->op_begin(), SMax->op_end());
|
||||
Ops.erase(Ops.begin()+Idx);
|
||||
DeletedSMax = true;
|
||||
@ -1389,10 +1389,10 @@ SCEVHandle ScalarEvolution::getUMaxExpr(std::vector<SCEVHandle> Ops) {
|
||||
|
||||
// If there are any constants, fold them together.
|
||||
unsigned Idx = 0;
|
||||
if (SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
|
||||
++Idx;
|
||||
assert(Idx < Ops.size());
|
||||
while (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = ConstantInt::get(
|
||||
APIntOps::umax(LHSC->getValue()->getValue(),
|
||||
@ -1420,7 +1420,7 @@ SCEVHandle ScalarEvolution::getUMaxExpr(std::vector<SCEVHandle> Ops) {
|
||||
// onto our operand list, and recurse to simplify.
|
||||
if (Idx < Ops.size()) {
|
||||
bool DeletedUMax = false;
|
||||
while (SCEVUMaxExpr *UMax = dyn_cast<SCEVUMaxExpr>(Ops[Idx])) {
|
||||
while (const SCEVUMaxExpr *UMax = dyn_cast<SCEVUMaxExpr>(Ops[Idx])) {
|
||||
Ops.insert(Ops.end(), UMax->op_begin(), UMax->op_end());
|
||||
Ops.erase(Ops.begin()+Idx);
|
||||
DeletedUMax = true;
|
||||
@ -1580,7 +1580,7 @@ SCEVHandle ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) {
|
||||
/// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V
|
||||
///
|
||||
SCEVHandle ScalarEvolution::getNegativeSCEV(const SCEVHandle &V) {
|
||||
if (SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
|
||||
if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
|
||||
return getUnknown(ConstantExpr::getNeg(VC->getValue()));
|
||||
|
||||
const Type *Ty = V->getType();
|
||||
@ -1590,7 +1590,7 @@ SCEVHandle ScalarEvolution::getNegativeSCEV(const SCEVHandle &V) {
|
||||
|
||||
/// getNotSCEV - Return a SCEV corresponding to ~V = -1-V
|
||||
SCEVHandle ScalarEvolution::getNotSCEV(const SCEVHandle &V) {
|
||||
if (SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
|
||||
if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
|
||||
return getUnknown(ConstantExpr::getNot(VC->getValue()));
|
||||
|
||||
const Type *Ty = V->getType();
|
||||
@ -1690,7 +1690,7 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) {
|
||||
|
||||
// If the value coming around the backedge is an add with the symbolic
|
||||
// value we just inserted, then we found a simple induction variable!
|
||||
if (SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(BEValue)) {
|
||||
if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(BEValue)) {
|
||||
// If there is a single occurrence of the symbolic value, replace it
|
||||
// with a recurrence.
|
||||
unsigned FoundIndex = Add->getNumOperands();
|
||||
@ -1726,7 +1726,8 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) {
|
||||
return PHISCEV;
|
||||
}
|
||||
}
|
||||
} else if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(BEValue)) {
|
||||
} else if (const SCEVAddRecExpr *AddRec =
|
||||
dyn_cast<SCEVAddRecExpr>(BEValue)) {
|
||||
// Otherwise, this could be a loop like this:
|
||||
// i = 0; for (j = 1; ..; ++j) { .... i = j; }
|
||||
// In this case, j = {1,+,1} and BEValue is j.
|
||||
@ -1765,26 +1766,26 @@ SCEVHandle ScalarEvolution::createNodeForPHI(PHINode *PN) {
|
||||
/// the minimum number of times S is divisible by 2. For example, given {4,+,8}
|
||||
/// it returns 2. If S is guaranteed to be 0, it returns the bitwidth of S.
|
||||
static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) {
|
||||
if (SCEVConstant *C = dyn_cast<SCEVConstant>(S))
|
||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S))
|
||||
return C->getValue()->getValue().countTrailingZeros();
|
||||
|
||||
if (SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(S))
|
||||
if (const SCEVTruncateExpr *T = dyn_cast<SCEVTruncateExpr>(S))
|
||||
return std::min(GetMinTrailingZeros(T->getOperand(), SE),
|
||||
(uint32_t)SE.getTypeSizeInBits(T->getType()));
|
||||
|
||||
if (SCEVZeroExtendExpr *E = dyn_cast<SCEVZeroExtendExpr>(S)) {
|
||||
if (const SCEVZeroExtendExpr *E = dyn_cast<SCEVZeroExtendExpr>(S)) {
|
||||
uint32_t OpRes = GetMinTrailingZeros(E->getOperand(), SE);
|
||||
return OpRes == SE.getTypeSizeInBits(E->getOperand()->getType()) ?
|
||||
SE.getTypeSizeInBits(E->getOperand()->getType()) : OpRes;
|
||||
}
|
||||
|
||||
if (SCEVSignExtendExpr *E = dyn_cast<SCEVSignExtendExpr>(S)) {
|
||||
if (const SCEVSignExtendExpr *E = dyn_cast<SCEVSignExtendExpr>(S)) {
|
||||
uint32_t OpRes = GetMinTrailingZeros(E->getOperand(), SE);
|
||||
return OpRes == SE.getTypeSizeInBits(E->getOperand()->getType()) ?
|
||||
SE.getTypeSizeInBits(E->getOperand()->getType()) : OpRes;
|
||||
}
|
||||
|
||||
if (SCEVAddExpr *A = dyn_cast<SCEVAddExpr>(S)) {
|
||||
if (const SCEVAddExpr *A = dyn_cast<SCEVAddExpr>(S)) {
|
||||
// The result is the min of all operands results.
|
||||
uint32_t MinOpRes = GetMinTrailingZeros(A->getOperand(0), SE);
|
||||
for (unsigned i = 1, e = A->getNumOperands(); MinOpRes && i != e; ++i)
|
||||
@ -1792,7 +1793,7 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) {
|
||||
return MinOpRes;
|
||||
}
|
||||
|
||||
if (SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
|
||||
if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) {
|
||||
// The result is the sum of all operands results.
|
||||
uint32_t SumOpRes = GetMinTrailingZeros(M->getOperand(0), SE);
|
||||
uint32_t BitWidth = SE.getTypeSizeInBits(M->getType());
|
||||
@ -1803,7 +1804,7 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) {
|
||||
return SumOpRes;
|
||||
}
|
||||
|
||||
if (SCEVAddRecExpr *A = dyn_cast<SCEVAddRecExpr>(S)) {
|
||||
if (const SCEVAddRecExpr *A = dyn_cast<SCEVAddRecExpr>(S)) {
|
||||
// The result is the min of all operands results.
|
||||
uint32_t MinOpRes = GetMinTrailingZeros(A->getOperand(0), SE);
|
||||
for (unsigned i = 1, e = A->getNumOperands(); MinOpRes && i != e; ++i)
|
||||
@ -1811,7 +1812,7 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) {
|
||||
return MinOpRes;
|
||||
}
|
||||
|
||||
if (SCEVSMaxExpr *M = dyn_cast<SCEVSMaxExpr>(S)) {
|
||||
if (const SCEVSMaxExpr *M = dyn_cast<SCEVSMaxExpr>(S)) {
|
||||
// The result is the min of all operands results.
|
||||
uint32_t MinOpRes = GetMinTrailingZeros(M->getOperand(0), SE);
|
||||
for (unsigned i = 1, e = M->getNumOperands(); MinOpRes && i != e; ++i)
|
||||
@ -1819,7 +1820,7 @@ static uint32_t GetMinTrailingZeros(SCEVHandle S, const ScalarEvolution &SE) {
|
||||
return MinOpRes;
|
||||
}
|
||||
|
||||
if (SCEVUMaxExpr *M = dyn_cast<SCEVUMaxExpr>(S)) {
|
||||
if (const SCEVUMaxExpr *M = dyn_cast<SCEVUMaxExpr>(S)) {
|
||||
// The result is the min of all operands results.
|
||||
uint32_t MinOpRes = GetMinTrailingZeros(M->getOperand(0), SE);
|
||||
for (unsigned i = 1, e = M->getNumOperands(); MinOpRes && i != e; ++i)
|
||||
@ -2224,8 +2225,8 @@ ScalarEvolution::ComputeBackedgeTakenCount(const Loop *L) {
|
||||
|
||||
// If we have a comparison of a chrec against a constant, try to use value
|
||||
// ranges to answer this query.
|
||||
if (SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS))
|
||||
if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(LHS))
|
||||
if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS))
|
||||
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(LHS))
|
||||
if (AddRec->getLoop() == L) {
|
||||
// Form the comparison range using the constant of the correct type so
|
||||
// that the ConstantRange class knows to do a signed or unsigned
|
||||
@ -2610,7 +2611,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
|
||||
// If this instruction is evolved from a constant-evolving PHI, compute the
|
||||
// exit value from the loop without using SCEVs.
|
||||
if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(V)) {
|
||||
if (const SCEVUnknown *SU = dyn_cast<SCEVUnknown>(V)) {
|
||||
if (Instruction *I = dyn_cast<Instruction>(SU->getValue())) {
|
||||
const Loop *LI = (*this->LI)[I->getParent()];
|
||||
if (LI && LI->getParentLoop() == L) // Looking for loop exit value.
|
||||
@ -2621,7 +2622,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
// count. If so, we may be able to force computation of the exit
|
||||
// value.
|
||||
SCEVHandle BackedgeTakenCount = getBackedgeTakenCount(LI);
|
||||
if (SCEVConstant *BTCC =
|
||||
if (const SCEVConstant *BTCC =
|
||||
dyn_cast<SCEVConstant>(BackedgeTakenCount)) {
|
||||
// Okay, we know how many times the containing loop executes. If
|
||||
// this is a constant evolving PHI node, get the final value at
|
||||
@ -2652,7 +2653,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
return V;
|
||||
|
||||
SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV)) {
|
||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV)) {
|
||||
Constant *C = SC->getValue();
|
||||
if (C->getType() != Op->getType())
|
||||
C = ConstantExpr::getCast(CastInst::getCastOpcode(C, false,
|
||||
@ -2660,7 +2661,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
false),
|
||||
C, Op->getType());
|
||||
Operands.push_back(C);
|
||||
} else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
|
||||
} else if (const SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
|
||||
if (Constant *C = dyn_cast<Constant>(SU->getValue())) {
|
||||
if (C->getType() != Op->getType())
|
||||
C =
|
||||
@ -2692,7 +2693,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
return V;
|
||||
}
|
||||
|
||||
if (SCEVCommutativeExpr *Comm = dyn_cast<SCEVCommutativeExpr>(V)) {
|
||||
if (const SCEVCommutativeExpr *Comm = dyn_cast<SCEVCommutativeExpr>(V)) {
|
||||
// Avoid performing the look-up in the common case where the specified
|
||||
// expression has no loop-variant portions.
|
||||
for (unsigned i = 0, e = Comm->getNumOperands(); i != e; ++i) {
|
||||
@ -2724,7 +2725,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
return Comm;
|
||||
}
|
||||
|
||||
if (SCEVUDivExpr *Div = dyn_cast<SCEVUDivExpr>(V)) {
|
||||
if (const SCEVUDivExpr *Div = dyn_cast<SCEVUDivExpr>(V)) {
|
||||
SCEVHandle LHS = getSCEVAtScope(Div->getLHS(), L);
|
||||
if (LHS == UnknownValue) return LHS;
|
||||
SCEVHandle RHS = getSCEVAtScope(Div->getRHS(), L);
|
||||
@ -2736,7 +2737,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
|
||||
// If this is a loop recurrence for a loop that does not contain L, then we
|
||||
// are dealing with the final value computed by the loop.
|
||||
if (SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(V)) {
|
||||
if (const SCEVAddRecExpr *AddRec = dyn_cast<SCEVAddRecExpr>(V)) {
|
||||
if (!L || !AddRec->getLoop()->contains(L->getHeader())) {
|
||||
// To evaluate this recurrence, we need to know how many times the AddRec
|
||||
// loop iterates. Compute this now.
|
||||
@ -2749,7 +2750,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
return UnknownValue;
|
||||
}
|
||||
|
||||
if (SCEVZeroExtendExpr *Cast = dyn_cast<SCEVZeroExtendExpr>(V)) {
|
||||
if (const SCEVZeroExtendExpr *Cast = dyn_cast<SCEVZeroExtendExpr>(V)) {
|
||||
SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L);
|
||||
if (Op == UnknownValue) return Op;
|
||||
if (Op == Cast->getOperand())
|
||||
@ -2757,7 +2758,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
return getZeroExtendExpr(Op, Cast->getType());
|
||||
}
|
||||
|
||||
if (SCEVSignExtendExpr *Cast = dyn_cast<SCEVSignExtendExpr>(V)) {
|
||||
if (const SCEVSignExtendExpr *Cast = dyn_cast<SCEVSignExtendExpr>(V)) {
|
||||
SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L);
|
||||
if (Op == UnknownValue) return Op;
|
||||
if (Op == Cast->getOperand())
|
||||
@ -2765,7 +2766,7 @@ SCEVHandle ScalarEvolution::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
return getSignExtendExpr(Op, Cast->getType());
|
||||
}
|
||||
|
||||
if (SCEVTruncateExpr *Cast = dyn_cast<SCEVTruncateExpr>(V)) {
|
||||
if (const SCEVTruncateExpr *Cast = dyn_cast<SCEVTruncateExpr>(V)) {
|
||||
SCEVHandle Op = getSCEVAtScope(Cast->getOperand(), L);
|
||||
if (Op == UnknownValue) return Op;
|
||||
if (Op == Cast->getOperand())
|
||||
@ -2903,7 +2904,7 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) {
|
||||
/// value to zero will execute. If not computable, return UnknownValue
|
||||
SCEVHandle ScalarEvolution::HowFarToZero(SCEV *V, const Loop *L) {
|
||||
// If the value is a constant
|
||||
if (SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
|
||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
|
||||
// If the value is already zero, the branch will execute zero times.
|
||||
if (C->getValue()->isZero()) return C;
|
||||
return UnknownValue; // Otherwise it will loop infinitely.
|
||||
@ -2931,7 +2932,7 @@ SCEVHandle ScalarEvolution::HowFarToZero(SCEV *V, const Loop *L) {
|
||||
|
||||
SCEVHandle Step = getSCEVAtScope(AddRec->getOperand(1), L->getParentLoop());
|
||||
|
||||
if (SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step)) {
|
||||
if (const SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step)) {
|
||||
// For now we handle only constant steps.
|
||||
|
||||
// First, handle unitary steps.
|
||||
@ -2941,7 +2942,7 @@ SCEVHandle ScalarEvolution::HowFarToZero(SCEV *V, const Loop *L) {
|
||||
return Start; // N = Start (as unsigned)
|
||||
|
||||
// Then, try to solve the above equation provided that Start is constant.
|
||||
if (SCEVConstant *StartC = dyn_cast<SCEVConstant>(Start))
|
||||
if (const SCEVConstant *StartC = dyn_cast<SCEVConstant>(Start))
|
||||
return SolveLinEquationWithOverflow(StepC->getValue()->getValue(),
|
||||
-StartC->getValue()->getValue(),
|
||||
*this);
|
||||
@ -2988,7 +2989,7 @@ SCEVHandle ScalarEvolution::HowFarToNonZero(SCEV *V, const Loop *L) {
|
||||
|
||||
// If the value is a constant, check to see if it is known to be non-zero
|
||||
// already. If so, the backedge will execute zero times.
|
||||
if (SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
|
||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
|
||||
if (!C->getValue()->isNullValue())
|
||||
return getIntegerSCEV(0, C->getType());
|
||||
return UnknownValue; // Otherwise it will loop infinitely.
|
||||
@ -3232,12 +3233,13 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
||||
return SE.getCouldNotCompute();
|
||||
|
||||
// If the start is a non-zero constant, shift the range to simplify things.
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(getStart()))
|
||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(getStart()))
|
||||
if (!SC->getValue()->isZero()) {
|
||||
std::vector<SCEVHandle> Operands(op_begin(), op_end());
|
||||
Operands[0] = SE.getIntegerSCEV(0, SC->getType());
|
||||
SCEVHandle Shifted = SE.getAddRecExpr(Operands, getLoop());
|
||||
if (SCEVAddRecExpr *ShiftedAddRec = dyn_cast<SCEVAddRecExpr>(Shifted))
|
||||
if (const SCEVAddRecExpr *ShiftedAddRec =
|
||||
dyn_cast<SCEVAddRecExpr>(Shifted))
|
||||
return ShiftedAddRec->getNumIterationsInRange(
|
||||
Range.subtract(SC->getValue()->getValue()), SE);
|
||||
// This is strange and shouldn't happen.
|
||||
|
@ -321,7 +321,7 @@ static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L,
|
||||
// for a nested AddRecExpr.
|
||||
if (const SCEVAddExpr *AE = dyn_cast<SCEVAddExpr>(SH)) {
|
||||
for (unsigned i = 0, e = AE->getNumOperands(); i != e; ++i)
|
||||
if (SCEVAddRecExpr *AddRec =
|
||||
if (const SCEVAddRecExpr *AddRec =
|
||||
dyn_cast<SCEVAddRecExpr>(AE->getOperand(i))) {
|
||||
if (AddRec->getLoop() == L)
|
||||
TheAddRec = SE->getAddExpr(AddRec, TheAddRec);
|
||||
@ -1400,8 +1400,8 @@ bool LoopStrengthReduce::ShouldUseFullStrengthReductionMode(
|
||||
// Iterate through the uses to find conditions that automatically rule out
|
||||
// full-lsr mode.
|
||||
for (unsigned i = 0, e = UsersToProcess.size(); i != e; ) {
|
||||
SCEV *Base = UsersToProcess[i].Base;
|
||||
SCEV *Imm = UsersToProcess[i].Imm;
|
||||
const SCEV *Base = UsersToProcess[i].Base;
|
||||
const SCEV *Imm = UsersToProcess[i].Imm;
|
||||
// If any users have a loop-variant component, they can't be fully
|
||||
// strength-reduced.
|
||||
if (Imm && !Imm->isLoopInvariant(L))
|
||||
@ -1410,7 +1410,7 @@ bool LoopStrengthReduce::ShouldUseFullStrengthReductionMode(
|
||||
// the two Imm values can't be folded into the address, full
|
||||
// strength reduction would increase register pressure.
|
||||
do {
|
||||
SCEV *CurImm = UsersToProcess[i].Imm;
|
||||
const SCEV *CurImm = UsersToProcess[i].Imm;
|
||||
if ((CurImm || Imm) && CurImm != Imm) {
|
||||
if (!CurImm) CurImm = SE->getIntegerSCEV(0, Stride->getType());
|
||||
if (!Imm) Imm = SE->getIntegerSCEV(0, Stride->getType());
|
||||
|
Loading…
x
Reference in New Issue
Block a user