[llvm] [RISCV] Optimize gather/scatter to unit-stride memop + shuffle (PR #66279)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 13:10:52 PDT 2023
================
@@ -13510,6 +13510,40 @@ static bool legalizeScatterGatherIndexType(SDLoc DL, SDValue &Index,
return true;
}
+/// Match the index vector of a scatter or gather node as the shuffle mask
+/// which performs the rearrangement if possible. Will only match if
+/// all lanes are touched, and thus replacing the scatter or gather with
+/// a unit strided access and shuffle is legal.
+static bool matchIndexAsShuffle(EVT VT, SDValue Index, SDValue Mask,
+ SmallVector<int> &ShuffleMask) {
+ if (!ISD::isConstantSplatVectorAllOnes(Mask.getNode()))
+ return false;
+ if (!ISD::isBuildVectorOfConstantSDNodes(Index.getNode()))
+ return false;
+
+ const unsigned ElementSize = VT.getScalarStoreSize();
+ const unsigned NumElems = VT.getVectorNumElements();
+
+ // Create the shuffle mask and check all bits active
+ assert(ShuffleMask.empty());
+ BitVector ActiveLanes(NumElems);
+ for (const auto Idx : enumerate(Index->ops())) {
----------------
topperc wrote:
Why are we using the ops iterator but then discarding the value() part? Can we just use `for (unsigned i = 0; i < Index->getNumOperands(); ++i)`?
https://github.com/llvm/llvm-project/pull/66279
More information about the llvm-commits
mailing list