[llvm] Changed stat passes to count instructions before and after optimizations (PR #188837)

IƱaki V Arrechea via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 18:05:24 PDT 2026


https://github.com/InakiVA updated https://github.com/llvm/llvm-project/pull/188837

>From 290534ec8089d47081587e51c131825ff91c93b1 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 26 Mar 2026 20:45:30 +0000
Subject: [PATCH 1/9] Changed stat passes to count instructions before and
 after optimizations

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  3 +
 llvm/include/llvm/Analysis/InstCount.h        |  5 +-
 .../Analysis/FunctionPropertiesAnalysis.cpp   | 29 ++++++--
 llvm/lib/Analysis/InstCount.cpp               | 74 +++++++++++++++----
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 49 +++++++++---
 .../func-properties-analysis-diff.ll          | 25 +++++++
 ...s-stats.ll => func-properties-analysis.ll} | 20 ++---
 .../test/Analysis/InstCount/instcount-diff.ll | 25 +++++++
 llvm/test/Analysis/InstCount/instcount.ll     | 24 +++---
 9 files changed, 200 insertions(+), 54 deletions(-)
 create mode 100644 llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
 rename llvm/test/Analysis/FunctionPropertiesAnalysis/{properties-stats.ll => func-properties-analysis.ll} (81%)
 create mode 100644 llvm/test/Analysis/InstCount/instcount-diff.ll

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index 1619671d8f7dc..50b58b7133d36 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -187,7 +187,10 @@ class FunctionPropertiesPrinterPass
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 struct FunctionPropertiesStatisticsPass
     : PassInfoMixin<FunctionPropertiesStatisticsPass> {
+  explicit FunctionPropertiesStatisticsPass(bool IsBeforeOptimization = false)
+      : IsBeforeOptimization(IsBeforeOptimization) {}
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
+  bool IsBeforeOptimization;
 };
 
 /// Correctly update FunctionPropertiesInfo post-inlining. A
diff --git a/llvm/include/llvm/Analysis/InstCount.h b/llvm/include/llvm/Analysis/InstCount.h
index e5ce822caf6ef..fe03ceb680f4c 100644
--- a/llvm/include/llvm/Analysis/InstCount.h
+++ b/llvm/include/llvm/Analysis/InstCount.h
@@ -20,7 +20,10 @@ namespace llvm {
 class Function;
 
 struct InstCountPass : PassInfoMixin<InstCountPass> {
-  PreservedAnalyses run(Function &F, FunctionAnalysisManager &);
+  explicit InstCountPass(bool IsBeforeOptimization = false)
+      : IsBeforeOptimization(IsBeforeOptimization) {}
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
+  bool IsBeforeOptimization;
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index 4a66d8835281a..bf63f2b559f52 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -29,9 +29,16 @@ using namespace llvm;
 
 #define DEBUG_TYPE "func-properties-stats"
 
-#define FUNCTION_PROPERTY(Name, Description) STATISTIC(Num##Name, Description);
+#define FUNCTION_PROPERTY(Name, Description)                                   \
+  STATISTIC(Num##Name##BeforeOptimization,                                     \
+            Description " (before optimizations)");                            \
+  STATISTIC(Num##Name##AfterOptimization, Description " (after "               \
+                                                      "optimizations)");
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  STATISTIC(Num##Name, Description);
+  STATISTIC(Num##Name##BeforeOptimization,                                     \
+            Description " (before optimizations)");                            \
+  STATISTIC(Num##Name##AfterOptimization, Description " (after "               \
+                                                      "optimizations)");
 #include "llvm/IR/FunctionProperties.def"
 
 namespace llvm {
@@ -378,11 +385,23 @@ FunctionPropertiesStatisticsPass::run(Function &F,
   LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
                     << "\n");
   auto &AnalysisResults = FAM.getResult<FunctionPropertiesAnalysis>(F);
-
-#define FUNCTION_PROPERTY(Name, Description) Num##Name += AnalysisResults.Name;
+  if (IsBeforeOptimization) {
+#define FUNCTION_PROPERTY(Name, Description)                                   \
+  Num##Name##BeforeOptimization += AnalysisResults.Name;
+#define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
+  Num##Name##BeforeOptimization += AnalysisResults.Name;
+#include "llvm/IR/FunctionProperties.def"
+#undef FUNCTION_PROPERTY
+#undef DETAILED_FUNCTION_PROPERTY
+  } else {
+#define FUNCTION_PROPERTY(Name, Description)                                   \
+  Num##Name##AfterOptimization += AnalysisResults.Name;
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  Num##Name += AnalysisResults.Name;
+  Num##Name##AfterOptimization += AnalysisResults.Name;
 #include "llvm/IR/FunctionProperties.def"
+#undef FUNCTION_PROPERTY
+#undef DETAILED_FUNCTION_PROPERTY
+  }
 
   return PreservedAnalyses::all();
 }
diff --git a/llvm/lib/Analysis/InstCount.cpp b/llvm/lib/Analysis/InstCount.cpp
index 7a797767f97cb..e65da22a57c39 100644
--- a/llvm/lib/Analysis/InstCount.cpp
+++ b/llvm/lib/Analysis/InstCount.cpp
@@ -21,34 +21,76 @@ using namespace llvm;
 
 #define DEBUG_TYPE "instcount"
 
-STATISTIC(TotalInsts, "Number of instructions (of all types)");
-STATISTIC(TotalBlocks, "Number of basic blocks");
-STATISTIC(TotalFuncs, "Number of non-external functions");
-STATISTIC(LargestFunctionSize,
-          "Largest number of instructions in a single function");
-STATISTIC(LargestFunctionBBCount,
-          "Largest number of basic blocks in a single function");
+STATISTIC(TotalInstsBeforeOptimization,
+          "Number of instructions of all types (before optimizations)");
+STATISTIC(TotalInstsAfterOptimization,
+          "Number of instructions of all types (after optimizations)");
+STATISTIC(TotalBlocksBeforeOptimization,
+          "Number of basic blocks (before optimizations)");
+STATISTIC(TotalBlocksAfterOptimization,
+          "Number of basic blocks (after optimizations)");
+STATISTIC(TotalFuncsBeforeOptimization,
+          "Number of non-external functions (before optimizations)");
+STATISTIC(TotalFuncsAfterOptimization,
+          "Number of non-external functions (after optimizations)");
+STATISTIC(LargestFunctionSizeBeforeOptimization,
+          "Largest number of instructions in a single function (before "
+          "optimizations)");
+STATISTIC(LargestFunctionSizeAfterOptimization,
+          "Largest number of instructions in a single function (after "
+          "optimizations)");
+STATISTIC(LargestFunctionBBCountBeforeOptimization,
+          "Largest number of basic blocks in a single function (before "
+          "optimizations)");
+STATISTIC(LargestFunctionBBCountAfterOptimization,
+          "Largest number of basic blocks in a single function (after "
+          "optimizations)");
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
-  STATISTIC(Num##OPCODE##Inst, "Number of " #OPCODE " insts");
+  STATISTIC(Num##OPCODE##InstBeforeOptimization,                               \
+            "Number of " #OPCODE " insts (before optimizations)");             \
+  STATISTIC(Num##OPCODE##InstAfterOptimization,                                \
+            "Number of " #OPCODE " insts (after optimizations)");
 
 #include "llvm/IR/Instruction.def"
 
 namespace {
 class InstCount : public InstVisitor<InstCount> {
   friend class InstVisitor<InstCount>;
+  bool IsBeforeOptimization;
+
+public:
+  InstCount(bool IsBeforeOptimization)
+      : IsBeforeOptimization(IsBeforeOptimization) {}
 
   void visitFunction(Function &F) {
-    ++TotalFuncs;
-    LargestFunctionSize.updateMax(F.getInstructionCount());
-    LargestFunctionBBCount.updateMax(F.size());
+    if (IsBeforeOptimization) {
+      ++TotalFuncsBeforeOptimization;
+      LargestFunctionSizeBeforeOptimization.updateMax(F.getInstructionCount());
+      LargestFunctionBBCountBeforeOptimization.updateMax(F.size());
+    } else {
+      ++TotalFuncsAfterOptimization;
+      LargestFunctionSizeAfterOptimization.updateMax(F.getInstructionCount());
+      LargestFunctionBBCountAfterOptimization.updateMax(F.size());
+    }
+  }
+
+  void visitBasicBlock(BasicBlock &BB) {
+    if (IsBeforeOptimization)
+      ++TotalBlocksBeforeOptimization;
+    else
+      ++TotalBlocksAfterOptimization;
   }
-  void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
   void visit##OPCODE(CLASS &) {                                                \
-    ++Num##OPCODE##Inst;                                                       \
-    ++TotalInsts;                                                              \
+    if (IsBeforeOptimization) {                                                \
+      ++Num##OPCODE##InstBeforeOptimization;                                   \
+      ++TotalInstsBeforeOptimization;                                          \
+    } else {                                                                   \
+      ++Num##OPCODE##InstAfterOptimization;                                    \
+      ++TotalInstsAfterOptimization;                                           \
+    }                                                                          \
   }
 
 #include "llvm/IR/Instruction.def"
@@ -64,7 +106,7 @@ PreservedAnalyses InstCountPass::run(Function &F,
                                      FunctionAnalysisManager &FAM) {
   LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
                     << "\n");
-  InstCount().visit(F);
+  InstCount(this->IsBeforeOptimization).visit(F);
 
   return PreservedAnalyses::all();
-}
+}
\ No newline at end of file
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 5e4688f4dd7ef..f42bf1326a6b2 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -417,13 +417,24 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 }
 
 // Helper to add AnnotationRemarksPass.
-static void addAnnotationRemarksPass(ModulePassManager &MPM) {
-  MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
+static void addAnnotationRemarksPass(ModulePassManager &MPM,
+                                     bool IsBeforeOptimization = false) {
   // Count the stats for InstCount and FunctionPropertiesAnalysis
+  if (IsBeforeOptimization && AreStatisticsEnabled()) {
+    MPM.addPass(
+        createModuleToFunctionPassAdaptor(InstCountPass(IsBeforeOptimization)));
+    MPM.addPass(createModuleToFunctionPassAdaptor(
+        FunctionPropertiesStatisticsPass(IsBeforeOptimization)));
+    return;
+  }
+
+  MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
+
   if (AreStatisticsEnabled()) {
-    MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass()));
     MPM.addPass(
-        createModuleToFunctionPassAdaptor(FunctionPropertiesStatisticsPass()));
+        createModuleToFunctionPassAdaptor(InstCountPass(IsBeforeOptimization)));
+    MPM.addPass(createModuleToFunctionPassAdaptor(
+        FunctionPropertiesStatisticsPass(IsBeforeOptimization)));
   }
 }
 
@@ -1719,6 +1730,9 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     return buildO0DefaultPipeline(Level, Phase);
 
   ModulePassManager MPM;
+  // Emit annotation remarks. Must go at the end of the pipeline to see the
+  // final state of the IR.
+  addAnnotationRemarksPass(MPM, true);
 
   // Currently this pipeline is only invoked in an LTO pre link pass or when we
   // are not running LTO. If that changes the below checks may need updating.
@@ -1752,11 +1766,12 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
       PGOOpt->Action == PGOOptions::SampleUse)
     MPM.addPass(PseudoProbeUpdatePass());
 
+  if (isLTOPreLink(Phase))
+    addRequiredLTOPreLinkPasses(MPM);
+
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  if (isLTOPreLink(Phase))
-    addRequiredLTOPreLinkPasses(MPM);
   return MPM;
 }
 
@@ -1764,6 +1779,9 @@ ModulePassManager
 PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
                                         bool EmitSummary) {
   ModulePassManager MPM;
+
+  addAnnotationRemarksPass(MPM, true);
+
   if (ThinLTO)
     MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
   else
@@ -1803,9 +1821,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
     // otherwise, just use module optimization
     MPM.addPass(
         buildModuleOptimizationPipeline(Level, ThinOrFullLTOPhase::None));
-    // Emit annotation remarks.
-    addAnnotationRemarksPass(MPM);
   }
+  // Emit annotation remarks.
+  addAnnotationRemarksPass(MPM);
+
   return MPM;
 }
 
@@ -1816,6 +1835,8 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   ModulePassManager MPM;
 
+  addAnnotationRemarksPass(MPM, true);
+
   // Convert @llvm.global.annotations to !annotation metadata.
   MPM.addPass(Annotation2MetadataPass());
 
@@ -1863,11 +1884,11 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
   invokeOptimizerLastEPCallbacks(MPM, Level,
                                  /*Phase=*/ThinOrFullLTOPhase::ThinLTOPreLink);
 
+  addRequiredLTOPreLinkPasses(MPM);
+
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  addRequiredLTOPreLinkPasses(MPM);
-
   return MPM;
 }
 
@@ -1875,6 +1896,8 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
   ModulePassManager MPM;
 
+  addAnnotationRemarksPass(MPM, true);
+
   // If we are invoking this without a summary index noting that we are linking
   // with a library containing the necessary APIs, remove any MemProf related
   // attributes and metadata.
@@ -1923,6 +1946,8 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     // globals in the object file.
     MPM.addPass(EliminateAvailableExternallyPass());
     MPM.addPass(GlobalDCEPass());
+
+    addAnnotationRemarksPass(MPM, false);
     return MPM;
   }
   if (!UseCtxProfile.empty()) {
@@ -1955,6 +1980,8 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                      ModuleSummaryIndex *ExportSummary) {
   ModulePassManager MPM;
 
+  addAnnotationRemarksPass(MPM, true);
+
   invokeFullLinkTimeOptimizationEarlyEPCallbacks(MPM, Level);
 
   // If we are invoking this without a summary index noting that we are linking
@@ -2328,6 +2355,8 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM;
 
+  addAnnotationRemarksPass(MPM, true);
+
   // Perform pseudo probe instrumentation in O0 mode. This is for the
   // consistency between different build modes. For example, a LTO build can be
   // mixed with an O0 prelink and an O2 postlink. Loading a sample profile in
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
new file mode 100644
index 0000000000000..40dc0271faa77
--- /dev/null
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
@@ -0,0 +1,25 @@
+; REQUIRES: asserts
+; RUN: opt -stats -enable-detailed-function-properties -O3 -disable-output < %s 2>&1 | FileCheck %s
+
+; CHECK-DAG: 4 func-properties-stats - Number of basic blocks (before optimizations)
+; CHECK-DAG: 5 func-properties-stats - Number of instructions (of all types) (before optimizations)
+; CHECK-DAG: 4 func-properties-stats - Number of basic block successors (before optimizations)
+; CHECK-DAG: 1 func-properties-stats - Number of basic blocks (after optimizations)
+; CHECK-DAG: 1 func-properties-stats - Number of instructions (of all types) (after optimizations)
+; CHECK-NOT: func-properties-stats - Number of basic block successors (after optimizations)
+
+define i32 @test_cfg() {
+entry:
+  ; This branch is trivially resolvable
+  br i1 true, label %then, label %else
+
+then:
+  br label %end
+
+else:
+  br label %end
+
+end:
+  %phi = phi i32 [ 1, %then ], [ 2, %else ]
+  ret i32 %phi
+}
\ No newline at end of file
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/properties-stats.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
similarity index 81%
rename from llvm/test/Analysis/FunctionPropertiesAnalysis/properties-stats.ll
rename to llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
index f7907c73728a5..45370b47e833d 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/properties-stats.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
@@ -7,15 +7,15 @@
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 func-properties-stats - Number of basic blocks
-; CHECK-DAG: 8 func-properties-stats - Number of branch instructions
-; CHECK-DAG: 10 func-properties-stats - Number of branch successors
-; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions
-; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions
-; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types)
-; CHECK-DAG: 14 func-properties-stats - Number of basic block successors
-; CHECK-DAG: 1 func-properties-stats - Number of switch instructions
-; CHECK-DAG: 4 func-properties-stats - Number of switch successors
+; CHECK-DAG: 10 func-properties-stats - Number of basic blocks ({{before|after}} optimizations)
+; CHECK-DAG: 8 func-properties-stats - Number of branch instructions ({{before|after}} optimizations)
+; CHECK-DAG: 10 func-properties-stats - Number of branch successors ({{before|after}} optimizations)
+; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions ({{before|after}} optimizations)
+; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions ({{before|after}} optimizations)
+; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types) ({{before|after}} optimizations)
+; CHECK-DAG: 14 func-properties-stats - Number of basic block successors ({{before|after}} optimizations)
+; CHECK-DAG: 1 func-properties-stats - Number of switch instructions ({{before|after}} optimizations)
+; CHECK-DAG: 4 func-properties-stats - Number of switch successors ({{before|after}} optimizations)
 
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
@@ -67,4 +67,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
+declare void @m()
\ No newline at end of file
diff --git a/llvm/test/Analysis/InstCount/instcount-diff.ll b/llvm/test/Analysis/InstCount/instcount-diff.ll
new file mode 100644
index 0000000000000..5096e21f2b668
--- /dev/null
+++ b/llvm/test/Analysis/InstCount/instcount-diff.ll
@@ -0,0 +1,25 @@
+; REQUIRES: asserts
+; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
+
+; CHECK-DAG: 4 instcount - Number of basic blocks (before optimizations)
+; CHECK-DAG: 1 instcount - Number of basic blocks (after optimizations)
+; CHECK-DAG: 5 instcount - Number of instructions of all types (before optimizations)
+; CHECK-DAG: 1 instcount - Number of instructions of all types (after optimizations)
+; CHECK-DAG: 1 instcount - Number of CondBr insts (before optimizations)
+; CHECK-NOT: instcount - Number of CondBr insts (after optimizations)
+
+define i32 @test_cfg() {
+entry:
+  ; This branch is trivially resolvable
+  br i1 true, label %then, label %else
+
+then:
+  br label %end
+
+else:
+  br label %end
+
+end:
+  %phi = phi i32 [ 1, %then ], [ 2, %else ]
+  ret i32 %phi
+}
\ No newline at end of file
diff --git a/llvm/test/Analysis/InstCount/instcount.ll b/llvm/test/Analysis/InstCount/instcount.ll
index 9c4d3f3d06457..df53527798efc 100644
--- a/llvm/test/Analysis/InstCount/instcount.ll
+++ b/llvm/test/Analysis/InstCount/instcount.ll
@@ -7,17 +7,17 @@
 ; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -O0 -disable-output < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function
-; CHECK-DAG: 18 instcount - Largest number of instructions in a single function
-; CHECK-DAG: 6 instcount - Number of UncondBr insts
-; CHECK-DAG: 2 instcount - Number of CondBr insts
-; CHECK-DAG: 6 instcount - Number of Call insts
-; CHECK-DAG: 2 instcount - Number of ICmp insts
-; CHECK-DAG: 2 instcount - Number of Ret insts
-; CHECK-DAG: 1 instcount - Number of Switch insts
-; CHECK-DAG: 11 instcount - Number of basic blocks
-; CHECK-DAG: 2 instcount - Number of non-external functions
-; CHECK-DAG: 19 instcount - Number of instructions (of all types)
+; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function ({{before|after}} optimizations)
+; CHECK-DAG: 18 instcount - Largest number of instructions in a single function ({{before|after}} optimizations)
+; CHECK-DAG: 6 instcount - Number of UncondBr insts ({{before|after}} optimizations)
+; CHECK-DAG: 2 instcount - Number of CondBr insts ({{before|after}} optimizations)
+; CHECK-DAG: 6 instcount - Number of Call insts ({{before|after}} optimizations)
+; CHECK-DAG: 2 instcount - Number of ICmp insts ({{before|after}} optimizations)
+; CHECK-DAG: 2 instcount - Number of Ret insts ({{before|after}} optimizations)
+; CHECK-DAG: 1 instcount - Number of Switch insts ({{before|after}} optimizations)
+; CHECK-DAG: 11 instcount - Number of basic blocks ({{before|after}} optimizations)
+; CHECK-DAG: 2 instcount - Number of non-external functions ({{before|after}} optimizations)
+; CHECK-DAG: 19 instcount - Number of instructions of all types ({{before|after}} optimizations)
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
 entry:
@@ -72,4 +72,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
+declare void @m()
\ No newline at end of file

>From fe8e0b39407e5d81475d3ecf6c4128c8b3feb65a Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Thu, 26 Mar 2026 21:20:21 +0000
Subject: [PATCH 2/9] Removed renaming of after opt metrics to maintain
 original names

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  6 +-
 llvm/include/llvm/Analysis/InstCount.h        |  6 +-
 .../Analysis/FunctionPropertiesAnalysis.cpp   | 23 ++++---
 llvm/lib/Analysis/InstCount.cpp               | 63 +++++++++----------
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 12 ++--
 5 files changed, 53 insertions(+), 57 deletions(-)

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index 50b58b7133d36..5fe20f29c58a5 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -187,10 +187,10 @@ class FunctionPropertiesPrinterPass
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 struct FunctionPropertiesStatisticsPass
     : PassInfoMixin<FunctionPropertiesStatisticsPass> {
-  explicit FunctionPropertiesStatisticsPass(bool IsBeforeOptimization = false)
-      : IsBeforeOptimization(IsBeforeOptimization) {}
+  explicit FunctionPropertiesStatisticsPass(bool IsPreOptimizations = false)
+      : IsPreOptimizations(IsPreOptimizations) {}
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
-  bool IsBeforeOptimization;
+  bool IsPreOptimizations;
 };
 
 /// Correctly update FunctionPropertiesInfo post-inlining. A
