[llvm] [AMDGPU] Support alloca in AS0 (PR #136584)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 07:03:10 PDT 2025


================
@@ -2355,6 +2358,23 @@ bool AMDGPUCodeGenPrepareImpl::visitSqrt(IntrinsicInst &Sqrt) {
   return true;
 }
 
+// Rewrite alloca with AS0 to alloca with AS5 followed by a addrspace cast.
+bool AMDGPUCodeGenPrepareImpl::visitAllocaInst(AllocaInst &I) {
+  if (I.getAddressSpace() == DL.getAllocaAddrSpace())
+    return false;
+  assert(I.getAddressSpace() == 0 && "An alloca can't be in random AS");
+  IRBuilder<> Builder(&I);
+  AllocaInst *NewAI = Builder.CreateAlloca(
+      I.getAllocatedType(), DL.getAllocaAddrSpace(), I.getArraySize());
+  NewAI->takeName(&I);
+  NewAI->copyMetadata(I);
----------------
shiltian wrote:

K, good to know. I added it.

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


More information about the llvm-commits mailing list