Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 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
17b7eda
Run script on LIT test
lbushi25 Aug 18, 2025
dc92d56
Fix conflict
lbushi25 Aug 18, 2025
8723efe
Fix E2E failures
lbushi25 Aug 18, 2025
28569aa
Revert "Fix E2E failures"
lbushi25 Aug 19, 2025
01e13bc
Comment out failing test case
lbushi25 Aug 19, 2025
06bc971
Update llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
lbushi25 Aug 20, 2025
e83e510
Remove extra blank line
lbushi25 Aug 21, 2025
5dccb9b
Merge branch 'intel:sycl' into disable_dead_arg_elimination_for_free_…
lbushi25 Aug 26, 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: 25 additions & 1 deletion llvm/test/Transforms/DeadArgElim/sycl-kernels-neg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,30 @@ define weak_odr void @NotASpirKernel(float %arg1, float %arg2) {

define weak_odr void @ESIMDKernel(float %arg1, float %arg2) !sycl_explicit_simd !0 {
; CHECK-LABEL: define {{[^@]+}}@ESIMDKernel
; CHECK-SAME: (float [[ARG1:%.*]], float [[ARG2:%.*]]) !sycl_explicit_simd !0 {
; CHECK-SAME: (float [[ARG1:%.*]], float [[ARG2:%.*]]) {{.*}}{
; CHECK-NEXT: call void @foo(float [[ARG1]])
; CHECK-NEXT: ret void
;
call void @foo(float %arg1)
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:%.*]]) #[[ATTR0:[0-9]+]] {
; 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:%.*]]) #[[ATTR1:[0-9]+]] {
; CHECK-NEXT: call void @foo(float [[ARG1]])
; CHECK-NEXT: ret void
;
Expand All @@ -34,4 +57,5 @@ define weak_odr void @ESIMDKernel(float %arg1, float %arg2) !sycl_explicit_simd

declare void @foo(float %arg)


!0 = !{}
13 changes: 0 additions & 13 deletions sycl/test-e2e/FreeFunctionKernels/template_specialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,6 @@ void F<float>(int X) {
volatile float Y = static_cast<float>(X);
}

template <typename... Args>
Copy link
Contributor Author

@lbushi25 lbushi25 Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variadic arguments are not allowed in free function kernels as per the spec here.
This case had been passing until now for some random reason, but disabling dead argument elimination causes it to fail.
It's illegal though, so might as well save a headache and remove it entirely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to line 99. I put the note on line 96 since its the start of the deleted section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to line 99. I put the note on line 96 since its the start of the deleted section.

Just to err on the safe side, I'm tagging @gmlueck. In the section of the spec that I have linked in my first comment in this thread, is the term "variadic argument" referring to the construct used in line 99 of this test that I've deleted or is it referring to some other construct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @aelovikov-intel. The code on line 96 is not a function with variadic arguments. It is a function template with a parameter pack. When the template is instantiated, there is a fixed number of template arguments (defined by this particular instantiation), and therefore the instantiated function has a fixed number of arguments.

Such a function is expected to be a legal free function kernel. If it does not work, we should investigate why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. There is already a tracker for this issue. In the meantime, to get this merged, I'm commenting out only this test case and adding a TODO to uncomment it once the tracker is solved. It's of course less than ideal to reduce test coverage but given that its important to have this change for free function kernels and the fact that the bug is exposed by this PR rather than caused by it, I think it's an acceptable compromise in light of the approaching deadline. Also tagging @AlexeySachkov for awareness.

SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(
(ext::oneapi::experimental::single_task_kernel))
void variadic_templated(Args... args) {}

template <>
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(
(ext::oneapi::experimental::single_task_kernel))
void variadic_templated<double>(double b) {
b = 20.0f;
}

template <auto *Func, typename T> void test_func() {
queue Q;
kernel_bundle bundle =
Expand Down Expand Up @@ -173,7 +161,6 @@ int main() {
test_func_custom_type<A::B::C::TestClass>();
test_func<F<float>, float>();
test_func<F<uint32_t>, uint32_t>();
test_func<variadic_templated<double>, double>();
test_func<sum1<3, float>, float>();
test_accessor();
test_shared();
Expand Down
Loading