diff --git a/llvm/include/llvm/Analysis/InstCount.h b/llvm/include/llvm/Analysis/InstCount.h
index fe03ceb680f4c..db20f31b71ba4 100644
--- a/llvm/include/llvm/Analysis/InstCount.h
+++ b/llvm/include/llvm/Analysis/InstCount.h
@@ -20,10 +20,10 @@ namespace llvm {
 class Function;
 
 struct InstCountPass : PassInfoMixin<InstCountPass> {
-  explicit InstCountPass(bool IsBeforeOptimization = false)
-      : IsBeforeOptimization(IsBeforeOptimization) {}
+  explicit InstCountPass(bool IsPreOptimizations = false)
+      : IsPreOptimizations(IsPreOptimizations) {}
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
-  bool IsBeforeOptimization;
+  bool IsPreOptimizations;
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index bf63f2b559f52..fa067a50c01ca 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -30,15 +30,15 @@ using namespace llvm;
 #define DEBUG_TYPE "func-properties-stats"
 
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  STATISTIC(Num##Name##BeforeOptimization,                                     \
+  STATISTIC(Num##Name##PreOptimizations,                                       \
             Description " (before optimizations)");                            \
-  STATISTIC(Num##Name##AfterOptimization, Description " (after "               \
-                                                      "optimizations)");
+  STATISTIC(Num##Name, Description " (after "                                  \
+                                   "optimizations)");
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  STATISTIC(Num##Name##BeforeOptimization,                                     \
+  STATISTIC(Num##Name##PreOptimizations,                                       \
             Description " (before optimizations)");                            \
-  STATISTIC(Num##Name##AfterOptimization, Description " (after "               \
-                                                      "optimizations)");
+  STATISTIC(Num##Name, Description " (after "                                  \
+                                   "optimizations)");
 #include "llvm/IR/FunctionProperties.def"
 
 namespace llvm {
@@ -385,19 +385,18 @@ FunctionPropertiesStatisticsPass::run(Function &F,
   LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
                     << "\n");
   auto &AnalysisResults = FAM.getResult<FunctionPropertiesAnalysis>(F);
-  if (IsBeforeOptimization) {
+  if (IsPreOptimizations) {
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  Num##Name##BeforeOptimization += AnalysisResults.Name;
+  Num##Name##PreOptimizations += AnalysisResults.Name;
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  Num##Name##BeforeOptimization += AnalysisResults.Name;
+  Num##Name##PreOptimizations += AnalysisResults.Name;
 #include "llvm/IR/FunctionProperties.def"
 #undef FUNCTION_PROPERTY
 #undef DETAILED_FUNCTION_PROPERTY
   } else {
-#define FUNCTION_PROPERTY(Name, Description)                                   \
-  Num##Name##AfterOptimization += AnalysisResults.Name;
+#define FUNCTION_PROPERTY(Name, Description) Num##Name += AnalysisResults.Name;
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  Num##Name##AfterOptimization += AnalysisResults.Name;
+  Num##Name += AnalysisResults.Name;
 #include "llvm/IR/FunctionProperties.def"
 #undef FUNCTION_PROPERTY
 #undef DETAILED_FUNCTION_PROPERTY
diff --git a/llvm/lib/Analysis/InstCount.cpp b/llvm/lib/Analysis/InstCount.cpp
index e65da22a57c39..6a999a1283431 100644
--- a/llvm/lib/Analysis/InstCount.cpp
+++ b/llvm/lib/Analysis/InstCount.cpp
@@ -21,35 +21,33 @@ using namespace llvm;
 
 #define DEBUG_TYPE "instcount"
 
-STATISTIC(TotalInstsBeforeOptimization,
+STATISTIC(TotalInstsPreOptimizations,
           "Number of instructions of all types (before optimizations)");
-STATISTIC(TotalInstsAfterOptimization,
+STATISTIC(TotalInsts,
           "Number of instructions of all types (after optimizations)");
-STATISTIC(TotalBlocksBeforeOptimization,
+STATISTIC(TotalBlocksPreOptimizations,
           "Number of basic blocks (before optimizations)");
-STATISTIC(TotalBlocksAfterOptimization,
-          "Number of basic blocks (after optimizations)");
-STATISTIC(TotalFuncsBeforeOptimization,
+STATISTIC(TotalBlocks, "Number of basic blocks (after optimizations)");
+STATISTIC(TotalFuncsPreOptimizations,
           "Number of non-external functions (before optimizations)");
-STATISTIC(TotalFuncsAfterOptimization,
-          "Number of non-external functions (after optimizations)");
-STATISTIC(LargestFunctionSizeBeforeOptimization,
+STATISTIC(TotalFuncs, "Number of non-external functions (after optimizations)");
+STATISTIC(LargestFunctionSizePreOptimizations,
           "Largest number of instructions in a single function (before "
           "optimizations)");
-STATISTIC(LargestFunctionSizeAfterOptimization,
+STATISTIC(LargestFunctionSize,
           "Largest number of instructions in a single function (after "
           "optimizations)");
-STATISTIC(LargestFunctionBBCountBeforeOptimization,
+STATISTIC(LargestFunctionBBCountPreOptimizations,
           "Largest number of basic blocks in a single function (before "
           "optimizations)");
-STATISTIC(LargestFunctionBBCountAfterOptimization,
+STATISTIC(LargestFunctionBBCount,
           "Largest number of basic blocks in a single function (after "
           "optimizations)");
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
-  STATISTIC(Num##OPCODE##InstBeforeOptimization,                               \
+  STATISTIC(Num##OPCODE##InstPreOptimizations,                                 \
             "Number of " #OPCODE " insts (before optimizations)");             \
-  STATISTIC(Num##OPCODE##InstAfterOptimization,                                \
+  STATISTIC(Num##OPCODE##Inst,                                                 \
             "Number of " #OPCODE " insts (after optimizations)");
 
 #include "llvm/IR/Instruction.def"
@@ -57,39 +55,38 @@ STATISTIC(LargestFunctionBBCountAfterOptimization,
 namespace {
 class InstCount : public InstVisitor<InstCount> {
   friend class InstVisitor<InstCount>;
-  bool IsBeforeOptimization;
+  bool IsPreOptimizations;
 
 public:
-  InstCount(bool IsBeforeOptimization)
-      : IsBeforeOptimization(IsBeforeOptimization) {}
+  InstCount(bool IsPreOptimizations) : IsPreOptimizations(IsPreOptimizations) {}
 
   void visitFunction(Function &F) {
-    if (IsBeforeOptimization) {
-      ++TotalFuncsBeforeOptimization;
-      LargestFunctionSizeBeforeOptimization.updateMax(F.getInstructionCount());
-      LargestFunctionBBCountBeforeOptimization.updateMax(F.size());
+    if (IsPreOptimizations) {
+      ++TotalFuncsPreOptimizations;
+      LargestFunctionSizePreOptimizations.updateMax(F.getInstructionCount());
+      LargestFunctionBBCountPreOptimizations.updateMax(F.size());
     } else {
-      ++TotalFuncsAfterOptimization;
-      LargestFunctionSizeAfterOptimization.updateMax(F.getInstructionCount());
-      LargestFunctionBBCountAfterOptimization.updateMax(F.size());
+      ++TotalFuncs;
+      LargestFunctionSize.updateMax(F.getInstructionCount());
+      LargestFunctionBBCount.updateMax(F.size());
     }
   }
 
   void visitBasicBlock(BasicBlock &BB) {
-    if (IsBeforeOptimization)
-      ++TotalBlocksBeforeOptimization;
+    if (IsPreOptimizations)
+      ++TotalBlocksPreOptimizations;
     else
-      ++TotalBlocksAfterOptimization;
+      ++TotalBlocks;
   }
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
   void visit##OPCODE(CLASS &) {                                                \
-    if (IsBeforeOptimization) {                                                \
-      ++Num##OPCODE##InstBeforeOptimization;                                   \
-      ++TotalInstsBeforeOptimization;                                          \
+    if (IsPreOptimizations) {                                                  \
+      ++Num##OPCODE##InstPreOptimizations;                                     \
+      ++TotalInstsPreOptimizations;                                            \
     } else {                                                                   \
-      ++Num##OPCODE##InstAfterOptimization;                                    \
-      ++TotalInstsAfterOptimization;                                           \
+      ++Num##OPCODE##Inst;                                                     \
+      ++TotalInsts;                                                            \
     }                                                                          \
   }
 
@@ -106,7 +103,7 @@ PreservedAnalyses InstCountPass::run(Function &F,
                                      FunctionAnalysisManager &FAM) {
   LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
                     << "\n");
-  InstCount(this->IsBeforeOptimization).visit(F);
+  InstCount(this->IsPreOptimizations).visit(F);
 
   return PreservedAnalyses::all();
 }
\ No newline at end of file
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index f42bf1326a6b2..7831f64a8e48c 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -418,13 +418,13 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 
 // Helper to add AnnotationRemarksPass.
 static void addAnnotationRemarksPass(ModulePassManager &MPM,
-                                     bool IsBeforeOptimization = false) {
+                                     bool IsIsPreOptimizations = false) {
   // Count the stats for InstCount and FunctionPropertiesAnalysis
-  if (IsBeforeOptimization && AreStatisticsEnabled()) {
+  if (IsIsPreOptimizations && AreStatisticsEnabled()) {
     MPM.addPass(
-        createModuleToFunctionPassAdaptor(InstCountPass(IsBeforeOptimization)));
+        createModuleToFunctionPassAdaptor(InstCountPass(IsIsPreOptimizations)));
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsBeforeOptimization)));
+        FunctionPropertiesStatisticsPass(IsIsPreOptimizations)));
     return;
   }
 
@@ -432,9 +432,9 @@ static void addAnnotationRemarksPass(ModulePassManager &MPM,
 
   if (AreStatisticsEnabled()) {
     MPM.addPass(
-        createModuleToFunctionPassAdaptor(InstCountPass(IsBeforeOptimization)));
+        createModuleToFunctionPassAdaptor(InstCountPass(IsIsPreOptimizations)));
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsBeforeOptimization)));
+        FunctionPropertiesStatisticsPass(IsIsPreOptimizations)));
   }
 }
 

>From c55b6af44dd0c297b2816fd2013906f1c027921a Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Fri, 27 Mar 2026 19:54:15 +0000
Subject: [PATCH 3/9] Refactor passes, separating instructionCounter passes
 from addAnnotationRemarksPass

---
 llvm/lib/Analysis/InstCount.cpp               |  2 +-
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 73 +++++++++++--------
 .../func-properties-analysis-diff.ll          |  2 +-
 .../func-properties-analysis.ll               |  2 +-
 .../test/Analysis/InstCount/instcount-diff.ll |  2 +-
 llvm/test/Analysis/InstCount/instcount.ll     |  2 +-
 6 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/llvm/lib/Analysis/InstCount.cpp b/llvm/lib/Analysis/InstCount.cpp
index 6a999a1283431..e504ea1866e24 100644
--- a/llvm/lib/Analysis/InstCount.cpp
+++ b/llvm/lib/Analysis/InstCount.cpp
@@ -106,4 +106,4 @@ PreservedAnalyses InstCountPass::run(Function &F,
   InstCount(this->IsPreOptimizations).visit(F);
 
   return PreservedAnalyses::all();
-}
\ No newline at end of file
+}
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 7831f64a8e48c..09ecc10121cbf 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -416,27 +416,22 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
     C(MPM, Level, Phase);
 }
 
-// Helper to add AnnotationRemarksPass.
-static void addAnnotationRemarksPass(ModulePassManager &MPM,
-                                     bool IsIsPreOptimizations = false) {
-  // Count the stats for InstCount and FunctionPropertiesAnalysis
-  if (IsIsPreOptimizations && AreStatisticsEnabled()) {
-    MPM.addPass(
-        createModuleToFunctionPassAdaptor(InstCountPass(IsIsPreOptimizations)));
-    MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsIsPreOptimizations)));
-    return;
-  }
-
-  MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
-
+// Count the stats for InstCount and FunctionPropertiesAnalysis. This is used in
+// both the pre-optimization and post-optimization pipelines for comparison
+// purposes.
+static void instructionCountersPass(ModulePassManager &MPM,
+                                    bool IsPreOptimizations) {
   if (AreStatisticsEnabled()) {
     MPM.addPass(
-        createModuleToFunctionPassAdaptor(InstCountPass(IsIsPreOptimizations)));
+        createModuleToFunctionPassAdaptor(InstCountPass(IsPreOptimizations)));
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsIsPreOptimizations)));
+        FunctionPropertiesStatisticsPass(IsPreOptimizations)));
   }
 }
+// Helper to add AnnotationRemarksPass.
+static void addAnnotationRemarksPass(ModulePassManager &MPM) {
+  MPM.addPass(createModuleToFunctionPassAdaptor(AnnotationRemarksPass()));
+}
 
 // Helper to check if the current compilation phase is preparing for LTO
 static bool isLTOPreLink(ThinOrFullLTOPhase Phase) {
@@ -1730,9 +1725,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     return buildO0DefaultPipeline(Level, Phase);
 
   ModulePassManager MPM;
-  // Emit annotation remarks. Must go at the end of the pipeline to see the
-  // final state of the IR.
-  addAnnotationRemarksPass(MPM, true);
+  instructionCountersPass(MPM, true);
 
   // Currently this pipeline is only invoked in an LTO pre link pass or when we
   // are not running LTO. If that changes the below checks may need updating.
@@ -1766,11 +1759,14 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
       PGOOpt->Action == PGOOptions::SampleUse)
     MPM.addPass(PseudoProbeUpdatePass());
 
+  // Emit annotation remarks.
+  addAnnotationRemarksPass(MPM);
+
   if (isLTOPreLink(Phase))
     addRequiredLTOPreLinkPasses(MPM);
 
-  // Emit annotation remarks.
-  addAnnotationRemarksPass(MPM);
+  // Count instruction types after optimization
+  instructionCountersPass(MPM, false);
 
   return MPM;
 }
@@ -1780,7 +1776,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
                                         bool EmitSummary) {
   ModulePassManager MPM;
 
-  addAnnotationRemarksPass(MPM, true);
+  instructionCountersPass(MPM, true);
 
   if (ThinLTO)
     MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
@@ -1821,9 +1817,12 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
     // otherwise, just use module optimization
     MPM.addPass(
         buildModuleOptimizationPipeline(Level, ThinOrFullLTOPhase::None));
+    // Emit annotation remarks.
+    addAnnotationRemarksPass(MPM);
   }
-  // Emit annotation remarks.
-  addAnnotationRemarksPass(MPM);
+
+  // Count instruction types after optimization
+  instructionCountersPass(MPM, false);
 
   return MPM;
 }
@@ -1835,7 +1834,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   ModulePassManager MPM;
 
-  addAnnotationRemarksPass(MPM, true);
+  instructionCountersPass(MPM, true);
 
   // Convert @llvm.global.annotations to !annotation metadata.
   MPM.addPass(Annotation2MetadataPass());
@@ -1884,11 +1883,14 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
   invokeOptimizerLastEPCallbacks(MPM, Level,
                                  /*Phase=*/ThinOrFullLTOPhase::ThinLTOPreLink);
 
-  addRequiredLTOPreLinkPasses(MPM);
-
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
+  addRequiredLTOPreLinkPasses(MPM);
+
+  // Count instruction types after optimization
+  instructionCountersPass(MPM, false);
+
   return MPM;
 }
 
@@ -1896,7 +1898,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
   ModulePassManager MPM;
 
-  addAnnotationRemarksPass(MPM, true);
+  instructionCountersPass(MPM, true);
 
   // If we are invoking this without a summary index noting that we are linking
   // with a library containing the necessary APIs, remove any MemProf related
@@ -1947,7 +1949,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     MPM.addPass(EliminateAvailableExternallyPass());
     MPM.addPass(GlobalDCEPass());
 
-    addAnnotationRemarksPass(MPM, false);
+    instructionCountersPass(MPM, false);
     return MPM;
   }
   if (!UseCtxProfile.empty()) {
@@ -1965,6 +1967,9 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
+  // Count instruction types after optimization
+  instructionCountersPass(MPM, false);
+
   return MPM;
 }
 
@@ -1980,7 +1985,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                      ModuleSummaryIndex *ExportSummary) {
   ModulePassManager MPM;
 
-  addAnnotationRemarksPass(MPM, true);
+  instructionCountersPass(MPM, true);
 
   invokeFullLinkTimeOptimizationEarlyEPCallbacks(MPM, Level);
 
@@ -2344,6 +2349,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
+  // Count instruction types after optimization
+  instructionCountersPass(MPM, false);
+
   return MPM;
 }
 
@@ -2355,7 +2363,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM;
 
-  addAnnotationRemarksPass(MPM, true);
+  instructionCountersPass(MPM, true);
 
   // Perform pseudo probe instrumentation in O0 mode. This is for the
   // consistency between different build modes. For example, a LTO build can be
@@ -2470,6 +2478,9 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
+  // Count instruction types after optimization
+  instructionCountersPass(MPM, false);
+
   return MPM;
 }
 
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
index 40dc0271faa77..12f342495b07f 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
@@ -22,4 +22,4 @@ else:
 end:
   %phi = phi i32 [ 1, %then ], [ 2, %else ]
   ret i32 %phi
-}
\ No newline at end of file
+}
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
index 45370b47e833d..6415b02b763a0 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
@@ -67,4 +67,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
\ No newline at end of file
+declare void @m()
diff --git a/llvm/test/Analysis/InstCount/instcount-diff.ll b/llvm/test/Analysis/InstCount/instcount-diff.ll
index 5096e21f2b668..fdfc56726d902 100644
--- a/llvm/test/Analysis/InstCount/instcount-diff.ll
+++ b/llvm/test/Analysis/InstCount/instcount-diff.ll
@@ -22,4 +22,4 @@ else:
 end:
   %phi = phi i32 [ 1, %then ], [ 2, %else ]
   ret i32 %phi
-}
\ No newline at end of file
+}
diff --git a/llvm/test/Analysis/InstCount/instcount.ll b/llvm/test/Analysis/InstCount/instcount.ll
index df53527798efc..dbe4cba409d3f 100644
--- a/llvm/test/Analysis/InstCount/instcount.ll
+++ b/llvm/test/Analysis/InstCount/instcount.ll
@@ -72,4 +72,4 @@ declare void @g()
 declare void @h()
 declare void @k()
 declare void @l()
-declare void @m()
\ No newline at end of file
+declare void @m()

>From 05581cdaa44c974dcad3baceda8d844c310fd459 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Wed, 1 Apr 2026 00:12:49 +0000
Subject: [PATCH 4/9] Fix tests and cleanup comments

---
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 32 ++++++++-----------
 ....ll => func-properties-analysis-preopt.ll} |  4 ++-
 .../func-properties-analysis.ll               | 19 ++++++-----
 ...{instcount-diff.ll => instcount-preopt.ll} |  4 ++-
 llvm/test/Analysis/InstCount/instcount.ll     | 23 +++++++------
 5 files changed, 39 insertions(+), 43 deletions(-)
 rename llvm/test/Analysis/FunctionPropertiesAnalysis/{func-properties-analysis-diff.ll => func-properties-analysis-preopt.ll} (69%)
 rename llvm/test/Analysis/InstCount/{instcount-diff.ll => instcount-preopt.ll} (75%)

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 09ecc10121cbf..0a09b8cd869a0 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1725,7 +1725,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     return buildO0DefaultPipeline(Level, Phase);
 
   ModulePassManager MPM;
-  instructionCountersPass(MPM, true);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
 
   // Currently this pipeline is only invoked in an LTO pre link pass or when we
   // are not running LTO. If that changes the below checks may need updating.
@@ -1765,8 +1765,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
   if (isLTOPreLink(Phase))
     addRequiredLTOPreLinkPasses(MPM);
 
-  // Count instruction types after optimization
-  instructionCountersPass(MPM, false);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
 
   return MPM;
 }
@@ -1776,7 +1775,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
                                         bool EmitSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, true);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
 
   if (ThinLTO)
     MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
@@ -1821,8 +1820,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
     addAnnotationRemarksPass(MPM);
   }
 
-  // Count instruction types after optimization
-  instructionCountersPass(MPM, false);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
 
   return MPM;
 }
@@ -1834,7 +1832,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, true);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
 
   // Convert @llvm.global.annotations to !annotation metadata.
   MPM.addPass(Annotation2MetadataPass());
@@ -1888,8 +1886,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   addRequiredLTOPreLinkPasses(MPM);
 
-  // Count instruction types after optimization
-  instructionCountersPass(MPM, false);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
 
   return MPM;
 }
@@ -1898,7 +1895,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, true);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
 
   // If we are invoking this without a summary index noting that we are linking
   // with a library containing the necessary APIs, remove any MemProf related
@@ -1949,7 +1946,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     MPM.addPass(EliminateAvailableExternallyPass());
     MPM.addPass(GlobalDCEPass());
 
-    instructionCountersPass(MPM, false);
+    instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
     return MPM;
   }
   if (!UseCtxProfile.empty()) {
@@ -1967,8 +1964,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  // Count instruction types after optimization
-  instructionCountersPass(MPM, false);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
 
   return MPM;
 }
