summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/DependenceAnalysis.cpp
diff options
context:
space:
mode:
authorBrendon Cahoon <bcahoon@codeaurora.org>2016-04-19 16:46:57 +0000
committerBrendon Cahoon <bcahoon@codeaurora.org>2016-04-19 16:46:57 +0000
commitbe2da82cd8cb57ab0d1cb33979c5c14e6d4eb137 (patch)
treedb608d295024c744497ebe55bd6cece22da0b6b6 /llvm/lib/Analysis/DependenceAnalysis.cpp
parent995e861ba6724a8a416407c36b4ef369befac928 (diff)
downloadbcm5719-llvm-be2da82cd8cb57ab0d1cb33979c5c14e6d4eb137.tar.gz
bcm5719-llvm-be2da82cd8cb57ab0d1cb33979c5c14e6d4eb137.zip
[DependenceAnalysis] Refactor uses of getConstantPart. NFC.
Rather than checking for the SCEV type prior to calling getContantPart, perform the checks in the function. This reduces the number of places where the checks are needed. Differential Revision: http://reviews.llvm.org/D19241 llvm-svn: 266759
Diffstat (limited to 'llvm/lib/Analysis/DependenceAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/DependenceAnalysis.cpp57
1 files changed, 21 insertions, 36 deletions
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index 93828904760..54a56803ff4 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -2256,11 +2256,12 @@ bool DependenceAnalysis::testMIV(const SCEV *Src,
// Given a product, e.g., 10*X*Y, returns the first constant operand,
// in this case 10. If there is no constant part, returns NULL.
static
-const SCEVConstant *getConstantPart(const SCEVMulExpr *Product) {
- for (unsigned Op = 0, Ops = Product->getNumOperands(); Op < Ops; Op++) {
- if (const SCEVConstant *Constant = dyn_cast<SCEVConstant>(Product->getOperand(Op)))
+const SCEVConstant *getConstantPart(const SCEV *Expr) {
+ if (const auto *Constant = dyn_cast<SCEVConstant>(Expr))
+ return Constant;
+ else if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
+ if (const auto *Constant = dyn_cast<SCEVConstant>(Product->getOperand(0)))
return Constant;
- }
return nullptr;
}
@@ -2299,11 +2300,9 @@ bool DependenceAnalysis::gcdMIVtest(const SCEV *Src,
while (const SCEVAddRecExpr *AddRec =
dyn_cast<SCEVAddRecExpr>(Coefficients)) {
const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
- const SCEVConstant *Constant = dyn_cast<SCEVConstant>(Coeff);
- if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Coeff))
- // If the coefficient is the product of a constant and other stuff,
- // we can use the constant in the GCD computation.
- Constant = getConstantPart(Product);
+ // If the coefficient is the product of a constant and other stuff,
+ // we can use the constant in the GCD computation.
+ const auto *Constant = getConstantPart(Coeff);
if (!Constant)
return false;
APInt ConstCoeff = Constant->getAPInt();
@@ -2320,11 +2319,9 @@ bool DependenceAnalysis::gcdMIVtest(const SCEV *Src,
while (const SCEVAddRecExpr *AddRec =
dyn_cast<SCEVAddRecExpr>(Coefficients)) {
const SCEV *Coeff = AddRec->getStepRecurrence(*SE);
- const SCEVConstant *Constant = dyn_cast<SCEVConstant>(Coeff);
- if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Coeff))
- // If the coefficient is the product of a constant and other stuff,
- // we can use the constant in the GCD computation.
- Constant = getConstantPart(Product);
+ // If the coefficient is the product of a constant and other stuff,
+ // we can use the constant in the GCD computation.
+ const auto *Constant = getConstantPart(Coeff);
if (!Constant)
return false;
APInt ConstCoeff = Constant->getAPInt();
@@ -2403,12 +2400,9 @@ bool DependenceAnalysis::gcdMIVtest(const SCEV *Src,
if (CurLoop == AddRec->getLoop())
; // SrcCoeff == Coeff
else {
- if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Coeff))
- // If the coefficient is the product of a constant and other stuff,
- // we can use the constant in the GCD computation.
- Constant = getConstantPart(Product);
- else
- Constant = cast<SCEVConstant>(Coeff);
+ // If the coefficient is the product of a constant and other stuff,
+ // we can use the constant in the GCD computation.
+ Constant = getConstantPart(Coeff);
if (!Constant)
return false;
APInt ConstCoeff = Constant->getAPInt();
@@ -2423,12 +2417,9 @@ bool DependenceAnalysis::gcdMIVtest(const SCEV *Src,
if (CurLoop == AddRec->getLoop())
DstCoeff = Coeff;
else {
- if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Coeff))
- // If the coefficient is the product of a constant and other stuff,
- // we can use the constant in the GCD computation.
- Constant = getConstantPart(Product);
- else
- Constant = cast<SCEVConstant>(Coeff);
+ // If the coefficient is the product of a constant and other stuff,
+ // we can use the constant in the GCD computation.
+ Constant = getConstantPart(Coeff);
if (!Constant)
return false;
APInt ConstCoeff = Constant->getAPInt();
@@ -2437,19 +2428,13 @@ bool DependenceAnalysis::gcdMIVtest(const SCEV *Src,
Inner = AddRec->getStart();
}
Delta = SE->getMinusSCEV(SrcCoeff, DstCoeff);
- if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Delta))
- // If the coefficient is the product of a constant and other stuff,
- // we can use the constant in the GCD computation.
- Constant = getConstantPart(Product);
- else if (isa<SCEVConstant>(Delta))
- Constant = cast<SCEVConstant>(Delta);
- else {
+ // If the coefficient is the product of a constant and other stuff,
+ // we can use the constant in the GCD computation.
+ Constant = getConstantPart(Delta);
+ if (!Constant)
// The difference of the two coefficients might not be a product
// or constant, in which case we give up on this direction.
continue;
- }
- if (!Constant)
- continue;
APInt ConstCoeff = Constant->getAPInt();
RunningGCD = APIntOps::GreatestCommonDivisor(RunningGCD, ConstCoeff.abs());
DEBUG(dbgs() << "\tRunningGCD = " << RunningGCD << "\n");
OpenPOWER on IntegriCloud