Skip to content

[SYCL][LowerWGScope] Fix getSizeTTy to use pointer size in global address space #19011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/SYCLLowerIR/LowerWGScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ template <typename T> static unsigned asUInt(T val) {

static IntegerType *getSizeTTy(Module &M) {
LLVMContext &Ctx = M.getContext();
auto PtrSize = M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(Ctx));
const DataLayout &DL = M.getDataLayout();
auto PtrSize = DL.getPointerTypeSize(
PointerType::get(Ctx, DL.getDefaultGlobalsAddressSpace()));
return PtrSize == 8 ? Type::getInt64Ty(Ctx) : Type::getInt32Ty(Ctx);
}

Expand Down
24 changes: 24 additions & 0 deletions llvm/test/SYCLLowerIR/convergent_ptr_size_in_addrspace.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: opt < %s -passes=LowerWGScope -S | FileCheck %s

; This test checks that pointer size in default global address space is used for
; size_t type, which is value type of GV __spirv_BuiltInLocalInvocationIndex.
; Note that pointer size in the default address space is 4.

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"

%struct.baz = type { i64 }

; CHECK: @__spirv_BuiltInLocalInvocationIndex = external addrspace(1) constant i64, align 8

define internal void @wibble(ptr byval(%struct.baz) %arg1) !work_group_scope !0 {
; CHECK: load i64, ptr addrspace(1) @__spirv_BuiltInLocalInvocationIndex, align 8
; CHECK: call void @_Z22__spirv_ControlBarrieriii(i32 2, i32 2, i32 272)
ret void
}

; CHECK: ; Function Attrs: convergent
; CHECK: declare void @_Z22__spirv_ControlBarrieriii(i32, i32, i32) #[[ATTR_NUM:[0-9]+]]

; CHECK: attributes #[[ATTR_NUM]] = { convergent }

!0 = !{}