@@ -1985,7 +1981,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                      ModuleSummaryIndex *ExportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, true);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
 
   invokeFullLinkTimeOptimizationEarlyEPCallbacks(MPM, Level);
 
@@ -2349,8 +2345,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  // Count instruction types after optimization
-  instructionCountersPass(MPM, false);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
 
   return MPM;
 }
@@ -2363,7 +2358,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, true);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
 
   // Perform pseudo probe instrumentation in O0 mode. This is for the
   // consistency between different build modes. For example, a LTO build can be
@@ -2478,8 +2473,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  // Count instruction types after optimization
-  instructionCountersPass(MPM, false);
+  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
 
   return MPM;
 }
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
similarity index 69%
rename from llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
rename to llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
index 12f342495b07f..f9037c4eaa9d1 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-diff.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
@@ -1,5 +1,7 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -enable-detailed-function-properties -O3 -disable-output < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
 
 ; CHECK-DAG: 4 func-properties-stats - Number of basic blocks (before optimizations)
 ; CHECK-DAG: 5 func-properties-stats - Number of instructions (of all types) (before optimizations)
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
index 6415b02b763a0..0299c32bf6da6 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
@@ -3,19 +3,18 @@
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-stats < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto<O1>' < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 func-properties-stats - Number of basic blocks ({{before|after}} optimizations)
-; CHECK-DAG: 8 func-properties-stats - Number of branch instructions ({{before|after}} optimizations)
-; CHECK-DAG: 10 func-properties-stats - Number of branch successors ({{before|after}} optimizations)
-; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions ({{before|after}} optimizations)
-; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions ({{before|after}} optimizations)
-; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types) ({{before|after}} optimizations)
-; CHECK-DAG: 14 func-properties-stats - Number of basic block successors ({{before|after}} optimizations)
-; CHECK-DAG: 1 func-properties-stats - Number of switch instructions ({{before|after}} optimizations)
-; CHECK-DAG: 4 func-properties-stats - Number of switch successors ({{before|after}} optimizations)
+; CHECK-DAG: 10 func-properties-stats - Number of basic blocks (after optimizations)
+; CHECK-DAG: 8 func-properties-stats - Number of branch instructions (after optimizations)
+; CHECK-DAG: 10 func-properties-stats - Number of branch successors (after optimizations)
+; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions (after optimizations)
+; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions (after optimizations)
+; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types) (after optimizations)
+; CHECK-DAG: 14 func-properties-stats - Number of basic block successors (after optimizations)
+; CHECK-DAG: 1 func-properties-stats - Number of switch instructions (after optimizations)
+; CHECK-DAG: 4 func-properties-stats - Number of switch successors (after optimizations)
 
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
diff --git a/llvm/test/Analysis/InstCount/instcount-diff.ll b/llvm/test/Analysis/InstCount/instcount-preopt.ll
similarity index 75%
rename from llvm/test/Analysis/InstCount/instcount-diff.ll
rename to llvm/test/Analysis/InstCount/instcount-preopt.ll
index fdfc56726d902..39cc2d257938a 100644
--- a/llvm/test/Analysis/InstCount/instcount-diff.ll
+++ b/llvm/test/Analysis/InstCount/instcount-preopt.ll
@@ -1,5 +1,7 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -disable-output -O3 < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
 
 ; CHECK-DAG: 4 instcount - Number of basic blocks (before optimizations)
 ; CHECK-DAG: 1 instcount - Number of basic blocks (after optimizations)
diff --git a/llvm/test/Analysis/InstCount/instcount.ll b/llvm/test/Analysis/InstCount/instcount.ll
index dbe4cba409d3f..58de202999ebb 100644
--- a/llvm/test/Analysis/InstCount/instcount.ll
+++ b/llvm/test/Analysis/InstCount/instcount.ll
@@ -2,22 +2,21 @@
 ; RUN: opt -stats -passes=instcount -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -passes='thinlto<O3>' -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -passes='thinlto-pre-link<O2>' -disable-output < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -passes='lto<O1>' -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -passes='lto-pre-link<Os>' -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -O0 -disable-output < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function ({{before|after}} optimizations)
-; CHECK-DAG: 18 instcount - Largest number of instructions in a single function ({{before|after}} optimizations)
-; CHECK-DAG: 6 instcount - Number of UncondBr insts ({{before|after}} optimizations)
-; CHECK-DAG: 2 instcount - Number of CondBr insts ({{before|after}} optimizations)
-; CHECK-DAG: 6 instcount - Number of Call insts ({{before|after}} optimizations)
-; CHECK-DAG: 2 instcount - Number of ICmp insts ({{before|after}} optimizations)
-; CHECK-DAG: 2 instcount - Number of Ret insts ({{before|after}} optimizations)
-; CHECK-DAG: 1 instcount - Number of Switch insts ({{before|after}} optimizations)
-; CHECK-DAG: 11 instcount - Number of basic blocks ({{before|after}} optimizations)
-; CHECK-DAG: 2 instcount - Number of non-external functions ({{before|after}} optimizations)
-; CHECK-DAG: 19 instcount - Number of instructions of all types ({{before|after}} optimizations)
+; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function (after optimizations)
+; CHECK-DAG: 18 instcount - Largest number of instructions in a single function (after optimizations)
+; CHECK-DAG: 6 instcount - Number of UncondBr insts (after optimizations)
+; CHECK-DAG: 2 instcount - Number of CondBr insts (after optimizations)
+; CHECK-DAG: 6 instcount - Number of Call insts (after optimizations)
+; CHECK-DAG: 2 instcount - Number of ICmp insts (after optimizations)
+; CHECK-DAG: 2 instcount - Number of Ret insts (after optimizations)
+; CHECK-DAG: 1 instcount - Number of Switch insts (after optimizations)
+; CHECK-DAG: 11 instcount - Number of basic blocks (after optimizations)
+; CHECK-DAG: 2 instcount - Number of non-external functions (after optimizations)
+; CHECK-DAG: 19 instcount - Number of instructions of all types (after optimizations)
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
 entry:

>From 63e61cd851790a3b9b55d876b80eba8087983088 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Wed, 8 Apr 2026 00:01:46 +0000
Subject: [PATCH 5/9] Function Pass with Params for Func Properties Analysis

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  9 ++++--
 llvm/lib/Passes/PassBuilder.cpp               |  6 ++++
 llvm/lib/Passes/PassRegistry.def              |  8 ++++-
 .../func-properties-analysis-preopt.ll        | 29 +++++++++++++------
 4 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index 5fe20f29c58a5..c1e9f78fae780 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -185,12 +185,15 @@ class FunctionPropertiesPrinterPass
 };
 
 /// Statistics pass for the FunctionPropertiesAnalysis results.
-struct FunctionPropertiesStatisticsPass
-    : PassInfoMixin<FunctionPropertiesStatisticsPass> {
+class FunctionPropertiesStatisticsPass
+    : public PassInfoMixin<FunctionPropertiesStatisticsPass> {
+  bool IsPreOptimizations;
+
+public:
   explicit FunctionPropertiesStatisticsPass(bool IsPreOptimizations = false)
       : IsPreOptimizations(IsPreOptimizations) {}
+
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
-  bool IsPreOptimizations;
 };
 
 /// Correctly update FunctionPropertiesInfo post-inlining. A
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index a23d64b491a79..ce39572644705 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -806,6 +806,12 @@ Expected<bool> parseLintOptions(StringRef Params) {
                                             "LintPass");
 }
 
+/// Parser of parameters for FunctionPropertiesStatistics pass.
+Expected<bool> parseFunctionPropertiesStatisticsOptions(StringRef Params) {
+  return PassBuilder::parseSinglePassOption(Params, "pre-opt",
+                                            "FunctionPropertiesStatisticsPass");
+}
+
 /// Parser of parameters for LoopUnroll pass.
 Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
   LoopUnrollOptions UnrollOpts;
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index c92d93d7ae396..cdcc19faba156 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -440,7 +440,6 @@ FUNCTION_PASS("fix-irreducible", FixIrreduciblePass())
 FUNCTION_PASS("flatten-cfg", FlattenCFGPass())
 FUNCTION_PASS("float2int", Float2IntPass())
 FUNCTION_PASS("free-machine-function", FreeMachineFunctionPass())
-FUNCTION_PASS("func-properties-stats", FunctionPropertiesStatisticsPass())
 FUNCTION_PASS("gc-lowering", GCLoweringPass())
 FUNCTION_PASS("guard-widening", GuardWideningPass())
 FUNCTION_PASS("gvn-hoist", GVNHoistPass())
@@ -589,6 +588,13 @@ FUNCTION_PASS_WITH_PARAMS(
     "ee-instrument", "EntryExitInstrumenterPass",
     [](bool PostInlining) { return EntryExitInstrumenterPass(PostInlining); },
     parseEntryExitInstrumenterPassOptions, "post-inline")
+FUNCTION_PASS_WITH_PARAMS(
+    "func-properties-stats", 
+    "FunctionPropertiesStatisticsPass",
+    [](bool IsPreOptimizations) { 
+      return FunctionPropertiesStatisticsPass(IsPreOptimizations); 
+    },
+    parseFunctionPropertiesStatisticsOptions, "pre-opt")
 FUNCTION_PASS_WITH_PARAMS(
     "function-simplification", "",
     [this](OptimizationLevel OL) {
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
index f9037c4eaa9d1..ca07c5134214f 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
@@ -1,14 +1,25 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats<pre-opt>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats' < %s 2>&1 | FileCheck %s --check-prefixes=POSTNOOPT
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POSTNOOPT
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 
-; CHECK-DAG: 4 func-properties-stats - Number of basic blocks (before optimizations)
-; CHECK-DAG: 5 func-properties-stats - Number of instructions (of all types) (before optimizations)
-; CHECK-DAG: 4 func-properties-stats - Number of basic block successors (before optimizations)
-; CHECK-DAG: 1 func-properties-stats - Number of basic blocks (after optimizations)
-; CHECK-DAG: 1 func-properties-stats - Number of instructions (of all types) (after optimizations)
-; CHECK-NOT: func-properties-stats - Number of basic block successors (after optimizations)
+; --- <pre-opt> ---
+; PRE-DAG: 4 func-properties-stats - Number of basic blocks (before optimizations)
+; PRE-DAG: 5 func-properties-stats - Number of instructions (of all types) (before optimizations)
+; PRE-DAG: 4 func-properties-stats - Number of basic block successors (before optimizations)
+
+; --- No <pre-opt> in pass but no optimizations ---
+; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic blocks (after optimizations)
+; POSTNOOPT-DAG: 5 func-properties-stats - Number of instructions (of all types) (after optimizations)
+; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic block successors (after optimizations)
+
+; --- Post optimization values ---
+; POST-DAG: 1 func-properties-stats - Number of basic blocks (after optimizations)
+; POST-DAG: 1 func-properties-stats - Number of instructions (of all types) (after optimizations)
+; POST-NOT: func-properties-stats - Number of basic block successors (after optimizations)
 
 define i32 @test_cfg() {
 entry:

>From 680dcfc4760fcb38fd3dbdbbcbe07f96f0fe3e21 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Wed, 8 Apr 2026 21:11:27 +0000
Subject: [PATCH 6/9] InstCount pass implemented too

---
 llvm/include/llvm/Analysis/InstCount.h        |  8 +++--
 llvm/lib/Passes/PassBuilder.cpp               | 10 +++++--
 llvm/lib/Passes/PassRegistry.def              |  7 ++++-
 .../Analysis/InstCount/instcount-preopt.ll    | 29 +++++++++++++------
 4 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/llvm/include/llvm/Analysis/InstCount.h b/llvm/include/llvm/Analysis/InstCount.h
index db20f31b71ba4..cadf8601b90a4 100644
--- a/llvm/include/llvm/Analysis/InstCount.h
+++ b/llvm/include/llvm/Analysis/InstCount.h
@@ -19,11 +19,15 @@ namespace llvm {
 
 class Function;
 
-struct InstCountPass : PassInfoMixin<InstCountPass> {
+/// Statistics pass for the FunctionPropertiesAnalysis results.
+class InstCountPass : public PassInfoMixin<InstCountPass> {
+  bool IsPreOptimizations;
+
+public:
   explicit InstCountPass(bool IsPreOptimizations = false)
       : IsPreOptimizations(IsPreOptimizations) {}
+
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
-  bool IsPreOptimizations;
 };
 
 } // end namespace llvm
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index ce39572644705..f63348df76626 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -812,6 +812,11 @@ Expected<bool> parseFunctionPropertiesStatisticsOptions(StringRef Params) {
                                             "FunctionPropertiesStatisticsPass");
 }
 
+/// Parser of parameters for InstCount pass.
+Expected<bool> parseInstCountOptions(StringRef Params) {
+  return PassBuilder::parseSinglePassOption(Params, "pre-opt", "InstCountPass");
+}
+
 /// Parser of parameters for LoopUnroll pass.
 Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
   LoopUnrollOptions UnrollOpts;
@@ -2641,8 +2646,9 @@ Error PassBuilder::parsePassPipeline(ModulePassManager &MPM,
                                  std::move(*Pipeline)}}}};
     } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
                               UseMemorySSA)) {
-      Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
-                                 std::move(*Pipeline)}}}};
+      Pipeline = {
+          {"function",
+           {{UseMemorySSA ? "loop-mssa" : "loop", std::move(*Pipeline)}}}};
     } else if (isMachineFunctionPassName(
                    FirstName, MachineFunctionPipelineParsingCallbacks)) {
       Pipeline = {{"function", {{"machine-function", std::move(*Pipeline)}}}};
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index cdcc19faba156..9fe40d441e0af 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -450,7 +450,6 @@ FUNCTION_PASS("infer-address-spaces", InferAddressSpacesPass())
 FUNCTION_PASS("infer-alignment", InferAlignmentPass())
 FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings())
 FUNCTION_PASS("inline-asm-prepare", InlineAsmPreparePass())
-FUNCTION_PASS("instcount", InstCountPass())
 FUNCTION_PASS("instnamer", InstructionNamerPass())
 FUNCTION_PASS("instsimplify", InstSimplifyPass())
 FUNCTION_PASS("interleaved-access", InterleavedAccessPass(*TM))
@@ -618,6 +617,12 @@ FUNCTION_PASS_WITH_PARAMS(
     [](InstCombineOptions Opts) { return InstCombinePass(Opts); },
     parseInstCombineOptions,
     "no-verify-fixpoint;verify-fixpoint;max-iterations=N")
+FUNCTION_PASS_WITH_PARAMS(
+    "instcount", "InstCountPass",
+    [](bool IsPreOptimizations) { 
+      return InstCountPass(IsPreOptimizations); 
+    },
+    parseInstCountOptions, "pre-opt")
 FUNCTION_PASS_WITH_PARAMS(
     "lint", "LintPass",
     [](bool AbortOnError) { return LintPass(AbortOnError); }, parseLintOptions,
diff --git a/llvm/test/Analysis/InstCount/instcount-preopt.ll b/llvm/test/Analysis/InstCount/instcount-preopt.ll
index 39cc2d257938a..4db29a34e283e 100644
--- a/llvm/test/Analysis/InstCount/instcount-preopt.ll
+++ b/llvm/test/Analysis/InstCount/instcount-preopt.ll
@@ -1,14 +1,25 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -disable-output -O3 < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
+; RUN: opt -stats -disable-output -passes='instcount<pre-opt>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
+; RUN: opt -stats -disable-output -passes='instcount' < %s 2>&1 | FileCheck %s --check-prefixes=POSTNOOPT
+; RUN: opt -stats -disable-output -O0 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POSTNOOPT
+; RUN: opt -stats -disable-output -O3 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 
-; CHECK-DAG: 4 instcount - Number of basic blocks (before optimizations)
-; CHECK-DAG: 1 instcount - Number of basic blocks (after optimizations)
-; CHECK-DAG: 5 instcount - Number of instructions of all types (before optimizations)
-; CHECK-DAG: 1 instcount - Number of instructions of all types (after optimizations)
-; CHECK-DAG: 1 instcount - Number of CondBr insts (before optimizations)
-; CHECK-NOT: instcount - Number of CondBr insts (after optimizations)
+; --- <pre-opt> ---
+; PRE-DAG: 4 instcount - Number of basic blocks (before optimizations)
+; PRE-DAG: 5 instcount - Number of instructions of all types (before optimizations)
+; PRE-DAG: 1 instcount - Number of CondBr insts (before optimizations)
+
+; --- No <pre-opt> in pass but no optimizations ---
+; POSTNOOPT-DAG: 4 instcount - Number of basic blocks (after optimizations)
+; POSTNOOPT-DAG: 5 instcount - Number of instructions of all types (after optimizations)
+; POSTNOOPT-DAG: 1 instcount - Number of CondBr insts (after optimizations)
+
+; --- Post optimization values ---
+; POST-DAG: 1 instcount - Number of basic blocks (after optimizations)
+; POST-DAG: 1 instcount - Number of instructions of all types (after optimizations)
+; POST-NOT: instcount - Number of CondBr insts (after optimizations)
 
 define i32 @test_cfg() {
 entry:

>From a9a8da54953d87a022d9d5f1fc72732d2c1ce22a Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Fri, 10 Apr 2026 16:13:21 +0000
Subject: [PATCH 7/9] Renamed optimizations to passes for future alternate uses

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  6 +-
 llvm/include/llvm/Analysis/InstCount.h        |  5 +-
 .../Analysis/FunctionPropertiesAnalysis.cpp   | 18 +++---
 llvm/lib/Analysis/InstCount.cpp               | 63 +++++++++----------
 llvm/lib/Passes/PassBuilder.cpp               | 10 +--
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 38 +++++------
 ... => func-properties-analysis-prepasses.ll} | 26 ++++----
 .../func-properties-analysis.ll               | 18 +++---
 ...count-preopt.ll => instcount-prepasses.ll} | 26 ++++----
 llvm/test/Analysis/InstCount/instcount.ll     | 22 +++----
 10 files changed, 109 insertions(+), 123 deletions(-)
 rename llvm/test/Analysis/FunctionPropertiesAnalysis/{func-properties-analysis-preopt.ll => func-properties-analysis-prepasses.ll} (75%)
 rename llvm/test/Analysis/InstCount/{instcount-preopt.ll => instcount-prepasses.ll} (53%)

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index c1e9f78fae780..4f68cb869ccd1 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -187,11 +187,11 @@ class FunctionPropertiesPrinterPass
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 class FunctionPropertiesStatisticsPass
     : public PassInfoMixin<FunctionPropertiesStatisticsPass> {
-  bool IsPreOptimizations;
+  bool IsPrePasses;
 
 public:
-  explicit FunctionPropertiesStatisticsPass(bool IsPreOptimizations = false)
-      : IsPreOptimizations(IsPreOptimizations) {}
+  explicit FunctionPropertiesStatisticsPass(bool IsPrePasses = false)
+      : IsPrePasses(IsPrePasses) {}
 
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
diff --git a/llvm/include/llvm/Analysis/InstCount.h b/llvm/include/llvm/Analysis/InstCount.h
index cadf8601b90a4..a12a4183edd19 100644
--- a/llvm/include/llvm/Analysis/InstCount.h
+++ b/llvm/include/llvm/Analysis/InstCount.h
@@ -21,11 +21,10 @@ class Function;
 
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 class InstCountPass : public PassInfoMixin<InstCountPass> {
-  bool IsPreOptimizations;
+  bool IsPrePasses;
 
 public:
-  explicit InstCountPass(bool IsPreOptimizations = false)
-      : IsPreOptimizations(IsPreOptimizations) {}
+  explicit InstCountPass(bool IsPrePasses = false) : IsPrePasses(IsPrePasses) {}
 
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index fa067a50c01ca..c0699f3b7ab96 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -30,15 +30,11 @@ using namespace llvm;
 #define DEBUG_TYPE "func-properties-stats"
 
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  STATISTIC(Num##Name##PreOptimizations,                                       \
-            Description " (before optimizations)");                            \
-  STATISTIC(Num##Name, Description " (after "                                  \
-                                   "optimizations)");
+  STATISTIC(Num##Name##PrePasses, Description " (before passes)");             \
+  STATISTIC(Num##Name, Description);
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  STATISTIC(Num##Name##PreOptimizations,                                       \
-            Description " (before optimizations)");                            \
-  STATISTIC(Num##Name, Description " (after "                                  \
-                                   "optimizations)");
+  STATISTIC(Num##Name##PrePasses, Description " (before passes)");             \
+  STATISTIC(Num##Name, Description);
 #include "llvm/IR/FunctionProperties.def"
 
 namespace llvm {
@@ -385,11 +381,11 @@ FunctionPropertiesStatisticsPass::run(Function &F,
   LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
                     << "\n");
   auto &AnalysisResults = FAM.getResult<FunctionPropertiesAnalysis>(F);
-  if (IsPreOptimizations) {
+  if (IsPrePasses) {
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  Num##Name##PreOptimizations += AnalysisResults.Name;
+  Num##Name##PrePasses += AnalysisResults.Name;
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  Num##Name##PreOptimizations += AnalysisResults.Name;
+  Num##Name##PrePasses += AnalysisResults.Name;
 #include "llvm/IR/FunctionProperties.def"
 #undef FUNCTION_PROPERTY
 #undef DETAILED_FUNCTION_PROPERTY
diff --git a/llvm/lib/Analysis/InstCount.cpp b/llvm/lib/Analysis/InstCount.cpp
index e504ea1866e24..08756262e93cf 100644
--- a/llvm/lib/Analysis/InstCount.cpp
+++ b/llvm/lib/Analysis/InstCount.cpp
@@ -21,50 +21,45 @@ using namespace llvm;
 
 #define DEBUG_TYPE "instcount"
 
-STATISTIC(TotalInstsPreOptimizations,
-          "Number of instructions of all types (before optimizations)");
-STATISTIC(TotalInsts,
-          "Number of instructions of all types (after optimizations)");
-STATISTIC(TotalBlocksPreOptimizations,
-          "Number of basic blocks (before optimizations)");
-STATISTIC(TotalBlocks, "Number of basic blocks (after optimizations)");
-STATISTIC(TotalFuncsPreOptimizations,
-          "Number of non-external functions (before optimizations)");
-STATISTIC(TotalFuncs, "Number of non-external functions (after optimizations)");
-STATISTIC(LargestFunctionSizePreOptimizations,
+STATISTIC(TotalInstsPrePasses,
+          "Number of instructions of all types (before passes)");
+STATISTIC(TotalInsts, "Number of instructions of all types");
+STATISTIC(TotalBlocksPrePasses, "Number of basic blocks (before passes)");
+STATISTIC(TotalBlocks, "Number of basic blocks");
+STATISTIC(TotalFuncsPrePasses,
+          "Number of non-external functions (before passes)");
+STATISTIC(TotalFuncs, "Number of non-external functions");
+STATISTIC(LargestFunctionSizePrePasses,
           "Largest number of instructions in a single function (before "
-          "optimizations)");
+          "passes)");
 STATISTIC(LargestFunctionSize,
-          "Largest number of instructions in a single function (after "
-          "optimizations)");
-STATISTIC(LargestFunctionBBCountPreOptimizations,
+          "Largest number of instructions in a single function");
+STATISTIC(LargestFunctionBBCountPrePasses,
           "Largest number of basic blocks in a single function (before "
-          "optimizations)");
+          "passes)");
 STATISTIC(LargestFunctionBBCount,
-          "Largest number of basic blocks in a single function (after "
-          "optimizations)");
+          "Largest number of basic blocks in a single function");
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
-  STATISTIC(Num##OPCODE##InstPreOptimizations,                                 \
-            "Number of " #OPCODE " insts (before optimizations)");             \
-  STATISTIC(Num##OPCODE##Inst,                                                 \
-            "Number of " #OPCODE " insts (after optimizations)");
+  STATISTIC(Num##OPCODE##InstPrePasses,                                        \
+            "Number of " #OPCODE " insts (before passes)");                    \
+  STATISTIC(Num##OPCODE##Inst, "Number of " #OPCODE " insts");
 
 #include "llvm/IR/Instruction.def"
 
 namespace {
 class InstCount : public InstVisitor<InstCount> {
   friend class InstVisitor<InstCount>;
-  bool IsPreOptimizations;
+  bool IsPrePasses;
 
 public:
-  InstCount(bool IsPreOptimizations) : IsPreOptimizations(IsPreOptimizations) {}
+  InstCount(bool IsPrePasses) : IsPrePasses(IsPrePasses) {}
 
   void visitFunction(Function &F) {
-    if (IsPreOptimizations) {
-      ++TotalFuncsPreOptimizations;
-      LargestFunctionSizePreOptimizations.updateMax(F.getInstructionCount());
-      LargestFunctionBBCountPreOptimizations.updateMax(F.size());
+    if (IsPrePasses) {
+      ++TotalFuncsPrePasses;
+      LargestFunctionSizePrePasses.updateMax(F.getInstructionCount());
+      LargestFunctionBBCountPrePasses.updateMax(F.size());
     } else {
       ++TotalFuncs;
       LargestFunctionSize.updateMax(F.getInstructionCount());
@@ -73,17 +68,17 @@ class InstCount : public InstVisitor<InstCount> {
   }
 
   void visitBasicBlock(BasicBlock &BB) {
-    if (IsPreOptimizations)
-      ++TotalBlocksPreOptimizations;
+    if (IsPrePasses)
+      ++TotalBlocksPrePasses;
     else
       ++TotalBlocks;
   }
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
   void visit##OPCODE(CLASS &) {                                                \
-    if (IsPreOptimizations) {                                                  \
-      ++Num##OPCODE##InstPreOptimizations;                                     \
-      ++TotalInstsPreOptimizations;                                            \
+    if (IsPrePasses) {                                                         \
+      ++Num##OPCODE##InstPrePasses;                                            \
+      ++TotalInstsPrePasses;                                                   \
     } else {                                                                   \
       ++Num##OPCODE##Inst;                                                     \
       ++TotalInsts;                                                            \
@@ -103,7 +98,7 @@ PreservedAnalyses InstCountPass::run(Function &F,
                                      FunctionAnalysisManager &FAM) {
   LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
                     << "\n");
-  InstCount(this->IsPreOptimizations).visit(F);
+  InstCount(this->IsPrePasses).visit(F);
 
   return PreservedAnalyses::all();
 }
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f63348df76626..1fcb847536e81 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -808,13 +808,14 @@ Expected<bool> parseLintOptions(StringRef Params) {
 
 /// Parser of parameters for FunctionPropertiesStatistics pass.
 Expected<bool> parseFunctionPropertiesStatisticsOptions(StringRef Params) {
-  return PassBuilder::parseSinglePassOption(Params, "pre-opt",
+  return PassBuilder::parseSinglePassOption(Params, "pre-passes",
                                             "FunctionPropertiesStatisticsPass");
 }
 
 /// Parser of parameters for InstCount pass.
 Expected<bool> parseInstCountOptions(StringRef Params) {
-  return PassBuilder::parseSinglePassOption(Params, "pre-opt", "InstCountPass");
+  return PassBuilder::parseSinglePassOption(Params, "pre-passes",
+                                            "InstCountPass");
 }
 
 /// Parser of parameters for LoopUnroll pass.
@@ -2646,9 +2647,8 @@ Error PassBuilder::parsePassPipeline(ModulePassManager &MPM,
                                  std::move(*Pipeline)}}}};
     } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
                               UseMemorySSA)) {
-      Pipeline = {
-          {"function",
-           {{UseMemorySSA ? "loop-mssa" : "loop", std::move(*Pipeline)}}}};
+      Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
+                                 std::move(*Pipeline)}}}};
     } else if (isMachineFunctionPassName(
                    FirstName, MachineFunctionPipelineParsingCallbacks)) {
       Pipeline = {{"function", {{"machine-function", std::move(*Pipeline)}}}};
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 0a09b8cd869a0..45e3cb705a3f1 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -416,16 +416,12 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
     C(MPM, Level, Phase);
 }
 
-// Count the stats for InstCount and FunctionPropertiesAnalysis. This is used in
-// both the pre-optimization and post-optimization pipelines for comparison
-// purposes.
-static void instructionCountersPass(ModulePassManager &MPM,
-                                    bool IsPreOptimizations) {
+// Get IR stats with InstCount and FunctionPropertiesAnalysis.
+static void instructionCountersPass(ModulePassManager &MPM, bool IsPrePasses) {
   if (AreStatisticsEnabled()) {
-    MPM.addPass(
-        createModuleToFunctionPassAdaptor(InstCountPass(IsPreOptimizations)));
+    MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass(IsPrePasses)));
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsPreOptimizations)));
+        FunctionPropertiesStatisticsPass(IsPrePasses)));
   }
 }
 // Helper to add AnnotationRemarksPass.
@@ -1725,7 +1721,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     return buildO0DefaultPipeline(Level, Phase);
 
   ModulePassManager MPM;
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
+  instructionCountersPass(MPM, /*IsPrePasses=*/true);
 
   // Currently this pipeline is only invoked in an LTO pre link pass or when we
   // are not running LTO. If that changes the below checks may need updating.
@@ -1765,7 +1761,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
   if (isLTOPreLink(Phase))
     addRequiredLTOPreLinkPasses(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+  instructionCountersPass(MPM, /*IsPrePasses=*/false);
 
   return MPM;
 }
@@ -1775,7 +1771,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
                                         bool EmitSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
+  instructionCountersPass(MPM, /*IsPrePasses=*/true);
 
   if (ThinLTO)
     MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
@@ -1820,7 +1816,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
     addAnnotationRemarksPass(MPM);
   }
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+  instructionCountersPass(MPM, /*IsPrePasses=*/false);
 
   return MPM;
 }
@@ -1832,7 +1828,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
+  instructionCountersPass(MPM, /*IsPrePasses=*/true);
 
   // Convert @llvm.global.annotations to !annotation metadata.
   MPM.addPass(Annotation2MetadataPass());
@@ -1886,7 +1882,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   addRequiredLTOPreLinkPasses(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+  instructionCountersPass(MPM, /*IsPrePasses=*/false);
 
   return MPM;
 }
@@ -1895,7 +1891,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
+  instructionCountersPass(MPM, /*IsPrePasses=*/true);
 
   // If we are invoking this without a summary index noting that we are linking
   // with a library containing the necessary APIs, remove any MemProf related
@@ -1946,7 +1942,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     MPM.addPass(EliminateAvailableExternallyPass());
     MPM.addPass(GlobalDCEPass());
 
-    instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+    instructionCountersPass(MPM, /*IsPrePasses=*/false);
     return MPM;
   }
   if (!UseCtxProfile.empty()) {
@@ -1964,7 +1960,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+  instructionCountersPass(MPM, /*IsPrePasses=*/false);
 
   return MPM;
 }
