Skip to content

[SYCL] Enable compiler rt builtin for SPIRV device code#21724

Draft
jinge90 wants to merge 30 commits intointel:syclfrom
jinge90:enable_compiler_rt_builtin_spirv
Draft

[SYCL] Enable compiler rt builtin for SPIRV device code#21724
jinge90 wants to merge 30 commits intointel:syclfrom
jinge90:enable_compiler_rt_builtin_spirv

Conversation

@jinge90
Copy link
Copy Markdown
Contributor

@jinge90 jinge90 commented Apr 10, 2026

This PR enables compiler-rt builtin library for SYCL device code. Currently, we only need __mulsc3/dc3 and __divsc3/dc3 for complex multiplication/division.

Signed-off-by: jinge90 <ge.jin@intel.com>
Signed-off-by: jinge90 <ge.jin@intel.com>
@jinge90 jinge90 requested review from a team and bader as code owners April 10, 2026 06:22
@jinge90 jinge90 requested a review from cperkinsintel April 10, 2026 06:22
@jinge90 jinge90 marked this pull request as draft April 10, 2026 06:22
@jinge90
Copy link
Copy Markdown
Contributor Author

jinge90 commented Apr 10, 2026

Hi, @bader
We begin to enable compiler-rt builtin library for SYCL device code, this PR is the first one.
For compiler-rt builtin library, we only need 4 functions (__mulsc3, __muldc3, __divsc3, __divdc3) on Linux platform only.
We ported corresponding compiler-rt tests to SYCL e2e in #21622. This PR is still in progress, it only builds the libclang_rt.builtins.bc for device code, more work is needed to support linking it in compiler driver. I will ping you to review when all parts are finished.
Thanks very much.

jinge90 added 2 commits April 10, 2026 14:43
Signed-off-by: jinge90 <ge.jin@intel.com>
Signed-off-by: jinge90 <ge.jin@intel.com>
@bader
Copy link
Copy Markdown
Contributor

bader commented Apr 10, 2026

Hi, @bader We begin to enable compiler-rt builtin library for SYCL device code, this PR is the first one. For compiler-rt builtin library, we only need 4 functions (__mulsc3, __muldc3, __divsc3, __divdc3) on Linux platform only. We ported corresponding compiler-rt tests to SYCL e2e in #21622. This PR is still in progress, it only builds the libclang_rt.builtins.bc for device code, more work is needed to support linking it in compiler driver. I will ping you to review when all parts are finished. Thanks very much.

Hi @jinge90. Thanks for tagging me. I suggest we move this PR to https://github.com/llvm/llvm-project/ to review these changes with compiler-rt code owners.

A couple of high-level notes/questions:

  1. I think we shouldn't switch from C to SYCL language compilation mode when we build for SPIR-V target. Have you tried using the C language mode?
  2. Do you have any estimation how hard it would be to enable the generic sources list?

Signed-off-by: jinge90 <ge.jin@intel.com>
@jinge90
Copy link
Copy Markdown
Contributor Author

jinge90 commented Apr 13, 2026

Hi, @bader We begin to enable compiler-rt builtin library for SYCL device code, this PR is the first one. For compiler-rt builtin library, we only need 4 functions (__mulsc3, __muldc3, __divsc3, __divdc3) on Linux platform only. We ported corresponding compiler-rt tests to SYCL e2e in #21622. This PR is still in progress, it only builds the libclang_rt.builtins.bc for device code, more work is needed to support linking it in compiler driver. I will ping you to review when all parts are finished. Thanks very much.

Hi @jinge90. Thanks for tagging me. I suggest we move this PR to https://github.com/llvm/llvm-project/ to review these changes with compiler-rt code owners.

A couple of high-level notes/questions:

  1. I think we shouldn't switch from C to SYCL language compilation mode when we build for SPIR-V target. Have you tried using the C language mode?
  2. Do you have any estimation how hard it would be to enable the generic sources list?

Hi, @bader
"Have you tried using the C language mode?"
Could you provide the compiling commands to use 'C language mode' for SPIRV target? Do you mean "clang -target spirv64 -Xclang -fdeclare_spirv_builtins -emit-llvm ...."?

"Do you have any estimation how hard it would be to enable the generic sources list?"
It seems that there should be no big problems for building float and double builtins. I will try to build these builtins later and reply to you about the results. The most obvious problem about enabling these builtins is how to test them, current sycl compiler doesn't use them, so these builtins will be removed in device linking phase due to 'only-needed' linking behavior.

"I suggest we move this PR to https://github.com/llvm/llvm-project/ to review these changes with compiler-rt code owners."
I want to align with you and resolve all high-level problem/concern here and then submit to community review, is it acceptable? And also, we can integrate spirv libclang_builtins into sycl compiler and use our pre-ci to verify.

By the way, could you also help review #21745? I observed this when integrating libclang_rt.builtins.
Thanks very much.

jinge90 added 2 commits April 13, 2026 20:16
Signed-off-by: jinge90 <ge.jin@intel.com>
Signed-off-by: jinge90 <ge.jin@intel.com>
@bader
Copy link
Copy Markdown
Contributor

bader commented Apr 13, 2026

Could you provide the compiling commands to use 'C language mode' for SPIRV target? Do you mean "clang -target spirv64 -Xclang -fdeclare_spirv_builtins -emit-llvm ...."?

I would expect clang -target spirv64 test.c to work. My understanding is that compiler-rt is built with -flto option. If this doesn't work, we should open an issue for that. Either we or AMD team could make this work.

"Do you have any estimation how hard it would be to enable the generic sources list?"
It seems that there should be no big problems for building float and double builtins. I will try to build these builtins later and reply to you about the results. The most obvious problem about enabling these builtins is how to test them, current sycl compiler doesn't use them, so these builtins will be removed in device linking phase due to 'only-needed' linking behavior.

compiler-rt library must be tested by compiler-rt tests, not SYCL tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants