Skip to content

[Clang][Inliner] Enable module-local optimizer hints by default - #238529

Merged
kubamracek merged 4 commits into
llvm:mainfrom
kubamracek:module-local-hints-on-by-default
Nov 19, 2026
Merged

kubamracek merged 4 commits into
llvm:mainfrom
kubamracek:module-local-hints-on-by-default

Conversation

@kubamracek

@kubamracek kubamracek commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Commit message:

For reference, see:

This enables emitting the likely-module-local function attr in Clang, as an LLVM optimizer hint that the linkonce_odr function, which would normally be subject to inlining and IPO restrictions, is in fact likely to be TU-local. Hence inlining and cloning should be considered benefitial.

I want to resolve a few things first, and show some data to back the reasoning for turning this one, let me maintain a list below. But after resolving those, the intent is to go ahead and enable this by default (again, see the discussion on the RFC, https://discourse.llvm.org/t/rfc-optimizing-linkonce-odr-functions-frontend-hints-inlining-and-internal-cloning/92423).

TODOs:

Assisted-by: Claude

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 3, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

@llvm/pr-subscribers-hlsl
@llvm/pr-subscribers-backend-nvptx
@llvm/pr-subscribers-backend-amdgpu
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Kuba (Brecka) Mracek (kubamracek)

Changes

Commit message:

> For reference, see:
> - 932a5ca
> - #228074
> - https://discourse.llvm.org/t/rfc-optimizing-linkonce-odr-functions-frontend-hints-inlining-and-internal-cloning/92423
>
> This enables emitting the likely-module-local function attr in Clang, as an LLVM optimizer hint that the linkonce_odr function, which would normally be subject to inlining and IPO restrictions, is in fact likely to be TU-local. Hence inlining and cloning should be considered benefitial.

I want to resolve a few things first, and show some data to back the reasoning for turning this one, let me maintain a list below. But after resolving those, the intent is to go ahead and enable this by default (again, see the discussion on the RFC, https://discourse.llvm.org/t/rfc-optimizing-linkonce-odr-functions-frontend-hints-inlining-and-internal-cloning/92423).

TODOs:

  • re-check compile time impact in general
  • investigate/discuss the outsized compile time impact on tramp3d-v4
  • show perf data on SPEC 2026 + other perf data
  • should we restrict emitting the flag only to linkonce_odr linkage?
  • update tests

Full diff: https://github.com/llvm/llvm-project/pull/238529.diff

3 Files Affected:

  • (modified) clang/include/clang/Basic/CodeGenOptions.def (+1-1)
  • (modified) clang/include/clang/Options/Options.td (+5-5)
  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4-2)
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index ff33f5be424ec..c6c8f23eb69ff 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -546,7 +546,7 @@ CODEGENOPT(DisableOutlining, 1, 0, Benign)
 
 /// Marks inline functions and template instantiations defined in the main
 /// source file as likely_module_local (`-fmodule-local-hints`)
-CODEGENOPT(ModuleLocalHints, 1, 0, Benign)
+CODEGENOPT(ModuleLocalHints, 1, 1, Benign)
 
 /// Controlls the emission of function name in PPA1 on z/OS.
 CODEGENOPT(ZOSPPA1Name, 1, 1, Benign)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 9c266b1bdaf7b..4e707f1b8f971 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3788,11 +3788,11 @@ def fexperimental_abi_lowering : Flag<["-"], "fexperimental-abi-lowering">,
   MarshallingInfoFlag<CodeGenOpts<"ExperimentalABILowering">>;
 
 defm module_local_hints : BoolFOption<"module-local-hints",
-  CodeGenOpts<"ModuleLocalHints">, DefaultFalse,
-  PosFlag<SetTrue, [], [ClangOption, CC1Option],
-          "Mark inline functions and template instantiations defined in the "
-          "main source file as likely_module_local">,
-  NegFlag<SetFalse>>;
+  CodeGenOpts<"ModuleLocalHints">, DefaultTrue,
+  PosFlag<SetTrue, [], [ClangOption], "Mark">,
+  NegFlag<SetFalse, [], [ClangOption, CC1Option], "Don't mark">,
+  BothFlags<[], [ClangOption], " inline functions and template instantiations "
+            "defined in the main source file as likely_module_local">>;
 
 def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index d8819c952e5ad..38747c5855461 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8611,8 +8611,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                     options::OPT_fno_keep_persistent_storage_variables);
   Args.addOptInFlag(CmdArgs, options::OPT_fkeep_inline_functions,
                     options::OPT_fno_keep_inline_functions);
