Skip to content

Conversation

wenju-he
Copy link
Contributor

When -internalize flag is passed to llvm-link, we only need to link in needed symbols. This PR reduces size of linked bitcode, e.g. by removing following symbols:
Z12__clc_sw_fmaDv16_fS_S
Z12__clc_sw_fmaDv2_fS_S
Z12__clc_sw_fmaDv3_fS_S
Z12__clc_sw_fmaDv4_fS_S
Z12__clc_sw_fmaDv8_fS_S
_Z12__clc_sw_fmafff

When -internalize flag is passed to llvm-link, we only need to link in
needed symbols. This PR reduces size of linked bitcode, e.g. by removing
following symbols:
_Z12__clc_sw_fmaDv16_fS_S_
_Z12__clc_sw_fmaDv2_fS_S_
_Z12__clc_sw_fmaDv3_fS_S_
_Z12__clc_sw_fmaDv4_fS_S_
_Z12__clc_sw_fmaDv8_fS_S_
_Z12__clc_sw_fmafff
@wenju-he
Copy link
Contributor Author

@frasercrmck could you please review? thanks

@frasercrmck
Copy link
Contributor

Interesting - I'm not seeing any change in bytecode modules before and after this change.

@wenju-he
Copy link
Contributor Author

@frasercrmck could you please try this PR on https://github.com/intel/llvm repo?

My experiment:
clang --version
clang version 21.0.0git (https://github.com/llvm/llvm-project f5ee105)

before PR:
find . -name "builtins.link*.bc" -printf "%s\n" | paste -sd+ | bc
101593692

after PR:
find . -name "builtins.link*.bc" -printf "%s\n" | paste -sd+ | bc
101316928

This PR reduces bitcode file sizes by 0.27%

@frasercrmck
Copy link
Contributor

You're right, my mistake: even on this repo.

I was using llvm-diff and only checking the error code. It reports e.g., function @_Z9__clc_minDv16_DhDh exists only in left module but still returns 0 so I missed it.

This only affects the builtin.link.* bytecode libraries and not the final ones, presumably due to optimizations.

@frasercrmck frasercrmck merged commit cb1e91c into llvm:main Mar 20, 2025
12 checks passed
@wenju-he wenju-he deleted the libclc-link-only-needed branch July 2, 2025 00:29
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