Skip to content

Commit a075ac0

Browse files
committed
[RISCV] Made vcompress pseudoinstruction SEW-aware
1 parent 5a0c27d commit a075ac0

File tree

2 files changed

+96
-11
lines changed

2 files changed

+96
-11
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,12 +1910,16 @@ multiclass VPseudoVIOT_M {
19101910
multiclass VPseudoVCPR_V {
19111911
foreach m = MxList in {
19121912
defvar mx = m.MX;
1913-
defvar WriteVCompressV_MX = !cast<SchedWrite>("WriteVCompressV_" # mx);
1914-
defvar ReadVCompressV_MX = !cast<SchedRead>("ReadVCompressV_" # mx);
1915-
1913+
defvar sews = SchedSEWSet<mx>.val;
19161914
let VLMul = m.value in
1917-
def _VM # "_" # m.MX : VPseudoUnaryAnyMask<m.vrclass, m.vrclass>,
1918-
Sched<[WriteVCompressV_MX, ReadVCompressV_MX, ReadVCompressV_MX]>;
1915+
foreach e = sews in {
1916+
defvar suffix = "_" # m.MX # "_E" # e;
1917+
defvar WriteVCompressV_MX_E = !cast<SchedWrite>("WriteVCompressV" # suffix);
1918+
defvar ReadVCompressV_MX_E = !cast<SchedRead>("ReadVCompressV" # suffix);
1919+
1920+
def _VM # suffix : VPseudoUnaryAnyMask<m.vrclass, m.vrclass>,
1921+
Sched<[WriteVCompressV_MX_E, ReadVCompressV_MX_E, ReadVCompressV_MX_E]>;
1922+
}
19191923
}
19201924
}
19211925

@@ -3860,6 +3864,28 @@ class VPatUnaryAnyMask<string intrinsic,
38603864
(mask_type VR:$rs2),
38613865
GPR:$vl, sew)>;
38623866

3867+
class VPatUnaryAnyMask_E<string intrinsic,
3868+
string inst,
3869+
string kind,
3870+
ValueType result_type,
3871+
ValueType op1_type,
3872+
ValueType mask_type,
3873+
int log2sew,
3874+
LMULInfo vlmul,
3875+
int sew,
3876+
VReg result_reg_class,
3877+
VReg op1_reg_class> :
3878+
Pat<(result_type (!cast<Intrinsic>(intrinsic)
3879+
(result_type result_reg_class:$merge),
3880+
(op1_type op1_reg_class:$rs1),
3881+
(mask_type VR:$rs2),
3882+
VLOpFrag)),
3883+
(!cast<Instruction>(inst#"_"#kind#"_"#vlmul.MX#"_E"#sew)
3884+
(result_type result_reg_class:$merge),
3885+
(op1_type op1_reg_class:$rs1),
3886+
(mask_type VR:$rs2),
3887+
GPR:$vl, log2sew)>;
3888+
38633889
class VPatBinaryM<string intrinsic_name,
38643890
string inst,
38653891
ValueType result_type,
@@ -4172,6 +4198,16 @@ multiclass VPatUnaryV_V_AnyMask<string intrinsic, string instruction,
41724198
}
41734199
}
41744200

4201+
multiclass VPatUnaryV_V_AnyMask_E<string intrinsic, string instruction,
4202+
list<VTypeInfo> vtilist> {
4203+
foreach vti = vtilist in {
4204+
def : VPatUnaryAnyMask_E<intrinsic, instruction, "VM",
4205+
vti.Vector, vti.Vector, vti.Mask,
4206+
vti.Log2SEW, vti.LMul, vti.SEW, vti.RegClass,
4207+
vti.RegClass>;
4208+
}
4209+
}
4210+
41754211
multiclass VPatUnaryM_M<string intrinsic,
41764212
string inst>
41774213
{
@@ -6434,11 +6470,11 @@ let Predicates = [HasVInstructionsAnyF] in {
64346470
// 16.5. Vector Compress Instruction
64356471
//===----------------------------------------------------------------------===//
64366472
let Predicates = [HasVInstructions] in {
6437-
defm : VPatUnaryV_V_AnyMask<"int_riscv_vcompress", "PseudoVCOMPRESS", AllIntegerVectors>;
6473+
defm : VPatUnaryV_V_AnyMask_E<"int_riscv_vcompress", "PseudoVCOMPRESS", AllIntegerVectors>;
64386474
} // Predicates = [HasVInstructions]
64396475

64406476
let Predicates = [HasVInstructionsAnyF] in {
6441-
defm : VPatUnaryV_V_AnyMask<"int_riscv_vcompress", "PseudoVCOMPRESS", AllFloatVectors>;
6477+
defm : VPatUnaryV_V_AnyMask_E<"int_riscv_vcompress", "PseudoVCOMPRESS", AllFloatVectors>;
64426478
} // Predicates = [HasVInstructionsAnyF]
64436479

64446480
// Include the non-intrinsic ISel patterns

llvm/lib/Target/RISCV/RISCVScheduleV.td

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,46 @@ multiclass LMULReadAdvanceImpl<string name, int val,
5454
}
5555
}
5656

57+
// Define multiclasses to define SchedWrite, SchedRead, WriteRes, and
58+
// ReadAdvance for each (name, LMUL, SEW) tuple for each LMUL in each of the
59+
// SchedMxList variants above.
60+
multiclass LMULSEWSchedWritesImpl<string name, list<string> MxList> {
61+
foreach mx = MxList in {
62+
if !eq(mx, "UpperBound") then
63+
def name # "_" # mx : SchedWrite;
64+
else
65+
foreach sew = SchedSEWSet<mx>.val in
66+
def name # "_" # mx # "_E" # sew : SchedWrite;
67+
}
68+
}
69+
multiclass LMULSEWSchedReadsImpl<string name, list<string> MxList> {
70+
foreach mx = MxList in {
71+
if !eq(mx, "UpperBound") then
72+
def name # "_" # mx : SchedRead;
73+
else
74+
foreach sew = SchedSEWSet<mx>.val in
75+
def name # "_" # mx # "_E" # sew : SchedRead;
76+
}
77+
}
78+
multiclass LMULSEWWriteResImpl<string name, list<ProcResourceKind> resources> {
79+
foreach mx = SchedMxList in {
80+
if !eq(mx, "UpperBound") then
81+
def : WriteRes<!cast<SchedWrite>(name # "_" # mx), resources>;
82+
else
83+
foreach sew = SchedSEWSet<mx>.val in
84+
def : WriteRes<!cast<SchedWrite>(name # "_" # mx # "_E" # sew), resources>;
85+
}
86+
}
87+
multiclass LMULSEWReadAdvanceImpl<string name, int val,
88+
list<SchedWrite> writes = []> {
89+
foreach mx = SchedMxList in {
90+
if !eq(mx, "UpperBound") then
91+
def : ReadAdvance<!cast<SchedRead>(name # "_" # mx), val, writes>;
92+
else
93+
foreach sew = SchedSEWSet<mx>.val in
94+
def : ReadAdvance<!cast<SchedRead>(name # "_" # mx # "_E" # sew), val, writes>;
95+
}
96+
}
5797
// Define classes to define list containing all SchedWrites for each (name, LMUL)
5898
// pair for each LMUL in each of the SchedMxList variants above and name in
5999
// argument `names`. These classes can be used to construct a list of existing
@@ -78,6 +118,13 @@ multiclass LMULReadAdvance<string name, int val, list<SchedWrite> writes = []>
78118
: LMULReadAdvanceImpl<name, val, writes>;
79119
class LMULSchedWriteList<list<string> names> : LMULSchedWriteListImpl<names, SchedMxList>;
80120

121+
multiclass LMULSEWSchedWrites<string name> : LMULSEWSchedWritesImpl<name, SchedMxList>;
122+
multiclass LMULSEWSchedReads<string name> : LMULSEWSchedReadsImpl<name, SchedMxList>;
123+
multiclass LMULSEWWriteRes<string name, list<ProcResourceKind> resources>
124+
: LMULSEWWriteResImpl<name, resources>;
125+
multiclass LMULSEWReadAdvance<string name, int val, list<SchedWrite> writes = []>
126+
: LMULSEWReadAdvanceImpl<name, val, writes>;
127+
81128
multiclass LMULSchedWritesW<string name> : LMULSchedWritesImpl<name, SchedMxListW>;
82129
multiclass LMULSchedReadsW<string name> : LMULSchedReadsImpl<name, SchedMxListW>;
83130
multiclass LMULWriteResW<string name, list<ProcResourceKind> resources>
@@ -340,7 +387,7 @@ defm "" : LMULSchedWrites<"WriteVRGatherVV">;
340387
defm "" : LMULSchedWrites<"WriteVRGatherVX">;
341388
defm "" : LMULSchedWrites<"WriteVRGatherVI">;
342389
// 16.5. Vector Compress Instruction
343-
defm "" : LMULSchedWrites<"WriteVCompressV">;
390+
defm "" : LMULSEWSchedWrites<"WriteVCompressV">;
344391
// 16.6. Whole Vector Register Move
345392
// These are already LMUL aware
346393
def WriteVMov1V : SchedWrite;
@@ -564,7 +611,7 @@ defm "" : LMULSchedReads<"ReadVRGatherVX_data">;
564611
defm "" : LMULSchedReads<"ReadVRGatherVX_index">;
565612
defm "" : LMULSchedReads<"ReadVRGatherVI_data">;
566613
// 16.5. Vector Compress Instruction
567-
defm "" : LMULSchedReads<"ReadVCompressV">;
614+
defm "" : LMULSEWSchedReads<"ReadVCompressV">;
568615
// 16.6. Whole Vector Register Move
569616
// These are already LMUL aware
570617
def ReadVMov1V : SchedRead;
@@ -756,7 +803,7 @@ defm "" : LMULWriteRes<"WriteVFSlide1F", []>;
756803
defm "" : LMULWriteRes<"WriteVRGatherVV", []>;
757804
defm "" : LMULWriteRes<"WriteVRGatherVX", []>;
758805
defm "" : LMULWriteRes<"WriteVRGatherVI", []>;
759-
defm "" : LMULWriteRes<"WriteVCompressV", []>;
806+
defm "" : LMULSEWWriteRes<"WriteVCompressV", []>;
760807
// These are already LMUL aware
761808
def : WriteRes<WriteVMov1V, []>;
762809
def : WriteRes<WriteVMov2V, []>;
@@ -916,7 +963,9 @@ defm "" : LMULReadAdvance<"ReadVRGatherVV_index", 0>;
916963
defm "" : LMULReadAdvance<"ReadVRGatherVX_data", 0>;
917964
defm "" : LMULReadAdvance<"ReadVRGatherVX_index", 0>;
918965
defm "" : LMULReadAdvance<"ReadVRGatherVI_data", 0>;
919-
defm "" : LMULReadAdvance<"ReadVCompressV", 0>;
966+
defm "" : LMULReadAdvance<"ReadVGatherV", 0>;
967+
defm "" : LMULReadAdvance<"ReadVGatherX", 0>;
968+
defm "" : LMULSEWReadAdvance<"ReadVCompressV", 0>;
920969
// These are already LMUL aware
921970
def : ReadAdvance<ReadVMov1V, 0>;
922971
def : ReadAdvance<ReadVMov2V, 0>;

0 commit comments

Comments
 (0)