Skip to content

Commit 51cf2ae

Browse files
committed
Make -O mean -C opt-level=3
1 parent 7a202a9 commit 51cf2ae

File tree

15 files changed

+41
-36
lines changed

15 files changed

+41
-36
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn build_isa(sess: &Session) -> Arc<dyn TargetIsa + 'static> {
290290
flags_builder.set("opt_level", "none").unwrap();
291291
}
292292
OptLevel::Less
293-
| OptLevel::Default
293+
| OptLevel::More
294294
| OptLevel::Size
295295
| OptLevel::SizeMin
296296
| OptLevel::Aggressive => {

compiler/rustc_codegen_gcc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
475475
Some(level) => match level {
476476
OptLevel::No => OptimizationLevel::None,
477477
OptLevel::Less => OptimizationLevel::Limited,
478-
OptLevel::Default => OptimizationLevel::Standard,
478+
OptLevel::More => OptimizationLevel::Standard,
479479
OptLevel::Aggressive => OptimizationLevel::Aggressive,
480480
OptLevel::Size | OptLevel::SizeMin => OptimizationLevel::Limited,
481481
},

compiler/rustc_codegen_llvm/src/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm::
138138
match cfg {
139139
No => (llvm::CodeGenOptLevel::None, llvm::CodeGenOptSizeNone),
140140
Less => (llvm::CodeGenOptLevel::Less, llvm::CodeGenOptSizeNone),
141-
Default => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone),
141+
More => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone),
142142
Aggressive => (llvm::CodeGenOptLevel::Aggressive, llvm::CodeGenOptSizeNone),
143143
Size => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeDefault),
144144
SizeMin => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeAggressive),
@@ -150,7 +150,7 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
150150
match cfg {
151151
No => llvm::PassBuilderOptLevel::O0,
152152
Less => llvm::PassBuilderOptLevel::O1,
153-
Default => llvm::PassBuilderOptLevel::O2,
153+
More => llvm::PassBuilderOptLevel::O2,
154154
Aggressive => llvm::PassBuilderOptLevel::O3,
155155
Size => llvm::PassBuilderOptLevel::Os,
156156
SizeMin => llvm::PassBuilderOptLevel::Oz,

compiler/rustc_codegen_ssa/src/back/linker.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<'a> GccLinker<'a> {
410410
let opt_level = match self.sess.opts.optimize {
411411
config::OptLevel::No => "O0",
412412
config::OptLevel::Less => "O1",
413-
config::OptLevel::Default | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
413+
config::OptLevel::More | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
414414
config::OptLevel::Aggressive => "O3",
415415
};
416416

@@ -685,7 +685,7 @@ impl<'a> Linker for GccLinker<'a> {
685685

686686
// GNU-style linkers support optimization with -O. GNU ld doesn't
687687
// need a numeric argument, but other linkers do.
688-
if self.sess.opts.optimize == config::OptLevel::Default
688+
if self.sess.opts.optimize == config::OptLevel::More
689689
|| self.sess.opts.optimize == config::OptLevel::Aggressive
690690
{
691691
self.link_arg("-O1");
@@ -1213,7 +1213,7 @@ impl<'a> Linker for EmLinker<'a> {
12131213
self.cc_arg(match self.sess.opts.optimize {
12141214
OptLevel::No => "-O0",
12151215
OptLevel::Less => "-O1",
1216-
OptLevel::Default => "-O2",
1216+
OptLevel::More => "-O2",
12171217
OptLevel::Aggressive => "-O3",
12181218
OptLevel::Size => "-Os",
12191219
OptLevel::SizeMin => "-Oz",
@@ -1384,7 +1384,7 @@ impl<'a> Linker for WasmLd<'a> {
13841384
self.link_arg(match self.sess.opts.optimize {
13851385
OptLevel::No => "-O0",
13861386
OptLevel::Less => "-O1",
1387-
OptLevel::Default => "-O2",
1387+
OptLevel::More => "-O2",
13881388
OptLevel::Aggressive => "-O3",
13891389
// Currently LLD doesn't support `Os` and `Oz`, so pass through `O2`
13901390
// instead.
@@ -1451,7 +1451,7 @@ impl<'a> WasmLd<'a> {
14511451
let opt_level = match self.sess.opts.optimize {
14521452
config::OptLevel::No => "O0",
14531453
config::OptLevel::Less => "O1",
1454-
config::OptLevel::Default => "O2",
1454+
config::OptLevel::More => "O2",
14551455
config::OptLevel::Aggressive => "O3",
14561456
// wasm-ld only handles integer LTO opt levels. Use O2
14571457
config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
@@ -1525,7 +1525,7 @@ impl<'a> Linker for L4Bender<'a> {
15251525
fn optimize(&mut self) {
15261526
// GNU-style linkers support optimization with -O. GNU ld doesn't
15271527
// need a numeric argument, but other linkers do.
1528-
if self.sess.opts.optimize == config::OptLevel::Default
1528+
if self.sess.opts.optimize == config::OptLevel::More
15291529
|| self.sess.opts.optimize == config::OptLevel::Aggressive
15301530
{
15311531
self.link_arg("-O1");
@@ -1929,7 +1929,7 @@ impl<'a> Linker for LlbcLinker<'a> {
19291929
match self.sess.opts.optimize {
19301930
OptLevel::No => "-O0",
19311931
OptLevel::Less => "-O1",
1932-
OptLevel::Default => "-O2",
1932+
OptLevel::More => "-O2",
19331933
OptLevel::Aggressive => "-O3",
19341934
OptLevel::Size => "-Os",
19351935
OptLevel::SizeMin => "-Oz",
@@ -2006,7 +2006,7 @@ impl<'a> Linker for BpfLinker<'a> {
20062006
self.link_arg(match self.sess.opts.optimize {
20072007
OptLevel::No => "-O0",
20082008
OptLevel::Less => "-O1",
2009-
OptLevel::Default => "-O2",
2009+
OptLevel::More => "-O2",
20102010
OptLevel::Aggressive => "-O3",
20112011
OptLevel::Size => "-Os",
20122012
OptLevel::SizeMin => "-Oz",

compiler/rustc_codegen_ssa/src/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl ModuleConfig {
234234
// Copy what clang does by turning on loop vectorization at O2 and
235235
// slp vectorization at O3.
236236
vectorize_loop: !sess.opts.cg.no_vectorize_loops
237-
&& (sess.opts.optimize == config::OptLevel::Default
237+
&& (sess.opts.optimize == config::OptLevel::More
238238
|| sess.opts.optimize == config::OptLevel::Aggressive),
239239
vectorize_slp: !sess.opts.cg.no_vectorize_slp
240240
&& sess.opts.optimize == config::OptLevel::Aggressive,
@@ -258,7 +258,7 @@ impl ModuleConfig {
258258
MergeFunctions::Trampolines | MergeFunctions::Aliases => {
259259
use config::OptLevel::*;
260260
match sess.opts.optimize {
261-
Aggressive | Default | SizeMin | Size => true,
261+
Aggressive | More | SizeMin | Size => true,
262262
Less | No => false,
263263
}
264264
}

compiler/rustc_codegen_ssa/src/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,12 @@ pub(crate) fn provide(providers: &mut Providers) {
10441044
config::OptLevel::No => return config::OptLevel::No,
10451045
// If globally optimise-speed is already specified, just use that level.
10461046
config::OptLevel::Less => return config::OptLevel::Less,
1047-
config::OptLevel::Default => return config::OptLevel::Default,
1047+
config::OptLevel::More => return config::OptLevel::More,
10481048
config::OptLevel::Aggressive => return config::OptLevel::Aggressive,
10491049
// If globally optimize-for-size has been requested, use -O2 instead (if optimize(size)
10501050
// are present).
1051-
config::OptLevel::Size => config::OptLevel::Default,
1052-
config::OptLevel::SizeMin => config::OptLevel::Default,
1051+
config::OptLevel::Size => config::OptLevel::More,
1052+
config::OptLevel::SizeMin => config::OptLevel::More,
10531053
};
10541054

10551055
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);

compiler/rustc_mir_transform/src/inline.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ impl<'tcx> crate::MirPass<'tcx> for Inline {
4949
match sess.mir_opt_level() {
5050
0 | 1 => false,
5151
2 => {
52-
(sess.opts.optimize == OptLevel::Default
53-
|| sess.opts.optimize == OptLevel::Aggressive)
52+
(sess.opts.optimize == OptLevel::More || sess.opts.optimize == OptLevel::Aggressive)
5453
&& sess.opts.incremental == None
5554
}
5655
_ => true,

compiler/rustc_session/src/config.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ pub enum CFProtection {
8686

8787
#[derive(Clone, Copy, Debug, PartialEq, Hash, HashStable_Generic)]
8888
pub enum OptLevel {
89-
No, // -O0
90-
Less, // -O1
91-
Default, // -O2
92-
Aggressive, // -O3
93-
Size, // -Os
94-
SizeMin, // -Oz
89+
/// `-Copt-level=0`
90+
No,
91+
/// `-Copt-level=1`
92+
Less,
93+
/// `-Copt-level=2`
94+
More,
95+
/// `-Copt-level=3` / `-O`
96+
Aggressive,
97+
/// `-Copt-level=s`
98+
Size,
99+
/// `-Copt-level=z`
100+
SizeMin,
95101
}
96102

97103
/// This is what the `LtoCli` values get mapped to after resolving defaults and
@@ -1226,7 +1232,7 @@ impl Options {
12261232
Some(setting) => setting,
12271233
None => match self.optimize {
12281234
OptLevel::No | OptLevel::Less | OptLevel::Size | OptLevel::SizeMin => true,
1229-
OptLevel::Default | OptLevel::Aggressive => false,
1235+
OptLevel::More | OptLevel::Aggressive => false,
12301236
},
12311237
}
12321238
}
@@ -1542,7 +1548,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
15421548
stack-protector-strategies|link-args|deployment-target]",
15431549
),
15441550
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
1545-
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=2", ""),
1551+
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
15461552
opt(Stable, Opt, "o", "", "Write output to <filename>", "FILENAME"),
15471553
opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
15481554
opt(
@@ -2097,12 +2103,12 @@ fn parse_opt_level(
20972103
})
20982104
.max();
20992105
if max_o > max_c {
2100-
OptLevel::Default
2106+
OptLevel::Aggressive
21012107
} else {
21022108
match cg.opt_level.as_ref() {
21032109
"0" => OptLevel::No,
21042110
"1" => OptLevel::Less,
2105-
"2" => OptLevel::Default,
2111+
"2" => OptLevel::More,
21062112
"3" => OptLevel::Aggressive,
21072113
"s" => OptLevel::Size,
21082114
"z" => OptLevel::SizeMin,

src/doc/rustc/src/codegen-options/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ This flag controls the optimization level.
368368
* `s`: optimize for binary size.
369369
* `z`: optimize for binary size, but also turn off loop vectorization.
370370

371-
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`.
371+
Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=3`.
372372

373373
The default is `0`.
374374

src/doc/rustc/src/command-line-arguments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ A synonym for [`-C debuginfo=2`](codegen-options/index.md#debuginfo).
308308
<a id="option-o-optimize"></a>
309309
## `-O`: optimize your code
310310

311-
A synonym for [`-C opt-level=2`](codegen-options/index.md#opt-level).
311+
A synonym for [`-C opt-level=3`](codegen-options/index.md#opt-level).
312312

313313
<a id="option-o-output"></a>
314314
## `-o`: filename of the output

src/tools/run-make-support/src/external_deps/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Rustc {
8383
self
8484
}
8585

86-
/// Specify default optimization level `-O` (alias for `-C opt-level=2`).
86+
/// Specify default optimization level `-O` (alias for `-C opt-level=3`).
8787
pub fn opt(&mut self) -> &mut Self {
8888
self.cmd.arg("-O");
8989
self

tests/assembly/x86_64-typed-swap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub fn swap_i32(x: &mut i32, y: &mut i32) {
2222
// CHECK-LABEL: swap_pair:
2323
#[no_mangle]
2424
pub fn swap_pair(x: &mut (i32, u32), y: &mut (i32, u32)) {
25-
// CHECK: movq (%[[ARG1]]), %[[T1:.+]]
2625
// CHECK: movq (%[[ARG2]]), %[[T2:.+]]
26+
// CHECK: movq (%[[ARG1]]), %[[T1:.+]]
2727
// CHECK: movq %[[T2]], (%[[ARG1]])
2828
// CHECK: movq %[[T1]], (%[[ARG2]])
2929
// CHECK: retq

tests/codegen/issues/issue-122805.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ revisions: OPT2 OPT3WINX64 OPT3LINX64
2-
//@ [OPT2] compile-flags: -O
2+
//@ [OPT2] compile-flags: -C opt-level=2
33
//@ [OPT3LINX64] compile-flags: -C opt-level=3
44
//@ [OPT3WINX64] compile-flags: -C opt-level=3
55
//@ [OPT3LINX64] only-linux

tests/run-make/rustc-help/help-v.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Options:
3232
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
3333
Compiler information to print on stdout
3434
-g Equivalent to -C debuginfo=2
35-
-O Equivalent to -C opt-level=2
35+
-O Equivalent to -C opt-level=3
3636
-o FILENAME Write output to <filename>
3737
--out-dir DIR Write output to compiler-chosen filename in <dir>
3838
--explain OPT Provide a detailed explanation of an error message

tests/run-make/rustc-help/help.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Options:
3232
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
3333
Compiler information to print on stdout
3434
-g Equivalent to -C debuginfo=2
35-
-O Equivalent to -C opt-level=2
35+
-O Equivalent to -C opt-level=3
3636
-o FILENAME Write output to <filename>
3737
--out-dir DIR Write output to compiler-chosen filename in <dir>
3838
--explain OPT Provide a detailed explanation of an error message

0 commit comments

Comments
 (0)