-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #106428 - saethlin:inline-diverging-functions, r=cjgillot
Permit the MIR inliner to inline diverging functions This heuristic prevents inlining of `hint::unreachable_unchecked`, which in turn makes `Option/Result::unwrap_unchecked` a bad inlining candidate. I looked through the changes to `core`, `alloc`, `std`, and `hashbrown` by hand and they all seem reasonable. Let's see how this looks in perf... --- Based on rustc-perf it looks like this regresses ctfe-stress, and the cachegrind diff indicates that this regression is in `InterpCx::statement`. I don't know how to do any deeper analysis because that function is _enormous_ in the try toolchain, which has no debuginfo in it. And a local build produces significantly different codegen for that function, even with LTO.
- Loading branch information
Showing
23 changed files
with
777 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![crate_type = "lib"] | ||
#![feature(unchecked_math)] | ||
|
||
// ignore-debug: the debug assertions prevent the inlining we are testing for | ||
// compile-flags: -Zmir-opt-level=2 -Zinline-mir | ||
|
||
// EMIT_MIR unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.diff | ||
// EMIT_MIR unchecked_shifts.unchecked_shl_unsigned_smaller.PreCodegen.after.mir | ||
pub unsafe fn unchecked_shl_unsigned_smaller(a: u16, b: u32) -> u16 { | ||
a.unchecked_shl(b) | ||
} | ||
|
||
// EMIT_MIR unchecked_shifts.unchecked_shr_signed_smaller.Inline.diff | ||
// EMIT_MIR unchecked_shifts.unchecked_shr_signed_smaller.PreCodegen.after.mir | ||
pub unsafe fn unchecked_shr_signed_smaller(a: i16, b: u32) -> i16 { | ||
a.unchecked_shr(b) | ||
} |
115 changes: 115 additions & 0 deletions
115
tests/mir-opt/inline/unchecked_shifts.unchecked_shl_unsigned_smaller.Inline.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
- // MIR for `unchecked_shl_unsigned_smaller` before Inline | ||
+ // MIR for `unchecked_shl_unsigned_smaller` after Inline | ||
|
||
fn unchecked_shl_unsigned_smaller(_1: u16, _2: u32) -> u16 { | ||
debug a => _1; // in scope 0 at $DIR/unchecked_shifts.rs:+0:46: +0:47 | ||
debug b => _2; // in scope 0 at $DIR/unchecked_shifts.rs:+0:54: +0:55 | ||
let mut _0: u16; // return place in scope 0 at $DIR/unchecked_shifts.rs:+0:65: +0:68 | ||
let mut _3: u16; // in scope 0 at $DIR/unchecked_shifts.rs:+1:5: +1:6 | ||
let mut _4: u32; // in scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22 | ||
+ scope 1 (inlined core::num::<impl u16>::unchecked_shl) { // at $DIR/unchecked_shifts.rs:10:7: 10:23 | ||
+ debug self => _3; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ debug rhs => _4; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ let mut _5: u16; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ let mut _6: std::option::Option<u16>; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ let mut _7: std::result::Result<u16, std::num::TryFromIntError>; // in scope 1 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ scope 2 { | ||
+ scope 3 (inlined Result::<u16, TryFromIntError>::ok) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ debug self => _7; // in scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ let mut _8: isize; // in scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ let _9: u16; // in scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ scope 4 { | ||
+ debug x => _9; // in scope 4 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ } | ||
+ scope 5 { | ||
+ scope 6 { | ||
+ debug x => const TryFromIntError(()); // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ } | ||
+ } | ||
+ } | ||
+ scope 7 (inlined #[track_caller] Option::<u16>::unwrap_unchecked) { // at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ debug self => _6; // in scope 7 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ let mut _10: &std::option::Option<u16>; // in scope 7 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ let mut _11: isize; // in scope 7 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ scope 8 { | ||
+ debug val => _5; // in scope 8 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ } | ||
+ scope 9 { | ||
+ scope 11 (inlined unreachable_unchecked) { // at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ scope 12 { | ||
+ scope 13 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL | ||
+ } | ||
+ } | ||
+ } | ||
+ } | ||
+ scope 10 (inlined Option::<u16>::is_some) { // at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ debug self => _10; // in scope 10 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ } | ||
+ } | ||
+ } | ||
+ } | ||
|
||
bb0: { | ||
StorageLive(_3); // scope 0 at $DIR/unchecked_shifts.rs:+1:5: +1:6 | ||
_3 = _1; // scope 0 at $DIR/unchecked_shifts.rs:+1:5: +1:6 | ||
StorageLive(_4); // scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22 | ||
_4 = _2; // scope 0 at $DIR/unchecked_shifts.rs:+1:21: +1:22 | ||
- _0 = core::num::<impl u16>::unchecked_shl(move _3, move _4) -> bb1; // scope 0 at $DIR/unchecked_shifts.rs:+1:5: +1:23 | ||
+ StorageLive(_5); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ StorageLive(_6); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ StorageLive(_7); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ _7 = <u32 as TryInto<u16>>::try_into(_4) -> bb1; // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
// mir::Constant | ||
- // + span: $DIR/unchecked_shifts.rs:10:7: 10:20 | ||
- // + literal: Const { ty: unsafe fn(u16, u32) -> u16 {core::num::<impl u16>::unchecked_shl}, val: Value(<ZST>) } | ||
+ // + span: $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ // + literal: Const { ty: fn(u32) -> Result<u16, <u32 as TryInto<u16>>::Error> {<u32 as TryInto<u16>>::try_into}, val: Value(<ZST>) } | ||
} | ||
|
||
bb1: { | ||
+ StorageLive(_9); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ _8 = discriminant(_7); // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ switchInt(move _8) -> [0: bb6, 1: bb4, otherwise: bb5]; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ } | ||
+ | ||
+ bb2: { | ||
+ StorageDead(_9); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ StorageDead(_7); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ StorageLive(_10); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ _11 = discriminant(_6); // scope 7 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ switchInt(move _11) -> [1: bb7, otherwise: bb5]; // scope 7 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ } | ||
+ | ||
+ bb3: { | ||
+ StorageDead(_5); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
StorageDead(_4); // scope 0 at $DIR/unchecked_shifts.rs:+1:22: +1:23 | ||
StorageDead(_3); // scope 0 at $DIR/unchecked_shifts.rs:+1:22: +1:23 | ||
return; // scope 0 at $DIR/unchecked_shifts.rs:+2:2: +2:2 | ||
+ } | ||
+ | ||
+ bb4: { | ||
+ _6 = Option::<u16>::None; // scope 6 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ goto -> bb2; // scope 5 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ } | ||
+ | ||
+ bb5: { | ||
+ unreachable; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ } | ||
+ | ||
+ bb6: { | ||
+ _9 = move ((_7 as Ok).0: u16); // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ _6 = Option::<u16>::Some(move _9); // scope 4 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ goto -> bb2; // scope 3 at $SRC_DIR/core/src/result.rs:LL:COL | ||
+ } | ||
+ | ||
+ bb7: { | ||
+ _5 = move ((_6 as Some).0: u16); // scope 7 at $SRC_DIR/core/src/option.rs:LL:COL | ||
+ StorageDead(_10); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ StorageDead(_6); // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ _0 = unchecked_shl::<u16>(_3, move _5) -> bb3; // scope 2 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ // mir::Constant | ||
+ // + span: $SRC_DIR/core/src/num/uint_macros.rs:LL:COL | ||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u16, u16) -> u16 {unchecked_shl::<u16>}, val: Value(<ZST>) } | ||
} | ||
} | ||
|
Oops, something went wrong.