Skip to content

[libclc] Remove __attribute__((always_inline)) - #158791

Merged
wenju-he merged 2 commits into
llvm:mainfrom
wenju-he:_CLC_DECL-to-_CLC_DEF
Sep 17, 2025
Merged

wenju-he merged 2 commits into
llvm:mainfrom
wenju-he:_CLC_DECL-to-_CLC_DEF

Conversation

@wenju-he

@wenju-he wenju-he commented Sep 16, 2025 •

Copy link
Copy Markdown
Contributor

always_inline doesn't guarantee performance improvement.
Target-specific optimizations decide whether inlining is profitable.
Changes to amdgcn--amdhsa.bc:

  • _Z9__clc_logDv16_f and Z15__clc_remainderDv16_fS are not inlined.
  • sincos vector function code size has doubled due to apparent duplication.

Also replace typo _CLC_DECL with _CLC_DEF for function definition.

Some built-ins miss alwaysinline attribute due to the typo.
@wenju-he
wenju-he requested a review from Copilot September 16, 2025 06:25
@llvmbot llvmbot added the libclc libclc OpenCL library label Sep 16, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a widespread typo where _CLC_DECL is incorrectly used instead of _CLC_DEF for function definitions in libclc, causing some built-ins to miss the alwaysinline attribute.

  • Replaces _CLC_DECL with _CLC_DEF in function definitions across multiple files
  • Ensures proper inline attributes are applied to OpenCL C library functions
  • Affects math helpers, atomic operations, and shuffle functions

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
libclc/clc/lib/generic/math/clc_sincos_helpers.inc Fixed macro for tangent helper function definition
libclc/clc/lib/generic/atomic/clc_atomic_def.inc Fixed macros for atomic operation function definitions
libclc/clc/lib/generic/atomic/clc_atomic_compare_exchange.inc Fixed macros for atomic compare exchange function definitions
libclc/clc/include/clc/misc/shuffle_def.inc Fixed macros for shuffle function definitions
libclc/clc/include/clc/misc/shuffle2_def.inc Fixed macros for shuffle2 function definitions

@wenju-he
wenju-he requested a review from arsenm September 16, 2025 06:26

@arsenm arsenm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think all the always_inline attributes should be removed, That's a good bug

@wenju-he wenju-he changed the title [libclc] Replace typo _CLC_DECL with _CLC_DEF for function definition [libclc] Remove __attribute__((always_inline)) Sep 16, 2025
@wenju-he

Copy link
Copy Markdown
Contributor Author

I think all the always_inline attributes should be removed, That's a good bug

done, thanks.
amdgcn--amdhsa.bc has two changes:

  1. _Z9__clc_logDv16_f and Z15__clc_remainderDv16_fS are not inlined.
  2. sincos vector function code size has doubled due to apparent duplication.

@wenju-he
wenju-he merged commit 7f36611 into llvm:main Sep 17, 2025
@wenju-he
wenju-he deleted the _CLC_DECL-to-_CLC_DEF branch September 17, 2025 23:47
@mgorny

mgorny commented Sep 20, 2025

Copy link
Copy Markdown
Member

This is causing test failures for me:

Start testing: Sep 20 09:13 -00
----------------------------------------------------------
2/3 Testing: external-calls-amdgcn--amdhsa.bc
2/3 Test: external-calls-amdgcn--amdhsa.bc
Command: "/var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc/check_external_calls.sh" "/var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc_build/amdgcn--amdhsa.bc" "/usr/lib/llvm/22/bin"
Directory: /var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc
"external-calls-amdgcn--amdhsa.bc" start time: Sep 20 09:13 -00
Output:
----------------------------------------------------------
ERROR: 5 unresolved calls detected in /var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc_build/amdgcn--amdhsa.bc
  %23 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %22) #20
  %24 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %23) #20
  %2 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %0) #20
  %3 = tail call fastcc <16 x float> @_Z15__clc_remainderDv16_fS_(<16 x float> noundef %0, <16 x float> noundef %1) #20
  %5 = tail call fastcc <16 x float> @_Z15__clc_remainderDv16_fS_(<16 x float> noundef %3, <16 x float> noundef %4) #20
<end of output>
Test time =   2.89 sec
----------------------------------------------------------
Test Failed.
"external-calls-amdgcn--amdhsa.bc" end time: Sep 20 09:13 -00
"external-calls-amdgcn--amdhsa.bc" time elapsed: 00:00:02
----------------------------------------------------------

