diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp @@ -1175,6 +1175,11 @@ const int NrOfSGPRUntilSpill = 26; const int NrOfVGPRUntilSpill = 32; + // In case of indirect calls, callee Function may not be retrievable from the + // CallBase. + if (!Callee) + return 0; + const DataLayout &DL = TTIImpl->getDataLayout(); unsigned adjustThreshold = 0; diff --git a/llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-stack-indirect-call-argument.ll b/llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-stack-indirect-call-argument.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-stack-indirect-call-argument.ll @@ -0,0 +1,22 @@ +; REQUIRES: asserts +; RUN: opt -mtriple=amdgcn-amd-amdhsa -S -passes=inline -inline-cost-full=true -debug-only=inline-cost < %s 2>&1 | FileCheck %s + +; CHECK: Analyzing call of Dummy... (caller:Caller) + +define void @Wrapper(ptr nocapture nofree noundef readonly %func, ptr noundef %arg, i32 noundef %a) { +entry: + call void %func(ptr noundef %arg, i32 noundef %a) + ret void +} + +define internal void @Dummy(ptr noundef %ptrarg, i32 noundef %intarg) { +entry: + ret void +} + +define void @Caller() { +entry: + %arg = alloca ptr + call void @Wrapper(ptr noundef @Dummy, ptr noundef %arg, i32 42) + ret void +}