From ce51c5d4a935cb1a4b99e5c95e0c4c5724b64375 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 26 Aug 2021 17:41:33 -0400 Subject: [PATCH] AMDGPU: Fix crashing on kernel declarations when lowering LDS This was trying to insert the used marker into a declaration. --- llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp | 15 ++++++++++----- llvm/test/CodeGen/AMDGPU/lower-module-lds.ll | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp index 26e2b5f..02bb3c4 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp @@ -163,6 +163,9 @@ public: 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 @@ private: if (!F) { IRBuilder<> Builder(Ctx); SmallPtrSet 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); } } } diff --git a/llvm/test/CodeGen/AMDGPU/lower-module-lds.ll b/llvm/test/CodeGen/AMDGPU/lower-module-lds.ll index e92d862..a620eb8 100644 --- a/llvm/test/CodeGen/AMDGPU/lower-module-lds.ll +++ b/llvm/test/CodeGen/AMDGPU/lower-module-lds.ll @@ -54,3 +54,7 @@ define amdgpu_kernel void @kern_call() { 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() -- 2.7.4