aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUtils.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2020-02-25 21:53:00 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2020-02-25 23:05:59 +0300
commit44edc6fd2c63b7db43e13cc8caf1fee79bebdb5f (patch)
treeaa5aa03ca00fa8a2f3a113ff1a7f4808d90d603d /llvm/lib/Transforms/Utils/LoopUtils.cpp
parentd6f47aeb5198b142072d8ce2bbf2fdd30d116db0 (diff)
downloadllvm-44edc6fd2c63b7db43e13cc8caf1fee79bebdb5f.zip
llvm-44edc6fd2c63b7db43e13cc8caf1fee79bebdb5f.tar.gz
llvm-44edc6fd2c63b7db43e13cc8caf1fee79bebdb5f.tar.bz2
[SCEV] rewriteLoopExitValues(): even if have hard uses, still rewrite if cheap (PR44668)
Summary: Replacing uses of IV outside of the loop is likely generally useful, but `rewriteLoopExitValues()` is cautious, and if it isn't told to always perform the replacement, and there are hard uses of IV in loop, it doesn't replace. In [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]], that prevents `-indvars` from replacing uses of induction variable after the loop, which might be one of the optimization failures preventing that code from being vectorized. Instead, now that the cost model is fixed, i believe we should be a little bit more optimistic, and also perform replacement if we believe it is within our budget. Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]]. Reviewers: reames, mkazantsev, asbirlea, fhahn, skatkov Reviewed By: mkazantsev Subscribers: nikic, hiraditya, zzheng, javed.absar, dmgreen, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73501
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUtils.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 347289e..6902021 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1353,16 +1353,16 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
// Computing the value outside of the loop brings no benefit if it is
// definitely used inside the loop in a way which can not be optimized
- // away. Avoid doing so unless we know we have a value which computes
- // the ExitValue already. TODO: This should be merged into SCEV
- // expander to leverage its knowledge of existing expressions.
- if (ReplaceExitValue != AlwaysRepl &&
- !isa<SCEVConstant>(ExitValue) && !isa<SCEVUnknown>(ExitValue) &&
+ // away. Avoid doing so unless either we know we have a value
+ // which computes the ExitValue already, or it is cheap to do so.
+ // TODO: This should be merged into SCEV expander to leverage
+ // its knowledge of existing expressions.
+ bool HighCost = Rewriter.isHighCostExpansion(
+ ExitValue, L, SCEVCheapExpansionBudget, TTI, Inst);
+ if (ReplaceExitValue != AlwaysRepl && HighCost &&
hasHardUserWithinLoop(L, Inst))
continue;
- bool HighCost = Rewriter.isHighCostExpansion(
- ExitValue, L, SCEVCheapExpansionBudget, TTI, Inst);
Value *ExitVal = Rewriter.expandCodeFor(ExitValue, PN->getType(), Inst);
LLVM_DEBUG(dbgs() << "rewriteLoopExitValues: AfterLoopVal = "