Skip to content

Commit

Permalink
Auto merge of #100035 - workingjubilee:merge-functions, r=nikic
Browse files Browse the repository at this point in the history
Enable function merging when opt is for size

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.

Closes #98215.
  • Loading branch information
bors committed Aug 5, 2022
2 parents affe0d3 + 80c9012 commit 55f4641
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 @@ -256,8 +256,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 55f4641

Please sign in to comment.