Skip to content

AMDGPU: Create InstrMapping from VGPR MFMA to equivalent AGPR instruction #117102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,11 @@ namespace AMDGPU {
LLVM_READONLY
int getMFMAEarlyClobberOp(uint16_t Opcode);

/// \returns Version of an MFMA instruction which uses AGPRs for srcC and
/// vdst, given an \p Opcode of an MFMA which uses VGPRs for srcC/vdst.
LLVM_READONLY
int getMFMASrcCVDstAGPROp(uint16_t Opcode);

/// \returns v_cmpx version of a v_cmp instruction.
LLVM_READONLY
int getVCMPXOpFromVCMP(uint16_t Opcode);
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/AMDGPU/SIInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,15 @@ def getMFMAEarlyClobberOp : InstrMapping {
let ValueCols = [["0"]];
}

// Map from an mfma using VGPRs to one using AGPRs.
def getMFMASrcCVDstAGPROp : InstrMapping {
let FilterClass = "MFMATable";
let RowFields = ["AGPROp"];
let ColFields = ["MFMAKind"];
let KeyCol = ["VGPR"];
let ValueCols = [["AGPR"]];
}

// Maps an v_cmp instruction to its v_cmpx equivalent.
def getVCMPXOpFromVCMP : InstrMapping {
let FilterClass = "VCMPVCMPXTable";
Expand Down
23 changes: 14 additions & 9 deletions llvm/lib/Target/AMDGPU/VOP3PInstructions.td
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,14 @@ def VOPProfileMAI_I32_V4I32_X16 : VOPProfileMAI<VOP_V16I32_V4I32_V4I32_V16I3
def VOPProfileMAI_I32_V4I32_X16_VCD : VOPProfileMAI<VOP_V16I32_V4I32_V4I32_V16I32, VISrc_512_b32, VDst_512, AVSrc_128>;


class MFMATable <bit is_mac, string Name> {
class MFMATable <bit is_mac, string Kind, string Name,
string AGPROpName = NAME> {
bit IsMac = is_mac;
string FMAOp = Name;
string AGPROp = AGPROpName;

// Does this MFMA use "AGPR" or "VGPR" for srcC/vdst
string MFMAKind = Kind;
}

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

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

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

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

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

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

if NoDstOverlap then {
let Constraints = !if(NoDstOverlap, "$vdst = $src2", ""),
isConvertibleToThreeAddress = NoDstOverlap,
Mnemonic = UnscaledOpName_ in {
def _mac_e64 : ScaledMAIInst<OpName # "_mac",
!cast<MAIInst>(UnscaledOpName # "_mac_e64"), AgprMAIFrag<node, HasAbid, true>>,
MFMATable<1, NAME # "_e64">;
MFMATable<1, "AGPR", NAME # "_e64">;

def _mac_vgprcd_e64 : ScaledMAIInst<OpName # " _mac_vgprcd",
!cast<MAIInst>(UnscaledOpName # "_mac_vgprcd_e64"), VgprMAIFrag<node, HasAbid, true>>,
MFMATable<1, NAME # "_vgprcd_e64">;
MFMATable<1, "VGPR", NAME # "_vgprcd_e64", NAME # "_mac_e64">;
}
}
}
Expand Down
Loading