[llvm] [AArch64] Expand FORM_TRANSPOSED_REG_TUPLE to copies before regalloc (PR #207205)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 03:17:40 PDT 2026
================
@@ -510,6 +510,37 @@ AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
return I.get();
}
+// Encourage placing FORM_TRANSPOSED_REG immediately before the instruction that
+// uses/consumes it. This ensures it has a short live range, which means we're
+// more likely to allocate registers its operands first (which works best for
+// the hints in AArch64RegisterInfo::getRegAllocationHints).
+static bool scheduleFormTransposedTupleAdjacentToUsers(
+ const TargetInstrInfo &TII, const TargetSubtargetInfo &TSI,
+ const MachineInstr *FirstMI, const MachineInstr &SecondMI) {
+
+ auto *TRI = TSI.getRegisterInfo();
+ if (!FirstMI) {
+ // The SecondMI must be a multi-vector operation. So limit this to
+ // instructions that use full tuple registers (not a sub-register).
+ const MachineRegisterInfo &MRI = SecondMI.getMF()->getRegInfo();
+ for (const MachineOperand &Use : SecondMI.uses()) {
+ if (Use.isReg() && Use.getReg().isVirtual() && !Use.getSubReg() &&
+ TRI->isSubRegValidForRegClass(MRI.getRegClass(Use.getReg()),
+ AArch64::zsub0))
----------------
MacDue wrote:
>From the docs of `MacroFusionPredTy`:
```
/// Check if the instr pair, FirstMI and SecondMI, should be fused
/// together. Given SecondMI, when FirstMI is unspecified, then check if
/// SecondMI may be part of a fused pair at all.
```
The check with `FirstMI == nullptr` is to filter out cases that definitely can't be "fused". I check for instructions that take full tuple operands to filter out any instructions that are not multi-vector operations.
If you return `true` when `FirstMI == nullptr`, that's saying every instruction is a fusion candidate, which results in extra work:
```
// With filter (only try multi-vector like instructions):
30 aarch64-macro-fusion - Fusion attempts
27 machine-scheduler - Number of instr pairs fused
```
```
// Without filter (always return true):
317 aarch64-macro-fusion - Fusion attempts
27 machine-scheduler - Number of instr pairs fused
```
Maybe it's not a concern, but it results it (for a moderately sized function), 10x more fusion attempts which may a compile-time impact.
https://github.com/llvm/llvm-project/pull/207205
More information about the llvm-commits
mailing list