Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d63f10b

Browse files
committed
resolve code reviews
1 parent 7135168 commit d63f10b

20 files changed

+118
-96
lines changed

tests/mir-opt/dataflow-const-prop/array_index.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ fn main() {
1010
// CHECK: debug x => [[x:_.*]];
1111

1212
let x: u32 = [0, 1, 2, 3][2];
13-
// CHECK: bb{{[0-9]+}}: {
14-
// CHECK: [[array_lit]] = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
15-
// CHECK: [[index:_.*]] = const 2_usize;
16-
// CHECK: bb{{[0-9]+}}: {
17-
// CHECK-NOT: [[x]] = [[array_lit]][[[index]]];
13+
// CHECK: [[array_lit]] = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
14+
// CHECK-LABEL: assert(const true,
1815
// CHECK: [[x]] = [[array_lit]][2 of 3];
1916
}

tests/mir-opt/dataflow-const-prop/boolean_identities.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
// CHECK-LABEL: fn test(
66
pub fn test(x: bool, y: bool) -> bool {
7+
// CHECK-NOT: BitAnd(
8+
// CHECK-NOT: BitOr(
79
(y | true) & (x & false)
810
// CHECK: _0 = const false;
11+
// CHECK-NOT: BitAnd(
12+
// CHECK-NOT: BitOr(
913
}
1014

1115
// CHECK-LABEL: fn main(

tests/mir-opt/dataflow-const-prop/checked.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ fn main() {
1919
// CHECK: [[b]] = const 2_i32;
2020
let b = 2;
2121

22+
// CHECK-LABEL: assert(!const false,
2223
// CHECK: [[c]] = const 3_i32;
2324
let c = a + b;
2425

2526
// CHECK: [[d]] = const _;
2627
let d = i32::MAX;
2728

29+
// CHECK-LABEL: assert(!const true,
2830
// CHECK: [[e]] = const i32::MIN;
2931
let e = d + 1;
3032
}

tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ fn main() {
1717
// Verify that `DataflowConstProp` does not ICE trying to dereference it directly.
1818

1919
// CHECK: debug a => [[a:_.*]];
20-
// CHECK: scope {{[0-9]+}} (inlined <Box<[bool]> as Default>::default) {
21-
// CHECK: scope {{[0-9]+}} (inlined Unique::<[bool; 0]>::dangling) {
22-
// CHECK: scope {{[0-9]+}} (inlined NonNull::<[bool; 0]>::dangling) {
2320
// We may check other inlined functions as well...
2421

25-
// CHECK: bb{{[0-9]+}}: {
2622
// CHECK: [[box_obj:_.*]] = Box::<[bool]>(_3, const std::alloc::Global);
2723
// CHECK: [[a]] = A { foo: move [[box_obj]] };
24+
// FIXME: we do not have `const Box::<[bool]>` after constprop right now.
2825
let a: A = A { foo: Box::default() };
2926
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn simple() {
2020
// CHECK: [[e]] = const E::V1(0_i32);
2121
let e = E::V1(0);
2222

23-
// CHECK: switchInt(const 0_isize) -> [0: bb[[target_bb:[0-9]+]], 1: bb1, otherwise: bb2];
24-
// CHECK: bb[[target_bb]]: {
23+
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
24+
// CHECK: [[target_bb]]: {
2525
// CHECK: [[x]] = const 0_i32;
2626
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
2727
}
@@ -36,8 +36,8 @@ fn constant() {
3636

3737
// CHECK: [[e]] = const _;
3838
let e = C;
39-
// CHECK: switchInt(const 0_isize) -> [0: bb[[target_bb:[0-9]+]], 1: bb1, otherwise: bb2];
40-
// CHECK: bb[[target_bb]]: {
39+
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
40+
// CHECK: [[target_bb]]: {
4141
// CHECK: [[x]] = const 0_i32;
4242
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
4343
}
@@ -55,8 +55,8 @@ fn statics() {
5555

5656
// CHECK: [[e1]] = const E::V1(0_i32);
5757
let e1 = C;
58-
// CHECK: switchInt(const 0_isize) -> [0: bb[[target_bb1:[0-9]+]], 1: bb1, otherwise: bb2];
59-
// CHECK: bb[[target_bb]]: {
58+
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb1, otherwise: bb2];
59+
// CHECK: [[target_bb]]: {
6060
// CHECK: [[x1]] = const 0_i32;
6161
let x1 = match e1 { E::V1(x11) => x11, E::V2(x12) => x12 };
6262

@@ -65,7 +65,8 @@ fn statics() {
6565
// CHECK: [[t:_.*]] = const {alloc2: &&E};
6666
// CHECK: [[e2]] = (*[[t]]);
6767
let e2 = RC;
68-
// CHECK: switchInt(move _{{[0-9]+}}) -> [0: bb{{[0-9]+}}, 1: bb{{[0-9]+}}, otherwise: bb{{[0-9]+}}];
68+
69+
// CHECK: switchInt({{move _.*}}) -> {{.*}}
6970
// FIXME: add checks for x2. Currently, their MIRs are not symmetric in the two
7071
// switch branches.
7172
// One is `_9 = &(*_12) and another is `_9 = _11`. It is different from what we can
@@ -91,10 +92,10 @@ fn mutate_discriminant() -> u8 {
9192
place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize;
9293
// So we cannot know the value of this discriminant.
9394

94-
// CHECK: [[a:_.*]] = discriminant(_{{[0-9]*}});
95+
// CHECK: [[a:_.*]] = discriminant({{_.*}});
9596
let a = Discriminant(x);
9697

97-
// CHECK: switchInt([[a]]) -> [0: bb{{[0-9]+}}, otherwise: bb{{[0-9]+}}];
98+
// CHECK: switchInt([[a]]) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
9899
match a {
99100
0 => bb1,
100101
_ => bad,
@@ -118,7 +119,7 @@ fn multiple(x: bool, i: u8) {
118119
// CHECK: debug e => [[e:_.*]];
119120
// CHECK: debug x2 => [[x2:_.*]];
120121
let e = if x {
121-
// CHECK: [[e]] = Option::<u8>::Some(move _{{[0-9]+}});
122+
// CHECK: [[e]] = Option::<u8>::Some(move {{_.*}});
122123
Some(i)
123124
} else {
124125
// CHECK: [[e]] = Option::<u8>::None;
@@ -128,7 +129,7 @@ fn multiple(x: bool, i: u8) {
128129
// discriminant(e) => Top
129130
// (e as Some).0 => Top
130131
// CHECK: [[x2]] = const 0_u8;
131-
// CHECK: [[x2]] = _{{[0-9]+}}
132+
// CHECK: [[x2]] = {{_.*}};
132133
let x2 = match e { Some(i) => i, None => 0 };
133134
// Therefore, `x2` should be `Top` here, and no replacement shall happen.
134135
let y = x2;

tests/mir-opt/dataflow-const-prop/if.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ fn main() {
1010

1111
let a = 1;
1212

13-
// CHECK: switchInt(const true) -> [0: {{bb[0-9]+}}, otherwise: [[bb_first_true:bb[0-9]+]]];
14-
// CHECK: [[bb_first_true]]: {
13+
// CHECK: switchInt(const true) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
1514
// CHECK: [[b]] = const 2_i32;
1615
let b = if a == 1 { 2 } else { 3 };
1716

1817
// CHECK: [[c]] = const 3_i32;
1918
let c = b + 1;
2019

21-
// CHECK: switchInt(const true) -> [0: {{bb[0-9]+}}, otherwise: [[bb_second_true:bb[0-9]+]]];
22-
// CHECK: [[bb_second_true]]: {
20+
// CHECK: switchInt(const true) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
2321
// CHECK: [[d]] = const 1_i32;
2422
let d = if a == 1 { a } else { a + 1 };
2523

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
// EMIT_MIR issue_81605.f.DataflowConstProp.diff
44

5-
// CHECK-LABEL: fn f
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(
612
fn f() -> usize {
7-
// CHECK: switchInt(const true) -> [0: {{bb[0-9]+}}, otherwise: {{bb[0-9]+}}];
13+
// CHECK: switchInt(const true) -> [0: {{bb.*}}, otherwise: {{bb.*}}];
814
1 + if true { 1 } else { 2 }
915
// CHECK: _0 = const 2_usize;
1016
}

tests/mir-opt/dataflow-const-prop/large_array_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// EMIT_MIR large_array_index.main.DataflowConstProp.diff
66

7-
// CHECK-LABEL: fn main
7+
// CHECK-LABEL: fn main(
88
fn main() {
99
// check that we don't propagate this, because it's too large
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// unit-test: DataflowConstProp
22

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

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,45 @@ struct Delta<T> {
2929

3030
// EMIT_MIR offset_of.concrete.DataflowConstProp.diff
3131

32-
// CHECK-LABEL: fn concrete
32+
// CHECK-LABEL: fn concrete(
3333
fn concrete() {
3434
// CHECK: debug x => [[x:_.*]];
3535
// CHECK: debug y => [[y:_.*]];
3636
// CHECK: debug z0 => [[z0:_.*]];
3737
// CHECK: debug z1 => [[z1:_.*]];
3838

39-
// CHECK: [[x]] = must_use::<usize>(const 4_usize) -> [return: {{bb[0-9]+}}, unwind continue];
39+
// CHECK: [[x]] = must_use::<usize>(const 4_usize) -> {{.*}}
4040
let x = offset_of!(Alpha, x);
4141

42-
// CHECK: [[y]] = must_use::<usize>(const 0_usize) -> [return: {{bb[0-9]+}}, unwind continue];
42+
// CHECK: [[y]] = must_use::<usize>(const 0_usize) -> {{.*}}
4343
let y = offset_of!(Alpha, y);
4444

45-
// CHECK: [[z0]] = must_use::<usize>(const 2_usize) -> [return: {{bb[0-9]+}}, unwind continue];
45+
// CHECK: [[z0]] = must_use::<usize>(const 2_usize) -> {{.*}}
4646
let z0 = offset_of!(Alpha, z.0);
4747

48-
// CHECK: [[z1]] = must_use::<usize>(const 3_usize) -> [return: {{bb[0-9]+}}, unwind continue];
48+
// CHECK: [[z1]] = must_use::<usize>(const 3_usize) -> {{.*}}
4949
let z1 = offset_of!(Alpha, z.1);
5050
}
5151

5252
// EMIT_MIR offset_of.generic.DataflowConstProp.diff
5353

54-
// CHECK-LABEL: generic
54+
// CHECK-LABEL: fn generic(
5555
fn generic<T>() {
5656
// CHECK: debug gx => [[gx:_.*]];
5757
// CHECK: debug gy => [[gy:_.*]];
5858
// CHECK: debug dx => [[dx:_.*]];
5959
// CHECK: debug dy => [[dy:_.*]];
6060

61-
// CHECK: [[gx]] = must_use::<usize>(move {{_[0-9]+}}) -> [return: {{bb[0-9]+}}, unwind continue];
61+
// CHECK: [[gx]] = must_use::<usize>(move {{_.*}}) -> {{.*}}
6262
let gx = offset_of!(Gamma<T>, x);
6363

64-
// CHECK: [[gy]] = must_use::<usize>(move {{_[0-9]+}}) -> [return: {{bb[0-9]+}}, unwind continue];
64+
// CHECK: [[gy]] = must_use::<usize>(move {{_.*}}) -> {{.*}}
6565
let gy = offset_of!(Gamma<T>, y);
6666

67-
// CHECK: [[dx]] = must_use::<usize>(const 0_usize) -> [return: {{bb[0-9]+}}, unwind continue];
67+
// CHECK: [[dx]] = must_use::<usize>(const 0_usize) -> {{.*}}
6868
let dx = offset_of!(Delta<T>, x);
6969

70-
// CHECK: [[dy]] = must_use::<usize>(const 2_usize) -> [return: {{bb[0-9]+}}, unwind continue];
70+
// CHECK: [[dy]] = must_use::<usize>(const 2_usize) -> {{.*}}
7171
let dy = offset_of!(Delta<T>, y);
7272
}
7373

0 commit comments

Comments
 (0)