Skip to content

Commit e2bd09d

Browse files
authored
[SYCL][LowerWGScope] Fix getSizeTTy to use pointer size in global address space (#19011)
In LowerWGScope pass, getSizeTTy is used as return type of local id functions. We should use pointer size in global address space, to ensure size_t is sufficient to represent the global range.
1 parent a99eae6 commit e2bd09d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

llvm/lib/SYCLLowerIR/LowerWGScope.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ template <typename T> static unsigned asUInt(T val) {
144144

145145
static IntegerType *getSizeTTy(Module &M) {
146146
LLVMContext &Ctx = M.getContext();
147-
auto PtrSize = M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(Ctx));
147+
const DataLayout &DL = M.getDataLayout();
148+
auto PtrSize = DL.getPointerTypeSize(
149+
PointerType::get(Ctx, DL.getDefaultGlobalsAddressSpace()));
148150
return PtrSize == 8 ? Type::getInt64Ty(Ctx) : Type::getInt32Ty(Ctx);
149151
}
150152

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: opt < %s -passes=LowerWGScope -S | FileCheck %s
2+
3+
; This test checks that pointer size in default global address space is used for
4+
; size_t type, which is value type of GV __spirv_BuiltInLocalInvocationIndex.
5+
; Note that pointer size in the default address space is 4.
6+
7+
target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-i64:64-v16:16-v32:32-n16:32:64-G1"
8+
9+
%struct.baz = type { i64 }
10+
11+
; CHECK: @__spirv_BuiltInLocalInvocationIndex = external addrspace(1) constant i64, align 8
12+
13+
define internal void @wibble(ptr byval(%struct.baz) %arg1) !work_group_scope !0 {
14+
; CHECK: load i64, ptr addrspace(1) @__spirv_BuiltInLocalInvocationIndex, align 8
15+
; CHECK: call void @_Z22__spirv_ControlBarrieriii(i32 2, i32 2, i32 272)
16+
ret void
17+
}
18+
19+
; CHECK: ; Function Attrs: convergent
20+
; CHECK: declare void @_Z22__spirv_ControlBarrieriii(i32, i32, i32) #[[ATTR_NUM:[0-9]+]]
21+
22+
; CHECK: attributes #[[ATTR_NUM]] = { convergent }
23+
24+
!0 = !{}

0 commit comments

Comments
 (0)