summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2009-08-06 22:56:40 +0000
committerDale Johannesen <dalej@apple.com>2009-08-06 22:56:40 +0000
commit15a5fad94bb8924a1d7cb8a5c87cb8c98ef72f52 (patch)
treeaec16e89daaca5f3a59c837b673e5f2c7ff7e569 /llvm/lib/CodeGen
parent352fa9299592fd01b344366f865c6f7367d3e599 (diff)
downloadbcm5719-llvm-15a5fad94bb8924a1d7cb8a5c87cb8c98ef72f52.tar.gz
bcm5719-llvm-15a5fad94bb8924a1d7cb8a5c87cb8c98ef72f52.zip
Fix PR 4626, a crash in branch folding after OptimizeBlock
produced a CFG it wasn't prepared for. llvm-svn: 78351
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 193bbb610f7..d25152b1e43 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -893,8 +893,24 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
while (!MBB->pred_empty()) {
MachineBasicBlock *Pred = *(MBB->pred_end()-1);
Pred->ReplaceUsesOfBlockWith(MBB, FallThrough);
+ // If this resulted in a predecessor with true and false edges
+ // both going to the fallthrough block, clean up;
+ // BranchFolding doesn't like this.
+ MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
+ bool found = false;
+ while (SI != Pred->succ_end()) {
+ if (*SI == FallThrough) {
+ if (!found) {
+ found = true;
+ ++SI;
+ } else {
+ SI = Pred->removeSuccessor(SI);
+ }
+ } else {
+ ++SI;
+ }
+ }
}
-
// If MBB was the target of a jump table, update jump tables to go to the
// fallthrough instead.
MBB->getParent()->getJumpTableInfo()->
OpenPOWER on IntegriCloud