Skip to content

Commit 5546cb6

Browse files
committed
Auto merge of #109247 - saethlin:inline-without-inline, r=oli-obk
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.
2 parents 23eb90f + 3541775 commit 5546cb6

13 files changed

+16
-22
lines changed

compiler/rustc_mir_transform/src/inline.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,8 @@ impl<'tcx> Inliner<'tcx> {
350350
callsite: &CallSite<'tcx>,
351351
callee_attrs: &CodegenFnAttrs,
352352
) -> Result<(), &'static str> {
353-
match callee_attrs.inline {
354-
InlineAttr::Never => return Err("never inline hint"),
355-
InlineAttr::Always | InlineAttr::Hint => {}
356-
InlineAttr::None => {
357-
if self.tcx.sess.mir_opt_level() <= 2 {
358-
return Err("at mir-opt-level=2, only #[inline] is inlined");
359-
}
360-
}
353+
if let InlineAttr::Never = callee_attrs.inline {
354+
return Err("never inline hint");
361355
}
362356

363357
// Only inline local functions if they would be eligible for cross-crate

tests/codegen-units/item-collection/cross-crate-trait-method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags:-Zprint-mono-items=eager
1+
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
22

33
#![deny(dead_code)]
44
#![feature(start)]

tests/codegen-units/item-collection/function-as-argument.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//
2-
// compile-flags:-Zprint-mono-items=eager
1+
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
32

43
#![deny(dead_code)]
54
#![feature(start)]

tests/codegen-units/item-collection/generic-functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags:-Zprint-mono-items=eager
1+
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
22

33
#![deny(dead_code)]
44
#![feature(start)]

tests/codegen-units/item-collection/generic-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags:-Zprint-mono-items=eager
1+
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
22

33
#![deny(dead_code)]
44
#![feature(start)]

tests/codegen-units/item-collection/trait-implementations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags:-Zprint-mono-items=eager
1+
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
22

33
#![deny(dead_code)]
44
#![feature(start)]

tests/codegen-units/item-collection/trait-method-as-argument.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//
2-
// compile-flags:-Zprint-mono-items=eager
1+
// compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
32

43
#![deny(dead_code)]
54
#![feature(start)]

tests/codegen-units/item-collection/trait-method-default-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on
1+
// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on -Zinline-mir=no
22

33
#![deny(dead_code)]
44
#![feature(start)]

tests/codegen/array-map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn short_integer_map(x: [u32; 8]) -> [u32; 8] {
2121
pub fn short_integer_zip_map(x: [u32; 8], y: [u32; 8]) -> [u32; 8] {
2222
// CHECK: %[[A:.+]] = load <8 x i32>
2323
// CHECK: %[[B:.+]] = load <8 x i32>
24-
// CHECK: sub <8 x i32> %[[A]], %[[B]]
24+
// CHECK: sub <8 x i32> %[[B]], %[[A]]
2525
// CHECK: store <8 x i32>
2626
x.zip(y).map(|(x, y)| x - y)
2727
}

tests/codegen/inline-hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Checks that closures, constructors, and shims except
22
// for a drop glue receive inline hint by default.
33
//
4-
// compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0
4+
// compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0 -Zinline-mir=no
55
#![crate_type = "lib"]
66

77
pub fn f() {

tests/codegen/local-generics-in-exe-internalized.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -C no-prepopulate-passes -Zshare-generics=yes
1+
// compile-flags: -C no-prepopulate-passes -Zshare-generics=yes -Zinline-mir=no
22

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

tests/codegen/remap_path_prefix/auxiliary/xcrate-generic.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
#![crate_type = "lib"]
55

6-
pub fn foo<T>() {}
6+
pub fn foo<T: Default>() -> T {
7+
T::default()
8+
}

tests/codegen/remap_path_prefix/xcrate-generic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extern crate xcrate_generic;
88

99
pub fn foo() {
10-
xcrate_generic::foo::<u32>();
10+
println!("{}", xcrate_generic::foo::<u32>());
1111
}
1212

1313
// Here we check that local debuginfo is mapped correctly.

0 commit comments

Comments
 (0)