Skip to content

Commit f9b2faf

Browse files
committed
AMDGPU: Create InstrMapping from VGPR MFMA to equivalent AGPR instruction
This provides infrastructure for a future optimization.
1 parent 7e3187e commit f9b2faf

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
@@ -3174,6 +3174,15 @@ def getMFMAEarlyClobberOp : InstrMapping {
31743174
let ValueCols = [["0"]];
31753175
}
31763176

3177+
// Map from an mfma using VGPRs to one using AGPRs.
3178+
def getMFMASrcCVDstAGPROp : InstrMapping {
3179+
let FilterClass = "MFMATable";
3180+
let RowFields = ["AGPROp"];
3181+
let ColFields = ["MFMAKind"];
3182+
let KeyCol = ["VGPR"];
3183+
let ValueCols = [["AGPR"]];
3184+
}
3185+
31773186
// Maps an v_cmp instruction to its v_cmpx equivalent.
31783187
def getVCMPXOpFromVCMP : InstrMapping {
31793188
let FilterClass = "VCMPVCMPXTable";

llvm/lib/Target/AMDGPU/VOP3PInstructions.td

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

744744

745-
class MFMATable <bit is_mac, string Name> {
745+
class MFMATable <bit is_mac, string Kind, string Name,
746+
string AGPROpName = NAME> {
746747
bit IsMac = is_mac;
747748
string FMAOp = Name;
749+
string AGPROp = AGPROpName;
750+
751+
// Does this MFMA use "AGPR" or "VGPR" for srcC/vdst
752+
string MFMAKind = Kind;
748753
}
749754

750755
class MFMA_F8F6F4_WithSizeTable<int A, int B, Instruction ThisVariant, Instruction F8F8Variant> {
@@ -850,12 +855,12 @@ multiclass MAIInst<string OpName, string P, SDPatternOperator node = null_frag,
850855
let Constraints = !if(NoDstOverlap, "@earlyclobber $vdst", "") in {
851856
def _e64 : MAIInst<OpName, !cast<VOPProfileMAI>("VOPProfileMAI_" # P),
852857
!if(!or(NoDstOverlap, !eq(node, null_frag)), null_frag, AgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
853-
MFMATable<0, NAME # "_e64">;
858+
MFMATable<0, "AGPR", NAME # "_e64">;
854859

855860
let OtherPredicates = [isGFX90APlus], Mnemonic = OpName in
856861
def _vgprcd_e64 : MAIInst<OpName # "_vgprcd", !cast<VOPProfileMAI>("VOPProfileMAI_" # P # "_VCD"),
857862
!if(!or(NoDstOverlap, !eq(node, null_frag)), null_frag, VgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
858-
MFMATable<0, NAME # "_vgprcd_e64">;
863+
MFMATable<0, "VGPR", NAME # "_vgprcd_e64", NAME # "_e64">;
859864
}
860865

861866
if NoDstOverlap then {
@@ -864,12 +869,12 @@ multiclass MAIInst<string OpName, string P, SDPatternOperator node = null_frag,
864869
Mnemonic = OpName in {
865870
def "_mac_e64" : MAIInst<OpName # "_mac", !cast<VOPProfileMAI>("VOPProfileMAI_" # P),
866871
!if(!eq(node, null_frag), null_frag, AgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
867-
MFMATable<1, NAME # "_e64">;
872+
MFMATable<1, "AGPR", NAME # "_e64", NAME # "_mac_e64">;
868873

869874
let OtherPredicates = [isGFX90APlus] in
870875
def _mac_vgprcd_e64 : MAIInst<OpName # "_mac_vgprcd", !cast<VOPProfileMAI>("VOPProfileMAI_" # P # "_VCD"),
871876
!if(!eq(node, null_frag), null_frag, VgprMAIFrag<node, HasAbid, Scaled>), Scaled>,
872-
MFMATable<1, NAME # "_vgprcd_e64">;
877+
MFMATable<1, "VGPR", NAME # "_vgprcd_e64">;
873878
}
874879
}
875880
} // End isConvergent = 1, mayRaiseFPException = 0, ReadsModeReg = 1
@@ -886,23 +891,23 @@ multiclass ScaledMAIInst_mc<string OpName, string UnscaledOpName_, SDPatternOper
886891

887892
def _e64 : ScaledMAIInst<OpName,
888893
!cast<MAIInst>(UnscaledOpName#"_e64"), !if(NoDstOverlap, null_frag, AgprMAIFrag<node, HasAbid, true>)>,
889-
MFMATable<0, NAME # "_e64">;
894+
MFMATable<0, "AGPR", NAME # "_e64">;
890895

891896
def _vgprcd_e64 : ScaledMAIInst<OpName # "_vgprcd",
892897
!cast<MAIInst>(UnscaledOpName#"_vgprcd_e64"), !if(NoDstOverlap, null_frag, VgprMAIFrag<node, HasAbid, true>)>,
893-
MFMATable<0, NAME # "_vgprcd_e64">;
898+
MFMATable<0, "VGPR", NAME # "_vgprcd_e64", NAME # "_e64">;
894899

895900
if NoDstOverlap then {
896901
let Constraints = !if(NoDstOverlap, "$vdst = $src2", ""),
897902
isConvertibleToThreeAddress = NoDstOverlap,
898903
Mnemonic = UnscaledOpName_ in {
899904
def _mac_e64 : ScaledMAIInst<OpName # "_mac",
900905
!cast<MAIInst>(UnscaledOpName # "_mac_e64"), AgprMAIFrag<node, HasAbid, true>>,
901-
MFMATable<1, NAME # "_e64">;
906+
MFMATable<1, "AGPR", NAME # "_e64">;
902907

903908
def _mac_vgprcd_e64 : ScaledMAIInst<OpName # " _mac_vgprcd",
904909
!cast<MAIInst>(UnscaledOpName # "_mac_vgprcd_e64"), VgprMAIFrag<node, HasAbid, true>>,
905-
MFMATable<1, NAME # "_vgprcd_e64">;
910+
MFMATable<1, "VGPR", NAME # "_vgprcd_e64", NAME # "_mac_e64">;
906911
}
907912
}
908913
}

0 commit comments

Comments
 (0)