@@ -1981,7 +1977,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                      ModuleSummaryIndex *ExportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
+  instructionCountersPass(MPM, /*IsPrePasses=*/true);
 
   invokeFullLinkTimeOptimizationEarlyEPCallbacks(MPM, Level);
 
@@ -2345,7 +2341,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+  instructionCountersPass(MPM, /*IsPrePasses=*/false);
 
   return MPM;
 }
@@ -2358,7 +2354,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/true);
+  instructionCountersPass(MPM, /*IsPrePasses=*/true);
 
   // Perform pseudo probe instrumentation in O0 mode. This is for the
   // consistency between different build modes. For example, a LTO build can be
@@ -2473,7 +2469,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOptimizations=*/false);
+  instructionCountersPass(MPM, /*IsPrePasses=*/false);
 
   return MPM;
 }
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-prepasses.ll
similarity index 75%
rename from llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
rename to llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-prepasses.ll
index ca07c5134214f..469fb1024a6db 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-preopt.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-prepasses.ll
@@ -1,27 +1,27 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats<pre-opt>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats<pre-passes>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats' < %s 2>&1 | FileCheck %s --check-prefixes=POSTNOOPT
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POSTNOOPT
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 
-; --- <pre-opt> ---
-; PRE-DAG: 4 func-properties-stats - Number of basic blocks (before optimizations)
-; PRE-DAG: 5 func-properties-stats - Number of instructions (of all types) (before optimizations)
-; PRE-DAG: 4 func-properties-stats - Number of basic block successors (before optimizations)
+; --- <pre-passes> ---
+; PRE-DAG: 4 func-properties-stats - Number of basic blocks (before passes)
+; PRE-DAG: 5 func-properties-stats - Number of instructions (of all types) (before passes)
+; PRE-DAG: 4 func-properties-stats - Number of basic block successors (before passes)
 
-; --- No <pre-opt> in pass but no optimizations ---
-; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic blocks (after optimizations)
-; POSTNOOPT-DAG: 5 func-properties-stats - Number of instructions (of all types) (after optimizations)
-; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic block successors (after optimizations)
+; --- No <pre-passes> in pass but no optimization passes run ---
+; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic blocks
+; POSTNOOPT-DAG: 5 func-properties-stats - Number of instructions (of all types)
+; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic block successors
 
 ; --- Post optimization values ---
-; POST-DAG: 1 func-properties-stats - Number of basic blocks (after optimizations)
-; POST-DAG: 1 func-properties-stats - Number of instructions (of all types) (after optimizations)
-; POST-NOT: func-properties-stats - Number of basic block successors (after optimizations)
+; POST-DAG: 1 func-properties-stats - Number of basic blocks
+; POST-DAG: 1 func-properties-stats - Number of instructions (of all types)
+; POST-NOT: func-properties-stats - Number of basic block successors
 
-define i32 @test_cfg() {
+define i32 @test_count() {
 entry:
   ; This branch is trivially resolvable
   br i1 true, label %then, label %else
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
index 0299c32bf6da6..8560b9103f3c0 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
@@ -6,15 +6,15 @@
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 func-properties-stats - Number of basic blocks (after optimizations)
-; CHECK-DAG: 8 func-properties-stats - Number of branch instructions (after optimizations)
-; CHECK-DAG: 10 func-properties-stats - Number of branch successors (after optimizations)
-; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions (after optimizations)
-; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions (after optimizations)
-; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types) (after optimizations)
-; CHECK-DAG: 14 func-properties-stats - Number of basic block successors (after optimizations)
-; CHECK-DAG: 1 func-properties-stats - Number of switch instructions (after optimizations)
-; CHECK-DAG: 4 func-properties-stats - Number of switch successors (after optimizations)
+; CHECK-DAG: 10 func-properties-stats - Number of basic blocks
+; CHECK-DAG: 8 func-properties-stats - Number of branch instructions
+; CHECK-DAG: 10 func-properties-stats - Number of branch successors
+; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions
+; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions
+; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types)
+; CHECK-DAG: 14 func-properties-stats - Number of basic block successors
+; CHECK-DAG: 1 func-properties-stats - Number of switch instructions
+; CHECK-DAG: 4 func-properties-stats - Number of switch successors
 
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
diff --git a/llvm/test/Analysis/InstCount/instcount-preopt.ll b/llvm/test/Analysis/InstCount/instcount-prepasses.ll
similarity index 53%
rename from llvm/test/Analysis/InstCount/instcount-preopt.ll
rename to llvm/test/Analysis/InstCount/instcount-prepasses.ll
index 4db29a34e283e..bdc2c7e8177af 100644
--- a/llvm/test/Analysis/InstCount/instcount-preopt.ll
+++ b/llvm/test/Analysis/InstCount/instcount-prepasses.ll
@@ -1,27 +1,27 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -disable-output -passes='instcount<pre-opt>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
+; RUN: opt -stats -disable-output -passes='instcount<pre-passes>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
 ; RUN: opt -stats -disable-output -passes='instcount' < %s 2>&1 | FileCheck %s --check-prefixes=POSTNOOPT
 ; RUN: opt -stats -disable-output -O0 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POSTNOOPT
 ; RUN: opt -stats -disable-output -O3 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 
-; --- <pre-opt> ---
-; PRE-DAG: 4 instcount - Number of basic blocks (before optimizations)
-; PRE-DAG: 5 instcount - Number of instructions of all types (before optimizations)
-; PRE-DAG: 1 instcount - Number of CondBr insts (before optimizations)
+; --- <pre-passes> ---
+; PRE-DAG: 4 instcount - Number of basic blocks (before passes)
+; PRE-DAG: 5 instcount - Number of instructions of all types (before passes)
+; PRE-DAG: 1 instcount - Number of CondBr insts (before passes)
 
-; --- No <pre-opt> in pass but no optimizations ---
-; POSTNOOPT-DAG: 4 instcount - Number of basic blocks (after optimizations)
-; POSTNOOPT-DAG: 5 instcount - Number of instructions of all types (after optimizations)
-; POSTNOOPT-DAG: 1 instcount - Number of CondBr insts (after optimizations)
+; --- No <pre-passes> in pass but no optimization passes run ---
+; POSTNOOPT-DAG: 4 instcount - Number of basic blocks
+; POSTNOOPT-DAG: 5 instcount - Number of instructions of all types
+; POSTNOOPT-DAG: 1 instcount - Number of CondBr insts
 
 ; --- Post optimization values ---
-; POST-DAG: 1 instcount - Number of basic blocks (after optimizations)
-; POST-DAG: 1 instcount - Number of instructions of all types (after optimizations)
-; POST-NOT: instcount - Number of CondBr insts (after optimizations)
+; POST-DAG: 1 instcount - Number of basic blocks
+; POST-DAG: 1 instcount - Number of instructions of all types
+; POST-NOT: instcount - Number of CondBr insts
 
