Skip to content

Commit a83be7b

Browse files
committed
[Machine-Combiner] Add option to apply machine-combiner recursively
This option allows applying patterns that depend on previous patterns firing. For example, we can rewrite chains of MLA operations into a tree for increased ILP, but only if the MLA rewriting pattern has already been applied
1 parent e258634 commit a83be7b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

llvm/lib/CodeGen/MachineCombiner.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ static cl::opt<bool> dump_intrs("machine-combiner-dump-subst-intrs", cl::Hidden,
4747
cl::desc("Dump all substituted intrs"),
4848
cl::init(false));
4949

50+
static cl::opt<bool> CombineRecurse(
51+
"machine-combiner-recurse", cl::Hidden,
52+
cl::desc("Apply machine combiner recursively until block is stable."),
53+
cl::init(false));
54+
5055
#ifdef EXPENSIVE_CHECKS
5156
static cl::opt<bool> VerifyPatternOrder(
5257
"machine-combiner-verify-pattern-order", cl::Hidden,
@@ -743,8 +748,20 @@ bool MachineCombiner::runOnMachineFunction(MachineFunction &MF) {
743748
bool Changed = false;
744749

745750
// Try to combine instructions.
746-
for (auto &MBB : MF)
747-
Changed |= combineInstructions(&MBB);
751+
for (auto &MBB : MF) {
752+
if (CombineRecurse) {
753+
bool MBBChanged = false;
754+
// Combine instructions recursively on the MBB, to allow applying patterns
755+
// iteratively, for example recombining chains of MLA instructions to
756+
// allow for more parallelism.
757+
do {
758+
MBBChanged = combineInstructions(&MBB);
759+
} while (MBBChanged);
760+
Changed |= MBBChanged;
761+
} else {
762+
Changed |= combineInstructions(&MBB);
763+
}
764+
}
748765

749766
return Changed;
750767
}

0 commit comments

Comments
 (0)