Skip to content

Commit 2047b27

Browse files
[LLVM][CodeGen][SVE] Clean up lowering of VECTOR_SPLICE operations.
Remove DAG combine that is performing type legalisation and instead add isel patterns for all legal types.
1 parent 8ea062a commit 2047b27

File tree

4 files changed

+32
-49
lines changed

4 files changed

+32
-49
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12249,9 +12249,8 @@ void SelectionDAGBuilder::visitVectorSplice(const CallInst &I) {
1224912249

1225012250
// VECTOR_SHUFFLE doesn't support a scalable mask so use a dedicated node.
1225112251
if (VT.isScalableVector()) {
12252-
MVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
1225312252
setValue(&I, DAG.getNode(ISD::VECTOR_SPLICE, DL, VT, V1, V2,
12254-
DAG.getConstant(Imm, DL, IdxVT)));
12253+
DAG.getVectorIdxConstant(Imm, DL)));
1225512254
return;
1225612255
}
1225712256

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,9 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
10481048
setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN);
10491049

10501050
setTargetDAGCombine({ISD::ANY_EXTEND, ISD::ZERO_EXTEND, ISD::SIGN_EXTEND,
1051-
ISD::VECTOR_SPLICE, ISD::SIGN_EXTEND_INREG,
1052-
ISD::CONCAT_VECTORS, ISD::EXTRACT_SUBVECTOR,
1053-
ISD::INSERT_SUBVECTOR, ISD::STORE, ISD::BUILD_VECTOR});
1051+
ISD::SIGN_EXTEND_INREG, ISD::CONCAT_VECTORS,
1052+
ISD::EXTRACT_SUBVECTOR, ISD::INSERT_SUBVECTOR,
1053+
ISD::STORE, ISD::BUILD_VECTOR});
10541054
setTargetDAGCombine(ISD::TRUNCATE);
10551055
setTargetDAGCombine(ISD::LOAD);
10561056

@@ -1580,6 +1580,7 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
15801580
setOperationAction(ISD::MLOAD, VT, Custom);
15811581
setOperationAction(ISD::INSERT_SUBVECTOR, VT, Custom);
15821582
setOperationAction(ISD::SPLAT_VECTOR, VT, Legal);
1583+
setOperationAction(ISD::VECTOR_SPLICE, VT, Custom);
15831584

15841585
if (!Subtarget->isLittleEndian())
15851586
setOperationAction(ISD::BITCAST, VT, Expand);
@@ -10102,10 +10103,9 @@ SDValue AArch64TargetLowering::LowerVECTOR_SPLICE(SDValue Op,
1010210103
Op.getOperand(1));
1010310104
}
1010410105

10105-
// This will select to an EXT instruction, which has a maximum immediate
10106-
// value of 255, hence 2048-bits is the maximum value we can lower.
10107-
if (IdxVal >= 0 &&
10108-
IdxVal < int64_t(2048 / Ty.getVectorElementType().getSizeInBits()))
10106+
// We can select to an EXT instruction when indexing the first 256 bytes.
10107+
unsigned BlockSize = AArch64::SVEBitsPerBlock / Ty.getVectorMinNumElements();
10108+
if (IdxVal >= 0 && (IdxVal * BlockSize / 8) < 256)
1010910109
return Op;
1011010110

1011110111
return SDValue();
@@ -24237,28 +24237,6 @@ performInsertVectorEltCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
2423724237
return performPostLD1Combine(N, DCI, true);
2423824238
}
2423924239

