summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDavid Green <david.green@arm.com>2017-10-21 13:58:37 +0000
committerDavid Green <david.green@arm.com>2017-10-21 13:58:37 +0000
commit907b60fbbadca4ea9b595110af7363bb96d55c69 (patch)
tree8bd9a1aa1bef1398fa1ae5cf077c01a2564298e6 /llvm/lib/Transforms
parentf793fa3335f0956f59a95698b44751de7d3a6ace (diff)
downloadbcm5719-llvm-907b60fbbadca4ea9b595110af7363bb96d55c69.tar.gz
bcm5719-llvm-907b60fbbadca4ea9b595110af7363bb96d55c69.zip
[LoopInterchange] Fix phi node ordering miscompile.
The way that splitInnerLoopHeader splits blocks requires that the induction PHI will be the first PHI in the inner loop header. This makes sure that is actually the case when there are both IV and reduction phis. Differential Revision: https://reviews.llvm.org/D38682 llvm-svn: 316261
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopInterchange.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 16e3151e851..4f8dafef230 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -1185,6 +1185,11 @@ bool LoopInterchangeTransform::transform() {
else
InnerIndexVar = dyn_cast<Instruction>(InductionPHI->getIncomingValue(0));
+ // Ensure that InductionPHI is the first Phi node as required by
+ // splitInnerLoopHeader
+ if (&InductionPHI->getParent()->front() != InductionPHI)
+ InductionPHI->moveBefore(&InductionPHI->getParent()->front());
+
// Split at the place were the induction variable is
// incremented/decremented.
// TODO: This splitting logic may not work always. Fix this.
@@ -1218,7 +1223,7 @@ void LoopInterchangeTransform::splitInnerLoopHeader() {
BasicBlock *InnerLoopHeader = InnerLoop->getHeader();
BasicBlock *InnerLoopPreHeader = InnerLoop->getLoopPreheader();
if (InnerLoopHasReduction) {
- // FIXME: Check if the induction PHI will always be the first PHI.
+ // Note: The induction PHI must be the first PHI for this to work
BasicBlock *New = InnerLoopHeader->splitBasicBlock(
++(InnerLoopHeader->begin()), InnerLoopHeader->getName() + ".split");
if (LI)
OpenPOWER on IntegriCloud