Skip to content

Commit 67b789b

Browse files
authored
[NVPTX] Fix global destructor handling not working with a single dtor (#162537)
Summary: Very small typo here caused it to not enter the main loop if the size was not greater than 1. The inner loop is "less than" so the inverse should be "greater than or equal" but we were only doing "greater than". Did not notice this because the libc handling does its own implementation and the OpenMP tests only tested multiple destructors, and most people only ever use global constructors when they show up on the GPU.
1 parent c083fa1 commit 67b789b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static Function *createInitOrFiniKernelFunction(Module &M, bool IsCtor) {
8888
// reinterpret_cast<InitCallback *>(*start)();
8989
// }
9090
//
91-
// void call_init_array_callbacks() {
91+
// void call_fini_array_callbacks() {
9292
// size_t fini_array_size = __fini_array_end - __fini_array_start;
9393
// for (size_t i = fini_array_size; i > 0; --i)
9494
// reinterpret_cast<FiniCallback *>(__fini_array_start[i - 1])();
@@ -153,7 +153,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
153153
"start");
154154
}
155155
IRB.CreateCondBr(
156-
IRB.CreateCmp(IsCtor ? ICmpInst::ICMP_NE : ICmpInst::ICMP_UGT, BeginVal,
156+
IRB.CreateCmp(IsCtor ? ICmpInst::ICMP_NE : ICmpInst::ICMP_UGE, BeginVal,
157157
EndVal),
158158
LoopBB, ExitBB);
159159
IRB.SetInsertPoint(LoopBB);

llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ define internal void @bar() {
7272
; CHECK-NEXT: [[OFFSET:%.*]] = ashr exact i64 [[TMP2]], 3
7373
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr ptr, ptr addrspace(1) [[BEGIN]], i64 [[OFFSET]]
7474
; CHECK-NEXT: [[START:%.*]] = getelementptr inbounds ptr, ptr addrspace(1) [[TMP3]], i64 -1
75-
; CHECK-NEXT: [[TMP4:%.*]] = icmp ugt ptr addrspace(1) [[START]], [[BEGIN]]
75+
; CHECK-NEXT: [[TMP4:%.*]] = icmp uge ptr addrspace(1) [[START]], [[BEGIN]]
7676
; CHECK-NEXT: br i1 [[TMP4]], label [[WHILE_ENTRY:%.*]], label [[WHILE_END:%.*]]
7777
; CHECK: while.entry:
7878
; CHECK-NEXT: [[PTR:%.*]] = phi ptr addrspace(1) [ [[START]], [[ENTRY:%.*]] ], [ [[NEXT:%.*]], [[WHILE_ENTRY]] ]

0 commit comments

Comments
 (0)