[clang] [llvm] [Clang]: Enable speculative devirtualization (PR #159685)
Hassnaa Hamdi via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 10:57:18 PST 2025
================
@@ -1641,6 +1642,24 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
if (!LTOPreLink)
MPM.addPass(RelLookupTableConverterPass());
+ if (PTO.DevirtualizeSpeculatively && LTOPhase == ThinOrFullLTOPhase::None) {
+ MPM.addPass(WholeProgramDevirtPass(
+ /*ExportSummary*/ nullptr,
+ /*ImportSummary*/ nullptr,
+ /*DevirtSpeculatively*/ PTO.DevirtualizeSpeculatively));
+ MPM.addPass(LowerTypeTestsPass(nullptr, nullptr,
+ lowertypetests::DropTestKind::Assume));
+ if (EnableModuleInliner) {
----------------
hassnaaHamdi wrote:
I think the inliner also is crucial for the global optimisation that both passes of GlobalOpt and GlobalDCE do.
As an example, if we disabled the inliner, the GVs will not be optimised, and as a result the devirtualization will not work.
So I think the inliner is needed to be run firstly.
Ex for the output when the inliner is enabled and when it's disabled : https://godbolt.org/z/r8oKh9qxa
So the inliner at the beginning is crucial for the devirtualization feature to work.
And the inliner at the end is useful for making the most gain out of the devirtualization because the devirtualized functions can be inlined.
https://github.com/llvm/llvm-project/pull/159685
More information about the llvm-commits
mailing list