-define i32 @test_cfg() {
+define i32 @test_count() {
 entry:
   ; This branch is trivially resolvable
   br i1 true, label %then, label %else
diff --git a/llvm/test/Analysis/InstCount/instcount.ll b/llvm/test/Analysis/InstCount/instcount.ll
index 58de202999ebb..663c62dbb4668 100644
--- a/llvm/test/Analysis/InstCount/instcount.ll
+++ b/llvm/test/Analysis/InstCount/instcount.ll
@@ -6,17 +6,17 @@
 ; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
 ; RUN: opt -stats -O0 -disable-output < %s 2>&1 | FileCheck %s
 
-; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function (after optimizations)
-; CHECK-DAG: 18 instcount - Largest number of instructions in a single function (after optimizations)
-; CHECK-DAG: 6 instcount - Number of UncondBr insts (after optimizations)
-; CHECK-DAG: 2 instcount - Number of CondBr insts (after optimizations)
-; CHECK-DAG: 6 instcount - Number of Call insts (after optimizations)
-; CHECK-DAG: 2 instcount - Number of ICmp insts (after optimizations)
-; CHECK-DAG: 2 instcount - Number of Ret insts (after optimizations)
-; CHECK-DAG: 1 instcount - Number of Switch insts (after optimizations)
-; CHECK-DAG: 11 instcount - Number of basic blocks (after optimizations)
-; CHECK-DAG: 2 instcount - Number of non-external functions (after optimizations)
-; CHECK-DAG: 19 instcount - Number of instructions of all types (after optimizations)
+; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function
+; CHECK-DAG: 18 instcount - Largest number of instructions in a single function
+; CHECK-DAG: 6 instcount - Number of UncondBr insts
+; CHECK-DAG: 2 instcount - Number of CondBr insts
+; CHECK-DAG: 6 instcount - Number of Call insts
+; CHECK-DAG: 2 instcount - Number of ICmp insts
+; CHECK-DAG: 2 instcount - Number of Ret insts
+; CHECK-DAG: 1 instcount - Number of Switch insts
+; CHECK-DAG: 11 instcount - Number of basic blocks
+; CHECK-DAG: 2 instcount - Number of non-external functions
+; CHECK-DAG: 19 instcount - Number of instructions of all types
 
 define void @foo(i32 %i, i32 %j, i32 %n) {
 entry:

>From 30c157a8151b8184c517dc4435d5daff375a26cf Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Fri, 10 Apr 2026 20:41:47 +0000
Subject: [PATCH 8/9] Renaming to optimization and test modification

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  6 +--
 llvm/include/llvm/Analysis/InstCount.h        |  5 +-
 .../Analysis/FunctionPropertiesAnalysis.cpp   | 10 ++--
 llvm/lib/Analysis/InstCount.cpp               | 46 +++++++++----------
 llvm/lib/Passes/PassBuilder.cpp               |  5 +-
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 32 ++++++-------
 ...sis.ll => function-properties-analysis.ll} |  6 ---
 ...ties-analysis-prepasses.ll => pipeline.ll} | 15 +++---
 llvm/test/Analysis/InstCount/instcount.ll     |  5 --
 .../{instcount-prepasses.ll => pipeline.ll}   | 15 +++---
 10 files changed, 69 insertions(+), 76 deletions(-)
 rename llvm/test/Analysis/FunctionPropertiesAnalysis/{func-properties-analysis.ll => function-properties-analysis.ll} (74%)
 rename llvm/test/Analysis/FunctionPropertiesAnalysis/{func-properties-analysis-prepasses.ll => pipeline.ll} (70%)
 rename llvm/test/Analysis/InstCount/{instcount-prepasses.ll => pipeline.ll} (63%)

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index 4f68cb869ccd1..5189583b5e93e 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -187,11 +187,11 @@ class FunctionPropertiesPrinterPass
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 class FunctionPropertiesStatisticsPass
     : public PassInfoMixin<FunctionPropertiesStatisticsPass> {
-  bool IsPrePasses;
+  bool IsPreOpt;
 
 public:
-  explicit FunctionPropertiesStatisticsPass(bool IsPrePasses = false)
-      : IsPrePasses(IsPrePasses) {}
+  explicit FunctionPropertiesStatisticsPass(bool IsPreOpt = false)
+      : IsPreOpt(IsPreOpt) {}
 
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
diff --git a/llvm/include/llvm/Analysis/InstCount.h b/llvm/include/llvm/Analysis/InstCount.h
index a12a4183edd19..a7c27e6f12eb4 100644
--- a/llvm/include/llvm/Analysis/InstCount.h
+++ b/llvm/include/llvm/Analysis/InstCount.h
@@ -19,12 +19,11 @@ namespace llvm {
 
 class Function;
 
-/// Statistics pass for the FunctionPropertiesAnalysis results.
 class InstCountPass : public PassInfoMixin<InstCountPass> {
-  bool IsPrePasses;
+  bool IsPreOpt;
 
 public:
-  explicit InstCountPass(bool IsPrePasses = false) : IsPrePasses(IsPrePasses) {}
+  explicit InstCountPass(bool IsPreOpt = false) : IsPreOpt(IsPreOpt) {}
 
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index c0699f3b7ab96..8a9aeb38b05a2 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -30,10 +30,10 @@ using namespace llvm;
 #define DEBUG_TYPE "func-properties-stats"
 
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  STATISTIC(Num##Name##PrePasses, Description " (before passes)");             \
+  STATISTIC(Num##Name##PreOpt, Description " (before optimizations)");         \
   STATISTIC(Num##Name, Description);
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  STATISTIC(Num##Name##PrePasses, Description " (before passes)");             \
+  STATISTIC(Num##Name##PreOpt, Description " (before optimizations)");         \
   STATISTIC(Num##Name, Description);
 #include "llvm/IR/FunctionProperties.def"
 
@@ -381,11 +381,11 @@ FunctionPropertiesStatisticsPass::run(Function &F,
   LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
                     << "\n");
   auto &AnalysisResults = FAM.getResult<FunctionPropertiesAnalysis>(F);
-  if (IsPrePasses) {
+  if (IsPreOpt) {
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  Num##Name##PrePasses += AnalysisResults.Name;
+  Num##Name##PreOpt += AnalysisResults.Name;
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  Num##Name##PrePasses += AnalysisResults.Name;
+  Num##Name##PreOpt += AnalysisResults.Name;
 #include "llvm/IR/FunctionProperties.def"
 #undef FUNCTION_PROPERTY
 #undef DETAILED_FUNCTION_PROPERTY
diff --git a/llvm/lib/Analysis/InstCount.cpp b/llvm/lib/Analysis/InstCount.cpp
index 08756262e93cf..2c85dacbcd04e 100644
--- a/llvm/lib/Analysis/InstCount.cpp
+++ b/llvm/lib/Analysis/InstCount.cpp
@@ -21,28 +21,28 @@ using namespace llvm;
 
 #define DEBUG_TYPE "instcount"
 
-STATISTIC(TotalInstsPrePasses,
-          "Number of instructions of all types (before passes)");
+STATISTIC(TotalInstsPreOpt,
+          "Number of instructions of all types (before optimizations)");
 STATISTIC(TotalInsts, "Number of instructions of all types");
-STATISTIC(TotalBlocksPrePasses, "Number of basic blocks (before passes)");
+STATISTIC(TotalBlocksPreOpt, "Number of basic blocks (before optimizations)");
 STATISTIC(TotalBlocks, "Number of basic blocks");
-STATISTIC(TotalFuncsPrePasses,
-          "Number of non-external functions (before passes)");
+STATISTIC(TotalFuncsPreOpt,
+          "Number of non-external functions (before optimizations)");
 STATISTIC(TotalFuncs, "Number of non-external functions");
-STATISTIC(LargestFunctionSizePrePasses,
+STATISTIC(LargestFunctionSizePreOpt,
           "Largest number of instructions in a single function (before "
-          "passes)");
+          "optimizations)");
 STATISTIC(LargestFunctionSize,
           "Largest number of instructions in a single function");
-STATISTIC(LargestFunctionBBCountPrePasses,
+STATISTIC(LargestFunctionBBCountPreOpt,
           "Largest number of basic blocks in a single function (before "
-          "passes)");
+          "optimizations)");
 STATISTIC(LargestFunctionBBCount,
           "Largest number of basic blocks in a single function");
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
-  STATISTIC(Num##OPCODE##InstPrePasses,                                        \
-            "Number of " #OPCODE " insts (before passes)");                    \
+  STATISTIC(Num##OPCODE##InstPreOpt,                                           \
+            "Number of " #OPCODE " insts (before optimizations)");             \
   STATISTIC(Num##OPCODE##Inst, "Number of " #OPCODE " insts");
 
 #include "llvm/IR/Instruction.def"
@@ -50,16 +50,16 @@ STATISTIC(LargestFunctionBBCount,
 namespace {
 class InstCount : public InstVisitor<InstCount> {
   friend class InstVisitor<InstCount>;
-  bool IsPrePasses;
+  bool IsPreOpt;
 
 public:
-  InstCount(bool IsPrePasses) : IsPrePasses(IsPrePasses) {}
+  InstCount(bool IsPreOpt) : IsPreOpt(IsPreOpt) {}
 
   void visitFunction(Function &F) {
-    if (IsPrePasses) {
-      ++TotalFuncsPrePasses;
-      LargestFunctionSizePrePasses.updateMax(F.getInstructionCount());
-      LargestFunctionBBCountPrePasses.updateMax(F.size());
+    if (IsPreOpt) {
+      ++TotalFuncsPreOpt;
+      LargestFunctionSizePreOpt.updateMax(F.getInstructionCount());
+      LargestFunctionBBCountPreOpt.updateMax(F.size());
     } else {
       ++TotalFuncs;
       LargestFunctionSize.updateMax(F.getInstructionCount());
@@ -68,17 +68,17 @@ class InstCount : public InstVisitor<InstCount> {
   }
 
   void visitBasicBlock(BasicBlock &BB) {
-    if (IsPrePasses)
-      ++TotalBlocksPrePasses;
+    if (IsPreOpt)
+      ++TotalBlocksPreOpt;
     else
       ++TotalBlocks;
   }
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
   void visit##OPCODE(CLASS &) {                                                \
-    if (IsPrePasses) {                                                         \
-      ++Num##OPCODE##InstPrePasses;                                            \
-      ++TotalInstsPrePasses;                                                   \
+    if (IsPreOpt) {                                                            \
+      ++Num##OPCODE##InstPreOpt;                                               \
+      ++TotalInstsPreOpt;                                                      \
     } else {                                                                   \
       ++Num##OPCODE##Inst;                                                     \
       ++TotalInsts;                                                            \
@@ -98,7 +98,7 @@ PreservedAnalyses InstCountPass::run(Function &F,
                                      FunctionAnalysisManager &FAM) {
   LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
                     << "\n");
-  InstCount(this->IsPrePasses).visit(F);
+  InstCount(this->IsPreOpt).visit(F);
 
   return PreservedAnalyses::all();
 }
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 1fcb847536e81..cb624c79cc6ef 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -808,14 +808,13 @@ Expected<bool> parseLintOptions(StringRef Params) {
 
 /// Parser of parameters for FunctionPropertiesStatistics pass.
 Expected<bool> parseFunctionPropertiesStatisticsOptions(StringRef Params) {
-  return PassBuilder::parseSinglePassOption(Params, "pre-passes",
+  return PassBuilder::parseSinglePassOption(Params, "pre-opt",
                                             "FunctionPropertiesStatisticsPass");
 }
 
 /// Parser of parameters for InstCount pass.
 Expected<bool> parseInstCountOptions(StringRef Params) {
-  return PassBuilder::parseSinglePassOption(Params, "pre-passes",
-                                            "InstCountPass");
+  return PassBuilder::parseSinglePassOption(Params, "pre-opt", "InstCountPass");
 }
 
 /// Parser of parameters for LoopUnroll pass.
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 45e3cb705a3f1..2b32ab786346b 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -417,11 +417,11 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 }
 
 // Get IR stats with InstCount and FunctionPropertiesAnalysis.
-static void instructionCountersPass(ModulePassManager &MPM, bool IsPrePasses) {
+static void instructionCountersPass(ModulePassManager &MPM, bool IsPreOpt) {
   if (AreStatisticsEnabled()) {
-    MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass(IsPrePasses)));
+    MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass(IsPreOpt)));
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsPrePasses)));
+        FunctionPropertiesStatisticsPass(IsPreOpt)));
   }
 }
 // Helper to add AnnotationRemarksPass.
@@ -1721,7 +1721,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     return buildO0DefaultPipeline(Level, Phase);
 
   ModulePassManager MPM;
-  instructionCountersPass(MPM, /*IsPrePasses=*/true);
+  instructionCountersPass(MPM, /*IsPreOpt=*/true);
 
   // Currently this pipeline is only invoked in an LTO pre link pass or when we
   // are not running LTO. If that changes the below checks may need updating.
@@ -1761,7 +1761,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
   if (isLTOPreLink(Phase))
     addRequiredLTOPreLinkPasses(MPM);
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/false);
+  instructionCountersPass(MPM, /*IsPreOpt=*/false);
 
   return MPM;
 }
@@ -1771,7 +1771,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
                                         bool EmitSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/true);
+  instructionCountersPass(MPM, /*IsPreOpt=*/true);
 
   if (ThinLTO)
     MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
@@ -1816,7 +1816,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
     addAnnotationRemarksPass(MPM);
   }
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/false);
+  instructionCountersPass(MPM, /*IsPreOpt=*/false);
 
   return MPM;
 }
@@ -1828,7 +1828,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/true);
+  instructionCountersPass(MPM, /*IsPreOpt=*/true);
 
   // Convert @llvm.global.annotations to !annotation metadata.
   MPM.addPass(Annotation2MetadataPass());
@@ -1882,7 +1882,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   addRequiredLTOPreLinkPasses(MPM);
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/false);
+  instructionCountersPass(MPM, /*IsPreOpt=*/false);
 
   return MPM;
 }
@@ -1891,7 +1891,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/true);
+  instructionCountersPass(MPM, /*IsPreOpt=*/true);
 
   // If we are invoking this without a summary index noting that we are linking
   // with a library containing the necessary APIs, remove any MemProf related
@@ -1942,7 +1942,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     MPM.addPass(EliminateAvailableExternallyPass());
     MPM.addPass(GlobalDCEPass());
 
-    instructionCountersPass(MPM, /*IsPrePasses=*/false);
+    instructionCountersPass(MPM, /*IsPreOpt=*/false);
     return MPM;
   }
   if (!UseCtxProfile.empty()) {
@@ -1960,7 +1960,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/false);
+  instructionCountersPass(MPM, /*IsPreOpt=*/false);
 
   return MPM;
 }
@@ -1977,7 +1977,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                      ModuleSummaryIndex *ExportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/true);
+  instructionCountersPass(MPM, /*IsPreOpt=*/true);
 
   invokeFullLinkTimeOptimizationEarlyEPCallbacks(MPM, Level);
 
@@ -2341,7 +2341,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/false);
+  instructionCountersPass(MPM, /*IsPreOpt=*/false);
 
   return MPM;
 }
@@ -2354,7 +2354,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/true);
+  instructionCountersPass(MPM, /*IsPreOpt=*/true);
 
   // Perform pseudo probe instrumentation in O0 mode. This is for the
   // consistency between different build modes. For example, a LTO build can be
@@ -2469,7 +2469,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPrePasses=*/false);
+  instructionCountersPass(MPM, /*IsPreOpt=*/false);
 
   return MPM;
 }
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/function-properties-analysis.ll
similarity index 74%
rename from llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
rename to llvm/test/Analysis/FunctionPropertiesAnalysis/function-properties-analysis.ll
index 8560b9103f3c0..555d73c82b50b 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/function-properties-analysis.ll
@@ -1,10 +1,5 @@
-; Testing with all of the below run lines that the pass gets added to the appropriate pipelines
 ; REQUIRES: asserts
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-stats < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
 
 ; CHECK-DAG: 10 func-properties-stats - Number of basic blocks
 ; CHECK-DAG: 8 func-properties-stats - Number of branch instructions
@@ -16,7 +11,6 @@
 ; CHECK-DAG: 1 func-properties-stats - Number of switch instructions
 ; CHECK-DAG: 4 func-properties-stats - Number of switch successors
 
