Skip to content

Commit bae4f80

Browse files
hjagasiaAMDarsenm
authored andcommitted
[AMDGPU] Fix AGPR_32 reg assign for mfma scale ops (llvm#168964)
In MFMA rewrite pass, prevent AGPR_32 reg class assignment for scale operands, not permitted by instruction format. --------- Co-authored-by: Matt Arsenault <[email protected]>
1 parent 087a61c commit bae4f80

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

llvm/lib/Target/AMDGPU/AMDGPURewriteAGPRCopyMFMA.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class AMDGPURewriteAGPRCopyMFMAImpl {
9797

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

103103
/// \p RewriteCandidates will collect the set of MFMA instructions that need
104104
/// to have the opcode mutated to perform the replacement.
@@ -152,9 +152,16 @@ bool AMDGPURewriteAGPRCopyMFMAImpl::recomputeRegClassExceptRewritable(
152152

153153
// We can swap the classes of dst + src2 as a pair to AGPR, so ignore the
154154
// effects of rewrite candidates. It just so happens that we can use
155-
// either AGPR or VGPR in src0/src1, so don't bother checking the
156-
// constraint effects of the individual operands.
155+
// either AGPR or VGPR in src0/src1. We still need to check constraint
156+
// effects for scale variant, which does not allow AGPR.
157157
if (isRewriteCandidate(*MI)) {
158+
int AGPROp = AMDGPU::getMFMASrcCVDstAGPROp(MI->getOpcode());
159+
const MCInstrDesc &AGPRDesc = TII.get(AGPROp);
160+
const TargetRegisterClass *NewRC =
161+
TII.getRegClass(AGPRDesc, MO.getOperandNo());
162+
if (!TRI.hasAGPRs(NewRC))
163+
return false;
164+
158165
const MachineOperand *VDst =
159166
TII.getNamedOperand(*MI, AMDGPU::OpName::vdst);
160167
const MachineOperand *Src2 =

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# RUN: not --crash 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: Illegal virtual register for instruction
3-
# CHECK: Expected a VGPR_32 register, but got a AGPR_32 register
4-
1+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -run-pass=greedy,amdgpu-rewrite-agpr-copy-mfma -verify-machineinstrs -o - %s | FileCheck %s
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)