[llvm] 41c96e9 - AMDGPU: Fix not emitting code for exotic constructor types
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 9 10:32:33 PST 2022
Author: Matt Arsenault
Date: 2022-12-09T13:22:12-05:00
New Revision: 41c96e94835df372ccdb6ad4df07b7bfaf257b51
URL: https://github.com/llvm/llvm-project/commit/41c96e94835df372ccdb6ad4df07b7bfaf257b51
DIFF: https://github.com/llvm/llvm-project/commit/41c96e94835df372ccdb6ad4df07b7bfaf257b51.diff
LOG: AMDGPU: Fix not emitting code for exotic constructor types
This was simply ignoring any entries that weren't direct function
calls. This really should have been erroring on anything
unexpected. We should be able to handle calling just about anything
these days, so just call anything.
Added:
llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
index 40476ce138d29..92399c39f4ac0 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp
@@ -56,16 +56,17 @@ class AMDGPUCtorDtorLowering final : public ModulePass {
ConstantArray *GA = dyn_cast<ConstantArray>(GV->getInitializer());
if (!GA || GA->getNumOperands() == 0)
return false;
+
Function *InitOrFiniKernel = createInitOrFiniKernelFunction(M, IsCtor);
IRBuilder<> IRB(InitOrFiniKernel->getEntryBlock().getTerminator());
+
+ FunctionType *ConstructorTy = InitOrFiniKernel->getFunctionType();
+
for (Value *V : GA->operands()) {
auto *CS = cast<ConstantStruct>(V);
- if (Function *F = dyn_cast<Function>(CS->getOperand(1))) {
- FunctionCallee Ctor =
- M.getOrInsertFunction(F->getName(), IRB.getVoidTy());
- IRB.CreateCall(Ctor);
- }
+ IRB.CreateCall(ConstructorTy, CS->getOperand(1));
}
+
appendToUsed(M, {InitOrFiniKernel});
return true;
}
diff --git a/llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll b/llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll
new file mode 100644
index 0000000000000..93c082362a669
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll
@@ -0,0 +1,82 @@
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -amdgpu-lower-ctor-dtor %s | FileCheck %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s | FileCheck -check-prefix=GCN %s
+
+; Make sure we emit code for constructor entries that aren't direct
+; function calls.
+
+; Check a constructor that's an alias, and an integer literal.
+ at llvm.global_ctors = appending addrspace(1) global [2 x { i32, ptr, ptr }] [
+ { i32, ptr, ptr } { i32 1, ptr @foo.alias, i8* null },
+ { i32, ptr, ptr } { i32 1, ptr inttoptr (i64 4096 to ptr), i8* null }
+]
+
+; Check a constantexpr addrspacecast
+ at llvm.global_dtors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [
+ { i32, ptr, ptr } { i32 1, ptr addrspacecast (ptr addrspace(1) @bar to ptr), i8* null }
+]
+
+ at foo.alias = hidden alias void (), ptr @foo
+
+;.
+; CHECK: @llvm.global_ctors = appending addrspace(1) global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @foo.alias, ptr null }, { i32, ptr, ptr } { i32 1, ptr inttoptr (i64 4096 to ptr), ptr null }]
+; CHECK: @llvm.global_dtors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr addrspacecast (ptr addrspace(1) @bar to ptr), ptr null }]
+; CHECK: @llvm.used = appending global [2 x ptr] [ptr @amdgcn.device.init, ptr @amdgcn.device.fini], section "llvm.metadata"
+; CHECK: @foo.alias = hidden alias void (), ptr @foo
+;.
+define void @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT: ret void
+;
+ ret void
+}
+
+define void @bar() addrspace(1) {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT: ret void
+;
+ ret void
+}
+
+; CHECK: define amdgpu_kernel void @amdgcn.device.init() #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: call void @foo.alias()
+; CHECK-NEXT: call void inttoptr (i64 4096 to ptr)()
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+
+; CHECK: define amdgpu_kernel void @amdgcn.device.fini() #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT: call void addrspacecast (ptr addrspace(1) @bar to ptr)()
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+
+;.
+; CHECK: attributes #[[ATTR0]] = { "device-init" }
+; CHECK: attributes #[[ATTR1]] = { "device-fini" }
+
+
+; GCN-LABEL: foo:
+; GCN: ; %bb.0:
+; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT: s_setpc_b64 s[30:31]
+;
+; GCN-LABEL: bar:
+; GCN: ; %bb.0:
+; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GCN-NEXT: s_setpc_b64 s[30:31]
+;
+; GCN-LABEL: amdgcn.device.init:
+; GCN: s_getpc_b64 s{{\[}}[[PC_LO:[0-9]+]]:[[PC_HI:[0-9]+]]{{\]}}
+; GCN-NEXT: s_add_u32 s[[PC_LO]], s[[PC_LO]], foo.alias at rel32@lo+4
+; GCN-NEXT: s_addc_u32 s[[PC_HI]], s[[PC_HI]], foo.alias at rel32@hi+12
+; GCN-NEXT: s_swappc_b64 s[30:31], s{{\[}}[[PC_LO]]:[[PC_HI]]{{\]}}
+
+; GCN: s_mov_b64 [[LIT_ADDR:s\[[0-9]+:[0-9]+\]]], 0x1000
+; GCN: s_swappc_b64 s[30:31], [[LIT_ADDR]]
+; GCN-NEXT: s_endpgm
+;
+; GCN-LABEL: amdgcn.device.fini:
+; GCN: s_getpc_b64 s{{\[}}[[PC_LO:[0-9]+]]:[[PC_HI:[0-9]+]]{{\]}}
+; GCN-NEXT: s_add_u32 s[[PC_LO]], s[[PC_LO]], bar at gotpcrel32@lo+4
+; GCN-NEXT: s_addc_u32 s[[PC_HI]], s[[PC_HI]], bar at gotpcrel32@hi+12
+; GCN-NEXT: s_load_dwordx2 s{{\[}}[[GOT_LO:[0-9]+]]:[[GOT_HI:[0-9]+]]{{\]}}, s{{\[}}[[PC_LO]]:[[PC_HI]]{{\]}}, 0x0
+; GCN: s_swappc_b64 s[30:31], s{{\[}}[[GOT_LO]]:[[GOT_HI]]{{\]}}
+; GCN-NEXT: s_endpgm
More information about the llvm-commits
mailing list