[llvm] [TTI] Simplify implementation (NFCI) (PR #136674)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 23 07:47:04 PDT 2025
s-barannikov wrote:
I did some measurements adding commits on top this PR. The results are [here](https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=s-barannikov), and I summarize them below.
Just adding `final` seem to change nothing [link](https://llvm-compile-time-tracker.com/compare.php?from=7509894f3f9053f20cc724bdab2a377dd57eebd2&to=d48ed1f33673e47413edb57ab7fc3dc147a1d2d2&stat=instructions:u). Measurements below don't include this commit.
1. Removing `TargetTransformInfoImplCRTPBase` slightly worsens compile time ([link](https://llvm-compile-time-tracker.com/compare.php?from=7509894f3f9053f20cc724bdab2a377dd57eebd2&to=67731ae740adbca6a1eb16de9d1ed2123b4e04b8&stat=instructions:u)).
2. Removing template argument of `BasicTTIImplBase` worsens compile time more ([link](https://llvm-compile-time-tracker.com/compare.php?from=67731ae740adbca6a1eb16de9d1ed2123b4e04b8&to=1b5a924f95fc52afb727fe141494ac7087bba156&stat=instructions:u)). This commit also makes `getTLI()` and `getST()` virtual for good measure. Two commits together: [link](https://llvm-compile-time-tracker.com/compare.php?from=7509894f3f9053f20cc724bdab2a377dd57eebd2&to=1b5a924f95fc52afb727fe141494ac7087bba156&stat=instructions%3Au).
3. Adding `final` *now* recovers compile time, but not completely. [link](https://llvm-compile-time-tracker.com/compare.php?from=1b5a924f95fc52afb727fe141494ac7087bba156&to=8ee7ecfdf2cd265948d22872445dbb4071ca5881&stat=instructions:u). Three commits together: [link](https://llvm-compile-time-tracker.com/compare.php?from=7509894f3f9053f20cc724bdab2a377dd57eebd2&to=8ee7ecfdf2cd265948d22872445dbb4071ca5881&stat=instructions%3Au).
4. So I thought that devirtualizing `getST()` and `getTLI()` would recover the compile time more, but instead it made it much worse ([link](https://llvm-compile-time-tracker.com/compare.php?from=8ee7ecfdf2cd265948d22872445dbb4071ca5881&to=91f1c7f3a6c5667780f894060a76bebc72747917&stat=instructions:u)). This puzzles me.
Three conclusions from this (YMMV):
1. De-templatizing introduces more virtual calls worsening compile time, meaning virtual dispatch is measurable in instruction count terms.
2. After de-templatizing, adding `final` helps in `AArch64TTIImpl` -> `AArch64TImpl` case, but doesn't help in `BasicTTIImplBase` -> `AArch64TTIImpl` / `BasicTTIImplBase` -> `BasicTTIImplBase` cases. This is expected, since `BasicTTIImpl` is no longer specialized for a concrete implementation, and calls from it can't be devirtualized (there are many derived classes).
3. The above results explain why this PR is compile time neutral: it doesn't introduce more virtual calls (well, maybe a few, but not 2.5 hundreds). If it introduced many virtual calls, measurements would show regression.
https://github.com/llvm/llvm-project/pull/136674
More information about the llvm-commits
mailing list