mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
Expose isNonConstantNegative to users of ScalarEvolution.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147700 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -119,6 +119,10 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
bool isAllOnesValue() const;
|
bool isAllOnesValue() const;
|
||||||
|
|
||||||
|
/// isNonConstantNegative - Return true if the specified scev is negated,
|
||||||
|
/// but not a constant.
|
||||||
|
bool isNonConstantNegative() const;
|
||||||
|
|
||||||
/// print - Print out the internal representation of this scalar to the
|
/// print - Print out the internal representation of this scalar to the
|
||||||
/// specified stream. This should really only be used for debugging
|
/// specified stream. This should really only be used for debugging
|
||||||
/// purposes.
|
/// purposes.
|
||||||
|
@@ -284,6 +284,20 @@ bool SCEV::isAllOnesValue() const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// isNonConstantNegative - Return true if the specified scev is negated, but
|
||||||
|
/// not a constant.
|
||||||
|
bool SCEV::isNonConstantNegative() const {
|
||||||
|
const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(this);
|
||||||
|
if (!Mul) return false;
|
||||||
|
|
||||||
|
// If there is a constant factor, it will be first.
|
||||||
|
const SCEVConstant *SC = dyn_cast<SCEVConstant>(Mul->getOperand(0));
|
||||||
|
if (!SC) return false;
|
||||||
|
|
||||||
|
// Return true if the value is negative, this matches things like (-42 * V).
|
||||||
|
return SC->getValue()->getValue().isNegative();
|
||||||
|
}
|
||||||
|
|
||||||
SCEVCouldNotCompute::SCEVCouldNotCompute() :
|
SCEVCouldNotCompute::SCEVCouldNotCompute() :
|
||||||
SCEV(FoldingSetNodeIDRef(), scCouldNotCompute) {}
|
SCEV(FoldingSetNodeIDRef(), scCouldNotCompute) {}
|
||||||
|
|
||||||
|
@@ -593,20 +593,6 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
|||||||
return expand(SE.getAddExpr(Ops));
|
return expand(SE.getAddExpr(Ops));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isNonConstantNegative - Return true if the specified scev is negated, but
|
|
||||||
/// not a constant.
|
|
||||||
static bool isNonConstantNegative(const SCEV *F) {
|
|
||||||
const SCEVMulExpr *Mul = dyn_cast<SCEVMulExpr>(F);
|
|
||||||
if (!Mul) return false;
|
|
||||||
|
|
||||||
// If there is a constant factor, it will be first.
|
|
||||||
const SCEVConstant *SC = dyn_cast<SCEVConstant>(Mul->getOperand(0));
|
|
||||||
if (!SC) return false;
|
|
||||||
|
|
||||||
// Return true if the value is negative, this matches things like (-42 * V).
|
|
||||||
return SC->getValue()->getValue().isNegative();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PickMostRelevantLoop - Given two loops pick the one that's most relevant for
|
/// PickMostRelevantLoop - Given two loops pick the one that's most relevant for
|
||||||
/// SCEV expansion. If they are nested, this is the most nested. If they are
|
/// SCEV expansion. If they are nested, this is the most nested. If they are
|
||||||
/// neighboring, pick the later.
|
/// neighboring, pick the later.
|
||||||
@@ -685,10 +671,10 @@ public:
|
|||||||
// If one operand is a non-constant negative and the other is not,
|
// If one operand is a non-constant negative and the other is not,
|
||||||
// put the non-constant negative on the right so that a sub can
|
// put the non-constant negative on the right so that a sub can
|
||||||
// be used instead of a negate and add.
|
// be used instead of a negate and add.
|
||||||
if (isNonConstantNegative(LHS.second)) {
|
if (LHS.second->isNonConstantNegative()) {
|
||||||
if (!isNonConstantNegative(RHS.second))
|
if (!RHS.second->isNonConstantNegative())
|
||||||
return false;
|
return false;
|
||||||
} else if (isNonConstantNegative(RHS.second))
|
} else if (RHS.second->isNonConstantNegative())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Otherwise they are equivalent according to this comparison.
|
// Otherwise they are equivalent according to this comparison.
|
||||||
@@ -749,7 +735,7 @@ Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) {
|
|||||||
for (++I; I != E && I->first == CurLoop; ++I)
|
for (++I; I != E && I->first == CurLoop; ++I)
|
||||||
NewOps.push_back(I->second);
|
NewOps.push_back(I->second);
|
||||||
Sum = expandAddToGEP(NewOps.begin(), NewOps.end(), PTy, Ty, expand(Op));
|
Sum = expandAddToGEP(NewOps.begin(), NewOps.end(), PTy, Ty, expand(Op));
|
||||||
} else if (isNonConstantNegative(Op)) {
|
} else if (Op->isNonConstantNegative()) {
|
||||||
// Instead of doing a negate and add, just do a subtract.
|
// Instead of doing a negate and add, just do a subtract.
|
||||||
Value *W = expandCodeFor(SE.getNegativeSCEV(Op), Ty);
|
Value *W = expandCodeFor(SE.getNegativeSCEV(Op), Ty);
|
||||||
Sum = InsertNoopCastOfTo(Sum, Ty);
|
Sum = InsertNoopCastOfTo(Sum, Ty);
|
||||||
@@ -1044,7 +1030,7 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
|
|||||||
// If the stride is negative, insert a sub instead of an add for the increment
|
// If the stride is negative, insert a sub instead of an add for the increment
|
||||||
// (unless it's a constant, because subtracts of constants are canonicalized
|
// (unless it's a constant, because subtracts of constants are canonicalized
|
||||||
// to adds).
|
// to adds).
|
||||||
bool useSubtract = !ExpandTy->isPointerTy() && isNonConstantNegative(Step);
|
bool useSubtract = !ExpandTy->isPointerTy() && Step->isNonConstantNegative();
|
||||||
if (useSubtract)
|
if (useSubtract)
|
||||||
Step = SE.getNegativeSCEV(Step);
|
Step = SE.getNegativeSCEV(Step);
|
||||||
// Expand the step somewhere that dominates the loop header.
|
// Expand the step somewhere that dominates the loop header.
|
||||||
@@ -1167,7 +1153,7 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
|
|||||||
// inserting an extra IV increment. StepV might fold into PostLoopOffset,
|
// inserting an extra IV increment. StepV might fold into PostLoopOffset,
|
||||||
// but hopefully expandCodeFor handles that.
|
// but hopefully expandCodeFor handles that.
|
||||||
bool useSubtract =
|
bool useSubtract =
|
||||||
!ExpandTy->isPointerTy() && isNonConstantNegative(Step);
|
!ExpandTy->isPointerTy() && Step->isNonConstantNegative();
|
||||||
if (useSubtract)
|
if (useSubtract)
|
||||||
Step = SE.getNegativeSCEV(Step);
|
Step = SE.getNegativeSCEV(Step);
|
||||||
// Expand the step somewhere that dominates the loop header.
|
// Expand the step somewhere that dominates the loop header.
|
||||||
|
Reference in New Issue
Block a user