diff options
author | Philip Reames <listmail@philipreames.com> | 2019-06-12 17:21:47 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-06-12 17:21:47 +0000 |
commit | e51c3d8b8247ae763ea8b6aa3344529b8ca184e3 (patch) | |
tree | 92ea3a7702affbbbff9f8484a542415937ea2020 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 4e0648a541f7a1da3cbda804d9cbce04c0843c30 (diff) | |
download | bcm5719-llvm-e51c3d8b8247ae763ea8b6aa3344529b8ca184e3.tar.gz bcm5719-llvm-e51c3d8b8247ae763ea8b6aa3344529b8ca184e3.zip |
[SCEV] Teach computeSCEVAtScope benefit from one-input Phi. PR39673
SCEV does not propagate arguments through one-input Phis so as to make it easy for the SCEV expander (and related code) to preserve LCSSA. It's not entirely clear this restriction is neccessary, but for the moment it exists. For this reason, we don't analyze single-entry phi inputs. However it is possible that when an this input leaves the loop through LCSSA Phi, it is a provable constant. Missing that results in an order of optimization issue in loop exit value rewriting where we miss some oppurtunities based on order in which we visit sibling loops.
This patch teaches computeSCEVAtScope about this case. We can generalize it later, but so far we can only replace LCSSA Phis with their constant loop-exiting values. We should probably also add similiar logic directly in the SCEV construction path itself.
Patch by: mkazantsev (with revised commit message by me)
Differential Revision: https://reviews.llvm.org/D58113
llvm-svn: 363180
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index dc2d32856cc..88686427127 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8138,6 +8138,16 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) { if (RV) return getSCEV(RV); } } + + // If there is a single-input Phi, evaluate it at our scope. If we can + // prove that this replacement does not break LCSSA form, use new value. + if (PN->getNumOperands() == 1) { + const SCEV *Input = getSCEV(PN->getOperand(0)); + const SCEV *InputAtScope = getSCEVAtScope(Input, L); + // TODO: We can generalize it using LI.replacementPreservesLCSSAForm, + // for the simplest case just support constants. + if (isa<SCEVConstant>(InputAtScope)) return InputAtScope; + } } // Okay, this is an expression that we cannot symbolically evaluate |