Skip to content

Commit d9405f2

Browse files
committed
Check operand constraints and update mir checks.
1 parent 1c2072f commit d9405f2

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class AMDGPURewriteAGPRCopyMFMAImpl {
9696

9797
/// Compute the register class constraints based on the uses of \p Reg,
9898
/// excluding MFMA uses from which can be rewritten to change the register
99-
/// class constraint. This should be nearly identical to
100-
/// MachineRegisterInfo::recomputeRegClass.
99+
/// class constraint. MFMA scale operands need to be constraint checked.
100+
/// This should be nearly identical to MachineRegisterInfo::recomputeRegClass.
101101

102102
/// \p RewriteCandidates will collect the set of MFMA instructions that need
103103
/// to have the opcode mutated to perform the replacement.
@@ -151,9 +151,26 @@ bool AMDGPURewriteAGPRCopyMFMAImpl::recomputeRegClassExceptRewritable(
151151

152152
// We can swap the classes of dst + src2 as a pair to AGPR, so ignore the
153153
// effects of rewrite candidates. It just so happens that we can use
154-
// either AGPR or VGPR in src0/src1, so don't bother checking the
155-
// constraint effects of the individual operands.
154+
// either AGPR or VGPR in src0/src1. We still need to check constraint
155+
// effects for scale variant, which does not allow AGPR.
156156
if (isRewriteCandidate(*MI)) {
157+
158+
int AGPROp = AMDGPU::getMFMASrcCVDstAGPROp(MI->getOpcode());
159+
MachineInstrBuilder TmpMIB =
160+
BuildMI(*MI->getParent(), MI->getIterator(), MI->getDebugLoc(),
161+
TII.get(AGPROp));
162+
for (const MachineOperand &TmpMO : MI->operands())
163+
TmpMIB.add(TmpMO);
164+
MachineInstr *TmpMI = TmpMIB.getInstr();
165+
unsigned OpNo = &MO - &MI->getOperand(0);
166+
const TargetRegisterClass *EquivalentAGPRRegClass =
167+
TRI.getEquivalentAGPRClass(MRI.getRegClass(Reg));
168+
const TargetRegisterClass *Allowed = TmpMI->getRegClassConstraintEffect(
169+
OpNo, EquivalentAGPRRegClass, &TII, &TRI);
170+
TmpMI->eraseFromParent();
171+
if (!Allowed || Allowed != EquivalentAGPRRegClass)
172+
return false;
173+
157174
const MachineOperand *VDst =
158175
TII.getNamedOperand(*MI, AMDGPU::OpName::vdst);
159176
const MachineOperand *Src2 =
@@ -302,10 +319,6 @@ bool AMDGPURewriteAGPRCopyMFMAImpl::attemptReassignmentsToAGPR(
302319
const TargetRegisterClass *EquivalentAGPRRegClass =
303320
TRI.getEquivalentAGPRClass(MRI.getRegClass(InterferingReg));
304321

305-
// Do not reassign scale operands
306-
if (EquivalentAGPRRegClass == &AMDGPU::AGPR_32RegClass)
307-
return false;
308-
309322
MCPhysReg Assignable = AMDGPU::NoRegister;
310323
if (EquivalentAGPRRegClass->contains(PrefPhysReg) &&
311324
LRM.checkInterference(ReassignLI, PrefPhysReg) ==

llvm/test/CodeGen/AMDGPU/rewrite-vgpr-mfma-scale-to-agpr.mir

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -run-pass=greedy,amdgpu-rewrite-agpr-copy-mfma -verify-machineinstrs -o - %s 2>&1 | FileCheck %s
2-
# CHECK-NOT: Illegal virtual register for instruction
3-
# CHECK-NOT: Expected a VGPR_32 register, but got a AGPR_32 register
4-
2+
# CHECK: bb.1:
3+
# CHECK: dead %{{[0-9]+}}:vreg_128_align2 = V_MFMA_SCALE_F32_16X16X128_F8F6F4_f4_f4_vgprcd_e64 %{{[0-9]+}}, %{{[0-9]+}}, %{{[0-9]+}}, 4, 4, %{{[0-9]+}}, %[[REG:[0-9]+]], 4, 0, implicit $mode, implicit $exec
4+
# CHECK: %{{[0-9]+}}:agpr_32 = IMPLICIT_DEF
5+
# CHECK: %[[REG]]:vgpr_32 = COPY %{{[0-9]+}}
6+
57
# Test for issue in amdgpu-rewrite-agpr-copy-mfma, which reassigns scale operand
68
# in vgpr_32 register to agpr_32, not permitted by instruction format.
79
---

0 commit comments

Comments
 (0)