@@ -99,8 +99,8 @@ class AMDGPURewriteAGPRCopyMFMAImpl {
9999
100100 // / Compute the register class constraints based on the uses of \p Reg,
101101 // / excluding MFMA uses from which can be rewritten to change the register
102- // / class constraint. This should be nearly identical to
103- // / MachineRegisterInfo::recomputeRegClass.
102+ // / class constraint. MFMA scale operands need to be constraint checked.
103+ // / This should be nearly identical to MachineRegisterInfo::recomputeRegClass.
104104
105105 // / \p RewriteCandidates will collect the set of MFMA instructions that need
106106 // / to have the opcode mutated to perform the replacement.
@@ -154,9 +154,26 @@ bool AMDGPURewriteAGPRCopyMFMAImpl::recomputeRegClassExceptRewritable(
154154
155155 // We can swap the classes of dst + src2 as a pair to AGPR, so ignore the
156156 // effects of rewrite candidates. It just so happens that we can use
157- // either AGPR or VGPR in src0/src1, so don't bother checking the
158- // constraint effects of the individual operands .
157+ // either AGPR or VGPR in src0/src1. We still need to check constraint
158+ // effects for scale variant, which does not allow AGPR .
159159 if (isRewriteCandidate (*MI)) {
160+
161+ int AGPROp = AMDGPU::getMFMASrcCVDstAGPROp (MI->getOpcode ());
162+ MachineInstrBuilder TmpMIB =
163+ BuildMI (*MI->getParent (), MI->getIterator (), MI->getDebugLoc (),
164+ TII.get (AGPROp));
165+ for (const MachineOperand &TmpMO : MI->operands ())
166+ TmpMIB.add (TmpMO);
167+ MachineInstr *TmpMI = TmpMIB.getInstr ();
168+ unsigned OpNo = &MO - &MI->getOperand (0 );
169+ const TargetRegisterClass *EquivalentAGPRRegClass =
170+ TRI.getEquivalentAGPRClass (MRI.getRegClass (Reg));
171+ const TargetRegisterClass *Allowed = TmpMI->getRegClassConstraintEffect (
172+ OpNo, EquivalentAGPRRegClass, &TII, &TRI);
173+ TmpMI->eraseFromParent ();
174+ if (!Allowed || Allowed != EquivalentAGPRRegClass)
175+ return false ;
176+
160177 const MachineOperand *VDst =
161178 TII.getNamedOperand (*MI, AMDGPU::OpName::vdst);
162179 const MachineOperand *Src2 =
0 commit comments