Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
48 changes: 48 additions & 0 deletions llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,54 @@ bool AArch64RegisterInfo::getRegAllocationHints(
SmallVectorImpl<MCPhysReg> &Hints, const MachineFunction &MF,
const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
const MachineRegisterInfo &MRI = MF.getRegInfo();
unsigned RegID = MRI.getRegClass(VirtReg)->getID();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move below the comment.


// Since the SVE calling convention preserves registers Z8-Z23, there are no
// ZPR2Strided or ZPR4Strided registers which do not overlap with the
// callee-saved registers. These will be pushed to the back of the allocation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
// Since the SVE calling convention preserves registers Z8-Z23, there are no
// ZPR2Strided or ZPR4Strided registers which do not overlap with the
// callee-saved registers. These will be pushed to the back of the allocation
// The SVE calling convention preserves registers Z8-Z23. As a result, there are no
// ZPR2Strided or ZPR4Strided registers that do not overlap with the
// callee-saved registers and so by default these will be pushed to the back of the allocation

// order for the ZPRStridedOrContiguous classes.
// However, if any of the instructions which define VirtReg are
// ZPRStridedOrContiguous registers used by a FORM_TRANSPOSED_REG_TUPLE
// pseudo, it will likely be better to try assigning a strided register
// anyway to avoid extra copy instructions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
// However, if any of the instructions which define VirtReg are
// ZPRStridedOrContiguous registers used by a FORM_TRANSPOSED_REG_TUPLE
// pseudo, it will likely be better to try assigning a strided register
// anyway to avoid extra copy instructions.
// If any of the instructions which define VirtReg are
// used by the FORM_TRANSPOSED_REG_TUPLE
// pseudo, we actually want to favour reducing copy instructions over reducing the number of clobbered callee-save registers, so we add the registers as a hint.

(+clang-format)


if (RegID == AArch64::ZPR2StridedOrContiguousRegClassID ||
RegID == AArch64::ZPR4StridedOrContiguousRegClassID) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty newline at start of basic block (also below)

if (!MF.getInfo<AArch64FunctionInfo>()->isSVECC())
return TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints,
MF, VRM);

for (MachineInstr &MI : MRI.def_instructions(VirtReg)) {
// Look through uses of the register and if the FORM_TRANSPOSED_REG_TUPLE
// pseudo is found in the uses, set HintStrided.
bool HintStrided = false;
for (MachineInstr &Use : MRI.use_nodbg_instructions(VirtReg)) {
unsigned UseOp = Use.getOpcode();
if (UseOp == AArch64::FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO ||
UseOp == AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO) {
HintStrided = true;
break;
}
}

if (!HintStrided)
continue;

// Push the list of 2/4 ZPRStrided registers to Hints to ensure we try to
// allocate these first.
TargetRegisterClass StridedRC =
RegID == AArch64::ZPR2StridedOrContiguousRegClassID
? AArch64::ZPR2StridedRegClass
: AArch64::ZPR4StridedRegClass;

for (MCPhysReg Reg : StridedRC.getRawAllocationOrder(MF))
Hints.push_back(Reg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than going through the raw allocation order, you can go through the registers in Order (they should already be ordered by preference) and add the registers if they are part of StridedRC.
You can then remove the check above for if (!MF.getInfo<AArch64FunctionInfo>()->isSVECC()) return ....

}

return TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints, MF,
VRM);
}

for (MachineInstr &MI : MRI.def_instructions(VirtReg)) {
if (MI.getOpcode() != AArch64::FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO &&
Expand Down
Loading
Loading