Skip to content

[Passes] Remove Os and Oz optimization pipelines#191363

Merged
nikic merged 1 commit into
llvm:mainfrom
nikic:remove-pipeline-optsize
Apr 22, 2026
Merged

[Passes] Remove Os and Oz optimization pipelines#191363
nikic merged 1 commit into
llvm:mainfrom
nikic:remove-pipeline-optsize

Conversation

@nikic

@nikic nikic commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

These should use O2 with the optsize or minsize attributes instead.

This enforces that there is no divergence between pipeline-level Os/Oz and function-level Os/Oz at an architectural level.

For the purpose of testing IR that does not have optsize/minsize itself, it's possible to use -force-attribute=optsize etc.

@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 201466 tests passed
  • 6388 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 139527 tests passed
  • 4707 tests skipped

✅ The build succeeded and all tests passed.

@nikic
nikic force-pushed the remove-pipeline-optsize branch from f8e1a8e to f24f3c7 Compare April 21, 2026 15:10
@nikic
nikic marked this pull request as ready for review April 21, 2026 15:14
@llvmbot llvmbot added backend:Hexagon clang:codegen IR generation bugs: mangling, exceptions, etc. mlir mlgo mlir:execution-engine llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Apr 21, 2026
@llvmbot

llvmbot commented Apr 21, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-transforms

Author: Nikita Popov (nikic)

Changes

These should use O2 with the optsize or minsize attributes instead.

This enforces that there is divergence between pipeline-level Os/Oz and function-level Os/Oz at an architectural level.

For the purpose of testing IR that does not have optsize/minsize itself, it's possible to use -force-attribute=optsize etc.


Patch is 122.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/191363.diff

38 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-13)
  • (modified) llvm/include/llvm/Passes/OptimizationLevel.h (+5-34)
  • (modified) llvm/lib/Passes/OptimizationLevel.cpp (+4-18)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (+7-4)
  • (modified) llvm/lib/Passes/PassRegistry.def (+2-1)
  • (modified) llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll (-1)
  • (modified) llvm/test/Analysis/InstCount/pipeline.ll (-1)
  • (modified) llvm/test/CodeGen/Hexagon/glob-align-volatile.ll (+1-1)
  • (modified) llvm/test/Other/function-simplification.ll (+5-7)
  • (modified) llvm/test/Other/new-pm-defaults.ll (+48-54)
  • (modified) llvm/test/Other/new-pm-lto-defaults.ll (+114-120)
  • (modified) llvm/test/Other/new-pm-pgo-preinline.ll (+16-17)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-defaults.ll (+33-39)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll (+29-35)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll (+29-37)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-defaults.ll (+37-49)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll (+29-37)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll (+28-36)
  • (modified) llvm/test/Other/opt-On.ll (-2)
  • (added) llvm/test/Other/opt-Os-Oz.ll (+5)
  • (modified) llvm/test/Other/opt-hot-cold-split.ll (+10-10)
  • (modified) llvm/test/Other/optimize-inrange-gep.ll (-2)
  • (modified) llvm/test/Other/pipeline-callbacks-string-api.ll (+1-1)
  • (modified) llvm/test/Transforms/Inline/always-inline-phase-ordering.ll (+1-1)
  • (modified) llvm/test/Transforms/Inline/devirtualize.ll (+2-2)
  • (modified) llvm/test/Transforms/Inline/inline-optsize.ll (+6-17)
  • (modified) llvm/test/Transforms/Inline/inline-threshold.ll (-2)
  • (removed) llvm/test/Transforms/LoopUnroll/opt-levels.ll (-47)
  • (removed) llvm/test/Transforms/LoopUnrollAndJam/opt-levels.ll (-61)
  • (modified) llvm/test/Transforms/PhaseOrdering/AArch64/Oz-and-forced-vectorize.ll (+1-1)
  • (modified) llvm/test/Transforms/PhaseOrdering/X86/loop-vectorize-metadata.ll (+21-153)
  • (modified) llvm/test/Transforms/PhaseOrdering/always-inline-alloca-promotion.ll (+1-1)
  • (modified) llvm/test/Transforms/PhaseOrdering/cmp-logic.ll (+13-13)
  • (modified) llvm/test/Transforms/PhaseOrdering/enable-loop-header-duplication-oz.ll (+2-2)
  • (modified) llvm/test/Transforms/PhaseOrdering/runtime-check-removal.ll (+3-3)
  • (modified) llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll (-2)
  • (modified) mlir/lib/ExecutionEngine/OptUtils.cpp (+1-10)
  • (modified) polly/test/Support/defaultpipelines.ll (-2)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 3b50c465c1c29..f34c5c007f115 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -629,19 +629,7 @@ static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
     return OptimizationLevel::O1;
 
   case 2:
-    switch (Opts.OptimizeSize) {
-    default:
-      llvm_unreachable("Invalid optimization level for size!");
-
-    case 0:
-      return OptimizationLevel::O2;
-
-    case 1:
-      return OptimizationLevel::Os;
-
-    case 2:
-      return OptimizationLevel::Oz;
-    }
+    return OptimizationLevel::O2;
 
   case 3:
     return OptimizationLevel::O3;
diff --git a/llvm/include/llvm/Passes/OptimizationLevel.h b/llvm/include/llvm/Passes/OptimizationLevel.h
index 1cf258f1ffd0d..c74407beb8598 100644
--- a/llvm/include/llvm/Passes/OptimizationLevel.h
+++ b/llvm/include/llvm/Passes/OptimizationLevel.h
@@ -22,16 +22,10 @@ namespace llvm {
 
 class OptimizationLevel final {
   unsigned SpeedLevel = 2;
-  unsigned SizeLevel = 0;
-  OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel)
-      : SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) {
-    // Check that only valid combinations are passed.
+  OptimizationLevel(unsigned SpeedLevel) : SpeedLevel(SpeedLevel) {
+    // Check that only valid values are passed.
     assert(SpeedLevel <= 3 &&
            "Optimization level for speed should be 0, 1, 2, or 3");
-    assert(SizeLevel <= 2 &&
-           "Optimization level for size should be 0, 1, or 2");
-    assert((SizeLevel == 0 || SpeedLevel == 2) &&
-           "Optimize for size should be encoded with speedup level == 2");
   }
 
 public:
@@ -88,40 +82,17 @@ class OptimizationLevel final {
   /// reasonably. This does not preclude very substantial constant factor
   /// costs though.
   LLVM_ABI static const OptimizationLevel O3;
-  /// Similar to \c O2 but tries to optimize for small code size instead of
-  /// fast execution without triggering significant incremental execution
-  /// time slowdowns.
-  ///
-  /// The logic here is exactly the same as \c O2, but with code size and
-  /// execution time metrics swapped.
-  ///
-  /// A consequence of the different core goal is that this should in general
-  /// produce substantially smaller executables that still run in
-  /// a reasonable amount of time.
-  LLVM_ABI static const OptimizationLevel Os;
-  /// A very specialized mode that will optimize for code size at any and all
-  /// costs.
-  ///
-  /// This is useful primarily when there are absolute size limitations and
-  /// any effort taken to reduce the size is worth it regardless of the
-  /// execution time impact. You should expect this level to produce rather
-  /// slow, but very small, code.
-  LLVM_ABI static const OptimizationLevel Oz;
 
-  bool isOptimizingForSpeed() const { return SizeLevel == 0 && SpeedLevel > 0; }
-
-  bool isOptimizingForSize() const { return SizeLevel > 0; }
+  bool isOptimizingForSpeed() const { return SpeedLevel > 0; }
 
   bool operator==(const OptimizationLevel &Other) const {
-    return SizeLevel == Other.SizeLevel && SpeedLevel == Other.SpeedLevel;
+    return SpeedLevel == Other.SpeedLevel;
   }
   bool operator!=(const OptimizationLevel &Other) const {
-    return SizeLevel != Other.SizeLevel || SpeedLevel != Other.SpeedLevel;
+    return SpeedLevel != Other.SpeedLevel;
   }
 
   unsigned getSpeedupLevel() const { return SpeedLevel; }
-
-  unsigned getSizeLevel() const { return SizeLevel; }
 };
 } // namespace llvm
 
diff --git a/llvm/lib/Passes/OptimizationLevel.cpp b/llvm/lib/Passes/OptimizationLevel.cpp
index a1f8c1e14b1f0..68c2ddc475b40 100644
--- a/llvm/lib/Passes/OptimizationLevel.cpp
+++ b/llvm/lib/Passes/OptimizationLevel.cpp
@@ -10,21 +10,7 @@
 
 using namespace llvm;
 
-const OptimizationLevel OptimizationLevel::O0 = {
-    /*SpeedLevel*/ 0,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O1 = {
-    /*SpeedLevel*/ 1,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O2 = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O3 = {
-    /*SpeedLevel*/ 3,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::Os = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 1};
-const OptimizationLevel OptimizationLevel::Oz = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 2};
+const OptimizationLevel OptimizationLevel::O0 = {0};
+const OptimizationLevel OptimizationLevel::O1 = {1};
+const OptimizationLevel OptimizationLevel::O2 = {2};
+const OptimizationLevel OptimizationLevel::O3 = {3};
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c3f9f1261ab0a..f412e9e68307f 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -489,13 +489,17 @@ class RequireAllMachineFunctionPropertiesPass
 } // namespace
 
 static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
+  if (S == "Os" || S == "Oz")
+    reportFatalUsageError(
+        Twine("The optimization level \"") + S +
+        "\" is no longer supported. Use O2 in conjunction with the " +
+        (S == "Os" ? "optsize" : "minsize") + " attribute instead.");
+
   return StringSwitch<std::optional<OptimizationLevel>>(S)
       .Case("O0", OptimizationLevel::O0)
       .Case("O1", OptimizationLevel::O1)
       .Case("O2", OptimizationLevel::O2)
       .Case("O3", OptimizationLevel::O3)
-      .Case("Os", OptimizationLevel::Os)
-      .Case("Oz", OptimizationLevel::Oz)
       .Default(std::nullopt);
 }
 
@@ -827,8 +831,7 @@ Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
     StringRef ParamName;
     std::tie(ParamName, Params) = Params.split(';');
     std::optional<OptimizationLevel> OptLevel = parseOptLevel(ParamName);
-    // Don't accept -Os/-Oz.
-    if (OptLevel && !OptLevel->isOptimizingForSize()) {
+    if (OptLevel) {
       UnrollOpts.setOptLevel(OptLevel->getSpeedupLevel());
       continue;
     }
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index bde6d0b3e5106..d2906eef8dd9d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -162,8 +162,9 @@ MODULE_PASS("rtsan", RealtimeSanitizerPass())
 MODULE_PASS("sample-profile", SampleProfileLoaderPass())
 MODULE_PASS("sancov-module", SanitizerCoveragePass())
 MODULE_PASS("sanmd-module", SanitizerBinaryMetadataPass())
+// TODO: Rename (or parameterize by optimization level)
 MODULE_PASS("scc-oz-module-inliner",
-            buildInlinerPipeline(OptimizationLevel::Oz,
+            buildInlinerPipeline(OptimizationLevel::O2,
                                  ThinOrFullLTOPhase::None))
 MODULE_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass())
 MODULE_PASS("strip", StripSymbolsPass())
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
index 5ed52f5bf982d..4a44bd2895a1f 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
@@ -4,7 +4,6 @@
 ; 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
diff --git a/llvm/test/Analysis/InstCount/pipeline.ll b/llvm/test/Analysis/InstCount/pipeline.ll
index bb203cca0a974..af2e9b26b2b5b 100644
--- a/llvm/test/Analysis/InstCount/pipeline.ll
+++ b/llvm/test/Analysis/InstCount/pipeline.ll
@@ -4,7 +4,6 @@
 ; 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
diff --git a/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll b/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
index 05ec0ae4c29cf..9944865d8c2ff 100644
--- a/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
+++ b/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
@@ -1,4 +1,4 @@
-; RUN: opt -Os -S < %s | FileCheck %s
+; RUN: opt -O2 -S < %s | FileCheck %s
 ; Don't reset the alignment on the struct to 1.
 ; CHECK: align 4
 
diff --git a/llvm/test/Other/function-simplification.ll b/llvm/test/Other/function-simplification.ll
index e782aa4a56342..7da1f7994beac 100644
--- a/llvm/test/Other/function-simplification.ll
+++ b/llvm/test/Other/function-simplification.ll
@@ -1,18 +1,16 @@
 ; RUN: opt -passes='function-simplification<O1>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O1
-; RUN: opt -passes='function-simplification<O2>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<O3>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<Os>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<Oz>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
+; RUN: opt -passes='function-simplification<O2>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23
+; RUN: opt -passes='function-simplification<O3>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23
 ; RUN: not opt -passes='function-simplification<O0>' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O0
 
 ; O1: Running pass: EarlyCSEPass
 ; O1-NOT: Running pass: GVNPass
 
-; O23SZ: Running pass: EarlyCSEPass
-; O23SZ: Running pass: GVNPass
+; O23: Running pass: EarlyCSEPass
+; O23: Running pass: GVNPass
 
 ; O0: invalid function-simplification parameter 'O0'
 
 define void @f() {
   ret void
-}
\ No newline at end of file
+}
diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll
index cebadfbda2fa5..9137f0ec1c8c3 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ b/llvm/test/Other/new-pm-defaults.ll
@@ -12,88 +12,82 @@
 ; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O1,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O2>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
