[llvm] [RISCV] Match single source deinterleave shuffles for vnsrl (PR #114878)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 07:18:26 PST 2024
================
@@ -4441,48 +4441,58 @@ static SDValue lowerScalarInsert(SDValue Scalar, SDValue VL, MVT VT,
}
// Is this a shuffle extracts either the even or odd elements of a vector?
-// That is, specifically, either (a) or (b) below.
-// t34: v8i8 = extract_subvector t11, Constant:i64<0>
-// t33: v8i8 = extract_subvector t11, Constant:i64<8>
-// a) t35: v8i8 = vector_shuffle<0,2,4,6,8,10,12,14> t34, t33
-// b) t35: v8i8 = vector_shuffle<1,3,5,7,9,11,13,15> t34, t33
-// Returns {Src Vector, Even Elements} on success
-static bool isDeinterleaveShuffle(MVT VT, MVT ContainerVT, SDValue V1,
- SDValue V2, ArrayRef<int> Mask,
- const RISCVSubtarget &Subtarget) {
+// That is, specifically, either (a) or (b) in the options below.
+// Single operand shuffle is easy:
+// a) t35: v8i8 = vector_shuffle<0,2,4,6,u,u,u,u> t34, undef
+// b) t35: v8i8 = vector_shuffle<1,3,5,7,u,u,u,u> t34, undef
+// Double operand shuffle:
+// t34: v8i8 = extract_subvector t11, Constant:i64<0>
+// t33: v8i8 = extract_subvector t11, Constant:i64<8>
+// a) t35: v8i8 = vector_shuffle<0,2,4,6,8,10,12,14> t34, t33
+// b) t35: v8i8 = vector_shuffle<1,3,5,7,9,11,13,15> t34, t33
+static SDValue isDeinterleaveShuffle(MVT VT, MVT ContainerVT, SDValue V1,
+ SDValue V2, ArrayRef<int> Mask,
+ const RISCVSubtarget &Subtarget) {
// Need to be able to widen the vector.
if (VT.getScalarSizeInBits() >= Subtarget.getELen())
- return false;
+ return SDValue();
+
+ // First index must be the first even or odd element from V1.
+ if (Mask[0] != 0 && Mask[0] != 1)
+ return SDValue();
+
+ // The others must increase by 2 each time.
+ for (unsigned i = 1; i != Mask.size(); ++i)
+ if (Mask[i] != -1 && Mask[i] != Mask[0] + (int)i * 2)
+ return SDValue();
+
+ if (1 == count_if(Mask, [](int Idx) { return Idx != -1; }))
+ return SDValue();
----------------
preames wrote:
Slides actually. If we can use a vslide, I think that is mildly preferable to vnsrl. Not a big deal either way mind you.
https://github.com/llvm/llvm-project/pull/114878
More information about the llvm-commits
mailing list