Skip to content

Commit c97bde7

Browse files
Rollup merge of rust-lang#135099 - Shunpoco:116971-mir-opt-copy-prop, r=davidtwco
Add FileCheck annotations to mir-opt/copy-prop This resolves a part of rust-lang#116971 . This PR adds FileCheck annotations to test files under mir-opt/copy-prop.
2 parents 35ebdf9 + 620b9b1 commit c97bde7

16 files changed

+110
-89
lines changed

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

Lines changed: 8 additions & 1 deletion
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 we bail out when there are multiple assignments to the same local.
43
//@ test-mir-pass: CopyProp
@@ -12,6 +11,14 @@ fn cond() -> bool {
1211

1312
// EMIT_MIR branch.foo.CopyProp.diff
1413
fn foo() -> i32 {
14+
// CHECK-LABEL: fn foo(
15+
// CHECK: debug x => [[x:_.*]];
16+
// CHECK: debug y => [[y:_.*]];
17+
// CHECK: bb3: {
18+
// CHECK: [[y]] = copy [[x]];
19+
// CHECK: bb5: {
20+
// CHECK: [[y]] = copy [[x]];
21+
// CHECK: _0 = copy [[y]];
1522
let x = val();
1623

1724
let y = if cond() {

tests/mir-opt/copy-prop/calls.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// Check that CopyProp does propagate return values of call terminators.
32
//@ test-mir-pass: CopyProp
43
//@ needs-unwind
@@ -13,13 +12,25 @@ fn dummy(x: u8) -> u8 {
1312

1413
// EMIT_MIR calls.nrvo.CopyProp.diff
1514
fn nrvo() -> u8 {
15+
// CHECK-LABEL: fn nrvo(
16+
// CHECK: debug y => _0;
17+
// CHECK-NOT: StorageLive(_1);
18+
// CHECK-NOT: _1 = dummy(const 5_u8)
19+
// CHECK: _0 = dummy(const 5_u8)
20+
// CHECK-NOT: _0 = copy _1;
21+
// CHECK-NOT: StorageDead(_1);
1622
let y = dummy(5); // this should get NRVO
1723
y
1824
}
1925

2026
// EMIT_MIR calls.multiple_edges.CopyProp.diff
2127
#[custom_mir(dialect = "runtime", phase = "initial")]
2228
fn multiple_edges(t: bool) -> u8 {
29+
// CHECK-LABEL: fn multiple_edges(
30+
// CHECK: bb1: {
31+
// CHECK: _2 = dummy(const 13_u8)
32+
// CHECK: bb2: {
33+
// CHECK: _0 = copy _2;
2334
mir! {
2435
let x: u8;
2536
{

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

Lines changed: 22 additions & 2 deletions
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 CopyProp does not propagate an assignment to a function argument
43
// (doing so can break usages of the original argument value)
@@ -9,25 +8,46 @@ fn dummy(x: u8) -> u8 {
98

109
// EMIT_MIR copy_propagation_arg.foo.CopyProp.diff
1110
fn foo(mut x: u8) {
11+
// CHECK-LABEL: fn foo(
12+
// CHECK: debug x => [[x:_.*]];
13+
// CHECK: [[three:_.*]] = copy [[x]];
14+
// CHECK: [[two:_.*]] = dummy(move [[three]])
15+
// CHECK: [[x]] = move [[two]];
1216
// calling `dummy` to make a use of `x` that copyprop cannot eliminate
1317
x = dummy(x); // this will assign a local to `x`
1418
}
1519

1620
// EMIT_MIR copy_propagation_arg.bar.CopyProp.diff
1721
fn bar(mut x: u8) {
22+
// CHECK-LABEL: fn bar(
23+
// CHECK: debug x => [[x:_.*]];
24+
// CHECK: [[three:_.*]] = copy [[x]];
25+
// CHECK: dummy(move [[three]])
26+
// CHECK: [[x]] = const 5_u8;
1827
dummy(x);
1928
x = 5;
2029
}
2130

2231
// EMIT_MIR copy_propagation_arg.baz.CopyProp.diff
2332
fn baz(mut x: i32) -> i32 {
24-
// self-assignment to a function argument should be eliminated
33+
// CHECK-LABEL: fn baz(
34+
// CHECK: debug x => [[x:_.*]];
35+
// CHECK: [[x2:_.*]] = copy [[x]];
36+
// CHECK: [[x]] = move [[x2]];
37+
// CHECK: _0 = copy [[x]];
38+
// In the original case for DestProp, the self-assignment to a function argument is eliminated,
39+
// but in CopyProp it is not eliminated.
2540
x = x;
2641
x
2742
}
2843

2944
// EMIT_MIR copy_propagation_arg.arg_src.CopyProp.diff
3045
fn arg_src(mut x: i32) -> i32 {
46+
// CHECK-LABEL: fn arg_src(
47+
// CHECK: debug x => [[x:_.*]];
48+
// CHECK: debug y => [[y:_.*]];
49+
// CHECK: [[y]] = copy [[x]];
50+
// CHECK: [[x]] = const 123_i32;
3151
let y = x;
3252
x = 123; // Don't propagate this assignment to `y`
3353
y

tests/mir-opt/copy-prop/custom_move_arg.rs

Lines changed: 7 additions & 1 deletion
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: CopyProp
43

@@ -12,6 +11,13 @@ struct NotCopy(bool);
1211
// EMIT_MIR custom_move_arg.f.CopyProp.diff
1312
#[custom_mir(dialect = "runtime")]
1413
fn f(_1: NotCopy) {
14+
// CHECK-LABEL: fn f(
15+
// CHECK: bb0: {
16+
// CHECK-NOT: _2 = copy _1;
17+
// CHECK: _0 = opaque::<NotCopy>(copy _1)
18+
// CHECK: bb1: {
19+
// CHECK-NOT: _3 = move _2;
20+
// CHECK: _0 = opaque::<NotCopy>(copy _1)
1521
mir! {
1622
{
1723
let _2 = _1;

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

Lines changed: 12 additions & 1 deletion
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 CopyProp, and result in reasonable code.
43
//@ test-mir-pass: CopyProp
@@ -8,6 +7,18 @@ fn val() -> i32 {
87

98
// EMIT_MIR cycle.main.CopyProp.diff
109
fn main() {
10+
// CHECK-LABEL: fn main(
11+
// CHECK: debug x => [[x:_.*]];
12+
// CHECK: debug y => [[y:_.*]];
13+
// CHECK: debug z => [[y]];
14+
// CHECK-NOT: StorageLive([[y]]);
15+
// CHECK: [[y]] = copy [[x]];
16+
// CHECK-NOT: StorageLive(_3);
17+
// CHECK-NOT: _3 = copy [[y]];
18+
// CHECK-NOT: StorageLive(_4);
19+
// CHECK-NOT: _4 = copy _3;
20+
// CHECK-NOT: _1 = move _4;
21+
// CHECK: [[x]] = copy [[y]];
1122
let mut x = val();
1223
let y = x;
1324
let z = y;

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

Lines changed: 8 additions & 1 deletion
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: CopyProp
43

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

98
// EMIT_MIR dead_stores_79191.f.CopyProp.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]] = copy [[a]];
14+
// CHECK: [[a]] = const 5_usize;
15+
// CHECK: [[a]] = copy [[b]];
16+
// CHECK: [[c:_.*]] = copy [[a]]
17+
// CHECK: id::<usize>(move [[c]])
1118
let b = a;
1219
a = 5;
1320
a = b;

tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-abort.mir

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-unwind.mir

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/mir-opt/copy-prop/issue_107511.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
//@ test-mir-pass: CopyProp
43

54
// EMIT_MIR issue_107511.main.CopyProp.diff
65
fn main() {
6+
// CHECK-LABEL: fn main(
7+
// CHECK: debug i => [[i:_.*]];
8+
// CHECK-NOT: StorageLive([[i]]);
9+
// CHECK-NOT: StorageDead([[i]]);
710
let mut sum = 0;
811
let a = [0, 10, 20, 30];
912

0 commit comments

Comments
 (0)