Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
37 changes: 37 additions & 0 deletions llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,43 @@ 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)

// Look through uses of the register and if the FORM_TRANSPOSED_REG_TUPLE
// pseudo is found in the uses, set HintStrided.
if (any_of(MRI.use_nodbg_instructions(VirtReg), [](MachineInstr &Use) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (any_of(MRI.use_nodbg_instructions(VirtReg), [](MachineInstr &Use) {
if (any_of(MRI.use_nodbg_instructions(VirtReg), [](const MachineInstr &Use) {

return Use.getOpcode() ==
AArch64::FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO ||
Use.getOpcode() ==
AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO;
})) {

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

for (MCPhysReg Reg : Order)
if (StridedRC->contains(Reg))
Hints.push_back(Reg);

return TargetRegisterInfo::getRegAllocationHints(VirtReg, Order, Hints,
MF, VRM);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: if you want to use the nested if's, then maybe move this to the outer if-then block? alternatively, you could fold the if condition above with the if above it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've folded the two nested if conditions at the beginning of this block

}
}

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