2023-01-12 14:04:42 -06:00
|
|
|
// This example is interesting because the non-transitive version of `MaybeLiveLocals` would
|
|
|
|
// report that *all* of these stores are live.
|
|
|
|
//
|
|
|
|
//@ needs-unwind
|
2024-01-06 12:34:25 -06:00
|
|
|
//@ unit-test: DeadStoreElimination-initial
|
2022-05-09 19:12:03 -05:00
|
|
|
|
2023-01-12 14:04:42 -06:00
|
|
|
#![feature(core_intrinsics, custom_mir)]
|
|
|
|
use std::intrinsics::mir::*;
|
|
|
|
|
2022-05-09 19:12:03 -05:00
|
|
|
#[inline(never)]
|
|
|
|
fn cond() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2024-01-06 12:34:25 -06:00
|
|
|
// EMIT_MIR cycle.cycle.DeadStoreElimination-initial.diff
|
2023-01-12 14:04:42 -06:00
|
|
|
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
|
2022-05-09 19:12:03 -05:00
|
|
|
fn cycle(mut x: i32, mut y: i32, mut z: i32) {
|
2024-01-06 12:34:25 -06:00
|
|
|
// CHECK-LABEL: fn cycle(
|
|
|
|
// CHECK-NOT: {{_.*}} = {{_.*}};
|
|
|
|
// CHECK-NOT: {{_.*}} = move {{_.*}};
|
|
|
|
|
2023-01-12 14:04:42 -06:00
|
|
|
// We use custom MIR to avoid generating debuginfo, that would force to preserve writes.
|
|
|
|
mir!(
|
|
|
|
let condition: bool;
|
|
|
|
{
|
2023-12-26 12:31:52 -06:00
|
|
|
Call(condition = cond(), ReturnTo(bb1), UnwindContinue())
|
2023-01-12 14:04:42 -06:00
|
|
|
}
|
|
|
|
bb1 = {
|
|
|
|
match condition { true => bb2, _ => ret }
|
|
|
|
}
|
|
|
|
bb2 = {
|
|
|
|
let temp = z;
|
|
|
|
z = y;
|
|
|
|
y = x;
|
|
|
|
x = temp;
|
2023-12-26 12:31:52 -06:00
|
|
|
Call(condition = cond(), ReturnTo(bb1), UnwindContinue())
|
2023-01-12 14:04:42 -06:00
|
|
|
}
|
|
|
|
ret = {
|
|
|
|
Return()
|
|
|
|
}
|
|
|
|
)
|
2022-05-09 19:12:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
cycle(1, 2, 3);
|
|
|
|
}
|