Skip to content

Commit

Permalink
[AMDGPU] Extend the SI Load/Store optimizer to combine more things.
Browse files Browse the repository at this point in the history
I've extended the load/store optimizer to be able to produce dwordx3
loads and stores, This change allows many more load/stores to be combined,
and results in much more optimal code for our hardware.

Differential Revision: https://reviews.llvm.org/D54042

llvm-svn: 348937
  • Loading branch information
Neil Henning committed Dec 12, 2018
1 parent ef8683a commit 76504a4
Show file tree
Hide file tree
Showing 13 changed files with 769 additions and 268 deletions.
41 changes: 41 additions & 0 deletions llvm/lib/Target/AMDGPU/BUFInstructions.td
Expand Up @@ -286,6 +286,12 @@ multiclass MTBUF_Pseudo_Stores<string opName, RegisterClass vdataClass,
// MUBUF classes
//===----------------------------------------------------------------------===//

class MUBUFGetBaseOpcode<string Op> {
string ret = !subst("DWORDX2", "DWORD",
!subst("DWORDX3", "DWORD",
!subst("DWORDX4", "DWORD", Op)));
}

class MUBUF_Pseudo <string opName, dag outs, dag ins,
string asmOps, list<dag> pattern=[]> :
InstSI<outs, ins, "", pattern>,
Expand All @@ -299,6 +305,9 @@ class MUBUF_Pseudo <string opName, dag outs, dag ins,
string Mnemonic = opName;
string AsmOperands = asmOps;

Instruction Opcode = !cast<Instruction>(NAME);
Instruction BaseOpcode = !cast<Instruction>(MUBUFGetBaseOpcode<NAME>.ret);

let VM_CNT = 1;
let EXP_CNT = 1;
let MUBUF = 1;
Expand All @@ -321,6 +330,7 @@ class MUBUF_Pseudo <string opName, dag outs, dag ins,
bits<1> has_offset = 1;
bits<1> has_slc = 1;
bits<1> has_tfe = 1;
bits<4> dwords = 0;
}

class MUBUF_Real <bits<7> op, MUBUF_Pseudo ps> :
Expand Down Expand Up @@ -394,6 +404,16 @@ class getMUBUFInsDA<list<RegisterClass> vdataList,
);
}

class getMUBUFDwords<RegisterClass regClass> {
string regClassAsInt = !cast<string>(regClass);
int ret =
!if(!eq(regClassAsInt, !cast<string>(VGPR_32)), 1,
!if(!eq(regClassAsInt, !cast<string>(VReg_64)), 2,
!if(!eq(regClassAsInt, !cast<string>(VReg_96)), 3,
!if(!eq(regClassAsInt, !cast<string>(VReg_128)), 4,
0))));
}

class getMUBUFIns<int addrKind, list<RegisterClass> vdataList=[], bit isLds = 0> {
dag ret =
!if(!eq(addrKind, BUFAddrKind.Offset), getMUBUFInsDA<vdataList, [], isLds>.ret,
Expand Down Expand Up @@ -454,6 +474,7 @@ class MUBUF_Load_Pseudo <string opName,
let Uses = !if(isLds, [EXEC, M0], [EXEC]);
let has_tfe = !if(isLds, 0, 1);
let lds = isLds;
let dwords = getMUBUFDwords<vdataClass>.ret;
}

// FIXME: tfe can't be an operand because it requires a separate
Expand Down Expand Up @@ -517,6 +538,7 @@ class MUBUF_Store_Pseudo <string opName,
let mayLoad = 0;
let mayStore = 1;
let maybeAtomic = 1;
let dwords = getMUBUFDwords<vdataClass>.ret;
}

multiclass MUBUF_Pseudo_Stores<string opName, RegisterClass vdataClass,
Expand Down Expand Up @@ -2068,3 +2090,22 @@ let SubtargetPredicate = HasPackedD16VMem in {
defm TBUFFER_STORE_FORMAT_D16_XYZ : MTBUF_Real_AllAddr_vi <0x0e>;
defm TBUFFER_STORE_FORMAT_D16_XYZW : MTBUF_Real_AllAddr_vi <0x0f>;
} // End HasUnpackedD16VMem.

def MUBUFInfoTable : GenericTable {
let FilterClass = "MUBUF_Pseudo";
let CppTypeName = "MUBUFInfo";
let Fields = ["Opcode", "BaseOpcode", "dwords", "has_vaddr", "has_srsrc", "has_soffset"];

let PrimaryKey = ["Opcode"];
let PrimaryKeyName = "getMUBUFOpcodeHelper";
}

def getMUBUFInfoFromOpcode : SearchIndex {
let Table = MUBUFInfoTable;
let Key = ["Opcode"];
}

def getMUBUFInfoFromBaseOpcodeAndDwords : SearchIndex {
let Table = MUBUFInfoTable;
let Key = ["BaseOpcode", "dwords"];
}

0 comments on commit 76504a4

Please sign in to comment.