Skip to content

Commit 1965237

Browse files
committed
Iterate ReferencePropagation to fixpoint.
1 parent 25ef277 commit 1965237

14 files changed

+801
-400
lines changed

compiler/rustc_mir_transform/src/ref_prop.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ impl<'tcx> MirPass<'tcx> for ReferencePropagation {
7777
#[instrument(level = "trace", skip(self, tcx, body))]
7878
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
7979
debug!(def_id = ?body.source.def_id());
80-
propagate_ssa(tcx, body);
80+
while propagate_ssa(tcx, body) {}
8181
}
8282
}
8383

84-
fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
84+
fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
8585
let ssa = SsaLocals::new(body);
8686

8787
let mut replacer = compute_replacement(tcx, body, &ssa);
@@ -94,6 +94,8 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
9494
if replacer.any_replacement {
9595
crate::simplify::remove_unused_definitions(body);
9696
}
97+
98+
replacer.any_replacement
9799
}
98100

99101
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
let _5: &u8; // in scope 2 at $DIR/reference_prop.rs:+7:9: +7:17
2929
scope 3 {
3030
- debug reborrow => _5; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17
31-
+ debug reborrow => _1; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17
31+
+ debug reborrow => &_2; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17
3232
let _9: &i32; // in scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
3333
let mut _22: &std::option::Option<i32>; // in scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
3434
scope 4 {
@@ -50,14 +50,14 @@
5050
}
5151

5252
bb0: {
53-
StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+3:9: +3:19
53+
- StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+3:9: +3:19
5454
StorageLive(_2); // scope 0 at $DIR/reference_prop.rs:+3:27: +3:31
5555
_2 = const 5_u8; // scope 0 at $DIR/reference_prop.rs:+3:27: +3:31
56-
_1 = &mut _2; // scope 0 at $DIR/reference_prop.rs:+3:22: +3:31
56+
- _1 = &mut _2; // scope 0 at $DIR/reference_prop.rs:+3:22: +3:31
5757
- StorageLive(_3); // scope 1 at $DIR/reference_prop.rs:+4:9: +4:14
5858
_23 = const _; // scope 1 at $DIR/reference_prop.rs:+4:17: +4:24
5959
// mir::Constant
60-
// + span: $DIR/reference_prop.rs:463:17: 463:24
60+
// + span: $DIR/reference_prop.rs:535:17: 535:24
6161
// + literal: Const { ty: &T, val: Unevaluated(debuginfo, [], Some(promoted[2])) }
6262
- _3 = &((*_23).0: u8); // scope 1 at $DIR/reference_prop.rs:+4:17: +4:24
6363
- StorageLive(_5); // scope 2 at $DIR/reference_prop.rs:+7:9: +7:17
@@ -73,7 +73,7 @@
7373
- StorageLive(_9); // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
7474
_22 = const _; // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
7575
// mir::Constant
76-
// + span: $DIR/reference_prop.rs:470:14: 470:31
76+
// + span: $DIR/reference_prop.rs:542:14: 542:31
7777
// + literal: Const { ty: &Option<i32>, val: Unevaluated(debuginfo, [], Some(promoted[1])) }
7878
- _9 = &(((*_22) as Some).0: i32); // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
7979
- _6 = const (); // scope 4 at $DIR/reference_prop.rs:+11:36: +11:38
@@ -98,14 +98,14 @@
9898
StorageLive(_12); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
9999
_21 = const _; // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
100100
// mir::Constant
101-
// + span: $DIR/reference_prop.rs:475:83: 475:90
101+
// + span: $DIR/reference_prop.rs:547:83: 547:90
102102
// + literal: Const { ty: &[i32; 10], val: Unevaluated(debuginfo, [], Some(promoted[0])) }
103103
_12 = &(*_21); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
104104
StorageLive(_14); // scope 5 at $DIR/reference_prop.rs:+16:91: +16:93
105105
_14 = RangeFull; // scope 5 at $DIR/reference_prop.rs:+16:91: +16:93
106106
_11 = <[i32; 10] as Index<RangeFull>>::index(move _12, move _14) -> bb5; // scope 5 at $DIR/reference_prop.rs:+16:83: +16:94
107107
// mir::Constant
108-
// + span: $DIR/reference_prop.rs:475:83: 475:94
108+
// + span: $DIR/reference_prop.rs:547:83: 547:94
109109
// + literal: Const { ty: for<'a> fn(&'a [i32; 10], RangeFull) -> &'a <[i32; 10] as Index<RangeFull>>::Output {<[i32; 10] as Index<RangeFull>>::index}, val: Value(<ZST>) }
110110
}
111111

@@ -142,7 +142,7 @@
142142
- StorageDead(_5); // scope 2 at $DIR/reference_prop.rs:+18:1: +18:2
143143
- StorageDead(_3); // scope 1 at $DIR/reference_prop.rs:+18:1: +18:2
144144
StorageDead(_2); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
145-
StorageDead(_1); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
145+
- StorageDead(_1); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
146146
StorageDead(_11); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
147147
StorageDead(_10); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
148148
return; // scope 0 at $DIR/reference_prop.rs:+18:2: +18:2

tests/mir-opt/reference_prop.dominate_storage.ReferencePropagation.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_5 = (*_2); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
2525
_0 = opaque::<i32>(_5) -> bb3; // scope 0 at $DIR/reference_prop.rs:+16:13: +16:38
2626
// mir::Constant
27-
// + span: $DIR/reference_prop.rs:383:28: 383:34
27+
// + span: $DIR/reference_prop.rs:455:28: 455:34
2828
// + literal: Const { ty: fn(i32) {opaque::<i32>}, val: Value(<ZST>) }
2929
}
3030

