1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Don't try to move a MBB into the fall-through position if it's a landing pad or

branches only to a landing pad. Without this check, the compiler would go into
an infinite loop because the branch to a landing pad is an "abnormal" edge which
wasn't being taken into account.

This is the meat of that fix:

  if (!PrevBB.canFallThrough() && !MBB->BranchesToLandingPad(MBB)) {

The other stuff is simplification of the "branches to a landing pad" code.

llvm-svn: 91161
This commit is contained in:
Bill Wendling 2009-12-11 21:47:36 +00:00
parent 888cd4aa89
commit 10e315eae4
2 changed files with 26 additions and 29 deletions

View File

@ -1205,11 +1205,11 @@ ReoptimizeBlock:
} }
} }
// If the prior block doesn't fall through into this block, and if this // If the prior block doesn't fall through into this block and if this block
// block doesn't fall through into some other block, see if we can find a // doesn't fall through into some other block and it's not branching only to a
// place to move this block where a fall-through will happen. // landing pad, then see if we can find a place to move this block where a
if (!PrevBB.canFallThrough()) { // fall-through will happen.
if (!PrevBB.canFallThrough() && !MBB->BranchesToLandingPad(MBB)) {
// Now we know that there was no fall-through into this block, check to // Now we know that there was no fall-through into this block, check to
// see if it has a fall-through into its successor. // see if it has a fall-through into its successor.
bool CurFallsThru = MBB->canFallThrough(); bool CurFallsThru = MBB->canFallThrough();
@ -1221,28 +1221,32 @@ ReoptimizeBlock:
E = MBB->pred_end(); PI != E; ++PI) { E = MBB->pred_end(); PI != E; ++PI) {
// Analyze the branch at the end of the pred. // Analyze the branch at the end of the pred.
MachineBasicBlock *PredBB = *PI; MachineBasicBlock *PredBB = *PI;
MachineFunction::iterator PredFallthrough = PredBB; ++PredFallthrough; MachineFunction::iterator PredNextBB = PredBB; ++PredNextBB;
MachineBasicBlock *PredTBB, *PredFBB; MachineBasicBlock *PredTBB, *PredFBB;
SmallVector<MachineOperand, 4> PredCond; SmallVector<MachineOperand, 4> PredCond;
if (PredBB != MBB && !PredBB->canFallThrough() && if (PredBB != MBB && !PredBB->canFallThrough()
!TII->AnalyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true) && !TII->AnalyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true)
&& (!CurFallsThru || !CurTBB || !CurFBB) && (!CurFallsThru || !CurTBB || !CurFBB)
&& (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) { && (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
// If the current block doesn't fall through, just move it. // If the current block doesn't fall through, just move it. If the
// If the current block can fall through and does not end with a // current block can fall through and does not end with a conditional
// conditional branch, we need to append an unconditional jump to // branch, we need to append an unconditional jump to the (current)
// the (current) next block. To avoid a possible compile-time // next block. To avoid a possible compile-time infinite loop, move
// infinite loop, move blocks only backward in this case. // blocks only backward in this case.
// Also, if there are already 2 branches here, we cannot add a third; //
// this means we have the case // Also, if there are already 2 branches here, we cannot add a third.
// Bcc next // I.e. we have the case:
// B elsewhere //
// next: // Bcc next
// B elsewhere
// next:
if (CurFallsThru) { if (CurFallsThru) {
MachineBasicBlock *NextBB = llvm::next(MachineFunction::iterator(MBB)); MachineBasicBlock *NextBB =
llvm::next(MachineFunction::iterator(MBB));
CurCond.clear(); CurCond.clear();
TII->InsertBranch(*MBB, NextBB, 0, CurCond); TII->InsertBranch(*MBB, NextBB, 0, CurCond);
} }
MBB->moveAfter(PredBB); MBB->moveAfter(PredBB);
MadeChange = true; MadeChange = true;
goto ReoptimizeBlock; goto ReoptimizeBlock;

View File

@ -457,16 +457,9 @@ MachineBasicBlock::BranchesToLandingPad(const MachineBasicBlock *MBB) const {
SmallSet<const MachineBasicBlock*, 32> Visited; SmallSet<const MachineBasicBlock*, 32> Visited;
const MachineBasicBlock *CurMBB = MBB; const MachineBasicBlock *CurMBB = MBB;
while (!Visited.count(CurMBB) && !CurMBB->isLandingPad()) { while (!CurMBB->isLandingPad()) {
if (CurMBB->size() != 1 || CurMBB->succ_empty() || CurMBB->succ_size() != 1) if (CurMBB->succ_size() != 1) break;
break; if (!Visited.insert(CurMBB)) break;
const TargetInstrInfo *TII =
CurMBB->getParent()->getTarget().getInstrInfo();
if (!TII->isUnpredicatedTerminator(CurMBB->begin()))
break;
Visited.insert(CurMBB);
CurMBB = *CurMBB->succ_begin(); CurMBB = *CurMBB->succ_begin();
} }