simplify-locals: Add yet to be optimized test cases

This commit is contained in:
Tomasz Miąsko 2020-10-26 00:00:00 +00:00
parent 1cd97cad6e
commit 124b63acf3
9 changed files with 294 additions and 0 deletions

View File

@ -0,0 +1,74 @@
// compile-flags: -C overflow-checks=off
#![feature(box_syntax)]
#![feature(thread_local)]
#[derive(Copy, Clone)]
enum E {
A,
B,
}
// EMIT_MIR simplify_locals.c.SimplifyLocals.diff
fn c() {
let bytes = [0u8; 10];
// Unused cast
let _: &[u8] = &bytes;
}
// EMIT_MIR simplify_locals.d1.SimplifyLocals.diff
fn d1() {
// Unused set discriminant
let _ = E::A;
}
// EMIT_MIR simplify_locals.d2.SimplifyLocals.diff
fn d2() {
// Unused set discriminant
{(10, E::A)}.1 = E::B;
}
// EMIT_MIR simplify_locals.r.SimplifyLocals.diff
fn r() {
let mut a = 1;
// Unused references
let _ = &a;
let _ = &mut a;
}
#[thread_local] static mut X: u32 = 0;
// EMIT_MIR simplify_locals.t1.SimplifyLocals.diff
fn t1() {
// Unused thread local
unsafe { X };
}
// EMIT_MIR simplify_locals.t2.SimplifyLocals.diff
fn t2() {
// Unused thread local
unsafe { &mut X };
}
// EMIT_MIR simplify_locals.t3.SimplifyLocals.diff
fn t3() {
// Unused thread local
unsafe { *&mut X };
}
// EMIT_MIR simplify_locals.t4.SimplifyLocals.diff
fn t4() -> u32 {
// Used thread local
unsafe { X + 1 }
}
fn main() {
c();
d1();
d2();
r();
t1();
t2();
t3();
t4();
}

View File

@ -0,0 +1,28 @@
- // MIR for `c` before SimplifyLocals
+ // MIR for `c` after SimplifyLocals
fn c() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:13:8: 13:8
let _1: [u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
let mut _2: &[u8]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
let mut _3: &[u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
- let _4: &[u8; 10]; // in scope 0 at $DIR/simplify-locals.rs:16:20: 16:26
scope 1 {
debug bytes => _1; // in scope 1 at $DIR/simplify-locals.rs:14:9: 14:14
scope 2 {
}
}
bb0: {
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
_1 = [const 0_u8; 10]; // scope 0 at $DIR/simplify-locals.rs:14:17: 14:26
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
_3 = &_1; // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
_2 = move _3 as &[u8] (Pointer(Unsize)); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
StorageDead(_2); // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:13:8: 17:2
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:17:1: 17:2
return; // scope 0 at $DIR/simplify-locals.rs:17:2: 17:2
}
}

View File

@ -0,0 +1,18 @@
- // MIR for `d1` before SimplifyLocals
+ // MIR for `d1` after SimplifyLocals
fn d1() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:20:9: 20:9
let mut _1: E; // in scope 0 at $DIR/simplify-locals.rs:22:13: 22:17
scope 1 {
}
bb0: {
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:22:13: 22:17
discriminant(_1) = 0; // scope 0 at $DIR/simplify-locals.rs:22:13: 22:17
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:22:17: 22:18
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:20:9: 23:2
return; // scope 0 at $DIR/simplify-locals.rs:23:2: 23:2
}
}

View File

@ -0,0 +1,42 @@
- // MIR for `d2` before SimplifyLocals
+ // MIR for `d2` after SimplifyLocals
fn d2() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:26:9: 26:9
let mut _1: E; // in scope 0 at $DIR/simplify-locals.rs:28:22: 28:26
- let mut _2: (i32, E); // in scope 0 at $DIR/simplify-locals.rs:28:5: 28:17
- let mut _3: E; // in scope 0 at $DIR/simplify-locals.rs:28:11: 28:15
+ let mut _2: E; // in scope 0 at $DIR/simplify-locals.rs:28:11: 28:15
bb0: {
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:28:22: 28:26
discriminant(_1) = 1; // scope 0 at $DIR/simplify-locals.rs:28:22: 28:26
- StorageLive(_2); // scope 0 at $DIR/simplify-locals.rs:28:5: 28:17
- StorageLive(_3); // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15
- discriminant(_3) = 0; // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15
- (_2.0: i32) = const 10_i32; // scope 0 at $DIR/simplify-locals.rs:28:6: 28:16
- (_2.1: E) = const E::A; // scope 0 at $DIR/simplify-locals.rs:28:6: 28:16
- // ty::Const
- // + ty: E
- // + val: Value(Scalar(0x00))
- // mir::Constant
- // + span: $DIR/simplify-locals.rs:28:6: 28:16
- // + literal: Const { ty: E, val: Value(Scalar(0x00)) }
- StorageDead(_3); // scope 0 at $DIR/simplify-locals.rs:28:15: 28:16
- (_2.1: E) = const E::B; // scope 0 at $DIR/simplify-locals.rs:28:5: 28:26
- // ty::Const
- // + ty: E
- // + val: Value(Scalar(0x01))
- // mir::Constant
- // + span: $DIR/simplify-locals.rs:28:5: 28:26
- // + literal: Const { ty: E, val: Value(Scalar(0x01)) }
+ StorageLive(_2); // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15
+ discriminant(_2) = 0; // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15
+ StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:28:15: 28:16
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:28:25: 28:26
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:28:26: 28:27
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:26:9: 29:2
return; // scope 0 at $DIR/simplify-locals.rs:29:2: 29:2
}
}

