mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 20:23:59 +00:00
Make the threshold used by branch folding softer. Before we would get a
sharp all or nothing transition when one extra predecessor was added. Now we still test first ones for merging. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132974 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -799,14 +799,22 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
|
|||||||
|
|
||||||
// First find blocks with no successors.
|
// First find blocks with no successors.
|
||||||
MergePotentials.clear();
|
MergePotentials.clear();
|
||||||
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
for (MachineFunction::iterator I = MF.begin(), E = MF.end();
|
||||||
|
I != E && MergePotentials.size() < TailMergeThreshold; ++I) {
|
||||||
|
if (TriedMerging.count(I))
|
||||||
|
continue;
|
||||||
if (I->succ_empty())
|
if (I->succ_empty())
|
||||||
MergePotentials.push_back(MergePotentialsElt(HashEndOfMBB(I), I));
|
MergePotentials.push_back(MergePotentialsElt(HashEndOfMBB(I), I));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this is a large problem, avoid visiting the same basic blocks
|
||||||
|
// multiple times.
|
||||||
|
if (MergePotentials.size() == TailMergeThreshold)
|
||||||
|
for (unsigned i = 0, e = MergePotentials.size(); i != e; ++i)
|
||||||
|
TriedMerging.insert(MergePotentials[i].getBlock());
|
||||||
|
|
||||||
// See if we can do any tail merging on those.
|
// See if we can do any tail merging on those.
|
||||||
if (MergePotentials.size() < TailMergeThreshold &&
|
if (MergePotentials.size() >= 2)
|
||||||
MergePotentials.size() >= 2)
|
|
||||||
MadeChange |= TryTailMergeBlocks(NULL, NULL);
|
MadeChange |= TryTailMergeBlocks(NULL, NULL);
|
||||||
|
|
||||||
// Look at blocks (IBB) with multiple predecessors (PBB).
|
// Look at blocks (IBB) with multiple predecessors (PBB).
|
||||||
@ -830,15 +838,17 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
|
|||||||
|
|
||||||
for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
|
for (MachineFunction::iterator I = llvm::next(MF.begin()), E = MF.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
if (I->pred_size() >= 2 && I->pred_size() < TailMergeThreshold) {
|
if (I->pred_size() >= 2) {
|
||||||
SmallPtrSet<MachineBasicBlock *, 8> UniquePreds;
|
SmallPtrSet<MachineBasicBlock *, 8> UniquePreds;
|
||||||
MachineBasicBlock *IBB = I;
|
MachineBasicBlock *IBB = I;
|
||||||
MachineBasicBlock *PredBB = prior(I);
|
MachineBasicBlock *PredBB = prior(I);
|
||||||
MergePotentials.clear();
|
MergePotentials.clear();
|
||||||
for (MachineBasicBlock::pred_iterator P = I->pred_begin(),
|
for (MachineBasicBlock::pred_iterator P = I->pred_begin(),
|
||||||
E2 = I->pred_end();
|
E2 = I->pred_end();
|
||||||
P != E2; ++P) {
|
P != E2 && MergePotentials.size() < TailMergeThreshold; ++P) {
|
||||||
MachineBasicBlock *PBB = *P;
|
MachineBasicBlock *PBB = *P;
|
||||||
|
if (TriedMerging.count(PBB))
|
||||||
|
continue;
|
||||||
// Skip blocks that loop to themselves, can't tail merge these.
|
// Skip blocks that loop to themselves, can't tail merge these.
|
||||||
if (PBB == IBB)
|
if (PBB == IBB)
|
||||||
continue;
|
continue;
|
||||||
@ -891,6 +901,12 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
|
|||||||
MergePotentials.push_back(MergePotentialsElt(HashEndOfMBB(PBB), *P));
|
MergePotentials.push_back(MergePotentialsElt(HashEndOfMBB(PBB), *P));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If this is a large problem, avoid visiting the same basic blocks
|
||||||
|
// multiple times.
|
||||||
|
if (MergePotentials.size() == TailMergeThreshold)
|
||||||
|
for (unsigned i = 0, e = MergePotentials.size(); i != e; ++i)
|
||||||
|
TriedMerging.insert(MergePotentials[i].getBlock());
|
||||||
|
|
||||||
if (MergePotentials.size() >= 2)
|
if (MergePotentials.size() >= 2)
|
||||||
MadeChange |= TryTailMergeBlocks(IBB, PredBB);
|
MadeChange |= TryTailMergeBlocks(IBB, PredBB);
|
||||||
// Reinsert an unconditional branch if needed.
|
// Reinsert an unconditional branch if needed.
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#ifndef LLVM_CODEGEN_BRANCHFOLDING_HPP
|
#ifndef LLVM_CODEGEN_BRANCHFOLDING_HPP
|
||||||
#define LLVM_CODEGEN_BRANCHFOLDING_HPP
|
#define LLVM_CODEGEN_BRANCHFOLDING_HPP
|
||||||
|
|
||||||
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/CodeGen/MachineBasicBlock.h"
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
typedef std::vector<MergePotentialsElt>::iterator MPIterator;
|
typedef std::vector<MergePotentialsElt>::iterator MPIterator;
|
||||||
std::vector<MergePotentialsElt> MergePotentials;
|
std::vector<MergePotentialsElt> MergePotentials;
|
||||||
|
SmallPtrSet<const MachineBasicBlock*, 2> TriedMerging;
|
||||||
|
|
||||||
class SameTailElt {
|
class SameTailElt {
|
||||||
MPIterator MPIter;
|
MPIterator MPIter;
|
||||||
|
41
test/CodeGen/X86/tail-threshold.ll
Normal file
41
test/CodeGen/X86/tail-threshold.ll
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
; RUN: llc %s -stats -tail-merge-threshold 2 -o /dev/null |& FileCheck %s
|
||||||
|
|
||||||
|
; Test that we still do some merging if a block has more than
|
||||||
|
; tail-merge-threshold predecessors.
|
||||||
|
|
||||||
|
; CHECK: 2 branchfolding - Number of block tails merged
|
||||||
|
|
||||||
|
declare void @bar()
|
||||||
|
|
||||||
|
define void @foo(i32 %xxx) {
|
||||||
|
entry:
|
||||||
|
switch i32 %xxx, label %bb4 [
|
||||||
|
i32 0, label %bb0
|
||||||
|
i32 1, label %bb1
|
||||||
|
i32 2, label %bb2
|
||||||
|
i32 3, label %bb3
|
||||||
|
]
|
||||||
|
|
||||||
|
bb0:
|
||||||
|
call void @bar()
|
||||||
|
br label %bb5
|
||||||
|
|
||||||
|
bb1:
|
||||||
|
call void @bar()
|
||||||
|
br label %bb5
|
||||||
|
|
||||||
|
bb2:
|
||||||
|
call void @bar()
|
||||||
|
br label %bb5
|
||||||
|
|
||||||
|
bb3:
|
||||||
|
call void @bar()
|
||||||
|
br label %bb5
|
||||||
|
|
||||||
|
bb4:
|
||||||
|
call void @bar()
|
||||||
|
br label %bb5
|
||||||
|
|
||||||
|
bb5:
|
||||||
|
ret void
|
||||||
|
}
|
Reference in New Issue
Block a user