Skip to content

[SYCL] Disable dead arg elimination for free function kernels #19776

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

Open
wants to merge 20 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
34a11ca
Provide supports for decomposable structs
lbushi25 May 28, 2025
edec2b4
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 May 28, 2025
c9680a2
Revert "Provide supports for decomposable structs"
lbushi25 Jun 3, 2025
b932fe6
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Jun 3, 2025
6b6da56
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Jun 10, 2025
ceaabfd
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Jun 23, 2025
714839e
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Jul 22, 2025
01b6936
Remove debugging artifacts from E2E test
lbushi25 Aug 11, 2025
dbc7f3e
Merge branch 'sycl' of https://github.com/lbushi25/llvm into sycl
lbushi25 Aug 11, 2025
3d3a618
Disable dear argument elimination for free function kernels
lbushi25 Aug 12, 2025
20bf581
Update DeadArgumentElimination.cpp
lbushi25 Aug 12, 2025
a95f22d
Update free_function_kernels.cpp
lbushi25 Aug 12, 2025
1060e14
Add test for dead argument elimination disabling for free function ke…
lbushi25 Aug 13, 2025
90422fb
Merge branch 'disable_dead_arg_elimination_for_free_function_kernels'…
lbushi25 Aug 13, 2025
2cb0ca7
Fix typo in RUN command
lbushi25 Aug 13, 2025
964e5af
Rename test and add an explnatory comment
lbushi25 Aug 13, 2025
6704b61
Refactor tests
lbushi25 Aug 14, 2025
e6740fd
Improve comments
lbushi25 Aug 14, 2025
4f76afe
Improve comments
lbushi25 Aug 14, 2025
54b372b
Update sycl-kernels-neg.ll
lbushi25 Aug 15, 2025
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
11 changes: 11 additions & 0 deletions llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,17 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) {
return;
}

// Do not modify arguments when the SYCL kernel is a free function kernel.
// In this case, the user sets the arguments of the kernel by themselves
// and dead argument elimination may interfere with their expectations.
bool FuncIsSyclFreeFunctionKernel =
F.hasFnAttribute("sycl-single-task-kernel") ||
F.hasFnAttribute("sycl-nd-range-kernel");
if (FuncIsSyclFreeFunctionKernel) {
markFrozen(F);
return;
}

LLVM_DEBUG(
dbgs() << "DeadArgumentEliminationPass - Inspecting callers for fn: "
<< F.getName() << "\n");
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/Transforms/DeadArgElim/sycl-kernels-neg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ define weak_odr void @ESIMDKernel(float %arg1, float %arg2) !sycl_explicit_simd
ret void
}

; The following two tests ensure that dead arguments are not eliminated
; from a free function kernel.

define weak_odr spir_kernel void @FreeFuncKernelSingleTask(float %arg1, float %arg2) "sycl-single-task-kernel"="0" {
; CHECK-LABEL: define {{[^@]+}}@FreeFuncKernelSingleTask
; CHECK-SAME: (float [[ARG1:%.*]], float [[ARG2:%.*]]) #[[SINGLE_TASK_ATTR]] {
; CHECK-NEXT: call void @foo(float [[ARG1]])
; CHECK-NEXT: ret void
;
call void @foo(float %arg1)
ret void
}

define weak_odr spir_kernel void @FreeFuncKernelNdRange(float %arg1, float %arg2) "sycl-nd-range-kernel"="0" {
; CHECK-LABEL: define {{[^@]+}}@FreeFuncKernelNdRange
; CHECK-SAME: (float [[ARG1:%.*]], float [[ARG2:%.*]]) #[[ND_RANGE_ATTR:[0-9]]] {
; CHECK-NEXT: call void @foo(float [[ARG1]])
; CHECK-NEXT: ret void
;
call void @foo(float %arg1)
ret void
}

declare void @foo(float %arg)

; CHECK: attributes #[[SINGLE_TASK_ATTR]] = { "sycl-single-task-kernel"="0" }
; CHECK: attributes #[[ND_RANGE_ATTR]] = { "sycl-nd-range-kernel"="0" }

!0 = !{}
Loading