diff options
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 2f25800cd0..ffde173e69 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -622,6 +622,28 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) { if (!FBB) FBB = next(MachineFunction::iterator(PBB)); } + // Failing case: the only way IBB can be reached from PBB is via + // exception handling. Happens for landing pads. Would be nice + // to have a bit in the edge so we didn't have to do all this. + if (IBB->isLandingPad()) { + MachineFunction::iterator IP = PBB; IP++; + MachineBasicBlock* PredNextBB = NULL; + if (IP!=MF.end()) + PredNextBB = IP; + if (TBB==NULL) { + if (IBB!=PredNextBB) // fallthrough + continue; + } else if (FBB) { + if (TBB!=IBB && FBB!=IBB) // cbr then ubr + continue; + } else if (Cond.size() == 0) { + if (TBB!=IBB) // ubr + continue; + } else { + if (TBB!=IBB && IBB!=PredNextBB) // cbr + continue; + } + } // Remove the unconditional branch at the end, if any. if (TBB && (Cond.size()==0 || FBB)) { TII->RemoveBranch(*PBB); |