[llvm] [AArch64][SVE] Rework VECTOR_COMPRESS lowering (PR #171162)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 12 07:57:17 PST 2025
================
@@ -7411,133 +7414,58 @@ SDValue AArch64TargetLowering::LowerLOAD(SDValue Op,
return SDValue();
}
-// Convert to ContainerVT with no-op casts where possible.
-static SDValue convertToSVEContainerType(SDLoc DL, SDValue Vec, EVT ContainerVT,
- SelectionDAG &DAG) {
- EVT VecVT = Vec.getValueType();
- if (VecVT.isFloatingPoint()) {
- // Use no-op casts for floating-point types.
- EVT PackedVT = getPackedSVEVectorVT(VecVT.getScalarType());
- Vec = DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, PackedVT, Vec);
- Vec = DAG.getNode(AArch64ISD::NVCAST, DL, ContainerVT, Vec);
- } else {
- // Extend integers (may not be a no-op).
- Vec = DAG.getNode(ISD::ANY_EXTEND, DL, ContainerVT, Vec);
- }
- return Vec;
-}
+SDValue AArch64TargetLowering::LowerFixedLengthVectorCompressToSVE(
+ SDValue Op, SelectionDAG &DAG) const {
+ SDLoc DL(Op);
+ EVT VT = Op.getValueType();
-// Convert to VecVT with no-op casts where possible.
-static SDValue convertFromSVEContainerType(SDLoc DL, SDValue Vec, EVT VecVT,
- SelectionDAG &DAG) {
- if (VecVT.isFloatingPoint()) {
- // Use no-op casts for floating-point types.
- EVT PackedVT = getPackedSVEVectorVT(VecVT.getScalarType());
- Vec = DAG.getNode(AArch64ISD::NVCAST, DL, PackedVT, Vec);
- Vec = DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, VecVT, Vec);
- } else {
- // Truncate integers (may not be a no-op).
- Vec = DAG.getNode(ISD::TRUNCATE, DL, VecVT, Vec);
- }
- return Vec;
+ EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
+ SDValue Vec = convertToScalableVector(DAG, ContainerVT, Op.getOperand(0));
+ SDValue Mask = convertFixedMaskToScalableVector(Op.getOperand(1), DAG);
+ SDValue Passthru =
+ convertToScalableVector(DAG, ContainerVT, Op.getOperand(2));
+
+ SDValue Result =
+ DAG.getNode(ISD::VECTOR_COMPRESS, DL, ContainerVT, Vec, Mask, Passthru);
+ return convertFromScalableVector(DAG, VT, Result);
}
SDValue AArch64TargetLowering::LowerVECTOR_COMPRESS(SDValue Op,
SelectionDAG &DAG) const {
SDLoc DL(Op);
- SDValue Vec = Op.getOperand(0);
- SDValue Mask = Op.getOperand(1);
- SDValue Passthru = Op.getOperand(2);
- EVT VecVT = Vec.getValueType();
- EVT MaskVT = Mask.getValueType();
- EVT ElmtVT = VecVT.getVectorElementType();
- const bool IsFixedLength = VecVT.isFixedLengthVector();
- const bool HasPassthru = !Passthru.isUndef();
- unsigned MinElmts = VecVT.getVectorElementCount().getKnownMinValue();
- EVT FixedVecVT = MVT::getVectorVT(ElmtVT.getSimpleVT(), MinElmts);
-
- assert(VecVT.isVector() && "Input to VECTOR_COMPRESS must be vector.");
+ EVT VT = Op.getValueType();
+ if (VT.isFixedLengthVector())
+ return LowerFixedLengthVectorCompressToSVE(Op, DAG);
----------------
paulwalker-arm wrote:
While we should not get here when SVE is not available, I'd still move the fixed length handling after the `isSVEAvailable` check because if it does happen at least common code can expand the fixed length variant.
https://github.com/llvm/llvm-project/pull/171162
More information about the llvm-commits
mailing list