Skip to content

Commit f2441a0

Browse files
committed
[LoongArch] Set some operations action for LSX and LASX
First, expand all truncationg stores and extending loads. Second, expand everything for `fixedlen_vector_valuetypes`. Finally, we selectively turn on ones that can be effectively codegen'd. Simultaneously, this patch adds floating-point vector types to load/store patterns. Additional test cases will be included in the IR instruction test patchs.
1 parent cadcc7b commit f2441a0

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,76 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
218218

219219
// Set operations for 'LSX' feature.
220220

221-
if (Subtarget.hasExtLSX())
222-
setOperationAction({ISD::UMAX, ISD::UMIN, ISD::SMAX, ISD::SMIN},
223-
{MVT::v2i64, MVT::v4i32, MVT::v8i16, MVT::v16i8}, Legal);
221+
if (Subtarget.hasExtLSX()) {
222+
for (MVT VT : MVT::fixedlen_vector_valuetypes()) {
223+
// Expand all truncating stores and extending loads.
224+
for (MVT InnerVT : MVT::fixedlen_vector_valuetypes()) {
225+
setTruncStoreAction(VT, InnerVT, Expand);
226+
setLoadExtAction(ISD::SEXTLOAD, VT, InnerVT, Expand);
227+
setLoadExtAction(ISD::ZEXTLOAD, VT, InnerVT, Expand);
228+
setLoadExtAction(ISD::EXTLOAD, VT, InnerVT, Expand);
229+
}
230+
// By default everything must be expanded. Then we will selectively turn
231+
// on ones that can be effectively codegen'd.
232+
for (unsigned Op = 0; Op < ISD::BUILTIN_OP_END; ++Op)
233+
setOperationAction(Op, VT, Expand);
234+
}
235+
236+
for (MVT VT : LSXVTs) {
237+
setOperationAction({ISD::LOAD, ISD::STORE}, VT, Legal);
238+
setOperationAction(ISD::BITCAST, VT, Legal);
239+
setOperationAction(ISD::UNDEF, VT, Legal);
240+
241+
// FIXME: For BUILD_VECTOR, it is temporarily set to `Legal` here, and it
242+
// will be `Custom` handled in the future.
243+
setOperationAction(ISD::BUILD_VECTOR, VT, Legal);
244+
setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Legal);
245+
}
246+
for (MVT VT : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64}) {
247+
setOperationAction({ISD::ADD, ISD::SUB}, VT, Legal);
248+
setOperationAction({ISD::UMAX, ISD::UMIN, ISD::SMAX, ISD::SMIN}, VT,
249+
Legal);
250+
setOperationAction({ISD::MUL, ISD::SDIV, ISD::SREM, ISD::UDIV, ISD::UREM},
251+
VT, Legal);
252+
setOperationAction({ISD::AND, ISD::OR, ISD::XOR}, VT, Legal);
253+
setOperationAction({ISD::SHL, ISD::SRA, ISD::SRL}, VT, Legal);
254+
setOperationAction(ISD::CTPOP, VT, Legal);
255+
}
256+
for (MVT VT : {MVT::v4f32, MVT::v2f64}) {
257+
setOperationAction({ISD::FADD, ISD::FSUB}, VT, Legal);
258+
setOperationAction({ISD::FMUL, ISD::FDIV}, VT, Legal);
259+
setOperationAction(ISD::FMA, VT, Legal);
260+
}
261+
}
224262

225263
// Set operations for 'LASX' feature.
226264

227-
if (Subtarget.hasExtLASX())
228-
setOperationAction({ISD::UMAX, ISD::UMIN, ISD::SMAX, ISD::SMIN},
229-
{MVT::v4i64, MVT::v8i32, MVT::v16i16, MVT::v32i8},
230-
Legal);
265+
if (Subtarget.hasExtLASX()) {
266+
for (MVT VT : LASXVTs) {
267+
setOperationAction({ISD::LOAD, ISD::STORE}, VT, Legal);
268+
setOperationAction(ISD::BITCAST, VT, Legal);
269+
setOperationAction(ISD::UNDEF, VT, Legal);
270+
271+
// FIXME: Same as above.
272+
setOperationAction(ISD::BUILD_VECTOR, VT, Legal);
273+
setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Legal);
274+
}
275+
for (MVT VT : {MVT::v4i64, MVT::v8i32, MVT::v16i16, MVT::v32i8}) {
276+
setOperationAction({ISD::ADD, ISD::SUB}, VT, Legal);
277+
setOperationAction({ISD::UMAX, ISD::UMIN, ISD::SMAX, ISD::SMIN}, VT,
278+
Legal);
279+
setOperationAction({ISD::MUL, ISD::SDIV, ISD::SREM, ISD::UDIV, ISD::UREM},
280+
VT, Legal);
281+
setOperationAction({ISD::AND, ISD::OR, ISD::XOR}, VT, Legal);
282+
setOperationAction({ISD::SHL, ISD::SRA, ISD::SRL}, VT, Legal);
283+
setOperationAction(ISD::CTPOP, VT, Legal);
284+
}
285+
for (MVT VT : {MVT::v8f32, MVT::v4f64}) {
286+
setOperationAction({ISD::FADD, ISD::FSUB}, VT, Legal);
287+
setOperationAction({ISD::FMUL, ISD::FDIV}, VT, Legal);
288+
setOperationAction(ISD::FMA, VT, Legal);
289+
}
290+
}
231291

232292
// Set DAG combine for LA32 and LA64.
233293

llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ def : Pat<(loongarch_vreplve v4i64:$xj, GRLenVT:$rk),
13941394
(XVREPLVE_D v4i64:$xj, GRLenVT:$rk)>;
13951395

13961396
// Loads/Stores
1397-
foreach vt = [v32i8, v16i16, v8i32, v4i64] in {
1397+
foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64] in {
13981398
defm : LdPat<load, XVLD, vt>;
13991399
def : RegRegLdPat<load, XVLDX, vt>;
14001400
defm : StPat<store, XVST, LASX256, vt>;

llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ def : Pat<(loongarch_vreplve v2i64:$vj, GRLenVT:$rk),
14941494
(VREPLVE_D v2i64:$vj, GRLenVT:$rk)>;
14951495

14961496
// Loads/Stores
1497-
foreach vt = [v16i8, v8i16, v4i32, v2i64] in {
1497+
foreach vt = [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64] in {
14981498
defm : LdPat<load, VLD, vt>;
14991499
def : RegRegLdPat<load, VLDX, vt>;
15001500
defm : StPat<store, VST, LSX128, vt>;

0 commit comments

Comments
 (0)