Skip to content

Commit f3af593

Browse files
authored
AMDGPU: Create InstrMapping from VGPR MFMA to equivalent AGPR instruction (#117102)
This provides infrastructure for a future optimization.
1 parent 15676ec commit f3af593

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,11 @@ namespace AMDGPU {
15681568
LLVM_READONLY
15691569
int getMFMAEarlyClobberOp(uint16_t Opcode);
15701570

1571+
/// \returns Version of an MFMA instruction which uses AGPRs for srcC and
1572+
/// vdst, given an \p Opcode of an MFMA which uses VGPRs for srcC/vdst.
1573+
LLVM_READONLY
1574+
int getMFMASrcCVDstAGPROp(uint16_t Opcode);
1575+
15711576
/// \returns v_cmpx version of a v_cmp instruction.
15721577
LLVM_READONLY
15731578
int getVCMPXOpFromVCMP(uint16_t Opcode);

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,15 @@ def getMFMAEarlyClobberOp : InstrMapping {
32113211
let ValueCols = [["0"]];
32123212
}
32133213

3214+
// Map from an mfma using VGPRs to one using AGPRs.
3215+
def getMFMASrcCVDstAGPROp : InstrMapping {
3216+
let FilterClass = "MFMATable";
3217+
let RowFields = ["AGPROp"];
3218+
let ColFields = ["MFMAKind"];
3219+
let KeyCol = ["VGPR"];
3220+
let ValueCols = [["AGPR"]];
3221+
}
3222+
32143223
// Maps an v_cmp instruction to its v_cmpx equivalent.
32153224
def getVCMPXOpFromVCMP : InstrMapping {
32163225
let FilterClass = "VCMPVCMPXTable";

llvm/lib/Target/AMDGPU/VOP3PInstructions.td

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,14 @@ def VOPProfileMAI_I32_V4I32_X16 : VOPProfileMAI<VOP_V16I32_V4I32_V4I32_V16I3
758758
def VOPProfileMAI_I32_V4I32_X16_VCD : VOPProfileMAI<VOP_V16I32_V4I32_V4I32_V16I32, VISrc_512_b32, VDst_512, AVSrc_128>;
759759

760760

761-
class MFMATable <bit is_mac, string Name> {
761+
class MFMATable <bit is_mac, string Kind, string Name,
762+
string AGPROpName = NAME> {
762763
bit IsMac = is_mac;
763764
string FMAOp = Name;
765+
string AGPROp = AGPROpName;
766+
767+
// Does this MFMA use "AGPR" or "VGPR" for srcC/vdst
768+
string MFMAKind = Kind;
764769
}
765770

766771
class MFMA_F8F6F4_WithSizeTable<int A, int B, Instruction ThisVariant, Instruction F8F8Variant> {
@@ -866,12 +871,12 @@ multiclass MAIInst<string OpName, string P, SDPatternOperator node = null_frag,
866871
let Constraints = !if(NoDstOverlap, "@earlyclobber $vdst", "") in {
867872
def _e64 : MAIInst<OpName, !cast<VOPProfileMAI>("VOPProfileMAI_" # P),
868873
!if(!or(NoDstOverlap, !eq(node, null_frag)), null_frag, AgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
869-
MFMATable<0, NAME # "_e64">;
874+
MFMATable<0, "AGPR", NAME # "_e64">;
870875

871876
let OtherPredicates = [isGFX90APlus], Mnemonic = OpName in
872877
def _vgprcd_e64 : MAIInst<OpName # "_vgprcd", !cast<VOPProfileMAI>("VOPProfileMAI_" # P # "_VCD"),
873878
!if(!or(NoDstOverlap, !eq(node, null_frag)), null_frag, VgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
874-
MFMATable<0, NAME # "_vgprcd_e64">;
879+
MFMATable<0, "VGPR", NAME # "_vgprcd_e64", NAME # "_e64">;
875880
}
876881

877882
if NoDstOverlap then {
@@ -880,12 +885,12 @@ multiclass MAIInst<string OpName, string P, SDPatternOperator node = null_frag,
880885
Mnemonic = OpName in {
881886
def "_mac_e64" : MAIInst<OpName # "_mac", !cast<VOPProfileMAI>("VOPProfileMAI_" # P),
882887
!if(!eq(node, null_frag), null_frag, AgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
883-
MFMATable<1, NAME # "_e64">;
888+
MFMATable<1, "AGPR", NAME # "_e64", NAME # "_mac_e64">;
884889

885890
let OtherPredicates = [isGFX90APlus] in
886891
def _mac_vgprcd_e64 : MAIInst<OpName # "_mac_vgprcd", !cast<VOPProfileMAI>("VOPProfileMAI_" # P # "_VCD"),
887892
!if(!eq(node, null_frag), null_frag, VgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
888-
MFMATable<1, NAME # "_vgprcd_e64">;
893+
MFMATable<1, "VGPR", NAME # "_vgprcd_e64">;
889894
}
890895
}
891896
} // End isConvergent = 1, mayRaiseFPException = 0, ReadsModeReg = 1
@@ -902,23 +907,23 @@ multiclass ScaledMAIInst_mc<string OpName, string UnscaledOpName_, SDPatternOper
902907

903908
def _e64 : ScaledMAIInst<OpName,
904909
!cast<MAIInst>(UnscaledOpName#"_e64"), !if(NoDstOverlap, null_frag, AgprMAIFrag<node, HasAbid, true>)>,
905-
MFMATable<0, NAME # "_e64">;
910+
MFMATable<0, "AGPR", NAME # "_e64">;
906911

907912
def _vgprcd_e64 : ScaledMAIInst<OpName # "_vgprcd",
908913
!cast<MAIInst>(UnscaledOpName#"_vgprcd_e64"), !if(NoDstOverlap, null_frag, VgprMAIFrag<node, HasAbid, true>)>,
909-
MFMATable<0, NAME # "_vgprcd_e64">;
914+
MFMATable<0, "VGPR", NAME # "_vgprcd_e64", NAME # "_e64">;
910915

911916
if NoDstOverlap then {
912917
let Constraints = !if(NoDstOverlap, "$vdst = $src2", ""),
913918
isConvertibleToThreeAddress = NoDstOverlap,
914919
Mnemonic = UnscaledOpName_ in {
915920
def _mac_e64 : ScaledMAIInst<OpName # "_mac",
916921
!cast<MAIInst>(UnscaledOpName # "_mac_e64"), AgprMAIFrag<node, HasAbid, true>>,
917-
MFMATable<1, NAME # "_e64">;
922+
MFMATable<1, "AGPR", NAME # "_e64">;
918923

919924
def _mac_vgprcd_e64 : ScaledMAIInst<OpName # " _mac_vgprcd",
920925
!cast<MAIInst>(UnscaledOpName # "_mac_vgprcd_e64"), VgprMAIFrag<node, HasAbid, true>>,
921-
MFMATable<1, NAME # "_vgprcd_e64">;
926+
MFMATable<1, "VGPR", NAME # "_vgprcd_e64", NAME # "_mac_e64">;
922927
}
923928
}
924929
}

0 commit comments

Comments
 (0)