-; RUN:     -passes='default<Os>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
-; RUN:     -passes='default<Oz>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='lto-pre-link<O2>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23,%llvmcheckext
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-peephole='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-late-loop-optimizations='no-op-loop' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-loop-optimizer-end='no-op-loop' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-scalar-optimizer-late='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-cgscc-optimizer-late='no-op-cgscc' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-vectorizer-start='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-vectorizer-end='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-END,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-END,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-start='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-early-simplification='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-start='no-op-module' \
 ; RUN:     -passes='lto-pre-link<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-optimizer-early='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-EARLY,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-EARLY,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-optimizer-last='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-jump-table-to-switch -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-JUMP-TABLE-TO-SWITCH,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-JUMP-TABLE-TO-SWITCH,CHECK-O23,%llvmcheckext
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-matrix -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-MATRIX
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-MATRIX
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-merge-functions -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-MERGE-FUNCS
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-MERGE-FUNCS
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -ir-outliner -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-IR-OUTLINER
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-IR-OUTLINER
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-...
[truncated]

@llvmbot

llvmbot commented Apr 21, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-mlir

Author: Nikita Popov (nikic)

Changes

These should use O2 with the optsize or minsize attributes instead.

This enforces that there is divergence between pipeline-level Os/Oz and function-level Os/Oz at an architectural level.

For the purpose of testing IR that does not have optsize/minsize itself, it's possible to use -force-attribute=optsize etc.


Patch is 122.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/191363.diff

38 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-13)
  • (modified) llvm/include/llvm/Passes/OptimizationLevel.h (+5-34)
  • (modified) llvm/lib/Passes/OptimizationLevel.cpp (+4-18)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (+7-4)
  • (modified) llvm/lib/Passes/PassRegistry.def (+2-1)
  • (modified) llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll (-1)
  • (modified) llvm/test/Analysis/InstCount/pipeline.ll (-1)
  • (modified) llvm/test/CodeGen/Hexagon/glob-align-volatile.ll (+1-1)
  • (modified) llvm/test/Other/function-simplification.ll (+5-7)
  • (modified) llvm/test/Other/new-pm-defaults.ll (+48-54)
  • (modified) llvm/test/Other/new-pm-lto-defaults.ll (+114-120)
  • (modified) llvm/test/Other/new-pm-pgo-preinline.ll (+16-17)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-defaults.ll (+33-39)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll (+29-35)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll (+29-37)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-defaults.ll (+37-49)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll (+29-37)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll (+28-36)
  • (modified) llvm/test/Other/opt-On.ll (-2)
  • (added) llvm/test/Other/opt-Os-Oz.ll (+5)
  • (modified) llvm/test/Other/opt-hot-cold-split.ll (+10-10)
  • (modified) llvm/test/Other/optimize-inrange-gep.ll (-2)
  • (modified) llvm/test/Other/pipeline-callbacks-string-api.ll (+1-1)
  • (modified) llvm/test/Transforms/Inline/always-inline-phase-ordering.ll (+1-1)
  • (modified) llvm/test/Transforms/Inline/devirtualize.ll (+2-2)
  • (modified) llvm/test/Transforms/Inline/inline-optsize.ll (+6-17)
  • (modified) llvm/test/Transforms/Inline/inline-threshold.ll (-2)
  • (removed) llvm/test/Transforms/LoopUnroll/opt-levels.ll (-47)
  • (removed) llvm/test/Transforms/LoopUnrollAndJam/opt-levels.ll (-61)
  • (modified) llvm/test/Transforms/PhaseOrdering/AArch64/Oz-and-forced-vectorize.ll (+1-1)
  • (modified) llvm/test/Transforms/PhaseOrdering/X86/loop-vectorize-metadata.ll (+21-153)
  • (modified) llvm/test/Transforms/PhaseOrdering/always-inline-alloca-promotion.ll (+1-1)
  • (modified) llvm/test/Transforms/PhaseOrdering/cmp-logic.ll (+13-13)
  • (modified) llvm/test/Transforms/PhaseOrdering/enable-loop-header-duplication-oz.ll (+2-2)
  • (modified) llvm/test/Transforms/PhaseOrdering/runtime-check-removal.ll (+3-3)
  • (modified) llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll (-2)
  • (modified) mlir/lib/ExecutionEngine/OptUtils.cpp (+1-10)
  • (modified) polly/test/Support/defaultpipelines.ll (-2)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 3b50c465c1c29..f34c5c007f115 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -629,19 +629,7 @@ static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
     return OptimizationLevel::O1;
 
   case 2:
-    switch (Opts.OptimizeSize) {
-    default:
-      llvm_unreachable("Invalid optimization level for size!");
-
-    case 0:
-      return OptimizationLevel::O2;
-
-    case 1:
-      return OptimizationLevel::Os;
-
-    case 2:
-      return OptimizationLevel::Oz;
-    }
+    return OptimizationLevel::O2;
 
   case 3:
     return OptimizationLevel::O3;
diff --git a/llvm/include/llvm/Passes/OptimizationLevel.h b/llvm/include/llvm/Passes/OptimizationLevel.h
index 1cf258f1ffd0d..c74407beb8598 100644
--- a/llvm/include/llvm/Passes/OptimizationLevel.h
+++ b/llvm/include/llvm/Passes/OptimizationLevel.h
@@ -22,16 +22,10 @@ namespace llvm {
 
 class OptimizationLevel final {
   unsigned SpeedLevel = 2;
-  unsigned SizeLevel = 0;
-  OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel)
-      : SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) {
-    // Check that only valid combinations are passed.
+  OptimizationLevel(unsigned SpeedLevel) : SpeedLevel(SpeedLevel) {
+    // Check that only valid values are passed.
     assert(SpeedLevel <= 3 &&
            "Optimization level for speed should be 0, 1, 2, or 3");
-    assert(SizeLevel <= 2 &&
-           "Optimization level for size should be 0, 1, or 2");
-    assert((SizeLevel == 0 || SpeedLevel == 2) &&
-           "Optimize for size should be encoded with speedup level == 2");
   }
 
 public:
@@ -88,40 +82,17 @@ class OptimizationLevel final {
   /// reasonably. This does not preclude very substantial constant factor
   /// costs though.
   LLVM_ABI static const OptimizationLevel O3;
-  /// Similar to \c O2 but tries to optimize for small code size instead of
-  /// fast execution without triggering significant incremental execution
-  /// time slowdowns.
-  ///
-  /// The logic here is exactly the same as \c O2, but with code size and
-  /// execution time metrics swapped.
-  ///
-  /// A consequence of the different core goal is that this should in general
-  /// produce substantially smaller executables that still run in
-  /// a reasonable amount of time.
-  LLVM_ABI static const OptimizationLevel Os;
-  /// A very specialized mode that will optimize for code size at any and all
-  /// costs.
-  ///
-  /// This is useful primarily when there are absolute size limitations and
-  /// any effort taken to reduce the size is worth it regardless of the
-  /// execution time impact. You should expect this level to produce rather
-  /// slow, but very small, code.
-  LLVM_ABI static const OptimizationLevel Oz;
 
-  bool isOptimizingForSpeed() const { return SizeLevel == 0 && SpeedLevel > 0; }
-
-  bool isOptimizingForSize() const { return SizeLevel > 0; }
+  bool isOptimizingForSpeed() const { return SpeedLevel > 0; }
 
   bool operator==(const OptimizationLevel &Other) const {
-    return SizeLevel == Other.SizeLevel && SpeedLevel == Other.SpeedLevel;
+    return SpeedLevel == Other.SpeedLevel;
   }
   bool operator!=(const OptimizationLevel &Other) const {
-    return SizeLevel != Other.SizeLevel || SpeedLevel != Other.SpeedLevel;
+    return SpeedLevel != Other.SpeedLevel;
   }
 
   unsigned getSpeedupLevel() const { return SpeedLevel; }
-
-  unsigned getSizeLevel() const { return SizeLevel; }
 };
 } // namespace llvm
 
diff --git a/llvm/lib/Passes/OptimizationLevel.cpp b/llvm/lib/Passes/OptimizationLevel.cpp
index a1f8c1e14b1f0..68c2ddc475b40 100644
--- a/llvm/lib/Passes/OptimizationLevel.cpp
+++ b/llvm/lib/Passes/OptimizationLevel.cpp
@@ -10,21 +10,7 @@
 
 using namespace llvm;
 
-const OptimizationLevel OptimizationLevel::O0 = {
-    /*SpeedLevel*/ 0,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O1 = {
-    /*SpeedLevel*/ 1,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O2 = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O3 = {
-    /*SpeedLevel*/ 3,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::Os = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 1};
-const OptimizationLevel OptimizationLevel::Oz = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 2};
+const OptimizationLevel OptimizationLevel::O0 = {0};
+const OptimizationLevel OptimizationLevel::O1 = {1};
+const OptimizationLevel OptimizationLevel::O2 = {2};
+const OptimizationLevel OptimizationLevel::O3 = {3};
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c3f9f1261ab0a..f412e9e68307f 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -489,13 +489,17 @@ class RequireAllMachineFunctionPropertiesPass
 } // namespace
 
 static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
+  if (S == "Os" || S == "Oz")
+    reportFatalUsageError(
+        Twine("The optimization level \"") + S +
+        "\" is no longer supported. Use O2 in conjunction with the " +
+        (S == "Os" ? "optsize" : "minsize") + " attribute instead.");
+
   return StringSwitch<std::optional<OptimizationLevel>>(S)
       .Case("O0", OptimizationLevel::O0)
       .Case("O1", OptimizationLevel::O1)
       .Case("O2", OptimizationLevel::O2)
       .Case("O3", OptimizationLevel::O3)
-      .Case("Os", OptimizationLevel::Os)
-      .Case("Oz", OptimizationLevel::Oz)
       .Default(std::nullopt);
 }
 
@@ -827,8 +831,7 @@ Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
     StringRef ParamName;
     std::tie(ParamName, Params) = Params.split(';');
     std::optional<OptimizationLevel> OptLevel = parseOptLevel(ParamName);
-    // Don't accept -Os/-Oz.
-    if (OptLevel && !OptLevel->isOptimizingForSize()) {
+    if (OptLevel) {
       UnrollOpts.setOptLevel(OptLevel->getSpeedupLevel());
       continue;
     }
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index bde6d0b3e5106..d2906eef8dd9d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -162,8 +162,9 @@ MODULE_PASS("rtsan", RealtimeSanitizerPass())
 MODULE_PASS("sample-profile", SampleProfileLoaderPass())
 MODULE_PASS("sancov-module", SanitizerCoveragePass())
 MODULE_PASS("sanmd-module", SanitizerBinaryMetadataPass())
+// TODO: Rename (or parameterize by optimization level)
 MODULE_PASS("scc-oz-module-inliner",
-            buildInlinerPipeline(OptimizationLevel::Oz,
+            buildInlinerPipeline(OptimizationLevel::O2,
                                  ThinOrFullLTOPhase::None))
 MODULE_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass())
 MODULE_PASS("strip", StripSymbolsPass())
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
index 5ed52f5bf982d..4a44bd2895a1f 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
@@ -4,7 +4,6 @@
 ; 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
diff --git a/llvm/test/Analysis/InstCount/pipeline.ll b/llvm/test/Analysis/InstCount/pipeline.ll
index bb203cca0a974..af2e9b26b2b5b 100644
--- a/llvm/test/Analysis/InstCount/pipeline.ll
+++ b/llvm/test/Analysis/InstCount/pipeline.ll
@@ -4,7 +4,6 @@
 ; 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
diff --git a/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll b/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
index 05ec0ae4c29cf..9944865d8c2ff 100644
--- a/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
+++ b/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
@@ -1,4 +1,4 @@
-; RUN: opt -Os -S < %s | FileCheck %s
+; RUN: opt -O2 -S < %s | FileCheck %s
 ; Don't reset the alignment on the struct to 1.
 ; CHECK: align 4
 
diff --git a/llvm/test/Other/function-simplification.ll b/llvm/test/Other/function-simplification.ll
index e782aa4a56342..7da1f7994beac 100644
--- a/llvm/test/Other/function-simplification.ll
+++ b/llvm/test/Other/function-simplification.ll
@@ -1,18 +1,16 @@
 ; RUN: opt -passes='function-simplification<O1>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O1
-; RUN: opt -passes='function-simplification<O2>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<O3>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<Os>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<Oz>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
+; RUN: opt -passes='function-simplification<O2>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23
+; RUN: opt -passes='function-simplification<O3>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23
 ; RUN: not opt -passes='function-simplification<O0>' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O0
 
 ; O1: Running pass: EarlyCSEPass
 ; O1-NOT: Running pass: GVNPass
 
-; O23SZ: Running pass: EarlyCSEPass
-; O23SZ: Running pass: GVNPass
+; O23: Running pass: EarlyCSEPass
+; O23: Running pass: GVNPass
 
 ; O0: invalid function-simplification parameter 'O0'
 
 define void @f() {
   ret void
-}
\ No newline at end of file
+}
diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll
index cebadfbda2fa5..9137f0ec1c8c3 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ b/llvm/test/Other/new-pm-defaults.ll
@@ -12,88 +12,82 @@
 ; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O1,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O2>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
-; RUN:     -passes='default<Os>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
-; RUN:     -passes='default<Oz>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='lto-pre-link<O2>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23,%llvmcheckext
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-peephole='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-late-loop-optimizations='no-op-loop' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-loop-optimizer-end='no-op-loop' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-scalar-optimizer-late='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-cgscc-optimizer-late='no-op-cgscc' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-vectorizer-start='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-vectorizer-end='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-END,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-END,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-start='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-early-simplification='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-start='no-op-module' \
 ; RUN:     -passes='lto-pre-link<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-optimizer-early='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-EARLY,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-EARLY,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-optimizer-last='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-jump-table-to-switch -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-JUMP-TABLE-TO-SWITCH,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-JUMP-TABLE-TO-SWITCH,CHECK-O23,%llvmcheckext
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-matrix -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-MATRIX
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-MATRIX
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-merge-functions -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-MERGE-FUNCS
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-MERGE-FUNCS
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -ir-outliner -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-IR-OUTLINER
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-IR-OUTLINER
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-...
[truncated]

@llvmbot

llvmbot commented Apr 21, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-backend-hexagon

Author: Nikita Popov (nikic)

Changes

These should use O2 with the optsize or minsize attributes instead.

This enforces that there is divergence between pipeline-level Os/Oz and function-level Os/Oz at an architectural level.

For the purpose of testing IR that does not have optsize/minsize itself, it's possible to use -force-attribute=optsize etc.


Patch is 122.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/191363.diff

38 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-13)
  • (modified) llvm/include/llvm/Passes/OptimizationLevel.h (+5-34)
  • (modified) llvm/lib/Passes/OptimizationLevel.cpp (+4-18)
  • (modified) llvm/lib/Passes/PassBuilder.cpp (+7-4)
  • (modified) llvm/lib/Passes/PassRegistry.def (+2-1)
  • (modified) llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll (-1)
  • (modified) llvm/test/Analysis/InstCount/pipeline.ll (-1)
  • (modified) llvm/test/CodeGen/Hexagon/glob-align-volatile.ll (+1-1)
  • (modified) llvm/test/Other/function-simplification.ll (+5-7)
  • (modified) llvm/test/Other/new-pm-defaults.ll (+48-54)
  • (modified) llvm/test/Other/new-pm-lto-defaults.ll (+114-120)
  • (modified) llvm/test/Other/new-pm-pgo-preinline.ll (+16-17)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-defaults.ll (+33-39)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll (+29-35)
  • (modified) llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll (+29-37)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-defaults.ll (+37-49)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll (+29-37)
  • (modified) llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll (+28-36)
  • (modified) llvm/test/Other/opt-On.ll (-2)
  • (added) llvm/test/Other/opt-Os-Oz.ll (+5)
  • (modified) llvm/test/Other/opt-hot-cold-split.ll (+10-10)
  • (modified) llvm/test/Other/optimize-inrange-gep.ll (-2)
  • (modified) llvm/test/Other/pipeline-callbacks-string-api.ll (+1-1)
  • (modified) llvm/test/Transforms/Inline/always-inline-phase-ordering.ll (+1-1)
  • (modified) llvm/test/Transforms/Inline/devirtualize.ll (+2-2)
  • (modified) llvm/test/Transforms/Inline/inline-optsize.ll (+6-17)
  • (modified) llvm/test/Transforms/Inline/inline-threshold.ll (-2)
  • (removed) llvm/test/Transforms/LoopUnroll/opt-levels.ll (-47)
  • (removed) llvm/test/Transforms/LoopUnrollAndJam/opt-levels.ll (-61)
  • (modified) llvm/test/Transforms/PhaseOrdering/AArch64/Oz-and-forced-vectorize.ll (+1-1)
  • (modified) llvm/test/Transforms/PhaseOrdering/X86/loop-vectorize-metadata.ll (+21-153)
  • (modified) llvm/test/Transforms/PhaseOrdering/always-inline-alloca-promotion.ll (+1-1)
  • (modified) llvm/test/Transforms/PhaseOrdering/cmp-logic.ll (+13-13)
  • (modified) llvm/test/Transforms/PhaseOrdering/enable-loop-header-duplication-oz.ll (+2-2)
  • (modified) llvm/test/Transforms/PhaseOrdering/runtime-check-removal.ll (+3-3)
  • (modified) llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll (-2)
  • (modified) mlir/lib/ExecutionEngine/OptUtils.cpp (+1-10)
  • (modified) polly/test/Support/defaultpipelines.ll (-2)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 3b50c465c1c29..f34c5c007f115 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -629,19 +629,7 @@ static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
     return OptimizationLevel::O1;
 
   case 2:
-    switch (Opts.OptimizeSize) {
-    default:
-      llvm_unreachable("Invalid optimization level for size!");
-
-    case 0:
-      return OptimizationLevel::O2;
-
-    case 1:
-      return OptimizationLevel::Os;
-
-    case 2:
-      return OptimizationLevel::Oz;
-    }
+    return OptimizationLevel::O2;
 
   case 3:
     return OptimizationLevel::O3;
diff --git a/llvm/include/llvm/Passes/OptimizationLevel.h b/llvm/include/llvm/Passes/OptimizationLevel.h
index 1cf258f1ffd0d..c74407beb8598 100644
--- a/llvm/include/llvm/Passes/OptimizationLevel.h
+++ b/llvm/include/llvm/Passes/OptimizationLevel.h
@@ -22,16 +22,10 @@ namespace llvm {
 
 class OptimizationLevel final {
   unsigned SpeedLevel = 2;
-  unsigned SizeLevel = 0;
-  OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel)
-      : SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) {
-    // Check that only valid combinations are passed.
+  OptimizationLevel(unsigned SpeedLevel) : SpeedLevel(SpeedLevel) {
+    // Check that only valid values are passed.
     assert(SpeedLevel <= 3 &&
            "Optimization level for speed should be 0, 1, 2, or 3");
-    assert(SizeLevel <= 2 &&
-           "Optimization level for size should be 0, 1, or 2");
-    assert((SizeLevel == 0 || SpeedLevel == 2) &&
-           "Optimize for size should be encoded with speedup level == 2");
   }
 
 public:
@@ -88,40 +82,17 @@ class OptimizationLevel final {
   /// reasonably. This does not preclude very substantial constant factor
   /// costs though.
   LLVM_ABI static const OptimizationLevel O3;
-  /// Similar to \c O2 but tries to optimize for small code size instead of
-  /// fast execution without triggering significant incremental execution
-  /// time slowdowns.
-  ///
-  /// The logic here is exactly the same as \c O2, but with code size and
-  /// execution time metrics swapped.
-  ///
-  /// A consequence of the different core goal is that this should in general
-  /// produce substantially smaller executables that still run in
-  /// a reasonable amount of time.
-  LLVM_ABI static const OptimizationLevel Os;
-  /// A very specialized mode that will optimize for code size at any and all
-  /// costs.
-  ///
-  /// This is useful primarily when there are absolute size limitations and
-  /// any effort taken to reduce the size is worth it regardless of the
-  /// execution time impact. You should expect this level to produce rather
-  /// slow, but very small, code.
-  LLVM_ABI static const OptimizationLevel Oz;
 
-  bool isOptimizingForSpeed() const { return SizeLevel == 0 && SpeedLevel > 0; }
-
-  bool isOptimizingForSize() const { return SizeLevel > 0; }
+  bool isOptimizingForSpeed() const { return SpeedLevel > 0; }
 
   bool operator==(const OptimizationLevel &Other) const {
-    return SizeLevel == Other.SizeLevel && SpeedLevel == Other.SpeedLevel;
+    return SpeedLevel == Other.SpeedLevel;
   }
   bool operator!=(const OptimizationLevel &Other) const {
-    return SizeLevel != Other.SizeLevel || SpeedLevel != Other.SpeedLevel;
+    return SpeedLevel != Other.SpeedLevel;
   }
 
   unsigned getSpeedupLevel() const { return SpeedLevel; }
-
-  unsigned getSizeLevel() const { return SizeLevel; }
 };
 } // namespace llvm
 
diff --git a/llvm/lib/Passes/OptimizationLevel.cpp b/llvm/lib/Passes/OptimizationLevel.cpp
index a1f8c1e14b1f0..68c2ddc475b40 100644
--- a/llvm/lib/Passes/OptimizationLevel.cpp
+++ b/llvm/lib/Passes/OptimizationLevel.cpp
@@ -10,21 +10,7 @@
 
 using namespace llvm;
 
-const OptimizationLevel OptimizationLevel::O0 = {
-    /*SpeedLevel*/ 0,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O1 = {
-    /*SpeedLevel*/ 1,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O2 = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::O3 = {
-    /*SpeedLevel*/ 3,
-    /*SizeLevel*/ 0};
-const OptimizationLevel OptimizationLevel::Os = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 1};
-const OptimizationLevel OptimizationLevel::Oz = {
-    /*SpeedLevel*/ 2,
-    /*SizeLevel*/ 2};
+const OptimizationLevel OptimizationLevel::O0 = {0};
+const OptimizationLevel OptimizationLevel::O1 = {1};
+const OptimizationLevel OptimizationLevel::O2 = {2};
+const OptimizationLevel OptimizationLevel::O3 = {3};
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index c3f9f1261ab0a..f412e9e68307f 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -489,13 +489,17 @@ class RequireAllMachineFunctionPropertiesPass
 } // namespace
 
 static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
+  if (S == "Os" || S == "Oz")
+    reportFatalUsageError(
+        Twine("The optimization level \"") + S +
+        "\" is no longer supported. Use O2 in conjunction with the " +
+        (S == "Os" ? "optsize" : "minsize") + " attribute instead.");
+
   return StringSwitch<std::optional<OptimizationLevel>>(S)
       .Case("O0", OptimizationLevel::O0)
       .Case("O1", OptimizationLevel::O1)
       .Case("O2", OptimizationLevel::O2)
       .Case("O3", OptimizationLevel::O3)
-      .Case("Os", OptimizationLevel::Os)
-      .Case("Oz", OptimizationLevel::Oz)
       .Default(std::nullopt);
 }
 
@@ -827,8 +831,7 @@ Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
     StringRef ParamName;
     std::tie(ParamName, Params) = Params.split(';');
     std::optional<OptimizationLevel> OptLevel = parseOptLevel(ParamName);
-    // Don't accept -Os/-Oz.
-    if (OptLevel && !OptLevel->isOptimizingForSize()) {
+    if (OptLevel) {
       UnrollOpts.setOptLevel(OptLevel->getSpeedupLevel());
       continue;
     }
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index bde6d0b3e5106..d2906eef8dd9d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -162,8 +162,9 @@ MODULE_PASS("rtsan", RealtimeSanitizerPass())
 MODULE_PASS("sample-profile", SampleProfileLoaderPass())
 MODULE_PASS("sancov-module", SanitizerCoveragePass())
 MODULE_PASS("sanmd-module", SanitizerBinaryMetadataPass())
+// TODO: Rename (or parameterize by optimization level)
 MODULE_PASS("scc-oz-module-inliner",
-            buildInlinerPipeline(OptimizationLevel::Oz,
+            buildInlinerPipeline(OptimizationLevel::O2,
                                  ThinOrFullLTOPhase::None))
 MODULE_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass())
 MODULE_PASS("strip", StripSymbolsPass())
diff --git a/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
index 5ed52f5bf982d..4a44bd2895a1f 100644
--- a/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
+++ b/llvm/test/Analysis/FunctionPropertiesAnalysis/pipeline.ll
@@ -4,7 +4,6 @@
 ; 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
diff --git a/llvm/test/Analysis/InstCount/pipeline.ll b/llvm/test/Analysis/InstCount/pipeline.ll
index bb203cca0a974..af2e9b26b2b5b 100644
--- a/llvm/test/Analysis/InstCount/pipeline.ll
+++ b/llvm/test/Analysis/InstCount/pipeline.ll
@@ -4,7 +4,6 @@
 ; 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
diff --git a/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll b/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
index 05ec0ae4c29cf..9944865d8c2ff 100644
--- a/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
+++ b/llvm/test/CodeGen/Hexagon/glob-align-volatile.ll
@@ -1,4 +1,4 @@
-; RUN: opt -Os -S < %s | FileCheck %s
+; RUN: opt -O2 -S < %s | FileCheck %s
 ; Don't reset the alignment on the struct to 1.
 ; CHECK: align 4
 
diff --git a/llvm/test/Other/function-simplification.ll b/llvm/test/Other/function-simplification.ll
index e782aa4a56342..7da1f7994beac 100644
--- a/llvm/test/Other/function-simplification.ll
+++ b/llvm/test/Other/function-simplification.ll
@@ -1,18 +1,16 @@
 ; RUN: opt -passes='function-simplification<O1>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O1
-; RUN: opt -passes='function-simplification<O2>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<O3>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<Os>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
-; RUN: opt -passes='function-simplification<Oz>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23SZ
+; RUN: opt -passes='function-simplification<O2>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23
+; RUN: opt -passes='function-simplification<O3>' -debug-pass-manager -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O23
 ; RUN: not opt -passes='function-simplification<O0>' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=O0
 
 ; O1: Running pass: EarlyCSEPass
 ; O1-NOT: Running pass: GVNPass
 
-; O23SZ: Running pass: EarlyCSEPass
-; O23SZ: Running pass: GVNPass
+; O23: Running pass: EarlyCSEPass
+; O23: Running pass: GVNPass
 
 ; O0: invalid function-simplification parameter 'O0'
 
 define void @f() {
   ret void
-}
\ No newline at end of file
+}
diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll
index cebadfbda2fa5..9137f0ec1c8c3 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ b/llvm/test/Other/new-pm-defaults.ll
@@ -12,88 +12,82 @@
 ; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O1,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O2>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
-; RUN:     -passes='default<Os>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
-; RUN:     -passes='default<Oz>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='lto-pre-link<O2>' -S %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23,%llvmcheckext
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-peephole='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-late-loop-optimizations='no-op-loop' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-loop-optimizer-end='no-op-loop' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-scalar-optimizer-late='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-cgscc-optimizer-late='no-op-cgscc' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-vectorizer-start='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-vectorizer-end='no-op-function' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-END,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-END,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-start='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-early-simplification='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-pipeline-start='no-op-module' \
 ; RUN:     -passes='lto-pre-link<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-optimizer-early='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-EARLY,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-EARLY,CHECK-O23
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes-ep-optimizer-last='no-op-module' \
 ; RUN:     -passes='default<O3>' -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23SZ
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-jump-table-to-switch -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-JUMP-TABLE-TO-SWITCH,CHECK-O23SZ,%llvmcheckext
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-JUMP-TABLE-TO-SWITCH,CHECK-O23,%llvmcheckext
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-matrix -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-MATRIX
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-MATRIX
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -enable-merge-functions -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-MERGE-FUNCS
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-MERGE-FUNCS
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN:     -passes='default<O3>' -ir-outliner -S  %s 2>&1 \
-; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext,CHECK-IR-OUTLINER
+; RUN:     | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23,%llvmcheckext,CHECK-IR-OUTLINER
 
 ; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-...
[truncated]

@nikic
nikic requested review from aeubanks and fhahn April 21, 2026 15:15
@nikic
nikic force-pushed the remove-pipeline-optsize branch 2 times, most recently from e11f86f to d703777 Compare April 21, 2026 15:56
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Apr 21, 2026

@aeubanks aeubanks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

@fhahn fhahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@davemgreen davemgreen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK in my (not super extensive) testing. LGTM

These should use O2 with the optsize or minsize attributes instead.

This enforces that there is divergence between pipeline-level Os/Oz
and function-level Os/Oz at an architectural level.
@nikic
nikic force-pushed the remove-pipeline-optsize branch from d703777 to f388255 Compare April 22, 2026 08:53
@nikic
nikic enabled auto-merge (squash) April 22, 2026 08:54
@nikic
nikic merged commit 86b9775 into llvm:main Apr 22, 2026
9 of 10 checks passed
@nikic
nikic deleted the remove-pipeline-optsize branch April 22, 2026 09:34
setupOptionsForPipelineAlias(PTO, L);
return buildPerModuleDefaultPipeline(L);
},
parseOptLevelParam, "O0;O1;O2;O3;Os;Oz")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Os/Oz should be removed here too?
Right now opt -print-passes includes

  default<O0;O1;O2;O3;Os;Oz>
  thinlto-pre-link<O0;O1;O2;O3;Os;Oz>
  thinlto<O0;O1;O2;O3;Os;Oz>
  lto-pre-link<O0;O1;O2;O3;Os;Oz>
  lto<O0;O1;O2;O3;Os;Oz>
  fatlto-pre-link<O0;O1;O2;O3;Os;Oz;thinlto;emit-summary>
  function-simplification<O1;O2;O3;Os;Oz>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping these in #193491, thanks!

pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Apr 24, 2026
rustc_llvm: update opt-level handling for LLVM 23

LLVM 23 removed Os and Oz optimization pipelines and the PR says to use O2 with optsize or minsize instead as appropriate.

See llvm/llvm-project#191363 for more details.
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 24, 2026
rustc_llvm: update opt-level handling for LLVM 23

LLVM 23 removed Os and Oz optimization pipelines and the PR says to use O2 with optsize or minsize instead as appropriate.

See llvm/llvm-project#191363 for more details.
llvm-upstreamsync Bot pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Apr 24, 2026
verdeving pushed a commit to verdeving/carbon-lang that referenced this pull request Apr 28, 2026
The `-Oz` flag has been [removed from
LLVM](llvm/llvm-project#191363). The documented
replacement is to use `-O2` in conjunction with the `optsize` or
`minsize` attributes, which we already apply in lowering.
yingopq pushed a commit to yingopq/llvm-project that referenced this pull request Apr 29, 2026
These should use O2 with the optsize or minsize attributes instead.

This enforces that there is no divergence between pipeline-level Os/Oz
and function-level Os/Oz at an architectural level.

For the purpose of testing IR that does not have optsize/minsize itself,
it's possible to use `-force-attribute=optsize` etc.
yingopq pushed a commit to yingopq/llvm-project that referenced this pull request Apr 29, 2026
KHicketts pushed a commit to KHicketts/llvm-project that referenced this pull request Apr 30, 2026
These should use O2 with the optsize or minsize attributes instead.

This enforces that there is no divergence between pipeline-level Os/Oz
and function-level Os/Oz at an architectural level.

For the purpose of testing IR that does not have optsize/minsize itself,
it's possible to use `-force-attribute=optsize` etc.
KHicketts pushed a commit to KHicketts/llvm-project that referenced this pull request Apr 30, 2026
AnthonyLatsis added a commit to swiftlang/swift that referenced this pull request Jun 4, 2026
Os is gone upstream: llvm/llvm-project#191363.
This can only affect `-O` builds:
* We always emit IR functions with the `optsize` and `minsize`
  attributes in `-Osize` mode.
* The only place in LLVM where pipeline Os matters is
  `FunctionSpecializer`, where we already skip functions with the
  `optsize` or `minsize` attribute.
AnthonyLatsis added a commit to swiftlang/swift that referenced this pull request Jun 4, 2026
Os is gone upstream: llvm/llvm-project#191363.
This can only affect `-O` builds:
* We always emit IR functions with the `optsize` and `minsize`
  attributes in `-Osize` mode.
* The only place in LLVM where pipeline Os matters is
  `FunctionSpecializer`, where we already skip functions with the
  `optsize` or `minsize` attribute.
AnthonyLatsis added a commit to swiftlang/swift that referenced this pull request Jun 4, 2026
Os is gone upstream: llvm/llvm-project#191363.
This can only affect `-O` builds:
* We always emit IR functions with the `optsize` and `minsize`
  attributes in `-Osize` mode.
* The only place in LLVM where pipeline Os matters is
  `FunctionSpecializer`, where we already skip functions with the
  `optsize` or `minsize` attribute.
antiagainst added a commit to triton-lang/triton that referenced this pull request Jun 4, 2026
- Dropped -Os and -Oz after llvm/llvm-project#191363
- Emit scalar `{add,sub,mul}.rn.bf16` ops after llvm/llvm-project#190414
- Also changed to avoid hardcoding line numbers in test_line_info.py
- Add identifier/discriminator arguments to DICompositeTypeAttr::get
  calls after llvm/llvm-project#195321
- Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing
  MCContext after llvm/llvm-project#195032
- Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with
  NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608
ThomasRaoux pushed a commit to ThomasRaoux/triton that referenced this pull request Jun 5, 2026
- Dropped -Os and -Oz after llvm/llvm-project#191363
- Emit scalar `{add,sub,mul}.rn.bf16` ops after llvm/llvm-project#190414
- Also changed to avoid hardcoding line numbers in test_line_info.py
- Add identifier/discriminator arguments to DICompositeTypeAttr::get
  calls after llvm/llvm-project#195321
- Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing
  MCContext after llvm/llvm-project#195032
- Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with
  NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608
ThomasRaoux added a commit to triton-lang/triton that referenced this pull request Jun 5, 2026
* Dropped -Os and -Oz after
llvm/llvm-project#191363
* Emit scalar {add,sub,mul}.rn.bf16 ops after
llvm/llvm-project#190414
* Also changed to avoid hardcoding line numbers in test_line_info.py
* Add identifier/discriminator arguments to DICompositeTypeAttr::get
* calls after llvm/llvm-project#195321
* Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing
* MCContext after llvm/llvm-project#195032
* Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with
* NVVM::BarrierOp/nvvm.barrier after
llvm/llvm-project#195608
* Update AMD target parser includes after
llvm/llvm-project#198433
* Add explicit TypeID for AMD UniformityAnalysis after
llvm/llvm-project#199634
* Update finite-trip-count AMD range analysis after
llvm/llvm-project#196616
* Update NVVM::BarrierOp creation after
llvm/llvm-project#199404

also disable SLP vectorizer on sm_80 to workaround a ptxas bug

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
Co-authored-by: Lei Zhang <Lei.Zhang2@amd.com>
neudinger pushed a commit to zml/intel-xpu-backend-for-triton that referenced this pull request Jun 23, 2026
* Dropped -Os and -Oz after
llvm/llvm-project#191363
* Emit scalar {add,sub,mul}.rn.bf16 ops after
llvm/llvm-project#190414
* Also changed to avoid hardcoding line numbers in test_line_info.py
* Add identifier/discriminator arguments to DICompositeTypeAttr::get
* calls after llvm/llvm-project#195321
* Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing
* MCContext after llvm/llvm-project#195032
* Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with
* NVVM::BarrierOp/nvvm.barrier after
llvm/llvm-project#195608
* Update AMD target parser includes after
llvm/llvm-project#198433
* Add explicit TypeID for AMD UniformityAnalysis after
llvm/llvm-project#199634
* Update finite-trip-count AMD range analysis after
llvm/llvm-project#196616
* Update NVVM::BarrierOp creation after
llvm/llvm-project#199404

also disable SLP vectorizer on sm_80 to workaround a ptxas bug

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
Co-authored-by: Lei Zhang <Lei.Zhang2@amd.com>
ngocson2vn pushed a commit to ngocson2vn/triton that referenced this pull request Jul 5, 2026
* Dropped -Os and -Oz after
llvm/llvm-project#191363
* Emit scalar {add,sub,mul}.rn.bf16 ops after
llvm/llvm-project#190414
* Also changed to avoid hardcoding line numbers in test_line_info.py
* Add identifier/discriminator arguments to DICompositeTypeAttr::get
* calls after llvm/llvm-project#195321
* Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing
* MCContext after llvm/llvm-project#195032
* Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with
* NVVM::BarrierOp/nvvm.barrier after
llvm/llvm-project#195608
* Update AMD target parser includes after
llvm/llvm-project#198433
* Add explicit TypeID for AMD UniformityAnalysis after
llvm/llvm-project#199634
* Update finite-trip-count AMD range analysis after
llvm/llvm-project#196616
* Update NVVM::BarrierOp creation after
llvm/llvm-project#199404

also disable SLP vectorizer on sm_80 to workaround a ptxas bug

---------

Co-authored-by: Lei Zhang <antiagainst@gmail.com>
Co-authored-by: Lei Zhang <Lei.Zhang2@amd.com>
AnthonyLatsis added a commit to bnbarham/swift that referenced this pull request Jul 21, 2026
…s (#191363)"

lib/IRGen/IRGen.cpp:398:38: error: no member named 'Os' in 'llvm::OptimizationLevel'
  398 |     level = llvm::OptimizationLevel::Os;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^

Upstream removed the dedicated Os/Oz size-optimization pipelines (and the
associated SizeLevel), mandating that size optimization be expressed by running
the O2 pipeline with the optsize/minsize function attributes instead. Swift's
performLLVMOptimizations() unconditionally selected the Os pipeline for
optimized builds. Switch it to O2, matching how in-tree consumers (clang's
BackendUtil.cpp, mlir's OptUtils.cpp) adapted. The size preference for -Osize is
preserved because IRGenModule::constructInitialFnAttributes already attaches
OptimizeForSize/MinSize to functions based on the optimization mode.

See 86b9775612f893c669466fc749643cfacb8df682 (llvm/llvm-project#191363)

Assisted-by: Claude Code
AnthonyLatsis added a commit to bnbarham/swift that referenced this pull request Jul 22, 2026
…s (#191363)"

lib/IRGen/IRGen.cpp:398:38: error: no member named 'Os' in 'llvm::OptimizationLevel'
  398 |     level = llvm::OptimizationLevel::Os;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^

Upstream removed the dedicated Os/Oz size-optimization pipelines (and the
associated SizeLevel), mandating that size optimization be expressed by running
the O2 pipeline with the optsize/minsize function attributes instead. Swift's
performLLVMOptimizations() unconditionally selected the Os pipeline for
optimized builds. Switch it to O2, matching how in-tree consumers (clang's
BackendUtil.cpp, mlir's OptUtils.cpp) adapted. The size preference for -Osize is
preserved because IRGenModule::constructInitialFnAttributes already attaches
OptimizeForSize/MinSize to functions based on the optimization mode.

See 86b9775612f893c669466fc749643cfacb8df682 (llvm/llvm-project#191363)

Assisted-by: Claude Code
AnthonyLatsis added a commit to bnbarham/swift that referenced this pull request Jul 22, 2026
…s (#191363)"

lib/IRGen/IRGen.cpp:398:38: error: no member named 'Os' in 'llvm::OptimizationLevel'
  398 |     level = llvm::OptimizationLevel::Os;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^

Upstream removed the dedicated Os/Oz size-optimization pipelines (and the
associated SizeLevel), mandating that size optimization be expressed by running
the O2 pipeline with the optsize/minsize function attributes instead. Swift's
performLLVMOptimizations() unconditionally selected the Os pipeline for
optimized builds. Switch it to O2, matching how in-tree consumers (clang's
BackendUtil.cpp, mlir's OptUtils.cpp) adapted. The size preference for -Osize is
preserved because IRGenModule::constructInitialFnAttributes already attaches
OptimizeForSize/MinSize to functions based on the optimization mode.

See 86b9775612f893c669466fc749643cfacb8df682 (llvm/llvm-project#191363)

Assisted-by: Claude Code
AnthonyLatsis added a commit to bnbarham/swift that referenced this pull request Jul 23, 2026
…s (#191363)"

lib/IRGen/IRGen.cpp:398:38: error: no member named 'Os' in 'llvm::OptimizationLevel'
  398 |     level = llvm::OptimizationLevel::Os;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^

Upstream removed the dedicated Os/Oz size-optimization pipelines (and the
associated SizeLevel), mandating that size optimization be expressed by running
the O2 pipeline with the optsize/minsize function attributes instead. Swift's
performLLVMOptimizations() unconditionally selected the Os pipeline for
optimized builds. Switch it to O2, matching how in-tree consumers (clang's
BackendUtil.cpp, mlir's OptUtils.cpp) adapted. The size preference for -Osize is
preserved because IRGenModule::constructInitialFnAttributes already attaches
OptimizeForSize/MinSize to functions based on the optimization mode.

See 86b9775612f893c669466fc749643cfacb8df682 (llvm/llvm-project#191363)

Assisted-by: Claude Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:Hexagon clang:codegen IR generation bugs: mangling, exceptions, etc. flang:fir-hlfir flang Flang issues not falling into any other category llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms mlgo mlir:execution-engine mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants