[llvm] [RISCV] Extract spread(2,4,8) shuffle lowering from interleave(2) (PR #118822)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 10:47:08 PST 2024
================
@@ -4816,12 +4816,46 @@ static SDValue lowerVECTOR_SHUFFLEAsVSlide1(const SDLoc &DL, MVT VT,
return convertFromScalableVector(VT, Vec, DAG, Subtarget);
}
+// Given a vector a, b, c, d return a vector Factor times longer
+// with Factor-1 undef's between elements. Ex:
+// a, undef, b, undef, c, undef, d, undef (Factor=2, Index=0)
+// undef, a, undef, b, undef, c, undef, d (Factor=2, Index=1)
+static SDValue getWideningSpread(SDValue V, unsigned Factor, unsigned Index,
+ const SDLoc &DL, SelectionDAG &DAG) {
+
+ MVT VT = V.getSimpleValueType();
+ unsigned EltBits = VT.getScalarSizeInBits();
+ ElementCount EC = VT.getVectorElementCount();
+ V = DAG.getBitcast(VT.changeTypeToInteger(), V);
+
+ MVT WideVT = MVT::getVectorVT(MVT::getIntegerVT(EltBits * Factor), EC);
+
+ SDValue Result = DAG.getNode(ISD::ZERO_EXTEND, DL, WideVT, V);
+ // TODO: On rv32, the constant becomes a splat_vector_parts which does not
+ // allow the SHL to fold away if Index is 0.
+ if (Index != 0)
+ Result = DAG.getNode(ISD::SHL, DL, WideVT, Result,
+ DAG.getConstant(EltBits * Index, DL, WideVT));
+ // Make sure to use original element type
+ MVT ResultVT = MVT::getVectorVT(VT.getVectorElementType(),
+ EC.multiplyCoefficientBy(Factor));
+ return DAG.getBitcast(ResultVT, Result);
+}
+
// Given two input vectors of <[vscale x ]n x ty>, use vwaddu.vv and vwmaccu.vx
// to create an interleaved vector of <[vscale x] n*2 x ty>.
// This requires that the size of ty is less than the subtarget's maximum ELEN.
static SDValue getWideningInterleave(SDValue EvenV, SDValue OddV,
const SDLoc &DL, SelectionDAG &DAG,
const RISCVSubtarget &Subtarget) {
+
+ // FIXME: Not only does this optimize the code, it fixes some correctness
+ // issues because MIR does not have freeze.
+ if (EvenV.isUndef())
+ return getWideningSpread(OddV, 2, 1, DL, DAG);
+ else if (OddV.isUndef())
----------------
topperc wrote:
Drop else
https://github.com/llvm/llvm-project/pull/118822
More information about the llvm-commits
mailing list