Skip to content

Commit

Permalink
Enable function merging when opt is for size
Browse files Browse the repository at this point in the history
It is, of course, natural to want to merge aliasing functions when
optimizing for code size, since that can eliminate several bytes.
And an exhaustive match helps make the code less brittle.
  • Loading branch information
workingjubilee committed Aug 5, 2022
1 parent b4151a4 commit 80c9012
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,11 @@ impl ModuleConfig {
{
MergeFunctions::Disabled => false,
MergeFunctions::Trampolines | MergeFunctions::Aliases => {
sess.opts.optimize == config::OptLevel::Default
|| sess.opts.optimize == config::OptLevel::Aggressive
use config::OptLevel::*;
match sess.opts.optimize {
Aggressive | Default | SizeMin | Size => true,
Less | No => false,
}
}
},

Expand Down
6 changes: 4 additions & 2 deletions src/test/codegen/merge-functions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// compile-flags: -O
// revisions: O Os
//[Os] compile-flags: -Copt-level=s
//[O] compile-flags: -O
#![crate_type = "lib"]

// CHECK: @func2 = {{.*}}alias{{.*}}@func1
// CHECK: @func{{2|1}} = {{.*}}alias{{.*}}@func{{1|2}}

#[no_mangle]
pub fn func1(c: char) -> bool {
Expand Down

0 comments on commit 80c9012

Please sign in to comment.