24240-
static SDValue performSVESpliceCombine(SDNode *N, SelectionDAG &DAG) {
24241-
EVT Ty = N->getValueType(0);
24242-
if (Ty.isInteger())
24243-
return SDValue();
24244-
24245-
EVT IntTy = Ty.changeVectorElementTypeToInteger();
24246-
EVT ExtIntTy = getPackedSVEVectorVT(IntTy.getVectorElementCount());
24247-
if (ExtIntTy.getVectorElementType().getScalarSizeInBits() <
24248-
IntTy.getVectorElementType().getScalarSizeInBits())
24249-
return SDValue();
24250-
24251-
SDLoc DL(N);
24252-
SDValue LHS = DAG.getAnyExtOrTrunc(DAG.getBitcast(IntTy, N->getOperand(0)),
24253-
DL, ExtIntTy);
24254-
SDValue RHS = DAG.getAnyExtOrTrunc(DAG.getBitcast(IntTy, N->getOperand(1)),
24255-
DL, ExtIntTy);
24256-
SDValue Idx = N->getOperand(2);
24257-
SDValue Splice = DAG.getNode(ISD::VECTOR_SPLICE, DL, ExtIntTy, LHS, RHS, Idx);
24258-
SDValue Trunc = DAG.getAnyExtOrTrunc(Splice, DL, IntTy);
24259-
return DAG.getBitcast(Ty, Trunc);
24260-
}
24261-
2426224240
static SDValue performFPExtendCombine(SDNode *N, SelectionDAG &DAG,
2426324241
TargetLowering::DAGCombinerInfo &DCI,
2426424242
const AArch64Subtarget *Subtarget) {
@@ -24643,8 +24621,6 @@ SDValue AArch64TargetLowering::PerformDAGCombine(SDNode *N,
2464324621
case ISD::MGATHER:
2464424622
case ISD::MSCATTER:
2464524623
return performMaskedGatherScatterCombine(N, DCI, DAG);
24646-
case ISD::VECTOR_SPLICE:
24647-
return performSVESpliceCombine(N, DAG);
2464824624
case ISD::FP_EXTEND:
2464924625
return performFPExtendCombine(N, DAG, DCI, Subtarget);
2465024626
case AArch64ISD::BRCOND:

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,14 +1994,21 @@ let Predicates = [HasSVEorSME] in {
19941994
(LASTB_VPZ_D (PTRUE_D 31), ZPR:$Z1), dsub))>;
19951995

19961996
// Splice with lane bigger or equal to 0
1997-
def : Pat<(nxv16i8 (vector_splice (nxv16i8 ZPR:$Z1), (nxv16i8 ZPR:$Z2), (i64 (sve_ext_imm_0_255 i32:$index)))),
1998-
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
1999-
def : Pat<(nxv8i16 (vector_splice (nxv8i16 ZPR:$Z1), (nxv8i16 ZPR:$Z2), (i64 (sve_ext_imm_0_127 i32:$index)))),
2000-
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
2001-
def : Pat<(nxv4i32 (vector_splice (nxv4i32 ZPR:$Z1), (nxv4i32 ZPR:$Z2), (i64 (sve_ext_imm_0_63 i32:$index)))),
2002-
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
2003-
def : Pat<(nxv2i64 (vector_splice (nxv2i64 ZPR:$Z1), (nxv2i64 ZPR:$Z2), (i64 (sve_ext_imm_0_31 i32:$index)))),
2004-
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
1997+
foreach VT = [nxv16i8] in
1998+
def : Pat<(VT (vector_splice (VT ZPR:$Z1), (VT ZPR:$Z2), (i64 (sve_ext_imm_0_255 i32:$index)))),
1999+
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
2000+
2001+
foreach VT = [nxv8i16, nxv8f16, nxv8bf16] in
2002+
def : Pat<(VT (vector_splice (VT ZPR:$Z1), (VT ZPR:$Z2), (i64 (sve_ext_imm_0_127 i32:$index)))),
2003+
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
2004+
2005+
foreach VT = [nxv4i32, nxv4f16, nxv4f32, nxv4bf16] in
2006+
def : Pat<(VT (vector_splice (VT ZPR:$Z1), (VT ZPR:$Z2), (i64 (sve_ext_imm_0_63 i32:$index)))),
2007+
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
2008+
2009+
foreach VT = [nxv2i64, nxv2f16, nxv2f32, nxv2f64, nxv2bf16] in
2010+
def : Pat<(VT (vector_splice (VT ZPR:$Z1), (VT ZPR:$Z2), (i64 (sve_ext_imm_0_31 i32:$index)))),
2011+
(EXT_ZZI ZPR:$Z1, ZPR:$Z2, imm0_255:$index)>;
20052012

20062013
defm CMPHS_PPzZZ : sve_int_cmp_0<0b000, "cmphs", SETUGE, SETULE>;
20072014
defm CMPHI_PPzZZ : sve_int_cmp_0<0b001, "cmphi", SETUGT, SETULT>;

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7060,16 +7060,17 @@ multiclass sve_int_perm_splice<string asm, SDPatternOperator op> {
70607060
def _S : sve_int_perm_splice<0b10, asm, ZPR32>;
70617061
def _D : sve_int_perm_splice<0b11, asm, ZPR64>;
70627062

7063-
def : SVE_3_Op_Pat<nxv16i8, op, nxv16i1, nxv16i8, nxv16i8, !cast<Instruction>(NAME # _B)>;
7064-
def : SVE_3_Op_Pat<nxv8i16, op, nxv8i1, nxv8i16, nxv8i16, !cast<Instruction>(NAME # _H)>;
7065-
def : SVE_3_Op_Pat<nxv4i32, op, nxv4i1, nxv4i32, nxv4i32, !cast<Instruction>(NAME # _S)>;
7066-
def : SVE_3_Op_Pat<nxv2i64, op, nxv2i1, nxv2i64, nxv2i64, !cast<Instruction>(NAME # _D)>;
7063+
foreach VT = [nxv16i8] in
7064+
def : SVE_3_Op_Pat<VT, op, nxv16i1, VT, VT, !cast<Instruction>(NAME # _B)>;
70677065

7068-
def : SVE_3_Op_Pat<nxv8f16, op, nxv8i1, nxv8f16, nxv8f16, !cast<Instruction>(NAME # _H)>;
7069-
def : SVE_3_Op_Pat<nxv4f32, op, nxv4i1, nxv4f32, nxv4f32, !cast<Instruction>(NAME # _S)>;
7070-
def : SVE_3_Op_Pat<nxv2f64, op, nxv2i1, nxv2f64, nxv2f64, !cast<Instruction>(NAME # _D)>;
7066+
foreach VT = [nxv8i16, nxv8f16, nxv8bf16] in
7067+
def : SVE_3_Op_Pat<VT, op, nxv8i1, VT, VT, !cast<Instruction>(NAME # _H)>;
70717068

7072-
def : SVE_3_Op_Pat<nxv8bf16, op, nxv8i1, nxv8bf16, nxv8bf16, !cast<Instruction>(NAME # _H)>;
7069+
foreach VT = [nxv4i32, nxv4f16, nxv4f32, nxv4bf16] in
7070+
def : SVE_3_Op_Pat<VT, op, nxv4i1, VT, VT, !cast<Instruction>(NAME # _S)>;
7071+
7072+
foreach VT = [nxv2i64, nxv2f16, nxv2f32, nxv2f64, nxv2bf16] in
7073+
def : SVE_3_Op_Pat<VT, op, nxv2i1, VT, VT, !cast<Instruction>(NAME # _D)>;
70737074
}
70747075

70757076
class sve2_int_perm_splice_cons<bits<2> sz8_64, string asm,

0 commit comments

Comments
 (0)