Skip to content

Commit d7ccfe1

Browse files
- Renamed CpySrc -> CopySrc
- Moved switch in shouldUseFormStridedPseudo outside of loop - Added a description of the pseudo nodes to SMEInstrFormats.td
1 parent 645e30b commit d7ccfe1

File tree

3 files changed

+44
-31
lines changed

3 files changed

+44
-31
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8656,6 +8656,18 @@ static bool checkZExtBool(SDValue Arg, const SelectionDAG &DAG) {
86568656
bool shouldUseFormStridedPseudo(MachineInstr &MI) {
86578657
MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
86588658

8659+
const TargetRegisterClass *RegClass = nullptr;
8660+
switch (MI.getOpcode()) {
8661+
case AArch64::FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO:
8662+
RegClass = &AArch64::ZPR2StridedOrContiguousRegClass;
8663+
break;
8664+
case AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO:
8665+
RegClass = &AArch64::ZPR4StridedOrContiguousRegClass;
8666+
break;
8667+
default:
8668+
llvm_unreachable("Unexpected opcode.");
8669+
}
8670+
86598671
MCRegister SubReg = MCRegister::NoRegister;
86608672
for (unsigned I = 1; I < MI.getNumOperands(); ++I) {
86618673
MachineOperand &MO = MI.getOperand(I);
@@ -8665,26 +8677,15 @@ bool shouldUseFormStridedPseudo(MachineInstr &MI) {
86658677
if (!Def || !Def->getParent()->isCopy())
86668678
return false;
86678679

8668-
const MachineOperand &CpySrc = Def->getParent()->getOperand(1);
8669-
MachineOperand *CopySrcOp = MRI.getOneDef(CpySrc.getReg());
8670-
unsigned OpSubReg = CpySrc.getSubReg();
8680+
const MachineOperand &CopySrc = Def->getParent()->getOperand(1);
8681+
unsigned OpSubReg = CopySrc.getSubReg();
86718682
if (SubReg == MCRegister::NoRegister)
86728683
SubReg = OpSubReg;
8684+
8685+
MachineOperand *CopySrcOp = MRI.getOneDef(CopySrc.getReg());
86738686
if (!CopySrcOp || !CopySrcOp->isReg() || OpSubReg != SubReg)
86748687
return false;
86758688

8676-
const TargetRegisterClass *RegClass = nullptr;
8677-
switch (MI.getNumOperands() - 1) {
8678-
case 2:
8679-
RegClass = &AArch64::ZPR2StridedOrContiguousRegClass;
8680-
break;
8681-
case 4:
8682-
RegClass = &AArch64::ZPR4StridedOrContiguousRegClass;
8683-
break;
8684-
default:
8685-
llvm_unreachable("Unexpected number of operands to pseudo.");
8686-
}
8687-
86888689
if (MRI.getRegClass(CopySrcOp->getReg()) != RegClass)
86898690
return false;
86908691
}
@@ -8721,22 +8722,23 @@ void AArch64TargetLowering::AdjustInstrPostInstrSelection(MachineInstr &MI,
87218722
MI.getOpcode() == AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO) {
87228723
// If input values to the FORM_TRANSPOSED_REG_TUPLE pseudo aren't copies
87238724
// from a StridedOrContiguous class, fall back on REG_SEQUENCE node.
8724-
if (!shouldUseFormStridedPseudo(MI)) {
8725-
static const unsigned SubRegs[] = {AArch64::zsub0, AArch64::zsub1,
8726-
AArch64::zsub2, AArch64::zsub3};
8727-
8728-
const TargetInstrInfo *TII = Subtarget->getInstrInfo();
8729-
MachineInstrBuilder MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
8730-
TII->get(TargetOpcode::REG_SEQUENCE),
8731-
MI.getOperand(0).getReg());
8732-
8733-
for (unsigned I = 1; I < MI.getNumOperands(); ++I) {
8734-
MIB.add(MI.getOperand(I));
8735-
MIB.addImm(SubRegs[I - 1]);
8736-
}
8725+
if (shouldUseFormStridedPseudo(MI))
8726+
return;
87378727

8738-
MI.eraseFromParent();
8728+
static const unsigned SubRegs[] = {AArch64::zsub0, AArch64::zsub1,
8729+
AArch64::zsub2, AArch64::zsub3};
8730+
8731+
const TargetInstrInfo *TII = Subtarget->getInstrInfo();
8732+
MachineInstrBuilder MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
8733+
TII->get(TargetOpcode::REG_SEQUENCE),
8734+
MI.getOperand(0).getReg());
8735+
8736+
for (unsigned I = 1; I < MI.getNumOperands(); ++I) {
8737+
MIB.add(MI.getOperand(I));
8738+
MIB.addImm(SubRegs[I - 1]);
87398739
}
8740+
8741+
MI.eraseFromParent();
87408742
return;
87418743
}
87428744

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,8 @@ bool AArch64RegisterInfo::getRegAllocationHints(
11301130
MI.getOpcode() != AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO)
11311131
continue;
11321132

1133-
switch (MI.getOperand(1).getSubReg()) {
1133+
unsigned FirstOpSubReg = MI.getOperand(1).getSubReg();
1134+
switch (FirstOpSubReg) {
11341135
case AArch64::zsub0:
11351136
case AArch64::zsub1:
11361137
case AArch64::zsub2:
@@ -1146,7 +1147,7 @@ bool AArch64RegisterInfo::getRegAllocationHints(
11461147
continue;
11471148

11481149
MCRegister TupleStartReg =
1149-
getSubReg(VRM->getPhys(FirstOpVirtReg), MI.getOperand(1).getSubReg());
1150+
getSubReg(VRM->getPhys(FirstOpVirtReg), FirstOpSubReg);
11501151
for (unsigned I = 0; I < Order.size(); ++I)
11511152
if (MCRegister R = getSubReg(Order[I], AArch64::zsub0))
11521153
if (R == TupleStartReg)

llvm/lib/Target/AArch64/SMEInstrFormats.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ def tileslicerange0s4 : ComplexPattern<i32, 2, "SelectSMETileSlice<0, 4>", []>;
3434

3535
def am_sme_indexed_b4 :ComplexPattern<iPTR, 2, "SelectAddrModeIndexedSVE<0,15>", [], [SDNPWantRoot]>;
3636

37+
// The FORM_TRANSPOSED_REG_TUPLE pseudos defined below are intended to
38+
// improve register allocation for intrinsics which use strided and contiguous
39+
// multi-vector registers, avoiding unnecessary copies.
40+
// If the operands of the pseudo are copies where the source register is in
41+
// the StridedOrContiguous class, the pseudo is used to provide a hint to the
42+
// register allocator suggesting a contigious multi-vector register which
43+
// matches the subregister sequence used by the operands.
44+
// If the operands do not match this pattern, the pseudos are expanded
45+
// to a REG_SEQUENCE using the post-isel hook.
46+
3747
def FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO :
3848
Pseudo<(outs ZPR2Mul2:$tup),
3949
(ins ZPR:$zn0, ZPR:$zn1), []>, Sched<[]>{

0 commit comments

Comments
 (0)