diff options
author | Dan Gohman <gohman@apple.com> | 2009-07-25 01:22:26 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-07-25 01:22:26 +0000 |
commit | 62ef6a7f1c185f2f18d259e80b4d00609d13ef46 (patch) | |
tree | ff61ca6d0d63031dd175bbc133a2f1f2169bbb07 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 29f2baf3b3994b28f79fb6cea05b1e8bd63bab34 (diff) | |
download | bcm5719-llvm-62ef6a7f1c185f2f18d259e80b4d00609d13ef46.tar.gz bcm5719-llvm-62ef6a7f1c185f2f18d259e80b4d00609d13ef46.zip |
Teach ScalarEvolution to make use of no-overflow flags when
analyzing add recurrences.
llvm-svn: 77034
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index c77c7c40ef1..49af5793662 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -734,6 +734,13 @@ const SCEV *ScalarEvolution::getZeroExtendExpr(const SCEV *Op, unsigned BitWidth = getTypeSizeInBits(AR->getType()); const Loop *L = AR->getLoop(); + // If we have special knowledge that this addrec won't overflow, + // we don't need to do any further analysis. + if (AR->hasNoUnsignedOverflow()) + return getAddRecExpr(getZeroExtendExpr(Start, Ty), + getZeroExtendExpr(Step, Ty), + L); + // Check whether the backedge-taken count is SCEVCouldNotCompute. // Note that this serves two purposes: It filters out loops that are // simply not analyzable, and it covers the case where this code is @@ -866,6 +873,13 @@ const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op, unsigned BitWidth = getTypeSizeInBits(AR->getType()); const Loop *L = AR->getLoop(); + // If we have special knowledge that this addrec won't overflow, + // we don't need to do any further analysis. + if (AR->hasNoSignedOverflow()) + return getAddRecExpr(getSignExtendExpr(Start, Ty), + getSignExtendExpr(Step, Ty), + L); + // Check whether the backedge-taken count is SCEVCouldNotCompute. // Note that this serves two purposes: It filters out loops that are // simply not analyzable, and it covers the case where this code is @@ -2344,8 +2358,29 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { cast<SCEVAddRecExpr>(Accum)->getLoop() == L)) { const SCEV *StartVal = getSCEV(PN->getIncomingValue(IncomingEdge)); - const SCEV *PHISCEV = - getAddRecExpr(StartVal, Accum, L); + const SCEVAddRecExpr *PHISCEV = + cast<SCEVAddRecExpr>(getAddRecExpr(StartVal, Accum, L)); + + // If the increment doesn't overflow, then neither the addrec nor the + // post-increment will overflow. + if (const AddOperator *OBO = dyn_cast<AddOperator>(BEValueV)) + if (OBO->getOperand(0) == PN && + getSCEV(OBO->getOperand(1)) == + PHISCEV->getStepRecurrence(*this)) { + const SCEVAddRecExpr *PostInc = PHISCEV->getPostIncExpr(*this); + if (OBO->hasNoUnsignedOverflow()) { + const_cast<SCEVAddRecExpr *>(PHISCEV) + ->setHasNoUnsignedOverflow(true); + const_cast<SCEVAddRecExpr *>(PostInc) + ->setHasNoUnsignedOverflow(true); + } + if (OBO->hasNoSignedOverflow()) { + const_cast<SCEVAddRecExpr *>(PHISCEV) + ->setHasNoSignedOverflow(true); + const_cast<SCEVAddRecExpr *>(PostInc) + ->setHasNoSignedOverflow(true); + } + } // Okay, for the entire analysis of this edge we assumed the PHI // to be symbolic. We now need to go back and purge all of the |