diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp @@ -736,6 +736,12 @@ continue; if (Use->getParent()->getParent() == &F) { + // Do not promote alloca to static LDS if this function uses any dynamic shared memory + // since mixed static/dynamic LDS is not fully supported yet. + uint64_t AllocSize = DL.getTypeAllocSize(GV.getValueType()); + if (AllocSize == 0) + return false; + unsigned Align = GV.getAlignment(); if (Align == 0) Align = DL.getABITypeAlignment(GV.getValueType()); @@ -744,7 +750,6 @@ // determined from the inverse order of uses in the function. I'm not // sure if the use list order is in any way connected to this, so the // total reported size is likely incorrect. - uint64_t AllocSize = DL.getTypeAllocSize(GV.getValueType()); CurrentLocalMemUsage = alignTo(CurrentLocalMemUsage, Align); CurrentLocalMemUsage += AllocSize; break;