Skip to content

Commit 7abf5cf

Browse files
Auto merge of #147614 - cjgillot:dest-prop-place, r=<try>
Perform DestinationPropagation on places.
2 parents e100792 + f4bd8b1 commit 7abf5cf

File tree

59 files changed

+820
-874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+820
-874
lines changed

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 198 additions & 59 deletions
Large diffs are not rendered by default.

tests/codegen-llvm/scalar-pair-bool.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
2020
pair
2121
}
2222

23-
// CHECK: define{{.*}}{ i1, i1 } @pair_and_or(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
23+
// CHECK: define{{.*}}{ i1, i1 } @pair_and_or(i1 noundef zeroext %0, i1 noundef zeroext %1)
2424
#[no_mangle]
2525
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
2626
// Make sure it can operate directly on the unpacked args
27-
// (but it might not be using simple and/or instructions)
28-
// CHECK-DAG: %_1.0
29-
// CHECK-DAG: %_1.1
27+
// CHECK: or i1 %0, %1
28+
// CHECK: and i1 %0, %1
3029
(a && b, a || b)
3130
}
3231

tests/mir-opt/debuginfo/dest_prop.remap_debuginfo_locals.DestinationPropagation.diff

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
fn remap_debuginfo_locals(_1: bool, _2: &bool) -> &bool {
55
- debug c => _3;
6-
+ debug c => _2;
6+
+ debug c => _0;
77
let mut _0: &bool;
88
let mut _3: &bool;
99
let mut _4: bool;
@@ -14,10 +14,10 @@
1414
- _4 = copy _1;
1515
- _3 = copy _2;
1616
- switchInt(copy _4) -> [1: bb1, otherwise: bb2];
17-
+ // DBG: _2 = &_1;
18-
+ nop;
17+
+ // DBG: _0 = &_1;
1918
+ nop;
2019
+ nop;
20+
+ _0 = copy _2;
2121
+ switchInt(copy _1) -> [1: bb1, otherwise: bb2];
2222
}
2323

@@ -29,7 +29,7 @@
2929
- StorageDead(_4);
3030
- _0 = copy _3;
3131
+ nop;
32-
+ _0 = copy _2;
32+
+ nop;
3333
return;
3434
}
3535
}

tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-abort.diff

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
let mut _3: u8;
99

1010
bb0: {
11-
StorageLive(_2);
12-
- StorageLive(_3);
13-
- _3 = copy _1;
14-
- _2 = dummy(move _3) -> [return: bb1, unwind unreachable];
15-
+ nop;
11+
- StorageLive(_2);
1612
+ nop;
17-
+ _2 = dummy(move _1) -> [return: bb1, unwind unreachable];
13+
StorageLive(_3);
14+
_3 = copy _1;
15+
- _2 = dummy(move _3) -> [return: bb1, unwind unreachable];
16+
+ _1 = dummy(move _3) -> [return: bb1, unwind unreachable];
1817
}
1918

2019
bb1: {
21-
- StorageDead(_3);
20+
StorageDead(_3);
21+
- _1 = move _2;
22+
- StorageDead(_2);
23+
+ nop;
2224
+ nop;
23-
_1 = move _2;
24-
StorageDead(_2);
2525
_0 = const ();
2626
return;
2727
}

tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
let mut _3: u8;
99

1010
bb0: {
11-
StorageLive(_2);
12-
- StorageLive(_3);
13-
- _3 = copy _1;
14-
- _2 = dummy(move _3) -> [return: bb1, unwind continue];
15-
+ nop;
11+
- StorageLive(_2);
1612
+ nop;
17-
+ _2 = dummy(move _1) -> [return: bb1, unwind continue];
13+
StorageLive(_3);
14+
_3 = copy _1;
15+
- _2 = dummy(move _3) -> [return: bb1, unwind continue];
16+
+ _1 = dummy(move _3) -> [return: bb1, unwind continue];
1817
}
1918

