diff options
| author | Philip Reames <listmail@philipreames.com> | 2019-11-19 14:06:36 -0800 |
|---|---|---|
| committer | Philip Reames <listmail@philipreames.com> | 2019-11-19 14:06:36 -0800 |
| commit | f3eb5dee5756876be0524c59c21478659eba8c4d (patch) | |
| tree | ed861d3467134323ebaa78b2c17d471a1377f54a /llvm/lib/Transforms/Scalar | |
| parent | cf823ce4ad9d04c69b7c29d236f7b14c875111c2 (diff) | |
| download | bcm5719-llvm-f3eb5dee5756876be0524c59c21478659eba8c4d.tar.gz bcm5719-llvm-f3eb5dee5756876be0524c59c21478659eba8c4d.zip | |
[LoopPred] Generalize profitability check to handle unswitch output
Unswitch (and other loop transforms) like to generate loop exit blocks with unconditional successors, and phi nodes (LCSSA, or simple multiple exiting blocks sharing an exit). Generalize the "likely very rare exit" check slightly to handle this form.
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopPredication.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index 9abf6deebb6..9d67046d743 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -1019,6 +1019,17 @@ static const SCEV *getMinAnalyzeableBackedgeTakenCount(ScalarEvolution &SE, return SE.getUMinFromMismatchedTypes(ExitCounts); } +/// Return true if we can be fairly sure that executing block BB will probably +/// lead to executing an __llvm_deoptimize. This is a profitability heuristic, +/// not a legality constraint. +static bool isVeryLikelyToDeopt(BasicBlock *BB) { + while (BB->getUniqueSuccessor()) + // Will skip side effects, that's okay + BB = BB->getUniqueSuccessor(); + + return BB->getTerminatingDeoptimizeCall(); +} + /// This implements an analogous, but entirely distinct transform from the main /// loop predication transform. This one is phrased in terms of using a /// widenable branch *outside* the loop to allow us to simplify loop exits in a @@ -1109,7 +1120,7 @@ bool LoopPredication::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) { const bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB)); BasicBlock *ExitBB = BI->getSuccessor(ExitIfTrue ? 0 : 1); - if (!ExitBB->getTerminatingDeoptimizeCall()) + if (!isVeryLikelyToDeopt(ExitBB)) // Profitability: indicator of rarely/never taken exit continue; |