3/3 Testing: external-calls-tahiti-amdgcn-mesa-mesa3d.bc
3/3 Test: external-calls-tahiti-amdgcn-mesa-mesa3d.bc
Command: "/var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc/check_external_calls.sh" "/var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc_build/tahiti-amdgcn-mesa-mesa3d.bc" "/usr/lib/llvm/22/bin"
Directory: /var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc
"external-calls-tahiti-amdgcn-mesa-mesa3d.bc" start time: Sep 20 09:13 -00
Output:
----------------------------------------------------------
ERROR: 5 unresolved calls detected in /var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc_build/tahiti-amdgcn-mesa-mesa3d.bc
  %23 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %22) #22
  %24 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %23) #22
  %2 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %0) #22
  %3 = tail call fastcc <16 x float> @_Z15__clc_remainderDv16_fS_(<16 x float> noundef %0, <16 x float> noundef %1) #22
  %5 = tail call fastcc <16 x float> @_Z15__clc_remainderDv16_fS_(<16 x float> noundef %3, <16 x float> noundef %4) #22
<end of output>
Test time =   2.89 sec
----------------------------------------------------------
Test Failed.
"external-calls-tahiti-amdgcn-mesa-mesa3d.bc" end time: Sep 20 09:13 -00
"external-calls-tahiti-amdgcn-mesa-mesa3d.bc" time elapsed: 00:00:02
----------------------------------------------------------

1/3 Testing: external-calls-tahiti-amdgcn--.bc
1/3 Test: external-calls-tahiti-amdgcn--.bc
Command: "/var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc/check_external_calls.sh" "/var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc_build/tahiti-amdgcn--.bc" "/usr/lib/llvm/22/bin"
Directory: /var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc
"external-calls-tahiti-amdgcn--.bc" start time: Sep 20 09:13 -00
Output:
----------------------------------------------------------
ERROR: 5 unresolved calls detected in /var/tmp/portage/llvm-core/libclc-22.0.0.9999/work/libclc_build/tahiti-amdgcn--.bc
  %23 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %22) #22
  %24 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %23) #22
  %2 = tail call fastcc <16 x float> @_Z9__clc_logDv16_f(<16 x float> noundef %0) #22
  %3 = tail call fastcc <16 x float> @_Z15__clc_remainderDv16_fS_(<16 x float> noundef %0, <16 x float> noundef %1) #22
  %5 = tail call fastcc <16 x float> @_Z15__clc_remainderDv16_fS_(<16 x float> noundef %3, <16 x float> noundef %4) #22
<end of output>
Test time =   2.90 sec
----------------------------------------------------------
Test Failed.
"external-calls-tahiti-amdgcn--.bc" end time: Sep 20 09:13 -00
"external-calls-tahiti-amdgcn--.bc" time elapsed: 00:00:02
----------------------------------------------------------

End testing: Sep 20 09:13 -00

@wenju-he

Copy link
Copy Markdown
Contributor Author

@mgorny thank you for the testing. Sorry I didn't run the tests for this PR.
The test failures will be fixed by #160036

Eric-Guo-NXP added a commit to Eric-Guo-NXP/llvm-project that referenced this pull request Jun 16, 2026
PR llvm#158791 removed always_inline from _CLC_INLINE/_CLC_DEF. SPIR-V
targets built at -O0 and never run 'opt', so helpers were marked
optnone/noinline and survived as real calls, causing NIR validation
failures in rusticl (e.g. OpenCL CTS math_brute_force -w cos).

Build with '-Xclang -disable-llvm-passes' instead: SPIRV is generic
target and doesn't have TTI interface, which can cause optimizations
pass to make suboptimal decisions. An alternative approach is to
selectively disable some passes , but this is not trivial.

Co-authored-by: Wenju He <[email protected]>
karolherbst added a commit to karolherbst/llvm-project that referenced this pull request Jul 2, 2026
The compiled SPIR-V libclc binaries ended up with an empty definition for
__clc_flush_denormal_if_not_supported.

b8a5888 ("[libclc] Fix memory fence scope mapping for OpenCL (llvm#170542)")
also added the static keyword probably due to the same issue.

Fixes: 7f36611 ("[libclc] Remove __attribute__((always_inline)) (llvm#158791)")
karolherbst added a commit to karolherbst/llvm-project that referenced this pull request Jul 2, 2026
The compiled SPIR-V libclc binaries ended up with an empty definition for
__clc_flush_denormal_if_not_supported.

b8a5888 ("[libclc] Fix memory fence scope mapping for OpenCL (llvm#170542)")
also added the static keyword probably due to the same issue.

Fixes: 7f36611 ("[libclc] Remove __attribute__((always_inline)) (llvm#158791)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libclc libclc OpenCL library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants