-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deduplicate unreachable blocks, for real this time #110569
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// compile-flags: -Zmir-opt-level=2 -Zinline-mir | ||
// ignore-debug: standard library debug assertions add a panic that breaks this optimization | ||
#![crate_type = "lib"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated: should we make mir-opt tests "lib" by default, to avoid to list all the cases in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can. The codegen tests could do with the same treatment; I pulled this style of testing from them. There's a |
||
|
||
pub enum Thing { | ||
A, | ||
B, | ||
} | ||
|
||
// EMIT_MIR instcombine_duplicate_switch_targets_e2e.ub_if_b.PreCodegen.after.mir | ||
pub unsafe fn ub_if_b(t: Thing) -> Thing { | ||
match t { | ||
Thing::A => t, | ||
Thing::B => std::hint::unreachable_unchecked(), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// MIR for `ub_if_b` after PreCodegen | ||
|
||
fn ub_if_b(_1: Thing) -> Thing { | ||
debug t => _1; // in scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+0:23: +0:24 | ||
let mut _0: Thing; // return place in scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+0:36: +0:41 | ||
let mut _2: isize; // in scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+2:9: +2:17 | ||
scope 1 (inlined unreachable_unchecked) { // at $DIR/instcombine_duplicate_switch_targets_e2e.rs:14:21: 14:55 | ||
scope 2 { | ||
scope 3 (inlined unreachable_unchecked::runtime) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
_2 = discriminant(_1); // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+1:11: +1:12 | ||
switchInt(move _2) -> [0: bb2, otherwise: bb1]; // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+1:5: +1:12 | ||
} | ||
|
||
bb1: { | ||
unreachable; // scope 2 at $SRC_DIR/core/src/intrinsics.rs:LL:COL | ||
} | ||
|
||
bb2: { | ||
_0 = move _1; // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+2:21: +2:22 | ||
return; // scope 0 at $DIR/instcombine_duplicate_switch_targets_e2e.rs:+5:2: +5:2 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blessing the
ignore-debug
tests requires to recompile everything, which is tedious.Can you use the intrinsic directly and cook your own
unreachable_unchecked
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really wary of doing things like that. Modifying the mir-opt test for the convenience of testing is what caused this regression in the first place, and this test is already somewhat removed from the code that was reported to not optimize.