tests/mir-opt/reference_prop.maybe_dead.ReferencePropagation.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
StorageDead(_3); // scope 0 at $DIR/reference_prop.rs:+21:13: +21:27
3030
_0 = opaque::<i32>(_6) -> bb2; // scope 0 at $DIR/reference_prop.rs:+22:13: +22:38
3131
// mir::Constant
32-
// + span: $DIR/reference_prop.rs:417:28: 417:34
32+
// + span: $DIR/reference_prop.rs:489:28: 489:34
3333
// + literal: Const { ty: fn(i32) {opaque::<i32>}, val: Value(<ZST>) }
3434
}
3535

3636
bb2: {
3737
_7 = (*_4); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
3838
_0 = opaque::<i32>(_7) -> bb3; // scope 0 at $DIR/reference_prop.rs:+27:13: +27:38
3939
// mir::Constant
40-
// + span: $DIR/reference_prop.rs:422:28: 422:34
40+
// + span: $DIR/reference_prop.rs:494:28: 494:34
4141
// + literal: Const { ty: fn(i32) {opaque::<i32>}, val: Value(<ZST>) }
4242
}
4343

4444
bb3: {
4545
_8 = (*_5); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
4646
_0 = opaque::<i32>(_8) -> bb4; // scope 0 at $DIR/reference_prop.rs:+33:13: +33:43
4747
// mir::Constant
48-
// + span: $DIR/reference_prop.rs:428:33: 428:39
48+
// + span: $DIR/reference_prop.rs:500:33: 500:39
4949
// + literal: Const { ty: fn(i32) {opaque::<i32>}, val: Value(<ZST>) }
5050
}
5151

tests/mir-opt/reference_prop.multiple_storage.ReferencePropagation.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_3 = (*_2); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
1717
_0 = opaque::<i32>(_3) -> bb1; // scope 0 at $DIR/reference_prop.rs:+14:13: +14:43
1818
// mir::Constant
19-
// + span: $DIR/reference_prop.rs:357:33: 357:39
19+
// + span: $DIR/reference_prop.rs:429:33: 429:39
2020
// + literal: Const { ty: fn(i32) {opaque::<i32>}, val: Value(<ZST>) }
2121
}
2222

tests/mir-opt/reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
let _3: *mut i32; // in scope 2 at $DIR/reference_prop.rs:+3:9: +3:13
1919
scope 3 {
2020
- debug xraw => _3; // in scope 3 at $DIR/reference_prop.rs:+3:9: +3:13
21-
+ debug xraw => _4; // in scope 3 at $DIR/reference_prop.rs:+3:9: +3:13
21+
+ debug xraw => &_1; // in scope 3 at $DIR/reference_prop.rs:+3:9: +3:13
2222
let _6: &i32; // in scope 3 at $DIR/reference_prop.rs:+4:9: +4:13
2323
scope 4 {
2424
- debug xshr => _6; // in scope 4 at $DIR/reference_prop.rs:+4:9: +4:13
25-
+ debug xshr => _2; // in scope 4 at $DIR/reference_prop.rs:+4:9: +4:13
25+
+ debug xshr => &_1; // in scope 4 at $DIR/reference_prop.rs:+4:9: +4:13
2626
let _7: i32; // in scope 4 at $DIR/reference_prop.rs:+6:9: +6:10
2727
scope 5 {
2828
debug a => _7; // in scope 5 at $DIR/reference_prop.rs:+6:9: +6:10
@@ -38,7 +38,7 @@
3838
StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+1:9: +1:14
3939
_1 = const 2_i32; // scope 0 at $DIR/reference_prop.rs:+1:17: +1:18
4040
- StorageLive(_2); // scope 1 at $DIR/reference_prop.rs:+2:9: +2:13
41-
_2 = &mut _1; // scope 1 at $DIR/reference_prop.rs:+2:16: +2:22
41+
- _2 = &mut _1; // scope 1 at $DIR/reference_prop.rs:+2:16: +2:22
4242
- StorageLive(_3); // scope 2 at $DIR/reference_prop.rs:+3:9: +3:13
4343
- StorageLive(_4); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:36
4444
- StorageLive(_5); // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
@@ -49,7 +49,6 @@
4949
- StorageDead(_4); // scope 2 at $DIR/reference_prop.rs:+3:36: +3:37
5050
- StorageLive(_6); // scope 3 at $DIR/reference_prop.rs:+4:9: +4:13
5151
- _6 = &(*_2); // scope 3 at $DIR/reference_prop.rs:+4:16: +4:22
52-
+ _4 = &raw mut _1; // scope 2 at $DIR/reference_prop.rs:+3:16: +3:26
5352
StorageLive(_7); // scope 4 at $DIR/reference_prop.rs:+6:9: +6:10
5453
- _7 = (*_6); // scope 4 at $DIR/reference_prop.rs:+6:13: +6:18
5554
- StorageLive(_8); // scope 5 at $DIR/reference_prop.rs:+7:5: +7:26

0 commit comments

Comments
 (0)