Skip to content

Commit 4c493db

Browse files
Rollup merge of rust-lang#122300 - CastilloDel:master, r=cjgillot
Add FileCheck annotations to mir-opt/dest-prop tests Part of rust-lang#116971, adds FileCheck annotations to MIR-opt tests in tests/mir-opt/dest-prop. I would like some feedback. Also, I don't know how to approach `union.rs`. I couldn't figure out what it is testing. r? cjgillot
2 parents 00167ab + 2d5a483 commit 4c493db

7 files changed

+48
-6
lines changed

tests/mir-opt/dest-prop/branch.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
//! Tests that assignment in both branches of an `if` are eliminated.
43
//@ test-mir-pass: DestinationPropagation
@@ -12,6 +11,10 @@ fn cond() -> bool {
1211

1312
// EMIT_MIR branch.foo.DestinationPropagation.diff
1413
fn foo() -> i32 {
14+
// CHECK-LABEL: fn foo(
15+
// CHECK: debug y => [[y:_.*]];
16+
// CHECK: [[y]] = val()
17+
// CHECK-NOT: [[y]] = {{_.*}};
1518
let x = val();
1619

1720
let y = if cond() {

tests/mir-opt/dest-prop/copy_propagation_arg.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// Check that DestinationPropagation does not propagate an assignment to a function argument
43
// (doing so can break usages of the original argument value)
@@ -9,25 +8,42 @@ fn dummy(x: u8) -> u8 {
98

109
// EMIT_MIR copy_propagation_arg.foo.DestinationPropagation.diff
1110
fn foo(mut x: u8) {
11+
// CHECK-LABEL: fn foo(
12+
// CHECK: debug x => [[x:_.*]];
13+
// CHECK: dummy(move [[x]])
14+
// CHECK: [[x]] = move {{_.*}};
1215
// calling `dummy` to make a use of `x` that copyprop cannot eliminate
1316
x = dummy(x); // this will assign a local to `x`
1417
}
1518

1619
// EMIT_MIR copy_propagation_arg.bar.DestinationPropagation.diff
1720
fn bar(mut x: u8) {
21+
// CHECK-LABEL: fn bar(
22+
// CHECK: debug x => [[x:_.*]];
23+
// CHECK: dummy(move [[x]])
24+
// CHECK: [[x]] = const 5_u8;
1825
dummy(x);
1926
x = 5;
2027
}
2128

2229
// EMIT_MIR copy_propagation_arg.baz.DestinationPropagation.diff
2330
fn baz(mut x: i32) -> i32 {
31+
// CHECK-LABEL: fn baz(
32+
// CHECK: debug x => [[x:_.*]];
33+
// CHECK-NOT: [[x]] =
2434
// self-assignment to a function argument should be eliminated
2535
x = x;
2636
x
2737
}
2838

2939
// EMIT_MIR copy_propagation_arg.arg_src.DestinationPropagation.diff
3040
fn arg_src(mut x: i32) -> i32 {
41+
// CHECK-LABEL: fn arg_src(
42+
// CHECK: debug x => [[x:_.*]];
43+
// CHECK: debug y => [[y:_.*]];
44+
// CHECK: [[y]] = [[x]]
45+
// CHECK: [[x]] = const 123_i32;
46+
// CHECK-NOT: {{_.*}} = [[y]];
3147
let y = x;
3248
x = 123; // Don't propagate this assignment to `y`
3349
y

tests/mir-opt/dest-prop/cycle.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
//! Tests that cyclic assignments don't hang DestinationPropagation, and result in reasonable code.
43
//@ test-mir-pass: DestinationPropagation
@@ -8,6 +7,10 @@ fn val() -> i32 {
87

98
// EMIT_MIR cycle.main.DestinationPropagation.diff
109
fn main() {
10+
// CHECK-LABEL: main(
11+
// CHECK: debug x => [[x:_.*]];
12+
// CHECK: [[x]] = val()
13+
// CHECK-NOT: [[x]] = {{_.*}};
1114
let mut x = val();
1215
let y = x;
1316
let z = y;

tests/mir-opt/dest-prop/dead_stores_79191.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
//@ test-mir-pass: DestinationPropagation
43

@@ -8,6 +7,13 @@ fn id<T>(x: T) -> T {
87

98
// EMIT_MIR dead_stores_79191.f.DestinationPropagation.after.mir
109
fn f(mut a: usize) -> usize {
10+
// CHECK-LABEL: fn f(
11+
// CHECK: debug a => [[a:_.*]];
12+
// CHECK: debug b => [[b:_.*]];
13+
// CHECK: [[b]] = [[a]];
14+
// CHECK: [[a]] = const 5_usize;
15+
// CHECK: [[a]] = move [[b]];
16+
// CHECK: id::<usize>(move [[a]])
1117
let b = a;
1218
a = 5;
1319
a = b;

tests/mir-opt/dest-prop/dead_stores_better.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// This is a copy of the `dead_stores_79191` test, except that we turn on DSE. This demonstrates
43
// that that pass enables this one to do more optimizations.
@@ -12,6 +11,13 @@ fn id<T>(x: T) -> T {
1211

1312
// EMIT_MIR dead_stores_better.f.DestinationPropagation.after.mir
1413
pub fn f(mut a: usize) -> usize {
14+
// CHECK-LABEL: fn f(
15+
// CHECK: debug a => [[a:_.*]];
16+
// CHECK: debug b => [[b:_.*]];
17+
// CHECK: [[b]] = [[a]];
18+
// CHECK: [[a]] = const 5_usize;
19+
// CHECK: [[a]] = move [[b]];
20+
// CHECK: id::<usize>(move [[a]])
1521
let b = a;
1622
a = 5;
1723
a = b;

tests/mir-opt/dest-prop/simple.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
//! Copy of `nrvo-simple.rs`, to ensure that full dest-prop handles it too.
43
//@ test-mir-pass: DestinationPropagation
54
// EMIT_MIR simple.nrvo.DestinationPropagation.diff
65
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
6+
// CHECK-LABEL: fn nrvo(
7+
// CHECK: debug init => [[init:_.*]];
8+
// CHECK: debug buf => [[buf:_.*]];
9+
// CHECK: [[buf]] = [const 0_u8; 1024];
10+
// CHECK-NOT: {{_.*}} = [[init]];
11+
// CHECK: move [[init]](move {{_.*}})
12+
// CHECK: {{_.*}} = [[buf]]
713
let mut buf = [0; 1024];
814
init(&mut buf);
915
buf

tests/mir-opt/dest-prop/union.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ fn val() -> u32 {
88

99
// EMIT_MIR union.main.DestinationPropagation.diff
1010
fn main() {
11+
// CHECK-LABEL: fn args(
12+
// CHECK: {{_.*}} = Un { us: const 1_u32 };
1113
union Un {
1214
us: u32,
1315
}

0 commit comments

Comments
 (0)