View File

@ -0,0 +1,31 @@
- // MIR for `r` before SimplifyLocals
+ // MIR for `r` after SimplifyLocals
fn r() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:32:8: 32:8
let mut _1: i32; // in scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
let mut _2: &i32; // in scope 0 at $DIR/simplify-locals.rs:35:13: 35:15
let mut _3: &mut i32; // in scope 0 at $DIR/simplify-locals.rs:36:13: 36:19
scope 1 {
debug a => _1; // in scope 1 at $DIR/simplify-locals.rs:33:9: 33:14
scope 2 {
scope 3 {
}
}
}
bb0: {
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:33:9: 33:14
_1 = const 1_i32; // scope 0 at $DIR/simplify-locals.rs:33:17: 33:18
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
_2 = &_1; // scope 1 at $DIR/simplify-locals.rs:35:13: 35:15
StorageDead(_2); // scope 1 at $DIR/simplify-locals.rs:35:15: 35:16
StorageLive(_3); // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
_3 = &mut _1; // scope 2 at $DIR/simplify-locals.rs:36:13: 36:19
StorageDead(_3); // scope 2 at $DIR/simplify-locals.rs:36:19: 36:20
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:32:8: 37:2
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:37:1: 37:2
return; // scope 0 at $DIR/simplify-locals.rs:37:2: 37:2
}
}

View File

@ -0,0 +1,25 @@
- // MIR for `t1` before SimplifyLocals
+ // MIR for `t1` after SimplifyLocals
fn t1() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:42:9: 42:9
- let _1: u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
- let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
+ let mut _1: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:44:14: 44:15
scope 1 {
}
bb0: {
- StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:44:5: 44:17
- StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
- _2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
- _1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
- StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
+ StorageLive(_1); // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
+ _1 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:44:14: 44:15
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:44:17: 44:18
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:42:9: 45:2
return; // scope 0 at $DIR/simplify-locals.rs:45:2: 45:2
}
}

View File

@ -0,0 +1,22 @@
- // MIR for `t2` before SimplifyLocals
+ // MIR for `t2` after SimplifyLocals
fn t2() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:48:9: 48:9
let _1: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:50:14: 50:20
let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:50:19: 50:20
scope 1 {
}
bb0: {
StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:50:5: 50:22
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
_2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:50:19: 50:20
_1 = &mut (*_2); // scope 1 at $DIR/simplify-locals.rs:50:14: 50:20
StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:50:22: 50:23
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:48:9: 51:2
return; // scope 0 at $DIR/simplify-locals.rs:51:2: 51:2
}
}

View File

@ -0,0 +1,32 @@
- // MIR for `t3` before SimplifyLocals
+ // MIR for `t3` after SimplifyLocals
fn t3() -> () {
let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:54:9: 54:9
- let _1: u32; // in scope 0 at $DIR/simplify-locals.rs:56:14: 56:21
- let mut _2: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
- let mut _3: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
+ let mut _1: &mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:15: 56:21
+ let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:56:20: 56:21
scope 1 {
}
bb0: {
- StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:56:5: 56:23
- StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
- StorageLive(_3); // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
- _3 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
- _2 = &mut (*_3); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
- _1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:56:14: 56:21
- StorageDead(_3); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
+ StorageLive(_1); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
+ StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
+ _2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:56:20: 56:21
+ _1 = &mut (*_2); // scope 1 at $DIR/simplify-locals.rs:56:15: 56:21
StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:56:23: 56:24
_0 = const (); // scope 0 at $DIR/simplify-locals.rs:54:9: 57:2
return; // scope 0 at $DIR/simplify-locals.rs:57:2: 57:2
}
}

View File

@ -0,0 +1,22 @@
- // MIR for `t4` before SimplifyLocals
+ // MIR for `t4` after SimplifyLocals
fn t4() -> u32 {
let mut _0: u32; // return place in scope 0 at $DIR/simplify-locals.rs:60:12: 60:15
let mut _1: u32; // in scope 0 at $DIR/simplify-locals.rs:62:14: 62:15
let mut _2: *mut u32; // in scope 0 at $DIR/simplify-locals.rs:62:14: 62:15
scope 1 {
}
bb0: {
StorageLive(_1); // scope 1 at $DIR/simplify-locals.rs:62:14: 62:15
StorageLive(_2); // scope 1 at $DIR/simplify-locals.rs:62:14: 62:15
_2 = &/*tls*/ mut X; // scope 1 at $DIR/simplify-locals.rs:62:14: 62:15
_1 = (*_2); // scope 1 at $DIR/simplify-locals.rs:62:14: 62:15
_0 = Add(move _1, const 1_u32); // scope 1 at $DIR/simplify-locals.rs:62:14: 62:19
StorageDead(_1); // scope 1 at $DIR/simplify-locals.rs:62:18: 62:19
StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:63:1: 63:2
return; // scope 0 at $DIR/simplify-locals.rs:63:2: 63:2
}
}