2019
bb1: {
21-
- StorageDead(_3);
20+
StorageDead(_3);
21+
- _1 = move _2;
22+
- StorageDead(_2);
23+
+ nop;
2224
+ nop;
23-
_1 = move _2;
24-
StorageDead(_2);
2525
_0 = const ();
2626
return;
2727
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ fn dummy(x: u8) -> u8 {
1010
fn foo(mut x: u8) {
1111
// CHECK-LABEL: fn foo(
1212
// CHECK: debug x => [[x:_.*]];
13-
// CHECK: dummy(move [[x]])
14-
// CHECK: [[x]] = move {{_.*}};
13+
// CHECK: [[tmp:_.*]] = copy [[x]];
14+
// CHECK: [[x]] = dummy(move [[tmp]])
15+
1516
// calling `dummy` to make a use of `x` that copyprop cannot eliminate
1617
x = dummy(x); // this will assign a local to `x`
1718
}

tests/mir-opt/dest-prop/cycle.main.DestinationPropagation.panic-abort.diff

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@
88
let _5: ();
99
let mut _6: i32;
1010
scope 1 {
11-
debug x => _1;
11+
- debug x => _1;
12+
+ debug x => _4;
1213
let _2: i32;
1314
scope 2 {
1415
- debug y => _2;
15-
+ debug y => _1;
16+
+ debug y => _4;
1617
let _3: i32;
1718
scope 3 {
1819
- debug z => _3;
19-
+ debug z => _1;
20+
+ debug z => _4;
2021
}
2122
}
2223
}
2324

2425
bb0: {
2526
- StorageLive(_1);
27+
- _1 = val() -> [return: bb1, unwind unreachable];
2628
+ nop;
27-
_1 = val() -> [return: bb1, unwind unreachable];
29+
+ _4 = val() -> [return: bb1, unwind unreachable];
2830
}
2931

3032
bb1: {
@@ -50,7 +52,7 @@
5052
- _5 = std::mem::drop::<i32>(move _6) -> [return: bb2, unwind unreachable];
5153
+ nop;
5254
+ nop;
53-
+ _5 = std::mem::drop::<i32>(move _1) -> [return: bb2, unwind unreachable];
55+
+ _5 = std::mem::drop::<i32>(move _4) -> [return: bb2, unwind unreachable];
5456
}
5557

5658
bb2: {

tests/mir-opt/dest-prop/cycle.main.DestinationPropagation.panic-unwind.diff

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@
88
let _5: ();
99
let mut _6: i32;
1010
scope 1 {
11-
debug x => _1;
11+
- debug x => _1;
12+
+ debug x => _4;
1213
let _2: i32;
1314
scope 2 {
1415
- debug y => _2;
15-
+ debug y => _1;
16+
+ debug y => _4;
1617
let _3: i32;
1718
scope 3 {
1819
- debug z => _3;
19-
+ debug z => _1;
20+
+ debug z => _4;
2021
}
2122
}
2223
}
2324

2425
bb0: {
2526
- StorageLive(_1);
27+
- _1 = val() -> [return: bb1, unwind continue];
2628
+ nop;
27-
_1 = val() -> [return: bb1, unwind continue];
29+
+ _4 = val() -> [return: bb1, unwind continue];
2830
}
2931

3032
bb1: {
@@ -50,7 +52,7 @@
5052
- _5 = std::mem::drop::<i32>(move _6) -> [return: bb2, unwind continue];
5153
+ nop;
5254
+ nop;
53-
+ _5 = std::mem::drop::<i32>(move _1) -> [return: bb2, unwind continue];
55+
+ _5 = std::mem::drop::<i32>(move _4) -> [return: bb2, unwind continue];
5456
}
5557

5658
bb2: {

tests/mir-opt/dest-prop/dead_stores_79191.f.DestinationPropagation.after.panic-abort.mir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ fn f(_1: usize) -> usize {
1111
}
1212

1313
bb0: {
14-
nop;
14+
StorageLive(_2);
1515
_2 = copy _1;
1616
_1 = const 5_usize;
1717
nop;
18+
_1 = copy _2;
1819
nop;
19-
_1 = move _2;
2020
nop;
2121
nop;
2222
nop;
@@ -25,7 +25,7 @@ fn f(_1: usize) -> usize {
2525

2626
bb1: {
2727
nop;
28-
nop;
28+
StorageDead(_2);
2929
return;
3030
}
3131
}

tests/mir-opt/dest-prop/dead_stores_79191.f.DestinationPropagation.after.panic-unwind.mir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ fn f(_1: usize) -> usize {
1111
}
1212

1313
bb0: {
14-
nop;
14+
StorageLive(_2);
1515
_2 = copy _1;
1616
_1 = const 5_usize;
1717
nop;
18+
_1 = copy _2;
1819
nop;
19-
_1 = move _2;
2020
nop;
2121
nop;
2222
nop;
@@ -25,7 +25,7 @@ fn f(_1: usize) -> usize {
2525

2626
bb1: {
2727
nop;
28-
nop;
28+
StorageDead(_2);
2929
return;
3030
}
3131
}

0 commit comments

Comments
 (0)