-  Args.addOptInFlag(CmdArgs, options::OPT_fmodule_local_hints,
-                    options::OPT_fno_module_local_hints);
+  Args.addOptOutFlag(CmdArgs, options::OPT_fmodule_local_hints,
+                     options::OPT_fno_module_local_hints);
+  Args.addOptInFlag(CmdArgs, options::OPT_fmodule_local_hints_template_args,
+                    options::OPT_fno_module_local_hints_template_args);
   Args.addOptInFlag(CmdArgs, options::OPT_fcomplete_member_pointers,
                     options::OPT_fno_complete_member_pointers);
   if (Arg *A = Args.getLastArg(options::OPT_cxx_static_destructors_EQ))

Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
options::OPT_fno_module_local_hints);
Args.addOptOutFlag(CmdArgs, options::OPT_fmodule_local_hints,
options::OPT_fno_module_local_hints);
Args.addOptInFlag(CmdArgs, options::OPT_fmodule_local_hints_template_args,

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.

Did this sneak into the wrong patch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes :) Removed.

@kubamracek
kubamracek force-pushed the module-local-hints-on-by-default branch from c8e6c5a to 8bb7701 Compare November 3, 2026 22:29
@kubamracek

Copy link
Copy Markdown
Member Author

re-check compile time impact in general

This is a fresh LLVM Compile Time Tracker result: https://llvm-compile-time-tracker.com/compare.php?from=71653467fa83249f7f748eb05347950f91c46f26&to=8bb77011b5687e90474f11a7536d5d969c59af73&stat=instructions:u

There is the one heavy outlier in llvm-test-suite, tramp3d-v4, which we already discovered in the previous PR. I think I'd want to discuss that one separately (the structure of this benchmark is... unusual and inherently makes it very heavy on this new optimization). The reported geomeans are heavily skewed because of tramp3d-v4, If I exclude it, the geomeans are between -0.16% and +0.07% for -O3 and/or LTO.

For -O0 the deltas are basically 0 for -O0 (as expected).

The compile time measurements that are beyond a 0.10% change are a small subset:

| stage1-O3:             |                             |
| - 7zip                 | 194177M -> 194450M (+0.14%) |
| - beman-execution      |   7686M ->   7705M (+0.24%) |
| stage1-ReleaseThinLTO: |                             |
| - kimwitu++            |  43950M ->  43251M (-1.59%) |
| stage1-ReleaseLTO-g:   |                             |
| - Bullet               |  99088M ->  99263M (+0.18%) |
| - 7zip                 | 240291M -> 240544M (+0.11%) |
| stage1-aarch64-O3:     |                             |
| - kimwitu++            |  36578M ->  36425M (-0.42%) |
| - Bullet               |  98775M ->  98872M (+0.10%) |
| - 7zip                 | 201448M -> 201749M (+0.15%) |
| stage2-O3:             |                             |
| - Bullet               |  83506M ->  83664M (+0.19%) |
| - 7zip                 | 173713M -> 173958M (+0.14%) |

I would tend to think that (again, with the exlusion of tramp3d-v4) this is reasonable and somewhat expected, we're inlining in some more cases, and in exchange we're getting more optimizations. There's a case of a compile-time reduction, too (kimwitu++).

@kubamracek

Copy link
Copy Markdown
Member Author

investigate/discuss the outsized compile time impact on tramp3d-v4

Now, tramp3d-v4 compiles significantly slower with this change. Very significantly: +20% on ThinLTO, +35% on full LTO, and +75% on non-LTO -O3.

