summaryrefslogtreecommitdiff
path: root/lib/Analysis
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
commit2f5f1c2ccb89b2285e966598ee29dcff919c75d2 (patch)
tree2b6877ab7a489b84edaf6353222e42b34673915a /lib/Analysis
parentd9673ebd340744ece3283f933e54af46d13abffb (diff)
downloadllvm-2f5f1c2ccb89b2285e966598ee29dcff919c75d2.tar.gz
llvm-2f5f1c2ccb89b2285e966598ee29dcff919c75d2.tar.bz2
llvm-2f5f1c2ccb89b2285e966598ee29dcff919c75d2.tar.xz
do not assert when delinearization fails
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208615 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ScalarEvolution.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 590ebe4b30..8073b270e1 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/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]";