[llvm] [NVPTX] Vectorize loads when lowering of byval calls, misc. cleanup (PR #151070)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 16:46:11 PDT 2025


================
@@ -382,6 +382,51 @@ static void ComputePTXValueVTs(const TargetLowering &TLI, const DataLayout &DL,
   }
 }
 
+static EVT getVectorizedVT(EVT VT, unsigned N, LLVMContext &C) {
+  if (N == 1)
+    return VT;
+
+  const unsigned PackingAmt = VT.isVector() ? VT.getVectorNumElements() : 1;
+  return EVT::getVectorVT(C, VT.getScalarType(), N * PackingAmt);
+}
+
+static SDValue getExtractVectorizedValue(SDValue V, unsigned I, EVT VT,
+                                         const SDLoc &dl, SelectionDAG &DAG) {
+  if (V.getValueType() == VT) {
+    assert(I == 0 && "Index must be 0 for scalar value");
+    return V;
+  }
+
+  if (!VT.isVector())
+    return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, VT, V,
+                       DAG.getVectorIdxConstant(I, dl));
+
+  return DAG.getNode(
+      ISD::EXTRACT_SUBVECTOR, dl, VT, V,
+      DAG.getVectorIdxConstant(I * VT.getVectorNumElements(), dl));
+}
+
+template <typename T>
+static inline SDValue getBuildVectorizedValue(T GetElement, unsigned N,
----------------
Artem-B wrote:

Nit: callables are somewhat more readable when they are passed as the last argument. Otherwise subsequent function argument are somewhat lost in the noise of closing brackets of the passed lambda.

https://github.com/llvm/llvm-project/pull/151070


More information about the llvm-commits mailing list