summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorSebastian Pop <spop@codeaurora.org>2014-05-12 19:01:53 +0000
committerSebastian Pop <spop@codeaurora.org>2014-05-12 19:01:53 +0000
commitb1a548f72d1cd6fd3b27d8d3ed8510d33b118859 (patch)
tree9a41f3185b55e41bcc4763a9cdd8a94dc95068c5 /llvm/lib/Analysis/ScalarEvolution.cpp
parent0e75c5cb644c5ad59959a2c79b2bdc5783248779 (diff)
downloadbcm5719-llvm-b1a548f72d1cd6fd3b27d8d3ed8510d33b118859.tar.gz
bcm5719-llvm-b1a548f72d1cd6fd3b27d8d3ed8510d33b118859.zip
do not assert when delinearization fails
llvm-svn: 208615
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 590ebe4b30f..8073b270e1c 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7192,7 +7192,7 @@ findGCD(ScalarEvolution &SE, SmallVectorImpl<const SCEV *> &Terms) {
return GCD;
}
-static void findArrayDimensionsRec(ScalarEvolution &SE,
+static bool findArrayDimensionsRec(ScalarEvolution &SE,
SmallVectorImpl<const SCEV *> &Terms,
SmallVectorImpl<const SCEV *> &Sizes) {
// The GCD of all Terms is the dimension of the innermost dimension.
@@ -7210,14 +7210,18 @@ static void findArrayDimensionsRec(ScalarEvolution &SE,
}
Sizes.push_back(GCD);
- return;
+ return true;
}
for (const SCEV *&Term : Terms) {
// Normalize the terms before the next call to findArrayDimensionsRec.
const SCEV *Q, *R;
SCEVDivision::divide(SE, Term, GCD, &Q, &R);
- assert(R->isZero() && "GCD does not evenly divide one of the terms");
+
+ // Bail out when GCD does not evenly divide one of the terms.
+ if (!R->isZero())
+ return false;
+
Term = Q;
}
@@ -7228,8 +7232,11 @@ static void findArrayDimensionsRec(ScalarEvolution &SE,
Terms.end());
if (Terms.size() > 0)
- findArrayDimensionsRec(SE, Terms, Sizes);
+ if (!findArrayDimensionsRec(SE, Terms, Sizes))
+ return false;
+
Sizes.push_back(GCD);
+ return true;
}
namespace {
@@ -7315,7 +7322,12 @@ void ScalarEvolution::findArrayDimensions(
});
ScalarEvolution &SE = *const_cast<ScalarEvolution *>(this);
- findArrayDimensionsRec(SE, Terms, Sizes);
+ bool Res = findArrayDimensionsRec(SE, Terms, Sizes);
+
+ if (!Res) {
+ Sizes.clear();
+ return;
+ }
DEBUG({
dbgs() << "Sizes:\n";
@@ -7329,11 +7341,12 @@ void ScalarEvolution::findArrayDimensions(
const SCEV *SCEVAddRecExpr::computeAccessFunctions(
ScalarEvolution &SE, SmallVectorImpl<const SCEV *> &Subscripts,
SmallVectorImpl<const SCEV *> &Sizes) const {
+
// Early exit in case this SCEV is not an affine multivariate function.
- const SCEV *Zero = SE.getConstant(this->getType(), 0);
- if (!this->isAffine())
- return Zero;
+ if (Sizes.empty() || !this->isAffine())
+ return NULL;
+ const SCEV *Zero = SE.getConstant(this->getType(), 0);
const SCEV *Res = this, *Remainder = Zero;
int Last = Sizes.size() - 1;
for (int i = Last; i >= 0; i--) {
@@ -7432,12 +7445,21 @@ SCEVAddRecExpr::delinearize(ScalarEvolution &SE,
SmallVector<const SCEV *, 4> Terms;
collectParametricTerms(SE, Terms);
+ if (Terms.empty())
+ return NULL;
+
// Second step: find subscript sizes.
SE.findArrayDimensions(Terms, Sizes);
+ if (Sizes.empty())
+ return NULL;
+
// Third step: compute the access functions for each subscript.
const SCEV *Remainder = computeAccessFunctions(SE, Subscripts, Sizes);
+ if (!Remainder || Subscripts.empty())
+ return NULL;
+
DEBUG({
dbgs() << "succeeded to delinearize " << *this << "\n";
dbgs() << "ArrayDecl[UnknownSize]";
OpenPOWER on IntegriCloud