From 0ddafe89b1c600cd2444fd16e5a65d7a67001bf7 Mon Sep 17 00:00:00 2001 From: Zheming Jin Date: Sun, 19 Jul 2026 10:51:39 -0700 Subject: [PATCH 1/3] [SYCL][HIP] Fix GlobalOffset bad-signature crash to enable Assert tests The GlobalOffsetPass crashed with "Calling a function with a bad signature!" when rewriting callers of functions that gained an implicit global-offset parameter, because non-call uses were handled with an early return and new call instructions were built from the callee's updated type instead of the original call's signature. Iterate over all uses (skipping non-direct-call uses) and construct the new call from the original call's function type with the implicit offset parameter appended. This unblocks assert-in-kernel support on AMD HIP. Re-enables the previously UNSUPPORTED Assert/* e2e tests on HIP. Co-authored-by: Cursor --- llvm/lib/SYCLLowerIR/GlobalOffset.cpp | 27 ++++++++++++++++--- sycl/test-e2e/Assert/assert_in_kernels.cpp | 3 --- .../Assert/assert_in_multiple_tus.cpp | 3 --- .../assert_in_multiple_tus_one_ndebug.cpp | 3 --- sycl/test-e2e/Assert/assert_in_one_kernel.cpp | 3 --- .../Assert/assert_in_simultaneous_kernels.cpp | 4 +-- .../assert_in_simultaneously_multiple_tus.cpp | 5 +--- ...simultaneously_multiple_tus_one_ndebug.cpp | 4 +-- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/llvm/lib/SYCLLowerIR/GlobalOffset.cpp b/llvm/lib/SYCLLowerIR/GlobalOffset.cpp index 019ef408f34d6..ef71532c7d592 100644 --- a/llvm/lib/SYCLLowerIR/GlobalOffset.cpp +++ b/llvm/lib/SYCLLowerIR/GlobalOffset.cpp @@ -224,8 +224,15 @@ void GlobalOffsetPass::addImplicitParameterToCallers( for (User *U : Users) { auto *CallToOld = dyn_cast(U); - if (!CallToOld) - return; + // Only direct calls where `Callee` is the callee are handled. If `Callee` + // is used in any other way (e.g. its address is taken or it is passed as a + // call argument), the implicit offset argument cannot be threaded through + // that use. Skipping such uses avoids constructing a call with a + // mismatched signature (which would otherwise crash the compiler). Note we + // must `continue` rather than `return` so remaining valid callers are still + // processed. + if (!CallToOld || CallToOld->getCalledOperand() != Callee) + continue; auto *Caller = CallToOld->getFunction(); @@ -273,10 +280,24 @@ void GlobalOffsetPass::addImplicitParameterToCallers( } ImplicitOffsets.push_back(ImplicitOffset); + // Build the callee type from the *original* call's function type rather + // than from the callee's declared signature, then append the implicit + // offset parameter. LLVM allows a call whose function type differs from + // the callee's declared type (e.g. SYCL device code frequently calls + // functions through address-space-mismatched pointer types such as + // generic `ptr` vs `ptr addrspace(4)`). Using the callee's declared + // signature here would create a call whose argument types disagree with + // the parameter types, tripping a "bad signature" assertion. + FunctionType *OldCallTy = CallToOld->getFunctionType(); + SmallVector NewParamTypes(OldCallTy->params()); + NewParamTypes.push_back(ImplicitOffset->getType()); + FunctionType *NewCallTy = FunctionType::get( + OldCallTy->getReturnType(), NewParamTypes, OldCallTy->isVarArg()); + // Replace call to other function (which now has a new parameter), // with a call including the new parameter to that same function. auto *NewCallInst = CallInst::Create( - /* Ty= */ CalleeWithImplicitParam->getFunctionType(), + /* Ty= */ NewCallTy, /* Func= */ CalleeWithImplicitParam, /* Args= */ ImplicitOffsets, /* NameStr= */ Twine(), diff --git a/sycl/test-e2e/Assert/assert_in_kernels.cpp b/sycl/test-e2e/Assert/assert_in_kernels.cpp index d88ea0ea38374..d7dea39a71ef2 100644 --- a/sycl/test-e2e/Assert/assert_in_kernels.cpp +++ b/sycl/test-e2e/Assert/assert_in_kernels.cpp @@ -1,8 +1,5 @@ // REQUIRES: linux -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/7634 -// // XFAIL: (opencl && gpu) // XFAIL-TRACKER: https://github.com/intel/llvm/issues/11364 diff --git a/sycl/test-e2e/Assert/assert_in_multiple_tus.cpp b/sycl/test-e2e/Assert/assert_in_multiple_tus.cpp index 2bbb2827030a2..8e4a49054f904 100644 --- a/sycl/test-e2e/Assert/assert_in_multiple_tus.cpp +++ b/sycl/test-e2e/Assert/assert_in_multiple_tus.cpp @@ -1,8 +1,5 @@ // REQUIRES: linux -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/7634 -// // UNSUPPORTED: cuda // UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/8832 // diff --git a/sycl/test-e2e/Assert/assert_in_multiple_tus_one_ndebug.cpp b/sycl/test-e2e/Assert/assert_in_multiple_tus_one_ndebug.cpp index 0f489aa730db2..81dae489b8cee 100644 --- a/sycl/test-e2e/Assert/assert_in_multiple_tus_one_ndebug.cpp +++ b/sycl/test-e2e/Assert/assert_in_multiple_tus_one_ndebug.cpp @@ -1,8 +1,5 @@ // REQUIRES: linux -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/7634 -// // UNSUPPORTED: cuda // UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/8832 // diff --git a/sycl/test-e2e/Assert/assert_in_one_kernel.cpp b/sycl/test-e2e/Assert/assert_in_one_kernel.cpp index 824869cfdd598..3444cf37df236 100644 --- a/sycl/test-e2e/Assert/assert_in_one_kernel.cpp +++ b/sycl/test-e2e/Assert/assert_in_one_kernel.cpp @@ -1,8 +1,5 @@ // REQUIRES: linux -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/7634 -// // XFAIL: (opencl && gpu) // XFAIL-TRACKER: https://github.com/intel/llvm/issues/11364 diff --git a/sycl/test-e2e/Assert/assert_in_simultaneous_kernels.cpp b/sycl/test-e2e/Assert/assert_in_simultaneous_kernels.cpp index 16900f8fb35f6..e4ac2d66e4016 100644 --- a/sycl/test-e2e/Assert/assert_in_simultaneous_kernels.cpp +++ b/sycl/test-e2e/Assert/assert_in_simultaneous_kernels.cpp @@ -1,7 +1,5 @@ // REQUIRES: linux -// FIXME: Flaky on HIP and cuda -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/22300 +// FIXME: Flaky on cuda // UNSUPPORTED: cuda // RUN: %{build} -o %t.out %threads_lib // diff --git a/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus.cpp b/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus.cpp index 143d0b225c066..d1751605f4134 100644 --- a/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus.cpp +++ b/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus.cpp @@ -1,9 +1,6 @@ -// FIXME flaky fail on CUDA and HIP +// FIXME flaky fail on CUDA // UNSUPPORTED: cuda // -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/22300 -// // XFAIL: (opencl && gpu) // XFAIL-TRACKER: https://github.com/intel/llvm/issues/11364 // diff --git a/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus_one_ndebug.cpp b/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus_one_ndebug.cpp index 5a736d184fd87..8ce59ef1ce46a 100644 --- a/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus_one_ndebug.cpp +++ b/sycl/test-e2e/Assert/assert_in_simultaneously_multiple_tus_one_ndebug.cpp @@ -1,6 +1,6 @@ // FIXME flaky fail on CUDA -// UNSUPPORTED: cuda, hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/7634 +// UNSUPPORTED: cuda +// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/8832 // // XFAIL: (opencl && gpu) // XFAIL-TRACKER: https://github.com/intel/llvm/issues/11364 From d38591c11a17fd4892702b38cae21a477554cf52 Mon Sep 17 00:00:00 2001 From: Zheming Jin Date: Sun, 19 Jul 2026 09:21:53 -0700 Subject: [PATCH 2/3] [SYCL][E2E] Re-enable Assert/check_resource_leak on HIP This test passes on HIP (gfx942) with the current toolchain, so remove the UNSUPPORTED: hip marker tracked by intel/llvm#22300. Co-authored-by: Cursor --- sycl/test-e2e/Assert/check_resource_leak.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sycl/test-e2e/Assert/check_resource_leak.cpp b/sycl/test-e2e/Assert/check_resource_leak.cpp index 68bd82b5b64d6..1fce6ee9de6dd 100644 --- a/sycl/test-e2e/Assert/check_resource_leak.cpp +++ b/sycl/test-e2e/Assert/check_resource_leak.cpp @@ -7,10 +7,6 @@ // Therefore not planned to be supported at the moment. See // https://github.com/intel/llvm/issues/22228 -// TODO: Fails at JIT compilation for some reason. -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/22300 - // XFAIL: target-native_cpu // XFAIL-TRACKER: https://github.com/intel/llvm/issues/20142 #define SYCL_FALLBACK_ASSERT 1 From d644957a0260a26e63618b410d45970c387f4d6c Mon Sep 17 00:00:00 2001 From: Zheming Jin Date: Sun, 19 Jul 2026 14:07:54 -0700 Subject: [PATCH 3/3] [SYCL][E2E] Re-enable DiscardEvents/discard_events_using_assert on HIP This test was marked UNSUPPORTED on HIP only because device-side assert did not work. assert now works on the HIP backend (GlobalOffset bad-signature crash fix), so remove the stale marker (issue 22300). The test remains UNSUPPORTED on CUDA per the existing fallback-libdevice FIXME. Co-authored-by: Cursor --- .../DiscardEvents/discard_events_using_assert.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sycl/test-e2e/DeprecatedFeatures/DiscardEvents/discard_events_using_assert.cpp b/sycl/test-e2e/DeprecatedFeatures/DiscardEvents/discard_events_using_assert.cpp index fbb8ea5861811..25636ba691eec 100644 --- a/sycl/test-e2e/DeprecatedFeatures/DiscardEvents/discard_events_using_assert.cpp +++ b/sycl/test-e2e/DeprecatedFeatures/DiscardEvents/discard_events_using_assert.cpp @@ -1,9 +1,6 @@ -// FIXME unsupported on CUDA and HIP until fallback libdevice becomes available +// FIXME unsupported on CUDA until fallback libdevice becomes available // UNSUPPORTED: cuda // -// UNSUPPORTED: hip -// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/22300 -// // RUN: %{build} -o %t.out // // RUN: env SYCL_UR_TRACE=2 %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt