Skip to content

Commit 1e357cd

Browse files
authored
AMDGPU: Use pointer types more consistently (#111651)
This was using addrspace 0 and 1 pointers interchangably. This works out since they happen to use the same size, but consistently query or use the correct one.
1 parent d25f1a1 commit 1e357cd

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCtorDtorLowering.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,22 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
7777
auto *LoopBB = BasicBlock::Create(C, "while.entry", &F);
7878
auto *ExitBB = BasicBlock::Create(C, "while.end", &F);
7979
Type *PtrTy = IRB.getPtrTy(AMDGPUAS::GLOBAL_ADDRESS);
80+
ArrayType *PtrArrayTy = ArrayType::get(PtrTy, 0);
8081

8182
auto *Begin = M.getOrInsertGlobal(
82-
IsCtor ? "__init_array_start" : "__fini_array_start",
83-
ArrayType::get(PtrTy, 0), [&]() {
83+
IsCtor ? "__init_array_start" : "__fini_array_start", PtrArrayTy, [&]() {
8484
return new GlobalVariable(
85-
M, ArrayType::get(PtrTy, 0),
85+
M, PtrArrayTy,
8686
/*isConstant=*/true, GlobalValue::ExternalLinkage,
8787
/*Initializer=*/nullptr,
8888
IsCtor ? "__init_array_start" : "__fini_array_start",
8989
/*InsertBefore=*/nullptr, GlobalVariable::NotThreadLocal,
9090
/*AddressSpace=*/AMDGPUAS::GLOBAL_ADDRESS);
9191
});
9292
auto *End = M.getOrInsertGlobal(
93-
IsCtor ? "__init_array_end" : "__fini_array_end",
94-
ArrayType::get(PtrTy, 0), [&]() {
93+
IsCtor ? "__init_array_end" : "__fini_array_end", PtrArrayTy, [&]() {
9594
return new GlobalVariable(
96-
M, ArrayType::get(PtrTy, 0),
95+
M, PtrArrayTy,
9796
/*isConstant=*/true, GlobalValue::ExternalLinkage,
9897
/*Initializer=*/nullptr,
9998
IsCtor ? "__init_array_end" : "__fini_array_end",
@@ -117,7 +116,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
117116
auto *Size = IRB.CreateAShr(ByteSize, ConstantInt::get(Int64Ty, 3));
118117
auto *Offset = IRB.CreateSub(Size, ConstantInt::get(Int64Ty, 1));
119118
Start = IRB.CreateInBoundsGEP(
120-
ArrayType::get(IRB.getPtrTy(), 0), Begin,
119+
PtrArrayTy, Begin,
121120
ArrayRef<Value *>({ConstantInt::get(Int64Ty, 0), Offset}));
122121
Stop = Begin;
123122
}
@@ -128,8 +127,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
128127
LoopBB, ExitBB);
129128
IRB.SetInsertPoint(LoopBB);
130129
auto *CallBackPHI = IRB.CreatePHI(PtrTy, 2, "ptr");
131-
auto *CallBack = IRB.CreateLoad(IRB.getPtrTy(F.getAddressSpace()),
132-
CallBackPHI, "callback");
130+
auto *CallBack = IRB.CreateLoad(F.getType(), CallBackPHI, "callback");
133131
IRB.CreateCall(CallBackTy, CallBack);
134132
auto *NewCallBack =
135133
IRB.CreateConstGEP1_64(PtrTy, CallBackPHI, IsCtor ? 1 : -1, "next");

llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ define void @bar() addrspace(1) {
6666
; CHECK-NEXT: entry:
6767
; CHECK-NEXT: [[TMP0:%.*]] = ashr i64 sub (i64 ptrtoint (ptr addrspace(1) @__fini_array_end to i64), i64 ptrtoint (ptr addrspace(1) @__fini_array_start to i64)), 3
6868
; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[TMP0]], 1
69-
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [0 x ptr], ptr addrspace(1) @__fini_array_start, i64 0, i64 [[TMP1]]
69+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [0 x ptr addrspace(1)], ptr addrspace(1) @__fini_array_start, i64 0, i64 [[TMP1]]
7070
; CHECK-NEXT: [[TMP3:%.*]] = icmp uge ptr addrspace(1) [[TMP2]], @__fini_array_start
7171
; CHECK-NEXT: br i1 [[TMP3]], label [[WHILE_ENTRY:%.*]], label [[WHILE_END:%.*]]
7272
; CHECK: while.entry:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ define internal void @bar() {
8181
; CHECK-NEXT: entry:
8282
; CHECK-NEXT: [[TMP0:%.*]] = ashr i64 sub (i64 ptrtoint (ptr addrspace(1) @__fini_array_end to i64), i64 ptrtoint (ptr addrspace(1) @__fini_array_start to i64)), 3
8383
; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[TMP0]], 1
84-
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [0 x ptr], ptr addrspace(1) @__fini_array_start, i64 0, i64 [[TMP1]]
84+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [0 x ptr addrspace(1)], ptr addrspace(1) @__fini_array_start, i64 0, i64 [[TMP1]]
8585
; CHECK-NEXT: [[TMP3:%.*]] = icmp uge ptr addrspace(1) [[TMP2]], @__fini_array_start
8686
; CHECK-NEXT: br i1 [[TMP3]], label [[WHILE_ENTRY:%.*]], label [[WHILE_END:%.*]]
8787
; CHECK: while.entry:

llvm/test/CodeGen/AMDGPU/lower-multiple-ctor-dtor.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ define internal void @bar.5() {
7373
; CHECK-NEXT: entry:
7474
; CHECK-NEXT: [[TMP0:%.*]] = ashr i64 sub (i64 ptrtoint (ptr addrspace(1) @__fini_array_end to i64), i64 ptrtoint (ptr addrspace(1) @__fini_array_start to i64)), 3
7575
; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[TMP0]], 1
76-
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [0 x ptr], ptr addrspace(1) @__fini_array_start, i64 0, i64 [[TMP1]]
76+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [0 x ptr addrspace(1)], ptr addrspace(1) @__fini_array_start, i64 0, i64 [[TMP1]]
7777
; CHECK-NEXT: [[TMP3:%.*]] = icmp uge ptr addrspace(1) [[TMP2]], @__fini_array_start
7878
; CHECK-NEXT: br i1 [[TMP3]], label [[WHILE_ENTRY:%.*]], label [[WHILE_END:%.*]]
7979
; CHECK: while.entry:

0 commit comments

Comments
 (0)