[clang] [llvm] [Clang]: Enable speculative devirtualization (PR #159685)

Hassnaa Hamdi via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 2 14:59:14 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:

Okay, I see that integrating the WPD pass into another pipeline is non-trivial and would require changes across multiple places. Additionally, I'm uncertain if this approach will succeed given that WPD is a module pass.
Maybe (maybe) it could be better to have a different pass for non-to speculative devirtualization isolated from all the LTO stuff and in that case it's easier to add any needed changes into the pass without touching LTO things. 
But anyway, I'll need to investigate the suggested approach further before implementing.

Does it make sense to keep the current opt-in speculative devirtualization changes for now, and revisit the pipeline integration as a follow-up? 
Of course, I'm still open to pursuing the correct approach if the current implementation is not good enough.

https://github.com/llvm/llvm-project/pull/159685


More information about the llvm-commits mailing list