[llvm] [AMDGPU] Fix RewriteMFMAFormSchedStage (PR #194887)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 02:12:58 PDT 2026
================
@@ -2255,6 +2250,31 @@ void GCNSchedStage::modifyRegionSchedule(unsigned RegionIdx,
DAG.Regions[RegionIdx].first = MIOrder.front();
}
+void RewriteMFMAFormStage::resetRewriteCandsToVGPR(
+ ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands) {
+ for (auto &[MI, OriginalOpcode] : RewriteCands) {
+ assert(TII->isMAI(*MI));
+ const TargetRegisterClass *ADefRC =
+ DAG.MRI.getRegClass(MI->getOperand(0).getReg());
+ const TargetRegisterClass *VDefRC = SRI->getEquivalentVGPRClass(ADefRC);
----------------
xgxanq wrote:
> Would be slightly safer to use the operand class from the TII->getRegClass() on the InstrDesc for OriginalOpcode
No, Can't do like this. In llvm/test/CodeGen/AMDGPU/sched_mfma_rewrite_diff_types.mir.
%13.sub0_sub1_sub2_sub3:vreg_1024_align2 = V_MFMA_SCALE_F32_16X16X128_F8F6F4_f4_f4_vgprcd_e64 %60, %61, %84:vreg_128_align2, ...
TII->getRegClass(TII->get(OriginalOpcode), 0) returns the register class of operand 0 of the instruction descriptor — for _vgprcd_e64 variant of V_MFMA_SCALE_F32_16X16X128_F8F6F4_f4_f4, that's VDst_128 = vreg_128_align2
(128-bit)
But the actual virtual register %13 is vreg_1024_align2 (1024-bit) because it's used with sub0_sub1_sub2_sub3 subreg. The instruction descriptor's operand 0 class describes the full destination, but the VReg is a larger
register that the MFMA writes to via subreg.instead of getting the register class from the instruction descriptor (which gives the "inner" 128-bit class, not the actual VReg class), we should derive it from the
current (AGPR) class by calling getEquivalentVGPRClass
https://github.com/llvm/llvm-project/pull/194887
More information about the llvm-commits
mailing list