[PATCH] D137904: [RISCV] Provide a isOneSourceVECTOR_SHUFFLE function. NFC.
Han-Kuan Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 13 00:38:17 PST 2022
HanKuanChen created this revision.
HanKuanChen added reviewers: craig.topper, reames, frasercrmck.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
HanKuanChen requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
This function is used to reduce multiple check about whether a
vector_shuffle is from a same and contiguous source.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137904
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -2729,6 +2729,31 @@
return splatSplitI64WithVL(DL, VT, Passthru, Scalar, VL, DAG);
}
+// If a vector_shuffle source is from a same and contiguous (and started with 0
+// index) vector, return the vector. Otherwise, return SDValue().
+static SDValue isOneSourceVECTOR_SHUFFLE(SDValue N0, SDValue N1,
+ ArrayRef<int> Mask) {
+ if (N1.isUndef())
+ return N0;
+
+ // Both input must be extracts.
+ if (N0.getOpcode() != ISD::EXTRACT_SUBVECTOR ||
+ N1.getOpcode() != ISD::EXTRACT_SUBVECTOR)
+ return SDValue();
+
+ // Extracting from the same source.
+ SDValue Src = N0.getOperand(0);
+ if (Src != N1.getOperand(0))
+ return SDValue();
+
+ // Make sure N0 and N1 are continuous.
+ if (N0.getConstantOperandVal(1) != 0 ||
+ N1.getConstantOperandVal(1) != Mask.size())
+ return SDValue();
+
+ return Src;
+}
+
// Mask can only be this form.
// X X X X ... -1 -1 -1 ..., while X is not -1.
// X X X X ... must be in ascending order.
@@ -2740,22 +2765,8 @@
// In addition, N0 and N1 must from a same vector (or N1 is undef).
static bool isVnsrlShuffle(SDValue N0, SDValue N1, ArrayRef<int> Mask, EVT VT,
const RISCVSubtarget &Subtarget) {
- if (!N1.isUndef()) {
- // Both input must be extracts.
- if (N0.getOpcode() != ISD::EXTRACT_SUBVECTOR ||
- N1.getOpcode() != ISD::EXTRACT_SUBVECTOR)
- return false;
-
- // Extracting from the same source.
- SDValue Src = N0.getOperand(0);
- if (Src != N1.getOperand(0))
- return false;
-
- // Make sure N0 and N1 are continuous.
- if (N0.getConstantOperandVal(1) != 0 ||
- N1.getConstantOperandVal(1) != Mask.size())
- return false;
- }
+ if (!isOneSourceVECTOR_SHUFFLE(N0, N1, Mask))
+ return false;
if (Mask.size() < 2)
return false;
// Find first -1 and check whether the mask behind is -1.
@@ -2962,22 +2973,9 @@
ArrayRef<int> Mask,
const RISCVSubtarget &Subtarget,
SelectionDAG &DAG) {
- // Both input must be extracts.
- if (V1.getOpcode() != ISD::EXTRACT_SUBVECTOR ||
- V2.getOpcode() != ISD::EXTRACT_SUBVECTOR)
+ SDValue Src = isOneSourceVECTOR_SHUFFLE(V1, V2, Mask);
+ if (!Src)
return SDValue();
-
- // Extracting from the same source.
- SDValue Src = V1.getOperand(0);
- if (Src != V2.getOperand(0))
- return SDValue();
-
- // V1 must be started with 0.
- // V1 and V2 are continuous.
- if (V1.getConstantOperandVal(1) != 0 ||
- VT.getVectorNumElements() != V2.getConstantOperandVal(1))
- return SDValue();
-
// First index must be known and non-zero. It will be used as the slidedown
// amount.
if (Mask[0] <= 0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137904.474986.patch
Type: text/x-patch
Size: 3036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221113/3670c820/attachment.bin>
More information about the llvm-commits
mailing list