mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-20 12:31:40 +00:00
Implement smarter algorithm for choosing which blocks to tail-merge.
See test/CodeGen/X86/test-pic-jtbl.ll for a case where it works well; shaves another 10K off our favorite benchmark. I was hesitant about this because of compile speed, but seems to do OK on a bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37392 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e770787be1
commit
a5a2117a46
@ -466,43 +466,58 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look through all the blocks that have the same hash as this one, and
|
// Look through all the pairs of blocks that have the same hash as this
|
||||||
// find the one that has the largest number of instructions in common.
|
// one, and find the pair that has the largest number of instructions in
|
||||||
// Since instructions may get combined later (e.g. single stores into
|
// common.
|
||||||
|
// Since instructions may get combined later (e.g. single stores into
|
||||||
// store multiple) this measure is not particularly accurate.
|
// store multiple) this measure is not particularly accurate.
|
||||||
MachineBasicBlock::iterator BBI1, BBI2;
|
MachineBasicBlock::iterator BBI1, BBI2;
|
||||||
|
|
||||||
unsigned FoundMatch = ~0U;
|
unsigned FoundI = ~0U, FoundJ = ~0U;
|
||||||
unsigned maxCommonTailLength = 0U;
|
unsigned maxCommonTailLength = 0U;
|
||||||
for (int i = MergePotentials.size()-2;
|
for (int i = MergePotentials.size()-1;
|
||||||
i != -1 && MergePotentials[i].first == CurHash; --i) {
|
i != -1 && MergePotentials[i].first == CurHash; --i) {
|
||||||
MachineBasicBlock::iterator TrialBBI1, TrialBBI2;
|
for (int j = i-1;
|
||||||
unsigned CommonTailLen = ComputeCommonTailLength(CurMBB,
|
j != -1 && MergePotentials[j].first == CurHash; --j) {
|
||||||
MergePotentials[i].second,
|
MachineBasicBlock::iterator TrialBBI1, TrialBBI2;
|
||||||
TrialBBI1, TrialBBI2);
|
unsigned CommonTailLen = ComputeCommonTailLength(
|
||||||
if (CommonTailLen >= minCommonTailLength &&
|
MergePotentials[i].second,
|
||||||
CommonTailLen >= maxCommonTailLength) {
|
MergePotentials[j].second,
|
||||||
FoundMatch = i;
|
TrialBBI1, TrialBBI2);
|
||||||
maxCommonTailLength = CommonTailLen;
|
if (CommonTailLen >= minCommonTailLength &&
|
||||||
BBI1 = TrialBBI1;
|
CommonTailLen > maxCommonTailLength) {
|
||||||
BBI2 = TrialBBI2;
|
FoundI = i;
|
||||||
|
FoundJ = j;
|
||||||
|
maxCommonTailLength = CommonTailLen;
|
||||||
|
BBI1 = TrialBBI1;
|
||||||
|
BBI2 = TrialBBI2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we didn't find anything that has at least minCommonTailLength
|
// If we didn't find any pair that has at least minCommonTailLength
|
||||||
// instructions matching this one, bail out.
|
// instructions in common, bail out. All entries with this
|
||||||
if (FoundMatch == ~0U) {
|
// hash code can go away now.
|
||||||
// Put the unconditional branch back, if we need one.
|
if (FoundI == ~0U) {
|
||||||
if (SuccBB && CurMBB != PredBB)
|
for (int i = MergePotentials.size()-1;
|
||||||
FixTail(CurMBB, SuccBB, TII);
|
i != -1 && MergePotentials[i].first == CurHash; --i) {
|
||||||
MergePotentials.pop_back();
|
// Put the unconditional branch back, if we need one.
|
||||||
|
CurMBB = MergePotentials[i].second;
|
||||||
|
if (SuccBB && CurMBB != PredBB)
|
||||||
|
FixTail(CurMBB, SuccBB, TII);
|
||||||
|
MergePotentials.pop_back();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, move the matching block to the right position.
|
// Otherwise, move the block(s) to the right position(s). So that
|
||||||
if (FoundMatch != MergePotentials.size()-2)
|
// BBI1/2 will be valid, the last must be I and the next-to-last J.
|
||||||
std::swap(MergePotentials[FoundMatch], *(MergePotentials.end()-2));
|
if (FoundI != MergePotentials.size()-1)
|
||||||
|
std::swap(MergePotentials[FoundI], *(MergePotentials.end()-1));
|
||||||
|
if (FoundJ != MergePotentials.size()-2)
|
||||||
|
std::swap(MergePotentials[FoundJ], *(MergePotentials.end()-2));
|
||||||
|
|
||||||
|
CurMBB = (MergePotentials.end()-1)->second;
|
||||||
MachineBasicBlock *MBB2 = (MergePotentials.end()-2)->second;
|
MachineBasicBlock *MBB2 = (MergePotentials.end()-2)->second;
|
||||||
|
|
||||||
// If neither block is the entire common tail, split the tail of one block
|
// If neither block is the entire common tail, split the tail of one block
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
; RUN: -o %t -f
|
; RUN: -o %t -f
|
||||||
; RUN: grep _GLOBAL_OFFSET_TABLE_ %t
|
; RUN: grep _GLOBAL_OFFSET_TABLE_ %t
|
||||||
; RUN: grep piclabel %t | wc -l | grep 3
|
; RUN: grep piclabel %t | wc -l | grep 3
|
||||||
; RUN: grep PLT %t | wc -l | grep 11
|
; RUN: grep PLT %t | wc -l | grep 6
|
||||||
; RUN: grep GOTOFF %t | wc -l | grep 1
|
; RUN: grep GOTOFF %t | wc -l | grep 1
|
||||||
; RUN: grep JTI %t | wc -l | grep 13
|
; RUN: grep JTI %t | wc -l | grep 8
|
||||||
; Improved tail merging could reduce the number of PLT's and JTI's further.
|
|
||||||
|
|
||||||
define void @bar(i32 %n.u) {
|
define void @bar(i32 %n.u) {
|
||||||
entry:
|
entry:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user