summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2019-05-14 17:20:10 +0000
committerPhilip Reames <listmail@philipreames.com>2019-05-14 17:20:10 +0000
commitbd8d3091117b334343c4d9775f53253f0ce02861 (patch)
tree759709ac215bda7a77d3eee71a5aa3c63506cd54 /llvm/lib/Transforms/Scalar
parent1362905e8c4a8fe95dfea81a37a2ad01a95cf926 (diff)
downloadbcm5719-llvm-bd8d3091117b334343c4d9775f53253f0ce02861.tar.gz
bcm5719-llvm-bd8d3091117b334343c4d9775f53253f0ce02861.zip
[IndVars] Extend reasoning about loop invariant exits to non-header blocks
Noticed while glancing through the code for other reasons. The extension is trivial enough, decided to just do it. llvm-svn: 360694
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r--llvm/lib/Transforms/Scalar/IndVarSimplify.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index ecf0bef13df..333de75c244 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -728,11 +728,13 @@ bool IndVarSimplify::rewriteFirstIterationLoopExitValues(Loop *L) {
IncomingValIdx != E; ++IncomingValIdx) {
auto *IncomingBB = PN.getIncomingBlock(IncomingValIdx);
- // We currently only support loop exits from loop header. If the
- // incoming block is not loop header, we need to recursively check
- // all conditions starting from loop header are loop invariants.
- // Additional support might be added in the future.
- if (IncomingBB != LoopHeader)
+ // Can we prove that the exit must run on the first iteration if it
+ // runs at all? (i.e. early exits are fine for our purposes, but
+ // traces which lead to this exit being taken on the 2nd iteration
+ // aren't.) Note that this is about whether the exit branch is
+ // executed, not about whether it is taken.
+ if (!L->getLoopLatch() ||
+ !DT->dominates(IncomingBB, L->getLoopLatch()))
continue;
// Get condition that leads to the exit path.
@@ -753,8 +755,8 @@ bool IndVarSimplify::rewriteFirstIterationLoopExitValues(Loop *L) {
auto *ExitVal = dyn_cast<PHINode>(PN.getIncomingValue(IncomingValIdx));
- // Only deal with PHIs.
- if (!ExitVal)
+ // Only deal with PHIs in the loop header.
+ if (!ExitVal || ExitVal->getParent() != L->getHeader())
continue;
// If ExitVal is a PHI on the loop header, then we know its
OpenPOWER on IntegriCloud