forked from OSchip/llvm-project
Tail merge at any size when there are two potentials blocks and one
can be made to fall through into the other. llvm-svn: 86909
This commit is contained in:
parent
a970d39ebf
commit
09478e975d
|
@ -495,6 +495,15 @@ static bool ProfitableToMerge(MachineBasicBlock *MBB1,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If one of the blocks can be completely merged and happens to be in
|
||||||
|
// a position where the other could fall through into it, merge any number
|
||||||
|
// of instructions, because it can be done without a branch.
|
||||||
|
// TODO: If the blocks are not adjacent, move one of them so that they are?
|
||||||
|
if (MBB1->isLayoutSuccessor(MBB2) && I2 == MBB2->begin())
|
||||||
|
return true;
|
||||||
|
if (MBB2->isLayoutSuccessor(MBB1) && I1 == MBB1->begin())
|
||||||
|
return true;
|
||||||
|
|
||||||
// If both blocks have an unconditional branch temporarily stripped out,
|
// If both blocks have an unconditional branch temporarily stripped out,
|
||||||
// treat that as an additional common instruction.
|
// treat that as an additional common instruction.
|
||||||
if (MBB1 != PredBB && MBB2 != PredBB &&
|
if (MBB1 != PredBB && MBB2 != PredBB &&
|
||||||
|
@ -716,16 +725,31 @@ bool BranchFolder::TryTailMergeBlocks(MachineBasicBlock *SuccBB,
|
||||||
MachineBasicBlock *EntryBB = MergePotentials.begin()->getBlock()->
|
MachineBasicBlock *EntryBB = MergePotentials.begin()->getBlock()->
|
||||||
getParent()->begin();
|
getParent()->begin();
|
||||||
unsigned commonTailIndex = SameTails.size();
|
unsigned commonTailIndex = SameTails.size();
|
||||||
for (unsigned i=0; i<SameTails.size(); i++) {
|
// If there are two blocks, check to see if one can be made to fall through
|
||||||
MachineBasicBlock *MBB = SameTails[i].getBlock();
|
// into the other.
|
||||||
if (MBB == EntryBB)
|
if (SameTails.size() == 2 &&
|
||||||
continue;
|
SameTails[0].getBlock()->isLayoutSuccessor(SameTails[1].getBlock()) &&
|
||||||
if (MBB == PredBB) {
|
SameTails[1].tailIsWholeBlock())
|
||||||
commonTailIndex = i;
|
commonTailIndex = 1;
|
||||||
break;
|
else if (SameTails.size() == 2 &&
|
||||||
|
SameTails[1].getBlock()->isLayoutSuccessor(
|
||||||
|
SameTails[0].getBlock()) &&
|
||||||
|
SameTails[0].tailIsWholeBlock())
|
||||||
|
commonTailIndex = 0;
|
||||||
|
else {
|
||||||
|
// Otherwise just pick one, favoring the fall-through predecessor if
|
||||||
|
// there is one.
|
||||||
|
for (unsigned i = 0, e = SameTails.size(); i != e; ++i) {
|
||||||
|
MachineBasicBlock *MBB = SameTails[i].getBlock();
|
||||||
|
if (MBB == EntryBB && SameTails[i].tailIsWholeBlock())
|
||||||
|
continue;
|
||||||
|
if (MBB == PredBB) {
|
||||||
|
commonTailIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (SameTails[i].tailIsWholeBlock())
|
||||||
|
commonTailIndex = i;
|
||||||
}
|
}
|
||||||
if (MBB->begin() == SameTails[i].getTailStartPos())
|
|
||||||
commonTailIndex = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commonTailIndex == SameTails.size() ||
|
if (commonTailIndex == SameTails.size() ||
|
||||||
|
@ -1049,7 +1073,7 @@ bool BranchFolder::TailDuplicate(MachineBasicBlock *TailBB,
|
||||||
continue;
|
continue;
|
||||||
// Don't duplicate into a fall-through predecessor unless its the
|
// Don't duplicate into a fall-through predecessor unless its the
|
||||||
// only predecessor.
|
// only predecessor.
|
||||||
if (&*next(MachineFunction::iterator(PredBB)) == TailBB &&
|
if (PredBB->isLayoutSuccessor(TailBB) &&
|
||||||
PrevFallsThrough &&
|
PrevFallsThrough &&
|
||||||
TailBB->pred_size() != 1)
|
TailBB->pred_size() != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -266,3 +266,30 @@ bb3: ; preds = %bb2, %bb1, %lvalue_
|
||||||
declare fastcc i32 @lvalue_p(%union.tree_node* nocapture) nounwind readonly
|
declare fastcc i32 @lvalue_p(%union.tree_node* nocapture) nounwind readonly
|
||||||
|
|
||||||
declare fastcc %union.tree_node* @default_conversion(%union.tree_node*) nounwind
|
declare fastcc %union.tree_node* @default_conversion(%union.tree_node*) nounwind
|
||||||
|
|
||||||
|
|
||||||
|
; If one tail merging candidate falls through into the other,
|
||||||
|
; tail merging is likely profitable regardless of how few
|
||||||
|
; instructions are involved. This function should have only
|
||||||
|
; one ret instruction.
|
||||||
|
|
||||||
|
; CHECK: foo:
|
||||||
|
; CHECK: call func
|
||||||
|
; CHECK-NEXT: .LBB5_2:
|
||||||
|
; CHECK-NEXT: addq $8, %rsp
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
|
||||||
|
define void @foo(i1* %V) nounwind {
|
||||||
|
entry:
|
||||||
|
%t0 = icmp eq i1* %V, null
|
||||||
|
br i1 %t0, label %return, label %bb
|
||||||
|
|
||||||
|
bb:
|
||||||
|
call void @func()
|
||||||
|
ret void
|
||||||
|
|
||||||
|
return:
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @func()
|
||||||
|
|
Loading…
Reference in New Issue