Skip to content

[BranchFolding] Add a hook to override tail merge size #99025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,12 @@ class TargetInstrInfo : public MCInstrInfo {
return OptLevel >= CodeGenOptLevel::Aggressive ? 4 : 2;
}

/// Returns the target-specific default value for tail merging.
/// This value will be used if the tail-merge-size argument is not provided.
virtual unsigned getTailMergeSize(const MachineFunction &MF) const {
return 3;
}

/// Returns the callee operand from the given \p MI.
virtual const MachineOperand &getCalleeOperand(const MachineInstr &MI) const {
return MI.getOperand(0);
Expand Down
9 changes: 6 additions & 3 deletions llvm/lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ TailMergeThreshold("tail-merge-threshold",
cl::init(150), cl::Hidden);

// Heuristic for tail merging (and, inversely, tail duplication).
// TODO: This should be replaced with a target query.
static cl::opt<unsigned>
TailMergeSize("tail-merge-size",
cl::desc("Min number of instructions to consider tail merging"),
Expand Down Expand Up @@ -145,8 +144,6 @@ BranchFolder::BranchFolder(bool DefaultEnableTailMerge, bool CommonHoist,
ProfileSummaryInfo *PSI, unsigned MinTailLength)
: EnableHoistCommonCode(CommonHoist), MinCommonTailLength(MinTailLength),
MBBFreqInfo(FreqInfo), MBPI(ProbInfo), PSI(PSI) {
if (MinCommonTailLength == 0)
MinCommonTailLength = TailMergeSize;
switch (FlagEnableTailMerge) {
case cl::BOU_UNSET:
EnableTailMerge = DefaultEnableTailMerge;
Expand Down Expand Up @@ -195,6 +192,12 @@ bool BranchFolder::OptimizeFunction(MachineFunction &MF,
MLI = mli;
this->MRI = &MRI;

if (MinCommonTailLength == 0) {
MinCommonTailLength = TailMergeSize.getNumOccurrences() > 0
? TailMergeSize
: TII->getTailMergeSize(MF);
}

UpdateLiveIns = MRI.tracksLiveness() && TRI->trackLivenessAfterRegAlloc(MF);
if (!UpdateLiveIns)
MRI.invalidateLiveness();
Expand Down
Loading