[llvm] [AMDGPU][PromoteAlloca] Support memsets to ptr allocas (PR #80678)

Mariusz Sikora via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 06:04:59 PST 2024


================
@@ -521,10 +521,18 @@ static Value *promoteAllocaUserToVector(
       // For memset, we don't need to know the previous value because we
       // currently only allow memsets that cover the whole alloca.
       Value *Elt = MSI->getOperand(1);
-      if (DL.getTypeStoreSize(VecEltTy) > 1) {
-        Value *EltBytes =
-            Builder.CreateVectorSplat(DL.getTypeStoreSize(VecEltTy), Elt);
-        Elt = Builder.CreateBitCast(EltBytes, VecEltTy);
+      const unsigned BytesPerElt = DL.getTypeStoreSize(VecEltTy);
+      if (BytesPerElt > 1) {
+        Value *EltBytes = Builder.CreateVectorSplat(BytesPerElt, Elt);
+
+        // If the element type of the vector is a pointer, we need to first cast
+        // to an integer, then use a PtrCast.
+        if (VecEltTy->isPointerTy()) {
----------------
mariusz-sikora-at-amd wrote:

I'm actually looking into PromoteAlloca to add support for two-dimensional arrays. We have couple shaders where these will remove scratch memory accesses. I was thinking of handling two-dimensional array as multiple one-dimensional arrays, but I'm open to any suggestions. I saw @Pierre-vh you refactored and added SSAUpdater to PromoteAlloca at some point.

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


More information about the llvm-commits mailing list