[llvm] [AArch64] Fold BUILD_VECTORs splats into users by using SVE immediates (PR #165559)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 29 06:37:30 PDT 2025
================
@@ -15501,6 +15501,72 @@ SDValue AArch64TargetLowering::LowerFixedLengthBuildVectorToSVE(
return convertFromScalableVector(DAG, VT, Vec);
}
+static std::optional<int64_t> getSplatConstant(SDValue V,
+ ConstantSDNode *&Const) {
+ if (auto *BV = dyn_cast<BuildVectorSDNode>(V))
+ if ((Const = dyn_cast_if_present<ConstantSDNode>(BV->getSplatValue())))
+ return Const->getZExtValue();
+ return std::nullopt;
+}
+
+static bool isSVESplatImmForOp(unsigned Opcode, MVT VT, int64_t SplatImm) {
+ // TODO: Support more than integer binops.
+ switch (Opcode) {
+ case ISD::SUB:
+ case ISD::ADD:
+ return isUInt<8>(SplatImm) || (VT.getFixedSizeInBits() > 8 &&
+ isUInt<16>(SplatImm) && SplatImm % 256 == 0);
+ case ISD::XOR:
+ case ISD::OR:
+ case ISD::AND:
+ return AArch64_AM::isLogicalImmediate(SplatImm, 64);
+ case ISD::MUL:
+ return isInt<8>(SplatImm);
+ default:
+ return false;
+ }
+}
+
+static SDValue tryFoldSplatIntoUsersWithSVE(SDValue Op, SelectionDAG &DAG) {
+ auto &Subtarget = DAG.getSubtarget<AArch64Subtarget>();
----------------
MacDue wrote:
I'm not sure if this is necessarily always preferable, or if there's some target property this should be dependent on?
https://github.com/llvm/llvm-project/pull/165559
More information about the llvm-commits
mailing list