[llvm] [Analysis] Count indirect calls as inline candidates when PrepareForLTO (PR #192154)

Justin Fargnoli via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 15:53:57 PDT 2026


https://github.com/justinfargnoli created https://github.com/llvm/llvm-project/pull/192154

## Summary
- When `PrepareForLTO` is set, treat indirect calls as potential inline candidates in `CodeMetrics::analyzeBasicBlock`
- LTO may resolve indirect calls via devirtualization, making the call target known and inlinable
- This extends the mechanism from https://github.com/llvm/llvm-project/pull/192153 to also cover indirect calls

## Test plan
- Tests will be added after the base PR (#192153) lands

>From 17207d5f4ff9919e72e3eb47abfb27603252eb1c Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Tue, 14 Apr 2026 22:51:47 +0000
Subject: [PATCH] [Analysis] Count indirect calls as inline candidates when
 PrepareForLTO

When preparing for LTO, treat indirect calls as potential inline
candidates. LTO may resolve indirect calls via devirtualization,
making the call target known and inlinable. This allows loop
transformations that defer based on inline candidates (e.g. loop
unrolling with prepare-for-lto) to also defer for loops containing
indirect calls.
---
 llvm/lib/Analysis/CodeMetrics.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Analysis/CodeMetrics.cpp b/llvm/lib/Analysis/CodeMetrics.cpp
index ea67b526423bf..52ed2444869d6 100644
--- a/llvm/lib/Analysis/CodeMetrics.cpp
+++ b/llvm/lib/Analysis/CodeMetrics.cpp
@@ -161,11 +161,14 @@ void CodeMetrics::analyzeBasicBlock(
 
         if (IsLoweredToCall)
           ++NumCalls;
-      } else {
+      } else if (!Call->isInlineAsm()) {
         // We don't want inline asm to count as a call - that would prevent loop
         // unrolling. The argument setup cost is still real, though.
-        if (!Call->isInlineAsm())
-          ++NumCalls;
+        ++NumCalls;
+        // When preparing for LTO, consider indirect calls as potential inline
+        // candidates since LTO may resolve them via devirtualization.
+        if (PrepareForLTO)
+          ++NumInlineCandidates;
       }
     }
 



More information about the llvm-commits mailing list