[PATCH] D108791: AMDGPU: Fix crashing on kernel declarations when lowering LDS

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 26 14:48:47 PDT 2021


arsenm created this revision.
arsenm added reviewers: JonChesterfield, hsmhsm, rampitec.
Herald added subscribers: foad, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

This was trying to insert the used marker into a declaration.


https://reviews.llvm.org/D108791

Files:
  llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
  llvm/test/CodeGen/AMDGPU/lower-module-lds.ll


Index: llvm/test/CodeGen/AMDGPU/lower-module-lds.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/lower-module-lds.ll
+++ llvm/test/CodeGen/AMDGPU/lower-module-lds.ll
@@ -54,3 +54,7 @@
 define spir_kernel void @kern_empty() {
   ret void
 }
+
+; Make sure we don't crash trying to insert code into a kernel
+; declaration.
+declare amdgpu_kernel void @kernel_declaration()
Index: llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -163,6 +163,9 @@
     bool Changed = processUsedLDS(M);
 
     for (Function &F : M.functions()) {
+      if (F.isDeclaration())
+        continue;
+
       // Only lower compute kernels' LDS.
       if (!AMDGPU::isKernel(F.getCallingConv()))
         continue;
@@ -347,11 +350,13 @@
     if (!F) {
       IRBuilder<> Builder(Ctx);
       SmallPtrSet<Function *, 32> Kernels;
-      for (auto &I : M.functions()) {
-        Function *Func = &I;
-        if (AMDGPU::isKernelCC(Func) && !Kernels.contains(Func)) {
-          markUsedByKernel(Builder, Func, SGV);
-          Kernels.insert(Func);
+      for (Function &Func : M.functions()) {
+        if (Func.isDeclaration())
+          continue;
+
+        if (AMDGPU::isKernelCC(&Func) && !Kernels.contains(&Func)) {
+          markUsedByKernel(Builder, &Func, SGV);
+          Kernels.insert(&Func);
         }
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108791.368993.patch
Type: text/x-patch
Size: 1546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210826/4b144e66/attachment.bin>


More information about the llvm-commits mailing list