[llvm] [Inliner] Add cost model loop penalty for -Os. (PR #227042)
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 09:57:17 PDT 2026
https://github.com/alinas created https://github.com/llvm/llvm-project/pull/227042
In addition to having the loop penaly for -Oz build mode, add it to -Os as well. Both optimization modes should cosider size implication and avoid inlining inside loops.
The reduction seen in an internal test build with -Os goes from 200+s to negligible in LoopFullUnrollPass, due to avoiding inlining at ~4k callsites of a function with a small loop, inside a loop nest.
>From cb6f047332126149736076bf53b500f695961237 Mon Sep 17 00:00:00 2001
From: Alina Sbirlea <asbirlea at google.com>
Date: Mon, 28 Sep 2026 03:08:07 +0000
Subject: [PATCH] [Inliner] Add cost model loop penalty for -Os.
In addition to having the loop penaly for -Oz build mode, add it to -Os
as well. Both optimization modes should cosider size implication and
avoid inlining inside loops.
The reduction seen in an internal test build with -Os goes from 200+s to
negligible in LoopFullUnrollPass, due to avoiding inlining at ~4k
callsites of a function with a small loop, inside a loop nest.
---
llvm/lib/Analysis/InlineCost.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index d4f4d937aa06a..a33c6fc852588 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -1084,7 +1084,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
// other costs here, so will likely only be dealing with relatively small
// functions (and hence LI will hopefully be cheap).
auto *Caller = CandidateCall.getFunction();
- if (Caller->hasMinSize()) {
+ if (Caller->hasMinSize() || Caller->hasOptSize()) {
LoopInfo LI;
LI.analyze(&F);
int NumLoops = 0;
@@ -1393,7 +1393,7 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
InlineResult finalizeAnalysis() override {
auto *Caller = CandidateCall.getFunction();
- if (Caller->hasMinSize()) {
+ if (Caller->hasMinSize() || Caller->hasOptSize()) {
LoopInfo LI;
LI.analyze(&F);
for (Loop *L : LI) {
More information about the llvm-commits
mailing list