-
 define void @foo(i32 %i, i32 %j, i32 %n) {
 entry:
   %cmp = icmp slt i32 %i, %j
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-prepasses.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
similarity index 70%
rename from llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-prepasses.ll
rename to llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
index 469fb1024a6db..5ed52f5bf982d 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/func-properties-analysis-prepasses.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
@@ -1,17 +1,20 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats<pre-passes>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats<pre-opt>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='func-properties-stats' < %s 2>&1 | FileCheck %s --check-prefixes=POSTNOOPT
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POSTNOOPT
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto-pre-link<Os>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto-pre-link<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 
-; --- <pre-passes> ---
-; PRE-DAG: 4 func-properties-stats - Number of basic blocks (before passes)
-; PRE-DAG: 5 func-properties-stats - Number of instructions (of all types) (before passes)
-; PRE-DAG: 4 func-properties-stats - Number of basic block successors (before passes)
+; --- <pre-opt> ---
+; PRE-DAG: 4 func-properties-stats - Number of basic blocks (before optimizations)
+; PRE-DAG: 5 func-properties-stats - Number of instructions (of all types) (before optimizations)
+; PRE-DAG: 4 func-properties-stats - Number of basic block successors (before optimizations)
 
-; --- No <pre-passes> in pass but no optimization passes run ---
+; --- No <pre-opt> in pass but no optimization passes run ---
 ; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic blocks
 ; POSTNOOPT-DAG: 5 func-properties-stats - Number of instructions (of all types)
 ; POSTNOOPT-DAG: 4 func-properties-stats - Number of basic block successors
diff --git a/llvm/test/Analysis/InstCount/instcount.ll b/llvm/test/Analysis/InstCount/instcount.ll
index 663c62dbb4668..6c7ba690fdf04 100644
--- a/llvm/test/Analysis/InstCount/instcount.ll
+++ b/llvm/test/Analysis/InstCount/instcount.ll
@@ -1,10 +1,5 @@
 ; REQUIRES: asserts
 ; RUN: opt -stats -passes=instcount -disable-output < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -passes='thinlto<O3>' -disable-output < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -passes='thinlto-pre-link<O2>' -disable-output < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -passes='lto-pre-link<Os>' -disable-output < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -O3 -disable-output < %s 2>&1 | FileCheck %s
-; RUN: opt -stats -O0 -disable-output < %s 2>&1 | FileCheck %s
 
 ; CHECK-DAG: 10 instcount - Largest number of basic blocks in a single function
 ; CHECK-DAG: 18 instcount - Largest number of instructions in a single function
diff --git a/llvm/test/Analysis/InstCount/instcount-prepasses.ll b/llvm/test/Analysis/InstCount/pipeline.ll
similarity index 63%
rename from llvm/test/Analysis/InstCount/instcount-prepasses.ll
rename to llvm/test/Analysis/InstCount/pipeline.ll
index bdc2c7e8177af..bb203cca0a974 100644
--- a/llvm/test/Analysis/InstCount/instcount-prepasses.ll
+++ b/llvm/test/Analysis/InstCount/pipeline.ll
@@ -1,17 +1,20 @@
 ; REQUIRES: asserts
-; RUN: opt -stats -disable-output -passes='instcount<pre-passes>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
+; RUN: opt -stats -disable-output -passes='instcount<pre-opt>' < %s 2>&1 | FileCheck %s --check-prefix=PRE
 ; RUN: opt -stats -disable-output -passes='instcount' < %s 2>&1 | FileCheck %s --check-prefixes=POSTNOOPT
 ; RUN: opt -stats -disable-output -O0 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POSTNOOPT
 ; RUN: opt -stats -disable-output -O3 < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -disable-output -passes='lto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -disable-output -passes='lto-pre-link<Os>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
+; RUN: opt -stats -disable-output -passes='lto-pre-link<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -disable-output -passes='thinlto<O3>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 ; RUN: opt -stats -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s --check-prefixes=PRE,POST
 
-; --- <pre-passes> ---
-; PRE-DAG: 4 instcount - Number of basic blocks (before passes)
-; PRE-DAG: 5 instcount - Number of instructions of all types (before passes)
-; PRE-DAG: 1 instcount - Number of CondBr insts (before passes)
+; --- <pre-opt> ---
+; PRE-DAG: 4 instcount - Number of basic blocks (before optimizations)
+; PRE-DAG: 5 instcount - Number of instructions of all types (before optimizations)
+; PRE-DAG: 1 instcount - Number of CondBr insts (before optimizations)
 
-; --- No <pre-passes> in pass but no optimization passes run ---
+; --- No <pre-opt> in pass but no optimization passes run ---
 ; POSTNOOPT-DAG: 4 instcount - Number of basic blocks
 ; POSTNOOPT-DAG: 5 instcount - Number of instructions of all types
 ; POSTNOOPT-DAG: 1 instcount - Number of CondBr insts

>From 122c1037a8aa6557b3ec673d664951206a2d4123 Mon Sep 17 00:00:00 2001
From: Inaki Arrechea <inakiarrechea at google.com>
Date: Sat, 11 Apr 2026 01:05:03 +0000
Subject: [PATCH 9/9] Opt to Optimization

---
 .../Analysis/FunctionPropertiesAnalysis.h     |  6 +--
 llvm/include/llvm/Analysis/InstCount.h        |  5 ++-
 .../Analysis/FunctionPropertiesAnalysis.cpp   | 12 +++---
 llvm/lib/Analysis/InstCount.cpp               | 37 ++++++++++---------
 llvm/lib/Passes/PassBuilderPipelines.cpp      | 34 +++++++++--------
 5 files changed, 50 insertions(+), 44 deletions(-)

diff --git a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
index 5189583b5e93e..aa3e20c914ab7 100644
--- a/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
+++ b/llvm/include/llvm/Analysis/FunctionPropertiesAnalysis.h
@@ -187,11 +187,11 @@ class FunctionPropertiesPrinterPass
 /// Statistics pass for the FunctionPropertiesAnalysis results.
 class FunctionPropertiesStatisticsPass
     : public PassInfoMixin<FunctionPropertiesStatisticsPass> {
-  bool IsPreOpt;
+  bool IsPreOptimization;
 
 public:
-  explicit FunctionPropertiesStatisticsPass(bool IsPreOpt = false)
-      : IsPreOpt(IsPreOpt) {}
+  explicit FunctionPropertiesStatisticsPass(bool IsPreOptimization = false)
+      : IsPreOptimization(IsPreOptimization) {}
 
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
diff --git a/llvm/include/llvm/Analysis/InstCount.h b/llvm/include/llvm/Analysis/InstCount.h
index a7c27e6f12eb4..4a19dbad57513 100644
--- a/llvm/include/llvm/Analysis/InstCount.h
+++ b/llvm/include/llvm/Analysis/InstCount.h
@@ -20,10 +20,11 @@ namespace llvm {
 class Function;
 
 class InstCountPass : public PassInfoMixin<InstCountPass> {
-  bool IsPreOpt;
+  bool IsPreOptimization;
 
 public:
-  explicit InstCountPass(bool IsPreOpt = false) : IsPreOpt(IsPreOpt) {}
+  explicit InstCountPass(bool IsPreOptimization = false)
+      : IsPreOptimization(IsPreOptimization) {}
 
   PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
 };
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index 8a9aeb38b05a2..21eeb05a9041c 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -30,10 +30,12 @@ using namespace llvm;
 #define DEBUG_TYPE "func-properties-stats"
 
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  STATISTIC(Num##Name##PreOpt, Description " (before optimizations)");         \
+  STATISTIC(Num##Name##PreOptimization,                                        \
+            Description " (before optimizations)");                            \
   STATISTIC(Num##Name, Description);
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  STATISTIC(Num##Name##PreOpt, Description " (before optimizations)");         \
+  STATISTIC(Num##Name##PreOptimization,                                        \
+            Description " (before optimizations)");                            \
   STATISTIC(Num##Name, Description);
 #include "llvm/IR/FunctionProperties.def"
 
@@ -381,11 +383,11 @@ FunctionPropertiesStatisticsPass::run(Function &F,
   LLVM_DEBUG(dbgs() << "STATSCOUNT: running on function " << F.getName()
                     << "\n");
   auto &AnalysisResults = FAM.getResult<FunctionPropertiesAnalysis>(F);
-  if (IsPreOpt) {
+  if (IsPreOptimization) {
 #define FUNCTION_PROPERTY(Name, Description)                                   \
-  Num##Name##PreOpt += AnalysisResults.Name;
+  Num##Name##PreOptimization += AnalysisResults.Name;
 #define DETAILED_FUNCTION_PROPERTY(Name, Description)                          \
-  Num##Name##PreOpt += AnalysisResults.Name;
+  Num##Name##PreOptimization += AnalysisResults.Name;
 #include "llvm/IR/FunctionProperties.def"
 #undef FUNCTION_PROPERTY
 #undef DETAILED_FUNCTION_PROPERTY
diff --git a/llvm/lib/Analysis/InstCount.cpp b/llvm/lib/Analysis/InstCount.cpp
index 2c85dacbcd04e..34a200dd879d2 100644
--- a/llvm/lib/Analysis/InstCount.cpp
+++ b/llvm/lib/Analysis/InstCount.cpp
@@ -21,27 +21,28 @@ using namespace llvm;
 
 #define DEBUG_TYPE "instcount"
 
-STATISTIC(TotalInstsPreOpt,
+STATISTIC(TotalInstsPreOptimization,
           "Number of instructions of all types (before optimizations)");
 STATISTIC(TotalInsts, "Number of instructions of all types");
-STATISTIC(TotalBlocksPreOpt, "Number of basic blocks (before optimizations)");
+STATISTIC(TotalBlocksPreOptimization,
+          "Number of basic blocks (before optimizations)");
 STATISTIC(TotalBlocks, "Number of basic blocks");
-STATISTIC(TotalFuncsPreOpt,
+STATISTIC(TotalFuncsPreOptimization,
           "Number of non-external functions (before optimizations)");
 STATISTIC(TotalFuncs, "Number of non-external functions");
-STATISTIC(LargestFunctionSizePreOpt,
+STATISTIC(LargestFunctionSizePreOptimization,
           "Largest number of instructions in a single function (before "
           "optimizations)");
 STATISTIC(LargestFunctionSize,
           "Largest number of instructions in a single function");
-STATISTIC(LargestFunctionBBCountPreOpt,
+STATISTIC(LargestFunctionBBCountPreOptimization,
           "Largest number of basic blocks in a single function (before "
           "optimizations)");
 STATISTIC(LargestFunctionBBCount,
           "Largest number of basic blocks in a single function");
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
-  STATISTIC(Num##OPCODE##InstPreOpt,                                           \
+  STATISTIC(Num##OPCODE##InstPreOptimization,                                  \
             "Number of " #OPCODE " insts (before optimizations)");             \
   STATISTIC(Num##OPCODE##Inst, "Number of " #OPCODE " insts");
 
@@ -50,16 +51,16 @@ STATISTIC(LargestFunctionBBCount,
 namespace {
 class InstCount : public InstVisitor<InstCount> {
   friend class InstVisitor<InstCount>;
-  bool IsPreOpt;
+  bool IsPreOptimization;
 
 public:
-  InstCount(bool IsPreOpt) : IsPreOpt(IsPreOpt) {}
+  InstCount(bool IsPreOptimization) : IsPreOptimization(IsPreOptimization) {}
 
   void visitFunction(Function &F) {
-    if (IsPreOpt) {
-      ++TotalFuncsPreOpt;
-      LargestFunctionSizePreOpt.updateMax(F.getInstructionCount());
-      LargestFunctionBBCountPreOpt.updateMax(F.size());
+    if (IsPreOptimization) {
+      ++TotalFuncsPreOptimization;
+      LargestFunctionSizePreOptimization.updateMax(F.getInstructionCount());
+      LargestFunctionBBCountPreOptimization.updateMax(F.size());
     } else {
       ++TotalFuncs;
       LargestFunctionSize.updateMax(F.getInstructionCount());
@@ -68,17 +69,17 @@ class InstCount : public InstVisitor<InstCount> {
   }
 
   void visitBasicBlock(BasicBlock &BB) {
-    if (IsPreOpt)
-      ++TotalBlocksPreOpt;
+    if (IsPreOptimization)
+      ++TotalBlocksPreOptimization;
     else
       ++TotalBlocks;
   }
 
 #define HANDLE_INST(N, OPCODE, CLASS)                                          \
   void visit##OPCODE(CLASS &) {                                                \
-    if (IsPreOpt) {                                                            \
-      ++Num##OPCODE##InstPreOpt;                                               \
-      ++TotalInstsPreOpt;                                                      \
+    if (IsPreOptimization) {                                                   \
+      ++Num##OPCODE##InstPreOptimization;                                      \
+      ++TotalInstsPreOptimization;                                             \
     } else {                                                                   \
       ++Num##OPCODE##Inst;                                                     \
       ++TotalInsts;                                                            \
@@ -98,7 +99,7 @@ PreservedAnalyses InstCountPass::run(Function &F,
                                      FunctionAnalysisManager &FAM) {
   LLVM_DEBUG(dbgs() << "INSTCOUNT: running on function " << F.getName()
                     << "\n");
-  InstCount(this->IsPreOpt).visit(F);
+  InstCount(this->IsPreOptimization).visit(F);
 
   return PreservedAnalyses::all();
 }
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 2b32ab786346b..e5a3cf386c07b 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -417,11 +417,13 @@ void PassBuilder::invokePipelineEarlySimplificationEPCallbacks(
 }
 
 // Get IR stats with InstCount and FunctionPropertiesAnalysis.
-static void instructionCountersPass(ModulePassManager &MPM, bool IsPreOpt) {
+static void instructionCountersPass(ModulePassManager &MPM,
+                                    bool IsPreOptimization) {
   if (AreStatisticsEnabled()) {
-    MPM.addPass(createModuleToFunctionPassAdaptor(InstCountPass(IsPreOpt)));
+    MPM.addPass(
+        createModuleToFunctionPassAdaptor(InstCountPass(IsPreOptimization)));
     MPM.addPass(createModuleToFunctionPassAdaptor(
-        FunctionPropertiesStatisticsPass(IsPreOpt)));
+        FunctionPropertiesStatisticsPass(IsPreOptimization)));
   }
 }
 // Helper to add AnnotationRemarksPass.
@@ -1721,7 +1723,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
     return buildO0DefaultPipeline(Level, Phase);
 
   ModulePassManager MPM;
-  instructionCountersPass(MPM, /*IsPreOpt=*/true);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/true);
 
   // Currently this pipeline is only invoked in an LTO pre link pass or when we
   // are not running LTO. If that changes the below checks may need updating.
@@ -1761,7 +1763,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
   if (isLTOPreLink(Phase))
     addRequiredLTOPreLinkPasses(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/false);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/false);
 
   return MPM;
 }
@@ -1771,7 +1773,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
                                         bool EmitSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/true);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/true);
 
   if (ThinLTO)
     MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level));
@@ -1816,7 +1818,7 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
     addAnnotationRemarksPass(MPM);
   }
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/false);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/false);
 
   return MPM;
 }
@@ -1828,7 +1830,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/true);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/true);
 
   // Convert @llvm.global.annotations to !annotation metadata.
   MPM.addPass(Annotation2MetadataPass());
@@ -1882,7 +1884,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
 
   addRequiredLTOPreLinkPasses(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/false);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/false);
 
   return MPM;
 }
@@ -1891,7 +1893,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/true);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/true);
 
   // If we are invoking this without a summary index noting that we are linking
   // with a library containing the necessary APIs, remove any MemProf related
@@ -1942,7 +1944,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
     MPM.addPass(EliminateAvailableExternallyPass());
     MPM.addPass(GlobalDCEPass());
 
-    instructionCountersPass(MPM, /*IsPreOpt=*/false);
+    instructionCountersPass(MPM, /*IsPreOptimization=*/false);
     return MPM;
   }
   if (!UseCtxProfile.empty()) {
@@ -1960,7 +1962,7 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/false);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/false);
 
   return MPM;
 }
@@ -1977,7 +1979,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                      ModuleSummaryIndex *ExportSummary) {
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/true);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/true);
 
   invokeFullLinkTimeOptimizationEarlyEPCallbacks(MPM, Level);
 
@@ -2341,7 +2343,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/false);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/false);
 
   return MPM;
 }
@@ -2354,7 +2356,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
 
   ModulePassManager MPM;
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/true);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/true);
 
   // Perform pseudo probe instrumentation in O0 mode. This is for the
   // consistency between different build modes. For example, a LTO build can be
@@ -2469,7 +2471,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
   // Emit annotation remarks.
   addAnnotationRemarksPass(MPM);
 
-  instructionCountersPass(MPM, /*IsPreOpt=*/false);
+  instructionCountersPass(MPM, /*IsPreOptimization=*/false);
 
   return MPM;
 }



More information about the llvm-commits mailing list