From 2f5f1c2ccb89b2285e966598ee29dcff919c75d2 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Mon, 12 May 2014 19:01:53 +0000 Subject: do not assert when delinearization fails git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208615 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'lib/Analysis') 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 &Terms) { return GCD; } -static void findArrayDimensionsRec(ScalarEvolution &SE, +static bool findArrayDimensionsRec(ScalarEvolution &SE, SmallVectorImpl &Terms, SmallVectorImpl &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(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 &Subscripts, SmallVectorImpl &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 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]"; -- cgit v1.2.3