Looking a the structure of tramp3d-v4, it's no surprise: The llvm-test-suite's version (https://github.com/llvm/llvm-test-suite/tree/main/MultiSource/Benchmarks/tramp3d-v4) is a single-file amalgamation in a single 56,000-line .cpp file very heavy on C++ templated code (almost all the code is from some template). This PR then triggers a lot more inlining basically everywhere and this makes many LLVM passes just process larger functions, all adding up. There's no single function or pass that would stand up heavily.

I assume that the original version of tramp3d-v4 is not structured this way, and what we have in llvm-test-suite is a result of some post-processing.

My understanding of why it's sometimes useful to concatenate a whole into one source file is:

  • (1) to speed up compilation by skipping re-parsing of the same headers ("unity builds")
    • ...but that doesn't seem to be the case here because that directly trades off build parallelism and is better done in "batches" instead of a single file, and also because the total "header content" and preprocessing/parsing time in this benchmark is very small, in contrast with e.g. some larger TUs of LLVM source code where the amount of #included code can be massive

or:

  • (2) to maximize optimizations by giving the compiler full visibility into all used code ("poor man's LTO"), and especially expecting more IPO and inlining
    • this is famously done in SQLite production builds, and I believe that's the same motivation here in tramp3d-v4

Under that assumption, I would argue that this change (allow more inlining of templated code) is exactly giving tramp3d-v4 what it's asking for. I'm wondering if anyone has a good sense on whether there's other C++ projects that also do this sort of amalgamation and whether longer compile times (in exchange for more optimizations!) on those builds are actually a concern?


As an almost unrelated data point, I also compared the compile time with GCC. But I wouldn't take this too seriously, my understanding is that GCC's -O3 is today already much slower on compile-times compared to Clang on essentially all inputs:

                       |     Clang before |     Clang after |           GCC 16 |
compile-time for -O3   |  8.8s (baseline) |    13.2s (+50%) |     16.2s (+84%) |

@llvmorg-github-actions llvmorg-github-actions Bot added backend:AMDGPU HLSL HLSL Language Support backend:NVPTX clang:openmp OpenMP related changes to Clang ClangIR Anything related to the ClangIR project labels Nov 7, 2026
@kubamracek
kubamracek force-pushed the module-local-hints-on-by-default branch from 1176dca to 9640116 Compare November 7, 2026 17:47
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 96161 tests passed
  • 4383 tests skipped

✅ The build succeeded and all tests passed.

@kubamracek

Copy link
Copy Markdown
Member Author

show perf data on SPEC 2026 + other perf data

Performance data is the primary motivator here:

(1) SPEC 2026 for -O3. Some workloads produce identical binaries (no change from this PR), usually because the workload is plain C, but not always, there's cases of C++ codebases there too.

    |  CODE SIZE CHANGE  | RUNTIME CHANGE |
    |                    |(lower = better)|
--------------------------------------------------------------------------------------------------------------
706 |    −512 B (−0.22%) |   −0.51% ±0.1  | ✅ real gain, repeatable, attributed to a hot func getting inlined
707 |  +3,200 B (+1.78%) |   +0.49% ±0.7  | noise / layout effect, not repeatable
708 |             identical binary
709 |             identical binary
710 |    −960 B (−0.03%) |   −0.97% ±0.8  | ✅ real gain, repeatable, attributed to a hot func getting inlined
714 |             identical binary
721 |  −2,304 B (−0.01%) |   −0.01% ±0.1  |
723 |  −7,040 B (−0.03%) |   −0.15% ±0.4  |
727 |    −256 B (−0.01%) |   −1.25% ±0.8  | noise / layout effect, not repeatable
729 |    −576 B (−0.01%) |   +0.09% ±0.1  |
731 |             identical binary
734 |  −2,496 B (−0.07%) |   −2.96% ±0.3  | ✅ real gain, repeatable, attributed to a hot func getting inlined
735 |    −704 B (−0.01%) |   −0.00% ±1.1  |
736 |  −7,040 B (−0.22%) |   +0.05% ±0.1  |
737 |  −1,728 B (−0.02%) |   +0.10% ±0.1  |
748 |    −128 B (−0.01%) |   −1.50% ±0.4  | noise / layout effect, not repeatable
750 |             identical binary
753 |  −4,032 B (−0.03%) |   −1.01% ±0.2  | noise / layout effect, not repeatable
766 | +40,128 B (+0.06%) |   −0.08% ±0.1  |
767 |  −1,152 B (−0.03%) |   +0.20% ±0.5  |
772 |  −2,304 B (−0.05%) |   +0.09% ±0.3  |
777 |             identical binary
782 |             identical binary

(2) On top of SPEC, we have a separate large C++-heavy benchmark that shows significant gains. The gains are showing across the board there (one of the main patterns are locally used lambdas in templated code that is in .cpp files).

@kubamracek
kubamracek force-pushed the module-local-hints-on-by-default branch from 9640116 to 9f2203b Compare November 7, 2026 19:17
@kubamracek

Copy link
Copy Markdown
Member Author

update tests

This now passes tests, and I've split the test changes into two separate commits, I recommend reviewing separately:

  • (1) opt-out via -fno-module-local-hints in RUN lines -- there's over a 100 test changes like that because the alternative would often be that we need to split attr groups and complicate the CHECK lines...
  • (2) actual much smaller set of test changes related to the hints

If we get close(r) to merging this, we can also pre-commit (1) to leave the PR clean of those changes (because adding -fno-module-local-hints is a no-op).

@nikic

nikic commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

(1) opt-out via -fno-module-local-hints in RUN lines -- there's over a 100 test changes like that because the alternative would often be that we need to split attr groups and complicate the CHECK lines...

A lot of those are generated tests, you should be able to just regenerate the check lines instead.

@kubamracek

Copy link
Copy Markdown
Member Author

should we restrict emitting the flag only to linkonce_odr linkage?

Right now, Clang emits the likely_module_local hint on .cpp-file code that's either templated or has the inline specifier, regardless of the linkage. That covers linkonce_odr definitions, but not exclusively: Anynomous namespaces are internal linkage, explicit instantiations are weak_odr.

Right now, LLVM only does anything with the hint on linkonce_odr functions.

The minimal implementation would be to restrict the Clang logic to only emit the hint for linkonce_odr. But I'm currently thinking that it'd be best to treat the hint as more general than that, because there's interesting future ideas that could allow optimizations beyond linkonce_odr (https://discourse.llvm.org/t/rfc-optimizing-linkonce-odr-functions-frontend-hints-inlining-and-internal-cloning/92423/15). There's no harm in the likely_module_local attribute getting emitted on unused linkages, and thus I would propose we keep emitting it beyond linkonce_odr.

(In fact, I am currently exploring perf opportunities about the same "is this from an implementation file instead of a header file" hint but for non-templated code, which means even expanding the Clang logic to even more linkage types.)

@kubamracek

Copy link
Copy Markdown
Member Author

(1) opt-out via -fno-module-local-hints in RUN lines -- there's over a 100 test changes like that because the alternative would often be that we need to split attr groups and complicate the CHECK lines...

A lot of those are generated tests, you should be able to just regenerate the check lines instead.

Ok, I have regenerated a bunch. But there's still a decent amount (60+) that don't work after re-generation, a lot of it is tests checking that the IR coming from direct compilation vs. through a PCH (mostly the OpenMP tests) is the same and they use the same CHECK group. Would you prefer in those cases to further duplicate the whole CHECK group? (Some of those tests are already massive and already duplicate the CHECK lines heavily, e.g. https://github.com/llvm/llvm-project/blob/main/clang/test/OpenMP/distribute_codegen.cpp)

@nikic

nikic commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Yeah, no, we should not duplicate those check lines further. It's fine to use the opt-out flag for the cases testing weird PCH things... (Assuming that the behavioral divergence with PCH use is, in fact, intentional.)

@kubamracek

Copy link
Copy Markdown
Member Author

Assuming that the behavioral divergence with PCH use is, in fact, intentional.

The pattern in the tests is that the test source (in a .cpp file) is compiled once normally, where the hints start to apply, and then once more where the .cpp file is compiled as input to PCH generation, and then the test imports the PCH and generates IR that way. We don't apply the hints to functions from a PCH. I think that's correct, because code in a PCH is intended for reuse across TUs (at least in real-world PCH usage, not so much in these tests, of course).

ronlieb added a commit to ROCm/llvm-project that referenced this pull request Nov 19, 2026
@kubamracek

Copy link
Copy Markdown
Member Author

Right, and my apologies for maybe not highlighting that enough ahead of time.

But I'm convinced that the change is not a compile time regression for actual users and real-world projects, and that the impact is only on our graphs. See the analysis in #238529 (comment).

I'm of course open to suggestions, I understand the graphs are important and a lot of people's efforts have been recently going into compile-time optimizations and the graphs are used to track and measure that. Maybe we should re-baseline tramp3d-v4 or something like that? Or maybe this is an opportunity to revisit what exact projects are in CTMark?

sbc100 pushed a commit to sbc100/emscripten that referenced this pull request Nov 23, 2026
This is an automatic change generated by tools/maint/rebaseline_tests.py --update-emsdk.

Additionally, build the JS-exceptions `libc++` variant in
`tools/system_libs.py` with `-fno-module-local-hints`. Upstream LLVM
enabled `-fmodule-local-hints` by default (llvm/llvm-project#238529),
which caused a +809 byte codesize regression under JS exceptions due
to inlining single-call-site helpers duplicating `invoke` wrappers,
while noexcept and Wasm exceptions `libc++` variants see a net size
reduction.

emsdk version updated: d140a29c => f0cf44cc

The following revisions were included in this update:

```
- f0cf44cc Roll llvm-project from 950baabb7fdf to c620a424a90a (20 revisions)
- c3d64cd4 Roll llvm-project from 5e410254168a to 950baabb7fdf (11 revisions)
- 5e44e028 Roll llvm-project from 18867a59d17a to 5e410254168a (12 revisions)
- 42ac2802 Roll emscripten from 4e590ff to 4942151 (3 revisions)
- 2bb84944 Roll v8 from f4bfd902e1c4 to 4f01bdeb2725 (2 revisions)
- 2d9e3ffe Roll emscripten from fc87b87 to 4e590ff (3 revisions)
- 018e72fa Roll llvm-project from f1afebcbe1c6 to 18867a59d17a (11 revisions)
- 2f468a0e Roll llvm-project from 8f7eb6f677a2 to f1afebcbe1c6 (4 revisions)
- 00524468 Roll llvm-project from cc5ed0cebe3e to 8f7eb6f677a2 (8 revisions)
- d0efbc8e Roll llvm-project from 1625c1a53d61 to cc5ed0cebe3e (7 revisions)
- 69b93276 Roll llvm-project from b6f762dad029 to 1625c1a53d61 (17 revisions)
- e2fd0fda Roll emscripten from 343150f to fc87b87 (1 revision)
- 0a85dec7 Roll llvm-project from 4c01a2991df8 to b6f762dad029 (15 revisions)
- e4066aa4 Roll binaryen from 4408fed200e9 to 89157cb30824 (1 revision)
- 9a73748e Fix version in DEPS.tagged-release
- ab27b19e Roll emscripten from c7360e7 to 343150f (1 revision)
- b18ce50f Roll v8 from 8b413f7c8252 to f4bfd902e1c4 (18 revisions)
- 44b4cd37 Roll llvm-project from 87764a902a9b to 4c01a2991df8 (9 revisions)
- 302dfa3a Roll emscripten from 68f53bd to c7360e7 (2 revisions)
- 39536303 Roll emscripten from de59e7b to 68f53bd (1 revision)
- 3c226351 Roll llvm-project from aab5b2033768 to 87764a902a9b (19 revisions)
- 9a4d68c3 Roll llvm-project from 0d8ca1bd8eec to aab5b2033768 (6 revisions)
- af31a894 Roll emscripten from 4d96a35 to de59e7b (1 revision)
- 0a12a760 Roll llvm-project from d361f7b3f594 to 0d8ca1bd8eec (13 revisions)
- 186239e Roll emscripten from ac05787 to 4d96a35 (5 revisions)
- 80803a3e Roll binaryen from e7a4b90f3c63 to 4408fed200e9 (1 revision)
- 9146b21a Version 7.0.1 RC3
- 0d19b078 Roll llvm-project from 61c665e40ec9 to d361f7b3f594 (35 revisions)
- 9d8afc53 Fix disabling Xcode libtool in macOS LLVM builds
- c1934886 Roll binaryen from d1ce9a596ee8 to e7a4b90f3c63 (1 revision)
  ... (and more, see full log)
```

Full log: https://chromium.googlesource.com/emscripten-releases/+log/d140a29c..f0cf44cc

The following (5) test expectation files were updated by
running the tests with `--rebaseline`:

```
codesize/test_codesize_cxx_except_wasm.json: 168668 => 168670 [+2 bytes / +0.00%]
codesize/test_codesize_cxx_except_wasm_legacy.json: 166527 => 166529 [+2 bytes / +0.00%]
codesize/test_codesize_cxx_noexcept.json: 155062 => 155066 [+4 bytes / +0.00%]
codesize/test_codesize_cxx_wasmfs.json: 181302 => 181306 [+4 bytes / +0.00%]
codesize/test_minimal_runtime_code_size_hello_embind.json: 15044 => 15044 [+0 bytes / +0.00%]

Average change: +0.00% (+0.00% - +0.00%)
```
sbc100 pushed a commit to sbc100/emscripten that referenced this pull request Nov 23, 2026
This is an automatic change generated by tools/maint/rebaseline_tests.py --update-emsdk.

Additionally, build the JS-exceptions `libc++` variant in
`tools/system_libs.py` with `-fno-module-local-hints`. Upstream LLVM
enabled `-fmodule-local-hints` by default (llvm/llvm-project#238529),
which caused a +809 byte codesize regression under JS exceptions due
to inlining single-call-site helpers duplicating `invoke` wrappers,
while noexcept and Wasm exceptions `libc++` variants see a net size
reduction.

emsdk version updated: d140a29c => f0cf44cc

The following revisions were included in this update:

```
- f0cf44cc Roll llvm-project from 950baabb7fdf to c620a424a90a (20 revisions)
- c3d64cd4 Roll llvm-project from 5e410254168a to 950baabb7fdf (11 revisions)
- 5e44e028 Roll llvm-project from 18867a59d17a to 5e410254168a (12 revisions)
- 42ac2802 Roll emscripten from 4e590ff to 4942151 (3 revisions)
- 2bb84944 Roll v8 from f4bfd902e1c4 to 4f01bdeb2725 (2 revisions)
- 2d9e3ffe Roll emscripten from fc87b87 to 4e590ff (3 revisions)
- 018e72fa Roll llvm-project from f1afebcbe1c6 to 18867a59d17a (11 revisions)
- 2f468a0e Roll llvm-project from 8f7eb6f677a2 to f1afebcbe1c6 (4 revisions)
- 00524468 Roll llvm-project from cc5ed0cebe3e to 8f7eb6f677a2 (8 revisions)
- d0efbc8e Roll llvm-project from 1625c1a53d61 to cc5ed0cebe3e (7 revisions)
- 69b93276 Roll llvm-project from b6f762dad029 to 1625c1a53d61 (17 revisions)
- e2fd0fda Roll emscripten from 343150f to fc87b87 (1 revision)
- 0a85dec7 Roll llvm-project from 4c01a2991df8 to b6f762dad029 (15 revisions)
- e4066aa4 Roll binaryen from 4408fed200e9 to 89157cb30824 (1 revision)
- 9a73748e Fix version in DEPS.tagged-release
- ab27b19e Roll emscripten from c7360e7 to 343150f (1 revision)
- b18ce50f Roll v8 from 8b413f7c8252 to f4bfd902e1c4 (18 revisions)
- 44b4cd37 Roll llvm-project from 87764a902a9b to 4c01a2991df8 (9 revisions)
- 302dfa3a Roll emscripten from 68f53bd to c7360e7 (2 revisions)
- 39536303 Roll emscripten from de59e7b to 68f53bd (1 revision)
- 3c226351 Roll llvm-project from aab5b2033768 to 87764a902a9b (19 revisions)
- 9a4d68c3 Roll llvm-project from 0d8ca1bd8eec to aab5b2033768 (6 revisions)
- af31a894 Roll emscripten from 4d96a35 to de59e7b (1 revision)
- 0a12a760 Roll llvm-project from d361f7b3f594 to 0d8ca1bd8eec (13 revisions)
- 186239e Roll emscripten from ac05787 to 4d96a35 (5 revisions)
- 80803a3e Roll binaryen from e7a4b90f3c63 to 4408fed200e9 (1 revision)
- 9146b21a Version 7.0.1 RC3
- 0d19b078 Roll llvm-project from 61c665e40ec9 to d361f7b3f594 (35 revisions)
- 9d8afc53 Fix disabling Xcode libtool in macOS LLVM builds
- c1934886 Roll binaryen from d1ce9a596ee8 to e7a4b90f3c63 (1 revision)
  ... (and more, see full log)
```

Full log: https://chromium.googlesource.com/emscripten-releases/+log/d140a29c..f0cf44cc

The following (5) test expectation files were updated by
running the tests with `--rebaseline`:

```
codesize/test_codesize_cxx_except_wasm.json: 168668 => 168670 [+2 bytes / +0.00%]
codesize/test_codesize_cxx_except_wasm_legacy.json: 166527 => 166529 [+2 bytes / +0.00%]
codesize/test_codesize_cxx_noexcept.json: 155062 => 155066 [+4 bytes / +0.00%]
codesize/test_codesize_cxx_wasmfs.json: 181302 => 181306 [+4 bytes / +0.00%]
codesize/test_minimal_runtime_code_size_hello_embind.json: 15044 => 15044 [+0 bytes / +0.00%]

Average change: +0.00% (+0.00% - +0.00%)
```
emscripten-bot added a commit to emscripten-core/emscripten that referenced this pull request Nov 23, 2026
This is an automatic change generated by tools/maint/rebaseline_tests.py
--update-emsdk.

Additionally, build the JS-exceptions `libc++` variant in
`tools/system_libs.py` with `-fno-module-local-hints`. Upstream LLVM
enabled `-fmodule-local-hints` by default (llvm/llvm-project#238529),
which caused a +809 byte codesize regression under JS exceptions due
to inlining single-call-site helpers duplicating `invoke` wrappers,
while noexcept and Wasm exceptions `libc++` variants see a net size
reduction.

emsdk version updated: d140a29c => f0cf44cc

The following revisions were included in this update:

```
- f0cf44cc Roll llvm-project from 950baabb7fdf to c620a424a90a (20 revisions)
- c3d64cd4 Roll llvm-project from 5e410254168a to 950baabb7fdf (11 revisions)
- 5e44e028 Roll llvm-project from 18867a59d17a to 5e410254168a (12 revisions)
- 42ac2802 Roll emscripten from 4e590ff to 4942151 (3 revisions)
- 2bb84944 Roll v8 from f4bfd902e1c4 to 4f01bdeb2725 (2 revisions)
- 2d9e3ffe Roll emscripten from fc87b87 to 4e590ff (3 revisions)
- 018e72fa Roll llvm-project from f1afebcbe1c6 to 18867a59d17a (11 revisions)
- 2f468a0e Roll llvm-project from 8f7eb6f677a2 to f1afebcbe1c6 (4 revisions)
- 00524468 Roll llvm-project from cc5ed0cebe3e to 8f7eb6f677a2 (8 revisions)
- d0efbc8e Roll llvm-project from 1625c1a53d61 to cc5ed0cebe3e (7 revisions)
- 69b93276 Roll llvm-project from b6f762dad029 to 1625c1a53d61 (17 revisions)
- e2fd0fda Roll emscripten from 343150f to fc87b87 (1 revision)
- 0a85dec7 Roll llvm-project from 4c01a2991df8 to b6f762dad029 (15 revisions)
- e4066aa4 Roll binaryen from 4408fed200e9 to 89157cb30824 (1 revision)
- 9a73748e Fix version in DEPS.tagged-release
- ab27b19e Roll emscripten from c7360e7 to 343150f (1 revision)
- b18ce50f Roll v8 from 8b413f7c8252 to f4bfd902e1c4 (18 revisions)
- 44b4cd37 Roll llvm-project from 87764a902a9b to 4c01a2991df8 (9 revisions)
- 302dfa3a Roll emscripten from 68f53bd to c7360e7 (2 revisions)
- 39536303 Roll emscripten from de59e7b to 68f53bd (1 revision)
- 3c226351 Roll llvm-project from aab5b2033768 to 87764a902a9b (19 revisions)
- 9a4d68c3 Roll llvm-project from 0d8ca1bd8eec to aab5b2033768 (6 revisions)
- af31a894 Roll emscripten from 4d96a35 to de59e7b (1 revision)
- 0a12a760 Roll llvm-project from d361f7b3f594 to 0d8ca1bd8eec (13 revisions)
- 186239e Roll emscripten from ac05787 to 4d96a35 (5 revisions)
- 80803a3e Roll binaryen from e7a4b90f3c63 to 4408fed200e9 (1 revision)
- 9146b21a Version 7.0.1 RC3
- 0d19b078 Roll llvm-project from 61c665e40ec9 to d361f7b3f594 (35 revisions)
- 9d8afc53 Fix disabling Xcode libtool in macOS LLVM builds
- c1934886 Roll binaryen from d1ce9a596ee8 to e7a4b90f3c63 (1 revision)
  ... (and more, see full log)
```

Full log:
https://chromium.googlesource.com/emscripten-releases/+log/d140a29c..f0cf44cc

The following (5) test expectation files were updated by
running the tests with `--rebaseline`:

```
codesize/test_codesize_cxx_except_wasm.json: 168668 => 168670 [+2 bytes / +0.00%]
codesize/test_codesize_cxx_except_wasm_legacy.json: 166527 => 166529 [+2 bytes / +0.00%]
codesize/test_codesize_cxx_noexcept.json: 155062 => 155066 [+4 bytes / +0.00%]
codesize/test_codesize_cxx_wasmfs.json: 181302 => 181306 [+4 bytes / +0.00%]
codesize/test_minimal_runtime_code_size_hello_embind.json: 15044 => 15044 [+0 bytes / +0.00%]

Average change: +0.00% (+0.00% - +0.00%)
```

Co-authored-by: emscripten-bot <[email protected]>
@nikic

nikic commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

I do think we should do something to address the tramp3d-v4 regression. After all, the size of the regression (77%) is in excess of the code size increase (7%), so even if we assume that the additional inlining is fully beneficial, the compile-time increase goes beyond a simple code size increase.

I believe that the core issue for tramp3d-v4 is repeated simplification. If we have a long chain of calls that are individually small, but then through successive inlining grow in size (and with the single-call bonus, the imposed size upper bound is very large) we end up re-running the entire function simplification pipeline on every single inlining layer, with most of the instructions being the same. This is very expensive.

A potential way to mitigate that would be to have some kind of "early inline", where we try to inline a function that is called only once and is subject to the one-call bonus into its callee before we try to simplify. That would allow collapsing long call-chains without a lot of intermediate simplification. I think the potential complications would be:

  1. Not rerunning simplification countless times will no doubt expose phase ordering issues, that were papered over by "luck".
  2. Inline cost heuristics that depend on caller simplification may not fire (because the caller will be fully unsimplified, rather than partially simplified), which may change overall inlining decisions.

I think this would be a good direction to experiment with, but I doubt I'll find the time myself...

@kubamracek

Copy link
Copy Markdown
Member Author

Good info, thanks for looking into it! I'll try to find some time to investigate that. Also I'll try to see if there's any other improvements we could make.

hebasto added a commit to hebasto/bitcoin that referenced this pull request Nov 29, 2026
`SignatureHash` and `SignatureHashSchnorr` are defined in
`interpreter.cpp` but are also used from other translation units,
which have relied on implicit instantiations being emitted there.
The standard does not guarantee that.

This fixes linker errors when building with Clang 24, where module-local
optimizer hints are now enabled by default.
See llvm/llvm-project#238529.
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Nov 30, 2026
…on templates

7ec6081 refactor: Add missing explicit instantiations of function templates (Hennadii Stepanov)

Pull request description:

  The `SignatureHash` and `SignatureHashSchnorr` function templates are defined in `interpreter.cpp` but are also used from other translation units, which have relied on implicit instantiations being emitted in that file. The standard does not guarantee that.

  This PR adds the missing explicit instantiations. It fixes linker errors (see the nightly builds with [libstdc++](https://cdash.fish.foo/builds/941/build) and [libc++](https://cdash.fish.foo/builds/951/build)) when building with Clang 24, where module-local optimizer hints are now enabled by default. The change was introduced in llvm/llvm-project#238529.

  A successful build of this branch with Clang 24 is available here: hebasto/bitcoin-core-nightly#496.

  As a workaround, Clang's previous behavior can be [restored](hebasto/bitcoin-core-nightly#495) with the `-fno-module-local-hints` flag.

ACKs for top commit:
  maflcko:
    review ACK 7ec6081 🔌
  sedited:
    ACK 7ec6081

Tree-SHA512: d49b578876df77f4636d750e5c11c094308b06c8803d3ef2bd1644303dcaf25a9af9afd695f93ecaf76f7dd43ef158221cc355518c039ad8fc80612fa229cf8d
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Nov 30, 2026
`SignatureHash` and `SignatureHashSchnorr` are defined in
`interpreter.cpp` but are also used from other translation units,
which have relied on implicit instantiations being emitted there.
The standard does not guarantee that.

This fixes linker errors when building with Clang 24, where module-local
optimizer hints are now enabled by default.
See llvm/llvm-project#238529.

Github-Pull: bitcoin#37007
Rebased-From: 7ec6081
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Nov 30, 2026
`SignatureHash` and `SignatureHashSchnorr` are defined in
`interpreter.cpp` but are also used from other translation units,
which have relied on implicit instantiations being emitted there.
The standard does not guarantee that.

This fixes linker errors when building with Clang 24, where module-local
optimizer hints are now enabled by default.
See llvm/llvm-project#238529.

Github-Pull: bitcoin#37007
Rebased-From: 7ec6081
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Nov 30, 2026
`SignatureHash` and `SignatureHashSchnorr` are defined in
`interpreter.cpp` but are also used from other translation units,
which have relied on implicit instantiations being emitted there.
The standard does not guarantee that.

This fixes linker errors when building with Clang 24, where module-local
optimizer hints are now enabled by default.
See llvm/llvm-project#238529.

Github-Pull: bitcoin#37007
Rebased-From: 7ec6081
github-actions Bot added a commit to BTC4Peace/bitcoin-agentic-workflow that referenced this pull request Nov 30, 2026
… function templates

7ec6081 refactor: Add missing explicit instantiations of function templates (Hennadii Stepanov)

Pull request description:

  The `SignatureHash` and `SignatureHashSchnorr` function templates are defined in `interpreter.cpp` but are also used from other translation units, which have relied on implicit instantiations being emitted in that file. The standard does not guarantee that.

  This PR adds the missing explicit instantiations. It fixes linker errors (see the nightly builds with [libstdc++](https://cdash.fish.foo/builds/941/build) and [libc++](https://cdash.fish.foo/builds/951/build)) when building with Clang 24, where module-local optimizer hints are now enabled by default. The change was introduced in llvm/llvm-project#238529.

  A successful build of this branch with Clang 24 is available here: hebasto/bitcoin-core-nightly#496.

  As a workaround, Clang's previous behavior can be [restored](hebasto/bitcoin-core-nightly#495) with the `-fno-module-local-hints` flag.

ACKs for top commit:
  maflcko:
    review ACK 7ec6081 🔌
  sedited:
    ACK 7ec6081

Tree-SHA512: d49b578876df77f4636d750e5c11c094308b06c8803d3ef2bd1644303dcaf25a9af9afd695f93ecaf76f7dd43ef158221cc355518c039ad8fc80612fa229cf8d

Cherry-picked-from: bitcoin/bitcoin@8e09dc7
@npmania

npmania commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@kubamracek @nikic, is anyone already working on the early single-call inlining idea above? If not, I'd like to pick this up.

@kubamracek

Copy link
Copy Markdown
Member Author

@npmania I only briefly looked into it so far, I definitely wouldn't mind help in this area :) That said, I expect any concrete suggestions/patches/prototypes to need a lot of iteration, and even more importantly some wide(r) benchmarking to get at least some confidence that it's not introducing any unacceptable regressions elsewhere. I can sign up for some benchmarking if we have some promising drafts (I have access to SPEC2026 and more benchmarks), but it'd be great if you were able to provide some benchmark numbers alongside the work.

npmania added a commit to npmania/llvm-project that referenced this pull request Dec 2, 2026
getNonLocalPointerDepFromBB() currently clears AATags to empty on any
mismatch, dropping shared metadata such as identical !tbaa when only
!noalias scopes differ. This uses AAMDNodes::intersect() instead to
preserve matching tags without creating new MDNodes, and allows us to
drop the recursive call and the IsIncomplete parameter. When a size
mismatch already clears the cache, AATags is reset directly to the new
query's tags rather than intersecting with the discarded entry.

The motivation here is deferring simplification of single-call functions
(see llvm#238529). Inlining before
GVN leaves loads of the same pointer with identical !tbaa and distinct
!noalias scopes, where dropping !tbaa causes false clobbers and prevents
redundant load elimination.

CTMark instructions:u geomean (x86_64): O3 +0.02%, ThinLTO +0.02%.
npmania added a commit to npmania/llvm-project that referenced this pull request Dec 2, 2026
getNonLocalPointerDepFromBB() currently clears AATags to empty on any
mismatch, dropping shared metadata such as identical !tbaa when only
!noalias scopes differ. This uses AAMDNodes::intersect() instead to
preserve matching tags without creating new MDNodes, and allows us to
drop the recursive call and the IsIncomplete parameter. When a size
mismatch already clears the cache, AATags is reset directly to the new
query's tags rather than intersecting with the discarded entry.

The motivation here is deferring simplification of single-call functions
(see llvm#238529). Inlining before
GVN leaves loads of the same pointer with identical !tbaa and distinct
!noalias scopes, where dropping !tbaa causes false clobbers and prevents
redundant load elimination.
@npmania

npmania commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

I have a working prototype that avoids repeated function simplification for loop-free single-call local/likely_module_local functions in the CGSCC pipeline. On x86_64 (Ryzen 7 5700X) CTMark (instructions:u) it improves most other benchmarks as well: geomean O3 -2.82%, ThinLTO -2.23% (tramp3d-v4 -21.79%/-18.48%), with .text slightly down (-0.10%/-0.08%).

I'm working through a few regressions exposed during measurements and will follow up with a draft PR for the main patch.

Thanks @kubamracek, I'll cc you on the main PR.

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

Labels

backend:AMDGPU backend:NVPTX clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project HLSL HLSL Language Support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants