Skip to content

Commit

Permalink
Auto merge of #109247 - saethlin:inline-without-inline, r=oli-obk
Browse files Browse the repository at this point in the history
Permit MIR inlining without #[inline]

I noticed that there are at least a handful of portable-simd functions that have no `#[inline]` but compile to an assign + return.

I locally benchmarked inlining thresholds between 0 and 50 in increments of 5, and 50 seems to be the best. Interesting. That didn't include check builds though, ~maybe perf will have something to say about that~.

Perf has little useful to say about this. We generally regress all the check builds, as best as I can tell, due to a number of small codegen changes in a particular hot function in the compiler. Probably this is because we've nudged the inlining outcomes all over, and uses of `#[inline(always)]`/`#[inline(never)]` might need to be adjusted.
  • Loading branch information
bors committed Apr 17, 2023
2 parents 23eb90f + 3541775 commit 5546cb6
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 22 deletions.
10 changes: 2 additions & 8 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,8 @@ impl<'tcx> Inliner<'tcx> {
callsite: &CallSite<'tcx>,
callee_attrs: &CodegenFnAttrs,
) -> Result<(), &'static str> {
match callee_attrs.inline {
InlineAttr::Never => return Err("never inline hint"),
InlineAttr::Always | InlineAttr::Hint => {}
InlineAttr::None => {
if self.tcx.sess.mir_opt_level() <= 2 {
return Err("at mir-opt-level=2, only #[inline] is inlined");
}
}
if let InlineAttr::Never = callee_attrs.inline {
return Err("never inline hint");
}

// Only inline local functions if they would be eligible for cross-crate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
3 changes: 1 addition & 2 deletions tests/codegen-units/item-collection/function-as-argument.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/generic-functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// compile-flags:-Zprint-mono-items=eager
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on
// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on -Zinline-mir=no

#![deny(dead_code)]
#![feature(start)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/array-map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn short_integer_map(x: [u32; 8]) -> [u32; 8] {
pub fn short_integer_zip_map(x: [u32; 8], y: [u32; 8]) -> [u32; 8] {
// CHECK: %[[A:.+]] = load <8 x i32>
// CHECK: %[[B:.+]] = load <8 x i32>
// CHECK: sub <8 x i32> %[[A]], %[[B]]
// CHECK: sub <8 x i32> %[[B]], %[[A]]
// CHECK: store <8 x i32>
x.zip(y).map(|(x, y)| x - y)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/inline-hint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Checks that closures, constructors, and shims except
// for a drop glue receive inline hint by default.
//
// compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0
// compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0 -Zinline-mir=no
#![crate_type = "lib"]

pub fn f() {
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/local-generics-in-exe-internalized.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -C no-prepopulate-passes -Zshare-generics=yes
// compile-flags: -C no-prepopulate-passes -Zshare-generics=yes -Zinline-mir=no

// Check that local generics are internalized if they are in the same CGU

Expand Down
4 changes: 3 additions & 1 deletion tests/codegen/remap_path_prefix/auxiliary/xcrate-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

#![crate_type = "lib"]

pub fn foo<T>() {}
pub fn foo<T: Default>() -> T {
T::default()
}
2 changes: 1 addition & 1 deletion tests/codegen/remap_path_prefix/xcrate-generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern crate xcrate_generic;

pub fn foo() {
xcrate_generic::foo::<u32>();
println!("{}", xcrate_generic::foo::<u32>());
}

// Here we check that local debuginfo is mapped correctly.
Expand Down

0 comments on commit 5546cb6

Please sign in to comment.