Rollup merge of #60745 - wesleywiser:const_prop_into_terminators, r=oli-obk
Perform constant propagation into terminators Perform constant propagation into MIR `Assert` and `SwitchInt` `Terminator`s which in some cases allows them to be removed by the branch simplification pass. r? @oli-obk
This commit is contained in:
commit
5c84d779b2
5 changed files with 152 additions and 73 deletions
|
|
@ -23,7 +23,7 @@ fn main() {
|
|||
// bb0: {
|
||||
// ...
|
||||
// _5 = const true;
|
||||
// assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1;
|
||||
// assert(const true, "index out of bounds: the len is move _4 but the index is _3") -> bb1;
|
||||
// }
|
||||
// bb1: {
|
||||
// _1 = _2[_3];
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ fn main() {
|
|||
// bb0: {
|
||||
// ...
|
||||
// _2 = (const 2u32, const false);
|
||||
// assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
|
||||
// assert(!const false, "attempt to add with overflow") -> bb1;
|
||||
// }
|
||||
// END rustc.main.ConstProp.after.mir
|
||||
|
|
|
|||
38
src/test/mir-opt/const_prop/switch_int.rs
Normal file
38
src/test/mir-opt/const_prop/switch_int.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#[inline(never)]
|
||||
fn foo(_: i32) { }
|
||||
|
||||
fn main() {
|
||||
match 1 {
|
||||
1 => foo(0),
|
||||
_ => foo(-1),
|
||||
}
|
||||
}
|
||||
|
||||
// END RUST SOURCE
|
||||
// START rustc.main.ConstProp.before.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _1 = const 1i32;
|
||||
// switchInt(_1) -> [1i32: bb1, otherwise: bb2];
|
||||
// }
|
||||
// END rustc.main.ConstProp.before.mir
|
||||
// START rustc.main.ConstProp.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// switchInt(const 1i32) -> [1i32: bb1, otherwise: bb2];
|
||||
// }
|
||||
// END rustc.main.ConstProp.after.mir
|
||||
// START rustc.main.SimplifyBranches-after-const-prop.before.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _1 = const 1i32;
|
||||
// switchInt(const 1i32) -> [1i32: bb1, otherwise: bb2];
|
||||
// }
|
||||
// END rustc.main.SimplifyBranches-after-const-prop.before.mir
|
||||
// START rustc.main.SimplifyBranches-after-const-prop.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _1 = const 1i32;
|
||||
// goto -> bb1;
|
||||
// }
|
||||
// END rustc.main.SimplifyBranches-after-const-prop.after.mir
|
||||
|
|
@ -5,15 +5,15 @@ fn main() {
|
|||
}
|
||||
|
||||
// END RUST SOURCE
|
||||
// START rustc.main.SimplifyBranches-after-copy-prop.before.mir
|
||||
// START rustc.main.SimplifyBranches-after-const-prop.before.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// switchInt(const false) -> [false: bb3, otherwise: bb1];
|
||||
// }
|
||||
// END rustc.main.SimplifyBranches-after-copy-prop.before.mir
|
||||
// START rustc.main.SimplifyBranches-after-copy-prop.after.mir
|
||||
// END rustc.main.SimplifyBranches-after-const-prop.before.mir
|
||||
// START rustc.main.SimplifyBranches-after-const-prop.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// goto -> bb3;
|
||||
// }
|
||||
// END rustc.main.SimplifyBranches-after-copy-prop.after.mir
|
||||
// END rustc.main.SimplifyBranches-after-const-prop.after.mir
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue