diff options
author | Brendon Cahoon <bcahoon@codeaurora.org> | 2017-04-17 19:11:04 +0000 |
---|---|---|
committer | Brendon Cahoon <bcahoon@codeaurora.org> | 2017-04-17 19:11:04 +0000 |
commit | 7769a0854efe4726422137d6d6aa33288e1c9a51 (patch) | |
tree | fd6027404b82a79e7707c498526a0e0e8b823fd8 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | 54c781a0b5d428d712af8bb610b8162bb9ef0a84 (diff) | |
download | bcm5719-llvm-7769a0854efe4726422137d6d6aa33288e1c9a51.tar.gz bcm5719-llvm-7769a0854efe4726422137d6d6aa33288e1c9a51.zip |
[CodeGenPrepare] Fix crash due to an invalid CFG
The splitIndirectCriticalEdges function generates and invalid CFG when the
'Target' basic block is a loop to itself. When this occurs, the code that
updates the predecessor terminator needs to update the terminator in the split
basic block.
This occurs when there is an edge from block D back to D. Since D is split in
to D0 and D1, the code needs to update the terminator in D1. But D1 is not in
the OtherPreds vector, so it was not getting updated.
Differential Revision: https://reviews.llvm.org/D32126
llvm-svn: 300480
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 2bdd189557b..aa0be910e3b 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -570,8 +570,14 @@ bool CodeGenPrepare::splitIndirectCriticalEdges(Function &F) { ValueToValueMapTy VMap; BasicBlock *DirectSucc = CloneBasicBlock(Target, VMap, ".clone", &F); - for (BasicBlock *Pred : OtherPreds) - Pred->getTerminator()->replaceUsesOfWith(Target, DirectSucc); + for (BasicBlock *Pred : OtherPreds) { + // If the target is a loop to itself, then the terminator of the split + // block needs to be updated. + if (Pred == Target) + BodyBlock->getTerminator()->replaceUsesOfWith(Target, DirectSucc); + else + Pred->getTerminator()->replaceUsesOfWith(Target, DirectSucc); + } // Ok, now fix up the PHIs. We know the two blocks only have PHIs, and that // they are clones, so the number of PHIs are the same. |