Be more strict when detecting critical edges before loop splitting.

An exit block with a critical edge must only have predecessors in the loop, or
just before the loop. This guarantees that the inserted copies in the loop
predecessors dominate the exit block.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117144 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2010-10-22 20:28:23 +00:00
parent 532de3dc6e
commit 2c1442e1b2

View File

@ -149,37 +149,33 @@ analyzeLoopPeripheralUse(const SplitAnalysis::LoopBlocks &Blocks) {
}
/// getCriticalExits - It may be necessary to partially break critical edges
/// leaving the loop if an exit block has phi uses of curli. Collect the exit
/// blocks that need special treatment into CriticalExits.
/// leaving the loop if an exit block has predecessors from outside the loop
/// periphery.
void SplitAnalysis::getCriticalExits(const SplitAnalysis::LoopBlocks &Blocks,
BlockPtrSet &CriticalExits) {
CriticalExits.clear();
// A critical exit block contains a phi def of curli, and has a predecessor
// that is not in the loop nor a loop predecessor.
// For such an exit block, the edges carrying the new variable must be moved
// to a new pre-exit block.
// A critical exit block has curli line-in, and has a predecessor that is not
// in the loop nor a loop predecessor. For such an exit block, the edges
// carrying the new variable must be moved to a new pre-exit block.
for (BlockPtrSet::iterator I = Blocks.Exits.begin(), E = Blocks.Exits.end();
I != E; ++I) {
const MachineBasicBlock *Succ = *I;
SlotIndex SuccIdx = lis_.getMBBStartIdx(Succ);
VNInfo *SuccVNI = curli_->getVNInfoAt(SuccIdx);
const MachineBasicBlock *Exit = *I;
// A single-predecessor exit block is definitely not a critical edge.
if (Exit->pred_size() == 1)
continue;
// This exit may not have curli live in at all. No need to split.
if (!SuccVNI)
if (!lis_.isLiveInToMBB(*curli_, Exit))
continue;
// If this is not a PHI def, it is either using a value from before the
// loop, or a value defined inside the loop. Both are safe.
if (!SuccVNI->isPHIDef() || SuccVNI->def.getBaseIndex() != SuccIdx)
continue;
// This exit block does have a PHI. Does it also have a predecessor that is
// not a loop block or loop predecessor?
for (MachineBasicBlock::const_pred_iterator PI = Succ->pred_begin(),
PE = Succ->pred_end(); PI != PE; ++PI) {
// Does this exit block have a predecessor that is not a loop block or loop
// predecessor?
for (MachineBasicBlock::const_pred_iterator PI = Exit->pred_begin(),
PE = Exit->pred_end(); PI != PE; ++PI) {
const MachineBasicBlock *Pred = *PI;
if (Blocks.Loop.count(Pred) || Blocks.Preds.count(Pred))
continue;
// This is a critical exit block, and we need to split the exit edge.
CriticalExits.insert(Succ);
CriticalExits.insert(Exit);
break;
}
}