[llvm] [DirectX] Implement `memcpy` in DXIL CBuffer Access pass (PR #144436)

Deric C. via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 17:01:13 PDT 2025


================
@@ -195,6 +195,82 @@ static void replaceLoad(LoadInst *LI, CBufferResource &CBR,
   DeadInsts.push_back(LI);
 }
 
+/// Replace memcpy from a cbuffer global with a memcpy from the cbuffer handle
+/// itself. Assumes the cbuffer global is an array, and the length of bytes to
+/// copy is divisible by array element allocation size.
+/// The memcpy source must also be a direct cbuffer global reference, not a GEP.
+static void replaceMemCpy(MemCpyInst *MCI, CBufferResource &CBR,
+                          SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
+
+  ArrayType *ArrTy = dyn_cast<ArrayType>(CBR.getValueType());
+  assert(ArrTy && "MemCpy lowering is only supported for array types");
+
+  // This assumption vastly simplifies the implementation
+  if (MCI->getSource() != CBR.Member)
+    reportFatalUsageError(
+        "Expected MemCpy source to be a cbuffer global variable");
----------------
Icohedron wrote:

Due to the unique data layout of cbuffers, handling the case of an arbitrary GEP is more complicated. It is also not necessary for this implementation.

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


More information about the llvm-commits mailing list