summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2013-11-22 19:24:39 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2013-11-22 19:24:39 +0000
commit6ea0aade264e626cce640ddbc96adac7530b1481 (patch)
treef632a36b5d8baaa83be47a902aee632568024291 /llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
parent9fb6e0ba58b03a642576268db2c6a7b8a64aa32b (diff)
downloadbcm5719-llvm-6ea0aade264e626cce640ddbc96adac7530b1481.tar.gz
bcm5719-llvm-6ea0aade264e626cce640ddbc96adac7530b1481.zip
StructurizeCFG: Fix verification failure with some loops.
If the beginning of the loop was also the entry block of the function, branches were inserted to the entry block which isn't allowed. If this occurs, create a new dummy function entry block that branches to the start of the loop. llvm-svn: 195493
Diffstat (limited to 'llvm/lib/Transforms/Scalar/StructurizeCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/StructurizeCFG.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
index 0124dfdbeb1..5045ff8fdfd 100644
--- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -779,6 +779,20 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
handleLoops(false, LoopEnd);
}
+ // If the start of the loop is the entry block, we can't branch to it so
+ // insert a new dummy entry block.
+ Function *LoopFunc = LoopStart->getParent();
+ if (LoopStart == &LoopFunc->getEntryBlock()) {
+ LoopStart->setName("entry.orig");
+
+ BasicBlock *NewEntry =
+ BasicBlock::Create(LoopStart->getContext(),
+ "entry",
+ LoopFunc,
+ LoopStart);
+ BranchInst::Create(LoopStart, NewEntry);
+ }
+
// Create an extra loop end node
LoopEnd = needPrefix(false);
BasicBlock *Next = needPostfix(LoopEnd, ExitUseAllowed);
OpenPOWER on IntegriCloud