Skip to content

Commit 799215f

Browse files
committed
[RISCV] refactor VPatTruncSatClipVL and VPatTruncSatClipSDNode.
1 parent 4d57623 commit 799215f

File tree

2 files changed

+51
-66
lines changed

2 files changed

+51
-66
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,50 +1167,41 @@ defm : VPatAVGADD_VV_VX_RM<avgflooru, 0b10>;
11671167
defm : VPatAVGADD_VV_VX_RM<avgceilu, 0b00>;
11681168

11691169
// 12.5. Vector Narrowing Fixed-Point Clip Instructions
1170-
class VPatTruncSatClipMaxMinSDNodeBase<VTypeInfo vti,
1171-
VTypeInfo wti,
1172-
SDPatternOperator op1,
1173-
int op1_value,
1174-
SDPatternOperator op2,
1175-
int op2_value> :
1176-
Pat<(vti.Vector (riscv_trunc_vector_vl
1177-
(wti.Vector (op1
1178-
(wti.Vector (op2 (wti.Vector wti.RegClass:$rs1),
1179-
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), op2_value, (XLenVT srcvalue))))),
1180-
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), op1_value, (XLenVT srcvalue))))),
1170+
multiclass VPatTruncSatClipSDNode<VTypeInfo vti, VTypeInfo wti> {
1171+
defvar sew = vti.SEW;
1172+
defvar uminval = !sub(!shl(1, sew), 1);
1173+
defvar sminval = !sub(!shl(1, !sub(sew, 1)), 1);
1174+
defvar smaxval = !sub(0, !shl(1, !sub(sew, 1)));
1175+
1176+
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
1177+
GetVTypePredicates<wti>.Predicates) in {
1178+
def : Pat<(vti.Vector (riscv_trunc_vector_vl
1179+
(wti.Vector (smin
1180+
(wti.Vector (smax (wti.Vector wti.RegClass:$rs1),
1181+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), smaxval, (XLenVT srcvalue))))),
1182+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), sminval, (XLenVT srcvalue))))),
1183+
(vti.Mask V0), VLOpFrag)),
1184+
(!cast<Instruction>("PseudoVNCLIP_WI_"#vti.LMul.MX#"_MASK")
1185+
(vti.Vector (IMPLICIT_DEF)), wti.RegClass:$rs1, 0,
1186+
(vti.Mask V0), 0, GPR:$vl, vti.Log2SEW, TA_MA)>;
1187+
1188+
def : Pat<(vti.Vector (riscv_trunc_vector_vl
1189+
(wti.Vector (smax
1190+
(wti.Vector (smin (wti.Vector wti.RegClass:$rs1),
1191+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), sminval, (XLenVT srcvalue))))),
1192+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), smaxval, (XLenVT srcvalue))))),
11811193
(vti.Mask V0), VLOpFrag)),
11821194
(!cast<Instruction>("PseudoVNCLIP_WI_"#vti.LMul.MX#"_MASK")
11831195
(vti.Vector (IMPLICIT_DEF)), wti.RegClass:$rs1, 0,
11841196
(vti.Mask V0), 0, GPR:$vl, vti.Log2SEW, TA_MA)>;
11851197

1186-
class VPatTruncSatClipUMinSDNode<VTypeInfo vti,
1187-
VTypeInfo wti,
1188-
int uminval> :
1189-
Pat<(vti.Vector (riscv_trunc_vector_vl
1198+
def : Pat<(vti.Vector (riscv_trunc_vector_vl
11901199
(wti.Vector (umin (wti.Vector wti.RegClass:$rs1),
11911200
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), uminval, (XLenVT srcvalue))))), (vti.Mask V0), VLOpFrag)),
11921201
(!cast<Instruction>("PseudoVNCLIPU_WI_"#vti.LMul.MX#"_MASK")
11931202
(vti.Vector (IMPLICIT_DEF)), wti.RegClass:$rs1, 0,
11941203
(vti.Mask V0), 0, GPR:$vl, vti.Log2SEW, TA_MA)>;
1195-
1196-
multiclass VPatTruncSatClipMaxMinSDNode<VTypeInfo vti, VTypeInfo wti,
1197-
SDPatternOperator max, int maxval, SDPatternOperator min, int minval> {
1198-
def : VPatTruncSatClipMaxMinSDNodeBase<vti, wti, max, maxval, min, minval>;
1199-
def : VPatTruncSatClipMaxMinSDNodeBase<vti, wti, min, minval, max, maxval>;
1200-
}
1201-
1202-
multiclass VPatTruncSatClipSDNode<VTypeInfo vti, VTypeInfo wti> {
1203-
defvar sew = vti.SEW;
1204-
defvar uminval = !sub(!shl(1, sew), 1);
1205-
defvar sminval = !sub(!shl(1, !sub(sew, 1)), 1);
1206-
defvar smaxval = !sub(0, !shl(1, !sub(sew, 1)));
1207-
1208-
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
1209-
GetVTypePredicates<wti>.Predicates) in {
1210-
defm : VPatTruncSatClipMaxMinSDNode<vti, wti, smin, sminval, smax, smaxval>;
1211-
def : VPatTruncSatClipUMinSDNode<vti, wti, uminval>;
12121204
}
1213-
12141205
}
12151206

12161207
foreach vtiToWti = AllWidenableIntVectors in

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,29 +2373,41 @@ defm : VPatAVGADDVL_VV_VX_RM<riscv_avgflooru_vl, 0b10>;
23732373
defm : VPatAVGADDVL_VV_VX_RM<riscv_avgceilu_vl, 0b00>;
23742374

23752375
// 12.5. Vector Narrowing Fixed-Point Clip Instructions
2376-
class VPatTruncSatClipMaxMinVLBase<VTypeInfo vti,
2377-
VTypeInfo wti,
2378-
SDPatternOperator op1,
2379-
int op1_value,
2380-
SDPatternOperator op2,
2381-
int op2_value> :
2382-
Pat<(vti.Vector (riscv_trunc_vector_vl
2383-
(wti.Vector (op1
2384-
(wti.Vector (op2
2376+
multiclass VPatTruncSatClipVL<VTypeInfo vti, VTypeInfo wti> {
2377+
defvar sew = vti.SEW;
2378+
defvar uminval = !sub(!shl(1, sew), 1);
2379+
defvar sminval = !sub(!shl(1, !sub(sew, 1)), 1);
2380+
defvar smaxval = !sub(0, !shl(1, !sub(sew, 1)));
2381+
2382+
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
2383+
GetVTypePredicates<wti>.Predicates) in {
2384+
def : Pat<(vti.Vector (riscv_trunc_vector_vl
2385+
(wti.Vector (riscv_smin_vl
2386+
(wti.Vector (riscv_smax_vl
2387+
(wti.Vector wti.RegClass:$rs1),
2388+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), smaxval, (XLenVT srcvalue))),
2389+
(wti.Vector undef),(wti.Mask V0), VLOpFrag)),
2390+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), sminval, (XLenVT srcvalue))),
2391+
(wti.Vector undef), (wti.Mask V0), VLOpFrag)),
2392+
(vti.Mask V0), VLOpFrag)),
2393+
(!cast<Instruction>("PseudoVNCLIP_WI_"#vti.LMul.MX#"_MASK")
2394+
(vti.Vector (IMPLICIT_DEF)), wti.RegClass:$rs1, 0,
2395+
(vti.Mask V0), 0, GPR:$vl, vti.Log2SEW, TA_MA)>;
2396+
2397+
def : Pat<(vti.Vector (riscv_trunc_vector_vl
2398+
(wti.Vector (riscv_smax_vl
2399+
(wti.Vector (riscv_smin_vl
23852400
(wti.Vector wti.RegClass:$rs1),
2386-
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), op2_value, (XLenVT srcvalue))),
2401+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), sminval, (XLenVT srcvalue))),
23872402
(wti.Vector undef),(wti.Mask V0), VLOpFrag)),
2388-
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), op1_value, (XLenVT srcvalue))),
2403+
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), smaxval, (XLenVT srcvalue))),
23892404
(wti.Vector undef), (wti.Mask V0), VLOpFrag)),
23902405
(vti.Mask V0), VLOpFrag)),
23912406
(!cast<Instruction>("PseudoVNCLIP_WI_"#vti.LMul.MX#"_MASK")
23922407
(vti.Vector (IMPLICIT_DEF)), wti.RegClass:$rs1, 0,
23932408
(vti.Mask V0), 0, GPR:$vl, vti.Log2SEW, TA_MA)>;
23942409

2395-
class VPatTruncSatClipUMinVL<VTypeInfo vti,
2396-
VTypeInfo wti,
2397-
int uminval> :
2398-
Pat<(vti.Vector (riscv_trunc_vector_vl
2410+
def : Pat<(vti.Vector (riscv_trunc_vector_vl
23992411
(wti.Vector (riscv_umin_vl
24002412
(wti.Vector wti.RegClass:$rs1),
24012413
(wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), uminval, (XLenVT srcvalue))),
@@ -2404,25 +2416,7 @@ class VPatTruncSatClipUMinVL<VTypeInfo vti,
24042416
(!cast<Instruction>("PseudoVNCLIPU_WI_"#vti.LMul.MX#"_MASK")
24052417
(vti.Vector (IMPLICIT_DEF)), wti.RegClass:$rs1, 0,
24062418
(vti.Mask V0), 0, GPR:$vl, vti.Log2SEW, TA_MA)>;
2407-
2408-
multiclass VPatTruncSatClipMaxMinVL<VTypeInfo vti, VTypeInfo wti,
2409-
SDPatternOperator max, int maxval, SDPatternOperator min, int minval> {
2410-
def : VPatTruncSatClipMaxMinVLBase<vti, wti, max, maxval, min, minval>;
2411-
def : VPatTruncSatClipMaxMinVLBase<vti, wti, min, minval, max, maxval>;
2412-
}
2413-
2414-
multiclass VPatTruncSatClipVL<VTypeInfo vti, VTypeInfo wti> {
2415-
defvar sew = vti.SEW;
2416-
defvar uminval = !sub(!shl(1, sew), 1);
2417-
defvar sminval = !sub(!shl(1, !sub(sew, 1)), 1);
2418-
defvar smaxval = !sub(0, !shl(1, !sub(sew, 1)));
2419-
2420-
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
2421-
GetVTypePredicates<wti>.Predicates) in {
2422-
defm : VPatTruncSatClipMaxMinVL<vti, wti, riscv_smin_vl, sminval, riscv_smax_vl, smaxval>;
2423-
def : VPatTruncSatClipUMinVL<vti, wti, uminval>;
24242419
}
2425-
24262420
}
24272421

24282422
foreach vtiToWti = AllWidenableIntVectors in

0 commit comments

Comments
 (0)