diff options
author | David Green <david.green@arm.com> | 2019-03-05 12:12:18 +0000 |
---|---|---|
committer | David Green <david.green@arm.com> | 2019-03-05 12:12:18 +0000 |
commit | 4511f3fa86de9579ded704b66a52492bc7ca08de (patch) | |
tree | 61793008d5b9fefbac3be9b5a1b7f72c9c1627a8 /llvm/lib/Analysis/ScalarEvolutionExpander.cpp | |
parent | 7523f743b4c0bbf59bb9dfd806fce43fbc4eb1ca (diff) | |
download | llvm-4511f3fa86de9579ded704b66a52492bc7ca08de.zip llvm-4511f3fa86de9579ded704b66a52492bc7ca08de.tar.gz llvm-4511f3fa86de9579ded704b66a52492bc7ca08de.tar.bz2 |
[SCEV] Ensure that isHighCostExpansion takes into account what is being divided
A SCEV is not low-cost just because you can divide it by a power of 2. We need to also
check what we are dividing to make sure it too is not a high-code expansion. This helps
to not expand the exit value of certain loops, helping not to bloat the code.
The change in no-iv-rewrite.ll is reverting back to what it was testing before rL194116,
and looks a lot like the other tests in replace-loop-exit-folds.ll.
Differential Revision: https://reviews.llvm.org/D58435
llvm-svn: 355393
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 939907c..78bb064 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -2070,10 +2070,13 @@ bool SCEVExpander::isHighCostExpansionHelper( if (auto *UDivExpr = dyn_cast<SCEVUDivExpr>(S)) { // If the divisor is a power of two and the SCEV type fits in a native - // integer, consider the division cheap irrespective of whether it occurs in - // the user code since it can be lowered into a right shift. + // integer (and the LHS not expensive), consider the division cheap + // irrespective of whether it occurs in the user code since it can be + // lowered into a right shift. if (auto *SC = dyn_cast<SCEVConstant>(UDivExpr->getRHS())) if (SC->getAPInt().isPowerOf2()) { + if (isHighCostExpansionHelper(UDivExpr->getLHS(), L, At, Processed)) + return true; const DataLayout &DL = L->getHeader()->getParent()->getParent()->getDataLayout(); unsigned Width = cast<IntegerType>(UDivExpr->getType())->getBitWidth(); |