[llvm] 84704d9 - AMDGPU: Fix not accounting for constantexpr uses of LDS globals
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 20 08:41:48 PDT 2020
Author: Matt Arsenault
Date: 2020-07-20T11:41:41-04:00
New Revision: 84704d989b31b7d4cfc0eacfe8a8a25cba541cd0
URL: https://github.com/llvm/llvm-project/commit/84704d989b31b7d4cfc0eacfe8a8a25cba541cd0
DIFF: https://github.com/llvm/llvm-project/commit/84704d989b31b7d4cfc0eacfe8a8a25cba541cd0.diff
LOG: AMDGPU: Fix not accounting for constantexpr uses of LDS globals
This was failing to add the size of LDS globals that weren't directly
used by an instruction. They could be used by constant expressions
which are transitively used by the function. This requires a better
search, but just abort on this for now for correctness.
Added:
llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-constantexpr-use.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 727f71b35049..de05c2119d98 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -759,8 +759,14 @@ bool AMDGPUPromoteAlloca::hasSufficientLocalMem(const Function &F) {
for (const User *U : GV.users()) {
const Instruction *Use = dyn_cast<Instruction>(U);
- if (!Use)
- continue;
+ if (!Use) {
+ // FIXME: This is probably a constant expression use. We should
+ // recursively search the users of it for the parent function instead of
+ // bailing.
+ LLVM_DEBUG(dbgs() << "Giving up on LDS size estimate "
+ "due to constant expression\n");
+ return false;
+ }
if (Use->getParent()->getParent() == &F) {
Align Alignment =
diff --git a/llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-constantexpr-use.ll b/llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-constantexpr-use.ll
new file mode 100644
index 000000000000..a6511910603e
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-constantexpr-use.ll
@@ -0,0 +1,35 @@
+; RUN: opt -S -disable-promote-alloca-to-vector -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -amdgpu-promote-alloca < %s | FileCheck -check-prefix=IR %s
+; RUN: llc -disable-promote-alloca-to-vector -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s | FileCheck -check-prefix=ASM %s
+
+target datalayout = "A5"
+
+ at all_lds = internal unnamed_addr addrspace(3) global [16384 x i32] undef, align 4
+
+; This function cannot promote to using LDS because of the size of the
+; constant expression use in the function, which was previously not
+; detected.
+; IR-LABEL: @constant_expression_uses_lds(
+; IR: alloca
+
+; ASM-LABEL: constant_expression_uses_lds:
+; ASM: .group_segment_fixed_size: 65536
+define amdgpu_kernel void @constant_expression_uses_lds(i32 addrspace(1)* nocapture %out, i32 %idx) #0 {
+entry:
+ %stack = alloca [4 x i32], align 4, addrspace(5)
+ %gep0 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %stack, i32 0, i32 0
+ %gep1 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %stack, i32 0, i32 1
+ %gep2 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %stack, i32 0, i32 2
+ %gep3 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %stack, i32 0, i32 3
+ store i32 9, i32 addrspace(5)* %gep0
+ store i32 10, i32 addrspace(5)* %gep1
+ store i32 99, i32 addrspace(5)* %gep2
+ store i32 43, i32 addrspace(5)* %gep3
+ %arrayidx = getelementptr inbounds [4 x i32], [4 x i32] addrspace(5)* %stack, i32 0, i32 %idx
+ %load = load i32, i32 addrspace(5)* %arrayidx, align 4
+ store i32 %load, i32 addrspace(1)* %out
+
+ store volatile i32 ptrtoint ([16384 x i32] addrspace(3)* @all_lds to i32), i32 addrspace(1)* undef
+ ret void
+}
+
+attributes #0 = { "amdgpu-waves-per-eu"="1,5" }
More information about the llvm-commits
mailing list