Repository navigation
[Clang][Inliner] Enable module-local optimizer hints by default - #238529
Conversation
|
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Kuba (Brecka) Mracek (kubamracek) ChangesCommit message: > For reference, see: 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:
3 Files Affected:
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))
|
| 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, |
There was a problem hiding this comment.
Did this sneak into the wrong patch?
c8e6c5a to
8bb7701
Compare
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: 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++). |
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:
or:
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: |
1176dca to
9640116
Compare
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
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. (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). |
9640116 to
9f2203b
Compare
This now passes tests, and I've split the test changes into two separate commits, I recommend reviewing separately:
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). |
A lot of those are generated tests, you should be able to just regenerate the check lines instead. |
Right now, Clang emits the 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 (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.) |
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) |
|
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.) |
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). |
…lt (llvm#238529)" This reverts commit 67cc115.
|
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? |
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%) ```
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%) ```
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]>
|
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:
I think this would be a good direction to experiment with, but I doubt I'll find the time myself... |
|
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. |
`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.
…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
`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
`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
`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
… 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
|
@kubamracek @nikic, is anyone already working on the early single-call inlining idea above? If not, I'd like to pick this up. |
|
@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. |
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%.
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.
|
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. |
Commit message:
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