Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 418ee63

Browse files
authoredFeb 5, 2024
Unrolled build for rust-lang#119759
Rollup merge of rust-lang#119759 - sfzhu93:master, r=cjgillot Add FileCheck annotations to dataflow-const-prop tests part of rust-lang#116971. A few shadowing variable names are changed, so that it is easier to match the variable names in MIR using FileCheck syntax. Also, there's a FIXME in [enum.rs](https://github.com/rust-lang/rust/pull/119759/files#diff-7621f55327838e489a95ac99ae1e6126b37c57aff582594e6bee9d7e7e56fc58) because the MIR looks suspicious to me. It has been explained in the comments. r? cjgillot
2 parents 268dbbb + 699b59c commit 418ee63

32 files changed

+394
-87
lines changed
 
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// unit-test: DataflowConstProp
43
// EMIT_MIR_FOR_EACH_BIT_WIDTH
54

65
// EMIT_MIR array_index.main.DataflowConstProp.diff
6+
7+
// CHECK-LABEL: fn main() -> () {
78
fn main() {
9+
// CHECK: let mut [[array_lit:_.*]]: [u32; 4];
10+
// CHECK: debug x => [[x:_.*]];
11+
12+
// CHECK: [[array_lit]] = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
13+
// CHECK-NOT: {{_.*}} = Len(
14+
// CHECK-NOT: {{_.*}} = Lt(
15+
// CHECK-NOT: assert(move _
16+
// CHECK: {{_.*}} = const 4_usize;
17+
// CHECK: {{_.*}} = const true;
18+
// CHECK: assert(const true
19+
// CHECK: [[x]] = [[array_lit]][2 of 3];
820
let x: u32 = [0, 1, 2, 3][2];
921
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR boolean_identities.test.DataflowConstProp.diff
4+
5+
// CHECK-LABEL: fn test(
56
pub fn test(x: bool, y: bool) -> bool {
7+
// CHECK-NOT: BitAnd(
8+
// CHECK-NOT: BitOr(
69
(y | true) & (x & false)
10+
// CHECK: _0 = const false;
11+
// CHECK-NOT: BitAnd(
12+
// CHECK-NOT: BitOr(
713
}
814

15+
// CHECK-LABEL: fn main(
916
fn main() {
1017
test(true, false);
1118
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR cast.main.DataflowConstProp.diff
4+
5+
// CHECK-LABEL: fn main(
56
fn main() {
7+
// CHECK: debug a => [[a:_.*]];
8+
// CHECK: debug b => [[b:_.*]];
9+
10+
// CHECK: [[a]] = const 257_i32;
611
let a = 257;
12+
// CHECK: [[b]] = const 2_u8;
713
let b = a as u8 + 1;
814
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// compile-flags: -Coverflow-checks=on
43
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
54

65
// EMIT_MIR checked.main.DataflowConstProp.diff
76
#[allow(arithmetic_overflow)]
7+
8+
// CHECK-LABEL: fn main(
89
fn main() {
10+
// CHECK: debug a => [[a:_.*]];
11+
// CHECK: debug b => [[b:_.*]];
12+
// CHECK: debug c => [[c:_.*]];
13+
// CHECK: debug d => [[d:_.*]];
14+
// CHECK: debug e => [[e:_.*]];
15+
16+
// CHECK: [[a]] = const 1_i32;
917
let a = 1;
18+
19+
// CHECK: [[b]] = const 2_i32;
1020
let b = 2;
21+
22+
// CHECK: assert(!const false,
23+
// CHECK: [[c]] = const 3_i32;
1124
let c = a + b;
1225

26+
// CHECK: [[d]] = const _;
1327
let d = i32::MAX;
28+
29+
// CHECK: assert(!const true,
30+
// CHECK: [[e]] = const i32::MIN;
1431
let e = d + 1;
1532
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// compile-flags: -Zmir-enable-passes=+GVN,+Inline
43
// ignore-debug assertions change the output MIR
54
// EMIT_MIR_FOR_EACH_BIT_WIDTH
65
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
76

7+
// This test is to check ICE in issue [#115789](https://github.com/rust-lang/rust/issues/115789).
8+
89
struct A {
910
foo: Box<[bool]>,
1011
}
1112

1213
// EMIT_MIR default_boxed_slice.main.GVN.diff
1314
// EMIT_MIR default_boxed_slice.main.DataflowConstProp.diff
15+
16+
// CHECK-LABEL: fn main(
1417
fn main() {
1518
// ConstProp will create a constant of type `Box<[bool]>`.
19+
// FIXME: it is not yet a constant.
20+
1621
// Verify that `DataflowConstProp` does not ICE trying to dereference it directly.
22+
23+
// CHECK: debug a => [[a:_.*]];
24+
// We may check other inlined functions as well...
25+
26+
// CHECK: {{_.*}} = Box::<[bool]>(
27+
// FIXME: should be `{{_.*}} = const Box::<[bool]>`
1728
let a: A = A { foo: Box::default() };
1829
}

‎tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.32bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

‎tests/mir-opt/dataflow-const-prop/enum.constant.DataflowConstProp.64bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

‎tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let _6: u8;
1515
let _8: u8;
1616
scope 2 {
17-
debug x => _6;
17+
debug x2 => _6;
1818
let _9: u8;
1919
scope 4 {
2020
debug y => _9;

‎tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let _6: u8;
1515
let _8: u8;
1616
scope 2 {
17-
debug x => _6;
17+
debug x2 => _6;
1818
let _9: u8;
1919
scope 4 {
2020
debug y => _9;

‎tests/mir-opt/dataflow-const-prop/enum.rs

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_BIT_WIDTH
43

@@ -13,34 +12,76 @@ enum E {
1312
}
1413

1514
// EMIT_MIR enum.simple.DataflowConstProp.diff
15+
16+
// CHECK-LABEL: fn simple(
1617
fn simple() {
18+
// CHECK: debug e => [[e:_.*]];
19+
// CHECK: debug x => [[x:_.*]];
20+
// CHECK: [[e]] = const E::V1(0_i32);
1721
let e = E::V1(0);
18-
let x = match e { E::V1(x) => x, E::V2(x) => x };
22+
23+
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
24+
// CHECK: [[target_bb]]: {
25+
// CHECK: [[x]] = const 0_i32;
26+
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
1927
}
2028

2129
// EMIT_MIR enum.constant.DataflowConstProp.diff
30+
31+
// CHECK-LABEL: fn constant(
2232
fn constant() {
33+
// CHECK: debug e => [[e:_.*]];
34+
// CHECK: debug x => [[x:_.*]];
2335
const C: E = E::V1(0);
36+
37+
// CHECK: [[e]] = const _;
2438
let e = C;
25-
let x = match e { E::V1(x) => x, E::V2(x) => x };
39+
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
40+
// CHECK: [[target_bb]]: {
41+
// CHECK: [[x]] = const 0_i32;
42+
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
2643
}
2744

2845
// EMIT_MIR enum.statics.DataflowConstProp.diff
46+
47+
// CHECK-LABEL: fn statics(
2948
fn statics() {
49+
// CHECK: debug e1 => [[e1:_.*]];
50+
// CHECK: debug x1 => [[x1:_.*]];
51+
// CHECK: debug e2 => [[e2:_.*]];
52+
// CHECK: debug x2 => [[x2:_.*]];
53+
3054
static C: E = E::V1(0);
31-
let e = C;
32-
let x = match e { E::V1(x) => x, E::V2(x) => x };
55+
56+
// CHECK: [[e1]] = const E::V1(0_i32);
57+
let e1 = C;
58+
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
59+
// CHECK: [[target_bb]]: {
60+
// CHECK: [[x1]] = const 0_i32;
61+
let x1 = match e1 { E::V1(x11) => x11, E::V2(x12) => x12 };
3362

3463
static RC: &E = &E::V2(4);
35-
let e = RC;
36-
let x = match e { E::V1(x) => x, E::V2(x) => x };
64+
65+
// CHECK: [[t:_.*]] = const {alloc2: &&E};
66+
// CHECK: [[e2]] = (*[[t]]);
67+
let e2 = RC;
68+
69+
// CHECK: switchInt({{move _.*}}) -> {{.*}}
70+
// FIXME: add checks for x2. Currently, their MIRs are not symmetric in the two
71+
// switch branches.
72+
// One is `_9 = &(*_12) and another is `_9 = _11`. It is different from what we can
73+
// get by printing MIR directly. It is better to check if there are any bugs in the
74+
// MIR passes around this stage.
75+
let x2 = match e2 { E::V1(x21) => x21, E::V2(x22) => x22 };
3776
}
3877

3978
#[rustc_layout_scalar_valid_range_start(1)]
4079
#[rustc_nonnull_optimization_guaranteed]
4180
struct NonZeroUsize(usize);
4281

4382
// EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff
83+
84+
// CHECK-LABEL: fn mutate_discriminant(
4485
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
4586
fn mutate_discriminant() -> u8 {
4687
mir!(
@@ -50,7 +91,11 @@ fn mutate_discriminant() -> u8 {
5091
// This assignment overwrites the niche in which the discriminant is stored.
5192
place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize;
5293
// So we cannot know the value of this discriminant.
94+
95+
// CHECK: [[a:_.*]] = discriminant({{_.*}});
5396
let a = Discriminant(x);
97+
98+
// CHECK: switchInt([[a]]) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
5499
match a {
55100
0 => bb1,
56101
_ => bad,
@@ -68,18 +113,33 @@ fn mutate_discriminant() -> u8 {
68113
}
69114

70115
// EMIT_MIR enum.multiple.DataflowConstProp.diff
116+
// CHECK-LABEL: fn multiple(
71117
fn multiple(x: bool, i: u8) {
118+
// CHECK: debug x => [[x:_.*]];
119+
// CHECK: debug e => [[e:_.*]];
120+
// CHECK: debug x2 => [[x2:_.*]];
121+
// CHECK: debug y => [[y:_.*]];
72122
let e = if x {
123+
// CHECK: [[e]] = Option::<u8>::Some(move {{_.*}});
73124
Some(i)
74125
} else {
126+
// CHECK: [[e]] = Option::<u8>::None;
75127
None
76128
};
77129
// The dataflow state must have:
78130
// discriminant(e) => Top
79131
// (e as Some).0 => Top
80-
let x = match e { Some(i) => i, None => 0 };
81-
// Therefore, `x` should be `Top` here, and no replacement shall happen.
82-
let y = x;
132+
// CHECK: [[x2]] = const 0_u8;
133+
// CHECK: [[some:_.*]] = (({{_.*}} as Some).0: u8)
134+
// CHECK: [[x2]] = [[some]];
135+
let x2 = match e { Some(i) => i, None => 0 };
136+
137+
// Therefore, `x2` should be `Top` here, and no replacement shall happen.
138+
139+
// CHECK-NOT: [[y]] = const
140+
// CHECK: [[y]] = [[x2]];
141+
// CHECK-NOT: [[y]] = const
142+
let y = x2;
83143
}
84144

85145
fn main() {

‎tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.32bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

‎tests/mir-opt/dataflow-const-prop/enum.simple.DataflowConstProp.64bit.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
debug x => _2;
1515
}
1616
scope 3 {
17-
debug x => _4;
17+
debug x1 => _4;
1818
}
1919
scope 4 {
20-
debug x => _5;
20+
debug x2 => _5;
2121
}
2222
}
2323

‎tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.32bit.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
let mut _8: &&E;
1010
let mut _10: isize;
1111
scope 1 {
12-
debug e => _1;
12+
debug e1 => _1;
1313
let _3: i32;
1414
let _5: i32;
1515
let _6: i32;
1616
scope 2 {
17-
debug x => _3;
17+
debug x1 => _3;
1818
let _7: &E;
1919
scope 5 {
20-
debug e => _7;
20+
debug e2 => _7;
2121
let _9: &i32;
2222
let _11: &i32;
2323
let _12: &i32;
2424
scope 6 {
25-
debug x => _9;
25+
debug x2 => _9;
2626
}
2727
scope 7 {
28-
debug x => _11;
28+
debug x21 => _11;
2929
}
3030
scope 8 {
31-
debug x => _12;
31+
debug x22 => _12;
3232
}
3333
}
3434
}
3535
scope 3 {
36-
debug x => _5;
36+
debug x11 => _5;
3737
}
3838
scope 4 {
39-
debug x => _6;
39+
debug x12 => _6;
4040
}
4141
}
4242

‎tests/mir-opt/dataflow-const-prop/enum.statics.DataflowConstProp.64bit.diff

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
let mut _8: &&E;
1010
let mut _10: isize;
1111
scope 1 {
12-
debug e => _1;
12+
debug e1 => _1;
1313
let _3: i32;
1414
let _5: i32;
1515
let _6: i32;
1616
scope 2 {
17-
debug x => _3;
17+
debug x1 => _3;
1818
let _7: &E;
1919
scope 5 {
20-
debug e => _7;
20+
debug e2 => _7;
2121
let _9: &i32;
2222
let _11: &i32;
2323
let _12: &i32;
2424
scope 6 {
25-
debug x => _9;
25+
debug x2 => _9;
2626
}
2727
scope 7 {
28-
debug x => _11;
28+
debug x21 => _11;
2929
}
3030
scope 8 {
31-
debug x => _12;
31+
debug x22 => _12;
3232
}
3333
}
3434
}
3535
scope 3 {
36-
debug x => _5;
36+
debug x11 => _5;
3737
}
3838
scope 4 {
39-
debug x => _6;
39+
debug x12 => _6;
4040
}
4141
}
4242

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR if.main.DataflowConstProp.diff
4+
// CHECK-LABEL: fn main(
55
fn main() {
6+
// CHECK: debug b => [[b:_.*]];
7+
// CHECK: debug c => [[c:_.*]];
8+
// CHECK: debug d => [[d:_.*]];
9+
// CHECK: debug e => [[e:_.*]];
10+
611
let a = 1;
12+
13+
// CHECK: switchInt(const true) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
14+
// CHECK: [[b]] = const 2_i32;
715
let b = if a == 1 { 2 } else { 3 };
16+
17+
// CHECK: [[c]] = const 3_i32;
818
let c = b + 1;
919

20+
// CHECK: switchInt(const true) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
21+
// CHECK: [[d]] = const 1_i32;
1022
let d = if a == 1 { a } else { a + 1 };
23+
24+
// CHECK: [[e]] = const 2_i32;
1125
let e = d + 1;
1226
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// unit-test: DataflowConstProp
43
// compile-flags: -Zmir-enable-passes=+Inline
54

65
// EMIT_MIR inherit_overflow.main.DataflowConstProp.diff
6+
// CHECK-LABEL: fn main(
77
fn main() {
88
// After inlining, this will contain a `CheckedBinaryOp`.
99
// Propagating the overflow is ok as codegen will just skip emitting the panic.
10+
11+
// CHECK: {{_.*}} = const (0_u8, true);
12+
// CHECK: assert(!const true,
1013
let _ = <u8 as std::ops::Add>::add(255, 1);
1114
}

‎tests/mir-opt/dataflow-const-prop/issue_81605.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR issue_81605.f.DataflowConstProp.diff
4+
5+
// Plese find the original issue [here](https://github.com/rust-lang/rust/issues/81605).
6+
// This test program comes directly from the issue. Prior to this issue,
7+
// the compiler cannot simplify the return value of `f` into 2. This was
8+
// solved by adding a new MIR constant propagation based on dataflow
9+
// analysis in [#101168](https://github.com/rust-lang/rust/pull/101168).
10+
11+
// CHECK-LABEL: fn f(
512
fn f() -> usize {
13+
// CHECK: switchInt(const true) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
614
1 + if true { 1 } else { 2 }
15+
// CHECK: _0 = const 2_usize;
716
}
817

918
fn main() {
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
43
// EMIT_MIR_FOR_EACH_BIT_WIDTH
54

65
// EMIT_MIR large_array_index.main.DataflowConstProp.diff
6+
7+
// CHECK-LABEL: fn main(
78
fn main() {
89
// check that we don't propagate this, because it's too large
10+
11+
// CHECK: debug x => [[x:_.*]];
12+
// CHECK: [[array_lit:_.*]] = [const 0_u8; 5000];
13+
// CHECK: {{_.*}} = const 5000_usize;
14+
// CHECK: {{_.*}} = const true;
15+
// CHECK: assert(const true
16+
// CHECK: [[x]] = [[array_lit]][2 of 3];
917
let x: u8 = [0_u8; 5000][2];
1018
}

‎tests/mir-opt/dataflow-const-prop/mult_by_zero.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR mult_by_zero.test.DataflowConstProp.diff
4+
// CHECK-LABEL: fn test(
55
fn test(x : i32) -> i32 {
66
x * 0
7+
// CHECK: _0 = const 0_i32;
78
}
89

910
fn main() {

‎tests/mir-opt/dataflow-const-prop/offset_of.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
43

@@ -29,18 +28,46 @@ struct Delta<T> {
2928
}
3029

3130
// EMIT_MIR offset_of.concrete.DataflowConstProp.diff
31+
32+
// CHECK-LABEL: fn concrete(
3233
fn concrete() {
34+
// CHECK: debug x => [[x:_.*]];
35+
// CHECK: debug y => [[y:_.*]];
36+
// CHECK: debug z0 => [[z0:_.*]];
37+
// CHECK: debug z1 => [[z1:_.*]];
38+
39+
// CHECK: [[x]] = must_use::<usize>(const 4_usize) -> {{.*}}
3340
let x = offset_of!(Alpha, x);
41+
42+
// CHECK: [[y]] = must_use::<usize>(const 0_usize) -> {{.*}}
3443
let y = offset_of!(Alpha, y);
44+
45+
// CHECK: [[z0]] = must_use::<usize>(const 2_usize) -> {{.*}}
3546
let z0 = offset_of!(Alpha, z.0);
47+
48+
// CHECK: [[z1]] = must_use::<usize>(const 3_usize) -> {{.*}}
3649
let z1 = offset_of!(Alpha, z.1);
3750
}
3851

3952
// EMIT_MIR offset_of.generic.DataflowConstProp.diff
53+
54+
// CHECK-LABEL: fn generic(
4055
fn generic<T>() {
56+
// CHECK: debug gx => [[gx:_.*]];
57+
// CHECK: debug gy => [[gy:_.*]];
58+
// CHECK: debug dx => [[dx:_.*]];
59+
// CHECK: debug dy => [[dy:_.*]];
60+
61+
// CHECK: [[gx]] = must_use::<usize>(move {{_.*}}) -> {{.*}}
4162
let gx = offset_of!(Gamma<T>, x);
63+
64+
// CHECK: [[gy]] = must_use::<usize>(move {{_.*}}) -> {{.*}}
4265
let gy = offset_of!(Gamma<T>, y);
66+
67+
// CHECK: [[dx]] = must_use::<usize>(const 0_usize) -> {{.*}}
4368
let dx = offset_of!(Delta<T>, x);
69+
70+
// CHECK: [[dy]] = must_use::<usize>(const 2_usize) -> {{.*}}
4471
let dy = offset_of!(Delta<T>, y);
4572
}
4673

‎tests/mir-opt/dataflow-const-prop/ref_without_sb.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
// unit-test: DataflowConstProp
43

@@ -9,11 +8,23 @@ fn escape<T>(x: &T) {}
98
fn some_function() {}
109

1110
// EMIT_MIR ref_without_sb.main.DataflowConstProp.diff
11+
// CHECK-LABEL: fn main(
1212
fn main() {
13+
// CHECK: debug a => [[a:_.*]];
14+
// CHECK: debug b => [[b:_.*]];
15+
1316
let mut a = 0;
17+
18+
// CHECK: {{_.*}} = escape::<i32>(move {{_.*}}) -> {{.*}}
1419
escape(&a);
1520
a = 1;
21+
22+
// CHECK: {{_.*}} = some_function() -> {{.*}}
1623
some_function();
1724
// This should currently not be propagated.
25+
26+
// CHECK-NOT: [[b]] = const
27+
// CHECK: [[b]] = [[a]];
28+
// CHECK-NOT: [[b]] = const
1829
let b = a;
1930
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
43
// EMIT_MIR_FOR_EACH_BIT_WIDTH
54

65
// EMIT_MIR repeat.main.DataflowConstProp.diff
6+
// CHECK-LABEL: fn main(
77
fn main() {
8+
// CHECK: debug x => [[x:_.*]];
9+
10+
// CHECK: [[array_lit:_.*]] = [const 42_u32; 8];
11+
// CHECK-NOT: {{_.*}} = Len(
12+
// CHECK-NOT: {{_.*}} = Lt(
13+
// CHECK: {{_.*}} = const 8_usize;
14+
// CHECK: {{_.*}} = const true;
15+
// CHECK: assert(const true
16+
17+
// CHECK-NOT: [[t:_.*]] = [[array_lit]][_
18+
// CHECK: [[t:_.*]] = [[array_lit]][2 of 3];
19+
// CHECK: [[x]] = Add(move [[t]], const 0_u32);
820
let x: u32 = [42; 8][2] + 0;
921
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// The struct has scalar ABI, but is not a scalar type.
@@ -7,7 +6,15 @@
76
struct I32(i32);
87

98
// EMIT_MIR repr_transparent.main.DataflowConstProp.diff
9+
10+
// CHECK-LABEL: fn main(
1011
fn main() {
12+
// CHECK: debug x => [[x:_.*]];
13+
// CHECK: debug y => [[y:_.*]];
14+
15+
// CHECK: [[x]] = const I32(0_i32);
1116
let x = I32(0);
17+
18+
// CHECK: [[y]] = const I32(0_i32);
1219
let y = I32(x.0 + x.0);
1320
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR self_assign.main.DataflowConstProp.diff
4+
5+
// CHECK-LABEL: fn main(
56
fn main() {
7+
// CHECK: debug a => [[a:_.*]];
8+
// CHECK: debug b => [[b:_.*]];
9+
610
let mut a = 0;
11+
12+
// CHECK: [[a]] = Add(move {{_.*}}, const 1_i32);
713
a = a + 1;
14+
15+
// CHECK: [[a]] = move {{_.*}};
816
a = a;
917

18+
// CHECK: [[b]] = &[[a]];
1019
let mut b = &a;
20+
21+
// CHECK: [[b]] = move {{_.*}};
1122
b = b;
23+
24+
// CHECK: [[a]] = move {{_.*}};
1225
a = *b;
1326
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32

43
// EMIT_MIR self_assign_add.main.DataflowConstProp.diff
4+
5+
// CHECK-LABEL: fn main(
56
fn main() {
7+
// CHECK: debug a => [[a:_.*]];
68
let mut a = 0;
9+
10+
// CHECK: [[a]] = const 1_i32;
711
a += 1;
12+
13+
// CHECK: [[a]] = const 2_i32;
814
a += 1;
915
}

‎tests/mir-opt/dataflow-const-prop/sibling_ptr.rs

Lines changed: 6 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
// This attempts to modify `x.1` via a pointer derived from `addr_of_mut!(x.0)`.
43
// According to Miri, that is UB. However, T-opsem has not finalized that
@@ -10,11 +9,17 @@
109
// unit-test: DataflowConstProp
1110

1211
// EMIT_MIR sibling_ptr.main.DataflowConstProp.diff
12+
13+
// CHECK-LABEL: fn main(
1314
fn main() {
15+
// CHECK: debug x1 => [[x1:_.*]];
16+
1417
let mut x: (u8, u8) = (0, 0);
1518
unsafe {
1619
let p = std::ptr::addr_of_mut!(x.0);
1720
*p.add(1) = 1;
1821
}
22+
23+
// CHECK: [[x1]] = ({{_.*}}.1: u8);
1924
let x1 = x.1; // should not be propagated
2025
}
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// unit-test: DataflowConstProp
43
// compile-flags: -Zmir-enable-passes=+InstSimplify
54
// EMIT_MIR_FOR_EACH_BIT_WIDTH
65

76
// EMIT_MIR slice_len.main.DataflowConstProp.diff
7+
8+
// CHECK-LABEL: fn main(
89
fn main() {
10+
// CHECK: debug local => [[local:_.*]];
11+
// CHECK: debug constant => [[constant:_.*]];
12+
13+
// CHECK-NOT: {{_.*}} = Len(
14+
// CHECK-NOT: {{_.*}} = Lt(
15+
// CHECK-NOT: assert(move _
16+
// CHECK: {{_.*}} = const 3_usize;
17+
// CHECK: {{_.*}} = const true;
18+
// CHECK: assert(const true,
19+
20+
// CHECK: [[local]] = (*{{_.*}})[1 of 2];
921
let local = (&[1u32, 2, 3] as &[u32])[1];
1022

23+
// CHECK-NOT: {{_.*}} = Len(
24+
// CHECK-NOT: {{_.*}} = Lt(
25+
// CHECK-NOT: assert(move _
1126
const SLICE: &[u32] = &[1, 2, 3];
27+
// CHECK: {{_.*}} = const 3_usize;
28+
// CHECK: {{_.*}} = const true;
29+
// CHECK: assert(const true,
30+
31+
// CHECK-NOT: [[constant]] = (*{{_.*}})[_
32+
// CHECK: [[constant]] = (*{{_.*}})[1 of 2];
1233
let constant = SLICE[1];
1334
}

‎tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.32bit.diff

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,33 @@
3737
let _8: std::option::Option<S>;
3838
let _9: &[f32];
3939
scope 4 {
40-
debug a => _7;
41-
debug b => _8;
42-
debug c => _9;
40+
debug a1 => _7;
41+
debug b1 => _8;
42+
debug c1 => _9;
4343
let _11: f32;
4444
let _12: std::option::Option<S>;
4545
let _13: &[f32];
4646
scope 5 {
47-
debug a => _11;
48-
debug b => _12;
49-
debug c => _13;
47+
debug a2 => _11;
48+
debug b2 => _12;
49+
debug c2 => _13;
5050
let _15: SmallStruct;
5151
scope 6 {
5252
debug ss => _15;
5353
let _19: f32;
5454
let _20: std::option::Option<S>;
5555
let _21: &[f32];
5656
scope 7 {
57-
debug a => _19;
58-
debug b => _20;
59-
debug c => _21;
57+
debug a3 => _19;
58+
debug b3 => _20;
59+
debug c3 => _21;
6060
let _23: f32;
6161
let _24: std::option::Option<S>;
6262
let _25: &[f32];
6363
scope 8 {
64-
debug a => _23;
65-
debug b => _24;
66-
debug c => _25;
64+
debug a4 => _23;
65+
debug b4 => _24;
66+
debug c4 => _25;
6767
let _27: BigStruct;
6868
scope 9 {
6969
debug bs => _27;

‎tests/mir-opt/dataflow-const-prop/struct.main.DataflowConstProp.64bit.diff

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,33 @@
3737
let _8: std::option::Option<S>;
3838
let _9: &[f32];
3939
scope 4 {
40-
debug a => _7;
41-
debug b => _8;
42-
debug c => _9;
40+
debug a1 => _7;
41+
debug b1 => _8;
42+
debug c1 => _9;
4343
let _11: f32;
4444
let _12: std::option::Option<S>;
4545
let _13: &[f32];
4646
scope 5 {
47-
debug a => _11;
48-
debug b => _12;
49-
debug c => _13;
47+
debug a2 => _11;
48+
debug b2 => _12;
49+
debug c2 => _13;
5050
let _15: SmallStruct;
5151
scope 6 {
5252
debug ss => _15;
5353
let _19: f32;
5454
let _20: std::option::Option<S>;
5555
let _21: &[f32];
5656
scope 7 {
57-
debug a => _19;
58-
debug b => _20;
59-
debug c => _21;
57+
debug a3 => _19;
58+
debug b3 => _20;
59+
debug c3 => _21;
6060
let _23: f32;
6161
let _24: std::option::Option<S>;
6262
let _25: &[f32];
6363
scope 8 {
64-
debug a => _23;
65-
debug b => _24;
66-
debug c => _25;
64+
debug a4 => _23;
65+
debug b4 => _24;
66+
debug c4 => _25;
6767
let _27: BigStruct;
6868
scope 9 {
6969
debug bs => _27;
Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_BIT_WIDTH
43

@@ -12,27 +11,69 @@ struct SmallStruct(f32, Option<S>, &'static [f32]);
1211
struct BigStruct(f32, Option<S>, &'static [f32]);
1312

1413
// EMIT_MIR struct.main.DataflowConstProp.diff
14+
15+
// CHECK-LABEL: fn main(
1516
fn main() {
17+
// CHECK: debug s => [[s:_.*]];
18+
// CHECK: debug a => [[a:_.*]];
19+
// CHECK: debug b => [[b:_.*]];
20+
// CHECK: debug a1 => [[a1:_.*]];
21+
// CHECK: debug b1 => [[b1:_.*]];
22+
// CHECK: debug c1 => [[c1:_.*]];
23+
// CHECK: debug a2 => [[a2:_.*]];
24+
// CHECK: debug b2 => [[b2:_.*]];
25+
// CHECK: debug c2 => [[c2:_.*]];
26+
// CHECK: debug ss => [[ss:_.*]];
27+
// CHECK: debug a3 => [[a3:_.*]];
28+
// CHECK: debug b3 => [[b3:_.*]];
29+
// CHECK: debug c3 => [[c3:_.*]];
30+
// CHECK: debug a4 => [[a4:_.*]];
31+
// CHECK: debug b4 => [[b4:_.*]];
32+
// CHECK: debug c4 => [[c4:_.*]];
33+
// CHECK: debug bs => [[bs:_.*]];
34+
35+
// CHECK: [[s]] = const S(1_i32);
1636
let mut s = S(1);
37+
38+
// CHECK: [[a]] = const 3_i32;
1739
let a = s.0 + 2;
1840
s.0 = 3;
41+
42+
// CHECK: [[b]] = const 6_i32;
1943
let b = a + s.0;
2044

2145
const SMALL_VAL: SmallStruct = SmallStruct(4., Some(S(1)), &[]);
22-
let SmallStruct(a, b, c) = SMALL_VAL;
46+
47+
// CHECK: [[a1]] = const 4f32;
48+
// CHECK: [[b1]] = const Option::<S>::Some(S(1_i32));
49+
// CHECK: [[c1]] = ({{_.*}}.2: &[f32]);
50+
let SmallStruct(a1, b1, c1) = SMALL_VAL;
2351

2452
static SMALL_STAT: &SmallStruct = &SmallStruct(9., None, &[13.]);
25-
let SmallStruct(a, b, c) = *SMALL_STAT;
2653

27-
let ss = SmallStruct(a, b, c);
54+
// CHECK: [[a2]] = const 9f32;
55+
// CHECK: [[b2]] = ((*{{_.*}}).1: std::option::Option<S>);
56+
// CHECK: [[c2]] = ((*{{_.*}}).2: &[f32]);
57+
let SmallStruct(a2, b2, c2) = *SMALL_STAT;
58+
59+
// CHECK: [[ss]] = SmallStruct(const 9f32, move {{_.*}}, move {{_.*}});
60+
let ss = SmallStruct(a2, b2, c2);
2861

2962
const BIG_VAL: BigStruct = BigStruct(25., None, &[]);
30-
let BigStruct(a, b, c) = BIG_VAL;
63+
64+
// CHECK: [[a3]] = const 25f32;
65+
// CHECK: [[b3]] = ({{_.*}}.1: std::option::Option<S>);
66+
// CHECK: [[c3]] = ({{_.*}}.2: &[f32]);
67+
let BigStruct(a3, b3, c3) = BIG_VAL;
3168

3269
static BIG_STAT: &BigStruct = &BigStruct(82., Some(S(35)), &[45., 72.]);
33-
let BigStruct(a, b, c) = *BIG_STAT;
70+
// CHECK: [[a4]] = const 82f32;
71+
// CHECK: [[b4]] = const Option::<S>::Some(S(35_i32));
72+
// CHECK: [[c4]] = ((*{{_.*}}).2: &[f32]);
73+
let BigStruct(a4, b4, c4) = *BIG_STAT;
3474

3575
// We arbitrarily limit the size of synthetized values to 4 pointers.
3676
// `BigStruct` can be read, but we will keep a MIR aggregate for this.
37-
let bs = BigStruct(a, b, c);
77+
// CHECK: [[bs]] = BigStruct(const 82f32, const Option::<S>::Some(S(35_i32)), move {{_.*}});
78+
let bs = BigStruct(a4, b4, c4);
3879
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// unit-test: DataflowConstProp
43

54
fn foo(n: i32) {}
65

76
// EMIT_MIR terminator.main.DataflowConstProp.diff
7+
8+
// CHECK-LABEL: fn main(
89
fn main() {
910
let a = 1;
1011
// Checks that we propagate into terminators.
12+
// CHECK: {{_.*}} = foo(const 2_i32) -> [return: {{bb.*}}, unwind
1113
foo(a + 1);
1214
}
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
// skip-filecheck
21
// unit-test: DataflowConstProp
32
// EMIT_MIR_FOR_EACH_BIT_WIDTH
43

54
// EMIT_MIR tuple.main.DataflowConstProp.diff
5+
6+
// CHECK-LABEL: fn main(
67
fn main() {
8+
// CHECK: debug a => [[a:_.*]];
9+
// CHECK: debug b => [[b:_.*]];
10+
// CHECK: debug c => [[c:_.*]];
11+
// CHECK: debug d => [[d:_.*]];
12+
13+
// CHECK: [[a]] = const (1_i32, 2_i32);
714
let mut a = (1, 2);
15+
16+
// CHECK: [[b]] = const 6_i32;
817
let b = a.0 + a.1 + 3;
18+
19+
// CHECK: [[a]] = const (2_i32, 3_i32);
920
a = (2, 3);
21+
22+
// CHECK: [[c]] = const 11_i32;
1023
let c = a.0 + a.1 + b;
1124

25+
// CHECK: [[d]] = (const 6_i32, const (2_i32, 3_i32), const 11_i32);
1226
let d = (b, a, c);
1327
}

0 commit comments

Comments
 (0)
This repository has been archived.