Skip to content

Commit 5e8c1cc

Browse files
committed
add lasx support
1 parent 71f2e29 commit 5e8c1cc

File tree

4 files changed

+108
-2702
lines changed

4 files changed

+108
-2702
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,10 @@ static SDValue lower256BitShuffle(const SDLoc &DL, ArrayRef<int> Mask, MVT VT,
16141614
SmallVector<int> NewMask(Mask);
16151615
canonicalizeShuffleVectorByLane(DL, NewMask, VT, V1, V2, DAG);
16161616

1617+
APInt KnownUndef, KnownZero;
1618+
computeZeroableShuffleElements(NewMask, V1, V2, KnownUndef, KnownZero);
1619+
APInt Zeroable = KnownUndef | KnownZero;
1620+
16171621
SDValue Result;
16181622
// TODO: Add more comparison patterns.
16191623
if (V2.isUndef()) {
@@ -1641,6 +1645,9 @@ static SDValue lower256BitShuffle(const SDLoc &DL, ArrayRef<int> Mask, MVT VT,
16411645
return Result;
16421646
if ((Result = lowerVECTOR_SHUFFLE_XVPICKOD(DL, NewMask, VT, V1, V2, DAG)))
16431647
return Result;
1648+
if ((Result =
1649+
lowerVECTOR_SHUFFLEAsShift(DL, NewMask, VT, V1, V2, DAG, Zeroable)))
1650+
return Result;
16441651
if ((Result = lowerVECTOR_SHUFFLE_XVSHUF(DL, NewMask, VT, V1, V2, DAG)))
16451652
return Result;
16461653

llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ multiclass PatShiftXrXr<SDPatternOperator OpNode, string Inst> {
11871187
(!cast<LAInst>(Inst#"_D") LASX256:$xj, LASX256:$xk)>;
11881188
}
11891189

1190-
multiclass PatShiftXrUimm<SDPatternOperator OpNode, string Inst> {
1190+
multiclass PatShiftXrSplatUimm<SDPatternOperator OpNode, string Inst> {
11911191
def : Pat<(OpNode (v32i8 LASX256:$xj), (v32i8 (SplatPat_uimm3 uimm3:$imm))),
11921192
(!cast<LAInst>(Inst#"_B") LASX256:$xj, uimm3:$imm)>;
11931193
def : Pat<(OpNode (v16i16 LASX256:$xj), (v16i16 (SplatPat_uimm4 uimm4:$imm))),
@@ -1198,6 +1198,17 @@ multiclass PatShiftXrUimm<SDPatternOperator OpNode, string Inst> {
11981198
(!cast<LAInst>(Inst#"_D") LASX256:$xj, uimm6:$imm)>;
11991199
}
12001200

1201+
multiclass PatShiftXrUimm<SDPatternOperator OpNode, string Inst> {
1202+
def : Pat<(OpNode(v32i8 LASX256:$vj), uimm3:$imm),
1203+
(!cast<LAInst>(Inst#"_B") LASX256:$vj, uimm3:$imm)>;
1204+
def : Pat<(OpNode(v16i16 LASX256:$vj), uimm4:$imm),
1205+
(!cast<LAInst>(Inst#"_H") LASX256:$vj, uimm4:$imm)>;
1206+
def : Pat<(OpNode(v8i32 LASX256:$vj), uimm5:$imm),
1207+
(!cast<LAInst>(Inst#"_W") LASX256:$vj, uimm5:$imm)>;
1208+
def : Pat<(OpNode(v4i64 LASX256:$vj), uimm6:$imm),
1209+
(!cast<LAInst>(Inst#"_D") LASX256:$vj, uimm6:$imm)>;
1210+
}
1211+
12011212
multiclass PatCCXrSimm5<CondCode CC, string Inst> {
12021213
def : Pat<(v32i8 (setcc (v32i8 LASX256:$xj),
12031214
(v32i8 (SplatPat_simm5 simm5:$imm)), CC)),
@@ -1335,20 +1346,32 @@ def : Pat<(or (v32i8 LASX256:$xj), (v32i8 (SplatPat_uimm8 uimm8:$imm))),
13351346
def : Pat<(xor (v32i8 LASX256:$xj), (v32i8 (SplatPat_uimm8 uimm8:$imm))),
13361347
(XVXORI_B LASX256:$xj, uimm8:$imm)>;
13371348

1349+
// XVBSLL_V
1350+
foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32,
1351+
v4f64] in def : Pat<(loongarch_vbsll(vt LASX256:$xj), uimm5:$imm),
1352+
(XVBSLL_V LASX256:$xj, uimm5:$imm)>;
1353+
1354+
// XVBSRL_V
1355+
foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32,
1356+
v4f64] in def : Pat<(loongarch_vbsrl(vt LASX256:$xj), uimm5:$imm),
1357+
(XVBSRL_V LASX256:$xj, uimm5:$imm)>;
1358+
13381359
// XVSLL[I]_{B/H/W/D}
13391360
defm : PatXrXr<shl, "XVSLL">;
13401361
defm : PatShiftXrXr<shl, "XVSLL">;
1341-
defm : PatShiftXrUimm<shl, "XVSLLI">;
1362+
defm : PatShiftXrSplatUimm<shl, "XVSLLI">;
1363+
defm : PatShiftXrUimm<loongarch_vslli, "XVSLLI">;
13421364

13431365
// XVSRL[I]_{B/H/W/D}
13441366
defm : PatXrXr<srl, "XVSRL">;
13451367
defm : PatShiftXrXr<srl, "XVSRL">;
1346-
defm : PatShiftXrUimm<srl, "XVSRLI">;
1368+
defm : PatShiftXrSplatUimm<srl, "XVSRLI">;
1369+
defm : PatShiftXrUimm<loongarch_vsrli, "XVSRLI">;
13471370

13481371
// XVSRA[I]_{B/H/W/D}
13491372
defm : PatXrXr<sra, "XVSRA">;
13501373
defm : PatShiftXrXr<sra, "XVSRA">;
1351-
defm : PatShiftXrUimm<sra, "XVSRAI">;
1374+
defm : PatShiftXrSplatUimm<sra, "XVSRAI">;
13521375

13531376
// XVCLZ_{B/H/W/D}
13541377
defm : PatXr<ctlz, "XVCLZ">;

0 commit comments

Comments
 (0)