summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2018-11-27 06:17:21 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2018-11-27 06:17:21 +0000
commitc4e4d6449a58d479df6404d6358c679917fa990c (patch)
tree3d1f9b7a8aee2b6bbc736c047b5c8a662d6304ef /llvm/lib
parentfe962736505ce2903b97ec774d5f56123477392a (diff)
downloadbcm5719-llvm-c4e4d6449a58d479df6404d6358c679917fa990c.tar.gz
bcm5719-llvm-c4e4d6449a58d479df6404d6358c679917fa990c.zip
[LoopSimplifyCFG] Fix corner case with duplicating successors
It fixes a bug that doesn't update Phi inputs of the only live successor that is in the list of block's successors more than once. Thanks @uabelho for finding this. Differential Revision: https://reviews.llvm.org/D54849 Reviewed By: anna llvm-svn: 347640
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
index 5ca412f1a20..f2d592f04c3 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -249,6 +249,7 @@ private:
SmallPtrSet<BasicBlock *, 2> DeadSuccessors;
// Remove all BB's successors except for the live one.
+ unsigned TheOnlySuccDuplicates = 0;
for (auto *Succ : successors(BB))
if (Succ != TheOnlySucc) {
DeadSuccessors.insert(Succ);
@@ -256,7 +257,16 @@ private:
// the one-input Phi because it is a LCSSA Phi.
bool PreserveLCSSAPhi = !L.contains(Succ);
Succ->removePredecessor(BB, PreserveLCSSAPhi);
- }
+ } else
+ ++TheOnlySuccDuplicates;
+
+ assert(TheOnlySuccDuplicates > 0 && "Should be!");
+ // If TheOnlySucc was BB's successor more than once, after transform it
+ // will be its successor only once. Remove redundant inputs from
+ // TheOnlySucc's Phis.
+ bool PreserveLCSSAPhi = !L.contains(TheOnlySucc);
+ for (unsigned Dup = 1; Dup < TheOnlySuccDuplicates; ++Dup)
+ TheOnlySucc->removePredecessor(BB, PreserveLCSSAPhi);
IRBuilder<> Builder(BB->getContext());
Instruction *Term = BB->getTerminator();
OpenPOWER on IntegriCloud