Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42752cb

Browse files
committedFeb 10, 2024
Auto merge of #117206 - cjgillot:jump-threading-default, r=tmiasko
Enable MIR JumpThreading by default Mostly for perf r? `@ghost`
2 parents 6cc4843 + 014b29e commit 42752cb

27 files changed

+466
-1286
lines changed
 

‎compiler/rustc_mir_transform/src/const_goto.rs

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

‎compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const MAX_PLACES: usize = 100;
6060

6161
impl<'tcx> MirPass<'tcx> for JumpThreading {
6262
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
63-
sess.mir_opt_level() >= 4
63+
sess.mir_opt_level() >= 2
6464
}
6565

6666
#[instrument(skip_all level = "debug")]

‎compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ mod remove_place_mention;
5959
mod add_subtyping_projections;
6060
pub mod cleanup_post_borrowck;
6161
mod const_debuginfo;
62-
mod const_goto;
6362
mod const_prop;
6463
mod const_prop_lint;
6564
mod copy_prop;
@@ -103,7 +102,6 @@ mod remove_unneeded_drops;
103102
mod remove_zsts;
104103
mod required_consts;
105104
mod reveal_all;
106-
mod separate_const_switch;
107105
mod shim;
108106
mod ssa;
109107
// This pass is public to allow external drivers to perform MIR cleanup
@@ -590,7 +588,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
590588

591589
// Has to run after `slice::len` lowering
592590
&normalize_array_len::NormalizeArrayLen,
593-
&const_goto::ConstGoto,
594591
&ref_prop::ReferencePropagation,
595592
&sroa::ScalarReplacementOfAggregates,
596593
&match_branches::MatchBranchSimplification,
@@ -601,10 +598,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
601598
&dead_store_elimination::DeadStoreElimination::Initial,
602599
&gvn::GVN,
603600
&simplify::SimplifyLocals::AfterGVN,
604-
// Perform `SeparateConstSwitch` after SSA-based analyses, as cloning blocks may
605-
// destroy the SSA property. It should still happen before const-propagation, so the
606-
// latter pass will leverage the created opportunities.
607-
&separate_const_switch::SeparateConstSwitch,
608601
&dataflow_const_prop::DataflowConstProp,
609602
&const_debuginfo::ConstDebugInfo,
610603
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),

‎compiler/rustc_mir_transform/src/separate_const_switch.rs

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

‎tests/coverage/closure.cov-map

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,16 @@ Number of file 0 mappings: 24
3333
- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 3, 2)
3434
= (c1 + (c0 - c1))
3535

36-
Function name: closure::main::{closure#0}
37-
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 28, 05, 02, 14, 05, 02, 15, 02, 0a, 02, 02, 0a, 00, 0b, 07, 01, 09, 01, 06]
36+
Function name: closure::main::{closure#0} (unused)
37+
Raw bytes (24): 0x[01, 01, 00, 04, 00, 28, 05, 02, 14, 00, 02, 15, 02, 0a, 00, 02, 0a, 00, 0b, 00, 01, 09, 01, 06]
3838
Number of files: 1
3939
- file 0 => global file 1
40-
Number of expressions: 2
41-
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
42-
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
40+
Number of expressions: 0
4341
Number of file 0 mappings: 4
44-
- Code(Counter(0)) at (prev + 40, 5) to (start + 2, 20)
45-
- Code(Counter(1)) at (prev + 2, 21) to (start + 2, 10)
46-
- Code(Expression(0, Sub)) at (prev + 2, 10) to (start + 0, 11)
47-
= (c0 - c1)
48-
- Code(Expression(1, Add)) at (prev + 1, 9) to (start + 1, 6)
49-
= (c1 + (c0 - c1))
42+
- Code(Zero) at (prev + 40, 5) to (start + 2, 20)
43+
- Code(Zero) at (prev + 2, 21) to (start + 2, 10)
44+
- Code(Zero) at (prev + 2, 10) to (start + 0, 11)
45+
- Code(Zero) at (prev + 1, 9) to (start + 1, 6)
5046

5147
Function name: closure::main::{closure#10} (unused)
5248
Raw bytes (10): 0x[01, 01, 00, 01, 00, 9b, 01, 07, 00, 21]
@@ -148,20 +144,16 @@ Number of file 0 mappings: 6
148144
- Code(Expression(0, Add)) at (prev + 2, 9) to (start + 0, 10)
149145
= (c1 + (c0 - c1))
150146

151-
Function name: closure::main::{closure#18}
152-
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 19, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 12, 00, 13, 07, 01, 11, 01, 0e]
147+
Function name: closure::main::{closure#18} (unused)
148+
Raw bytes (24): 0x[01, 01, 00, 04, 00, 19, 0d, 02, 1c, 00, 02, 1d, 02, 12, 00, 02, 12, 00, 13, 00, 01, 11, 01, 0e]
153149
Number of files: 1
154150
- file 0 => global file 1
155-
Number of expressions: 2
156-
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
157-
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
151+
Number of expressions: 0
158152
Number of file 0 mappings: 4
159-
- Code(Counter(0)) at (prev + 25, 13) to (start + 2, 28)
160-
- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18)
161-
- Code(Expression(0, Sub)) at (prev + 2, 18) to (start + 0, 19)
162-
= (c0 - c1)
163-
- Code(Expression(1, Add)) at (prev + 1, 17) to (start + 1, 14)
164-
= (c1 + (c0 - c1))
153+
- Code(Zero) at (prev + 25, 13) to (start + 2, 28)
154+
- Code(Zero) at (prev + 2, 29) to (start + 2, 18)
155+
- Code(Zero) at (prev + 2, 18) to (start + 0, 19)
156+
- Code(Zero) at (prev + 1, 17) to (start + 1, 14)
165157

166158
Function name: closure::main::{closure#19}
167159
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 43, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 12, 00, 13, 07, 01, 11, 01, 0e]

‎tests/coverage/issue-84561.cov-map

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Number of file 0 mappings: 1
7777
- Code(Counter(0)) at (prev + 167, 9) to (start + 2, 10)
7878

7979
Function name: issue_84561::test3
80-
Raw bytes (436): 0x[01, 01, 41, 05, 09, 0d, 00, 15, 19, 12, 00, 15, 19, 21, 00, 1e, 00, 21, 00, 31, 00, 3d, 41, 2e, 45, 3d, 41, 42, 49, 45, 00, 3f, 51, 42, 49, 45, 00, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 92, 01, 55, 51, 00, 8f, 01, 5d, 92, 01, 55, 51, 00, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 82, 01, 65, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, 71, fe, 01, 82, 02, 71, 69, 6d, 69, 6d, 82, 02, 71, 69, 6d, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, ee, 01, 00, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 71, fe, 01, 82, 02, 71, 69, 6d, 33, 01, 08, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 12, 02, 05, 00, 1f, 0e, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 1e, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 1a, 04, 09, 05, 06, 31, 06, 05, 03, 06, 22, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 2e, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 2a, 05, 09, 03, 0a, 3f, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 3a, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 87, 01, 03, 05, 00, 0f, 8f, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 8a, 01, 02, 0d, 00, 13, 82, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 7e, 02, 0d, 00, 13, f3, 01, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, fb, 01, 02, 0d, 00, 17, 82, 02, 01, 14, 00, 1b, 71, 01, 15, 00, 1b, fe, 01, 02, 15, 00, 1b, f6, 01, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, ee, 01, 02, 05, 00, 0f, ea, 01, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02]
80+
Raw bytes (436): 0x[01, 01, 41, 05, 09, 0d, 00, 15, 19, 12, 00, 15, 19, 21, 00, 1e, 00, 21, 00, 31, 00, 3d, 41, 2e, 45, 3d, 41, 42, 49, 45, 00, 3f, 51, 42, 49, 45, 00, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 92, 01, 55, 51, 00, 8f, 01, 5d, 92, 01, 55, 51, 00, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 82, 01, 65, 87, 01, 61, 5d, 8a, 01, 8f, 01, 5d, 92, 01, 55, 51, 00, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, 00, fe, 01, 82, 02, 00, 69, 6d, 69, 6d, 82, 02, 00, 69, 6d, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, ee, 01, 00, f3, 01, 7d, 75, f6, 01, fb, 01, 79, 00, fe, 01, 82, 02, 00, 69, 6d, 33, 01, 08, 01, 03, 1c, 05, 04, 09, 01, 1c, 02, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 06, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 12, 02, 05, 00, 1f, 0e, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 1e, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 1a, 04, 09, 05, 06, 31, 06, 05, 03, 06, 22, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 2e, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 2a, 05, 09, 03, 0a, 3f, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 3a, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 87, 01, 03, 05, 00, 0f, 8f, 01, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 8a, 01, 02, 0d, 00, 13, 82, 01, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 7e, 02, 0d, 00, 13, f3, 01, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 75, 04, 0d, 00, 13, fb, 01, 02, 0d, 00, 17, 82, 02, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, fe, 01, 02, 15, 00, 1b, f6, 01, 04, 0d, 00, 13, 7d, 03, 09, 00, 19, ee, 01, 02, 05, 00, 0f, ea, 01, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02]
8181
Number of files: 1
8282
- file 0 => global file 1
8383
Number of expressions: 65
@@ -120,31 +120,31 @@ Number of expressions: 65
120120
- expression 36 operands: lhs = Counter(20), rhs = Zero
121121
- expression 37 operands: lhs = Counter(29), rhs = Expression(61, Sub)
122122
- expression 38 operands: lhs = Expression(62, Add), rhs = Counter(30)
123-
- expression 39 operands: lhs = Counter(28), rhs = Expression(63, Sub)
124-
- expression 40 operands: lhs = Expression(64, Sub), rhs = Counter(28)
123+
- expression 39 operands: lhs = Zero, rhs = Expression(63, Sub)
124+
- expression 40 operands: lhs = Expression(64, Sub), rhs = Zero
125125
- expression 41 operands: lhs = Counter(26), rhs = Counter(27)
126-
- expression 42 operands: lhs = Counter(28), rhs = Expression(63, Sub)
127-
- expression 43 operands: lhs = Expression(64, Sub), rhs = Counter(28)
126+
- expression 42 operands: lhs = Zero, rhs = Expression(63, Sub)
127+
- expression 43 operands: lhs = Expression(64, Sub), rhs = Zero
128128
- expression 44 operands: lhs = Counter(26), rhs = Counter(27)
129129
- expression 45 operands: lhs = Counter(26), rhs = Counter(27)
130-
- expression 46 operands: lhs = Expression(64, Sub), rhs = Counter(28)
130+
- expression 46 operands: lhs = Expression(64, Sub), rhs = Zero
131131
- expression 47 operands: lhs = Counter(26), rhs = Counter(27)
132132
- expression 48 operands: lhs = Expression(62, Add), rhs = Counter(30)
133-
- expression 49 operands: lhs = Counter(28), rhs = Expression(63, Sub)
134-
- expression 50 operands: lhs = Expression(64, Sub), rhs = Counter(28)
133+
- expression 49 operands: lhs = Zero, rhs = Expression(63, Sub)
134+
- expression 50 operands: lhs = Expression(64, Sub), rhs = Zero
135135
- expression 51 operands: lhs = Counter(26), rhs = Counter(27)
136136
- expression 52 operands: lhs = Expression(60, Add), rhs = Counter(31)
137137
- expression 53 operands: lhs = Counter(29), rhs = Expression(61, Sub)
138138
- expression 54 operands: lhs = Expression(62, Add), rhs = Counter(30)
139-
- expression 55 operands: lhs = Counter(28), rhs = Expression(63, Sub)
140-
- expression 56 operands: lhs = Expression(64, Sub), rhs = Counter(28)
139+
- expression 55 operands: lhs = Zero, rhs = Expression(63, Sub)
140+
- expression 56 operands: lhs = Expression(64, Sub), rhs = Zero
141141
- expression 57 operands: lhs = Counter(26), rhs = Counter(27)
142142
- expression 58 operands: lhs = Expression(59, Sub), rhs = Zero
143143
- expression 59 operands: lhs = Expression(60, Add), rhs = Counter(31)
144144
- expression 60 operands: lhs = Counter(29), rhs = Expression(61, Sub)
145145
- expression 61 operands: lhs = Expression(62, Add), rhs = Counter(30)
146-
- expression 62 operands: lhs = Counter(28), rhs = Expression(63, Sub)
147-
- expression 63 operands: lhs = Expression(64, Sub), rhs = Counter(28)
146+
- expression 62 operands: lhs = Zero, rhs = Expression(63, Sub)
147+
- expression 63 operands: lhs = Expression(64, Sub), rhs = Zero
148148
- expression 64 operands: lhs = Counter(26), rhs = Counter(27)
149149
Number of file 0 mappings: 51
150150
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 28)
@@ -200,24 +200,24 @@ Number of file 0 mappings: 51
200200
- Code(Expression(31, Sub)) at (prev + 2, 13) to (start + 0, 19)
201201
= (((c23 + (((c20 - Zero) + c21) - c23)) - c24) - c25)
202202
- Code(Expression(60, Add)) at (prev + 3, 5) to (start + 0, 15)
203-
= (c29 + ((c28 + ((c26 - c27) - c28)) - c30))
203+
= (c29 + ((Zero + ((c26 - c27) - Zero)) - c30))
204204
- Code(Counter(26)) at (prev + 1, 12) to (start + 0, 19)
205205
- Code(Counter(27)) at (prev + 1, 13) to (start + 3, 14)
206206
- Code(Counter(29)) at (prev + 4, 13) to (start + 0, 19)
207207
- Code(Expression(62, Add)) at (prev + 2, 13) to (start + 0, 23)
208-
= (c28 + ((c26 - c27) - c28))
208+
= (Zero + ((c26 - c27) - Zero))
209209
- Code(Expression(64, Sub)) at (prev + 1, 20) to (start + 0, 27)
210210
= (c26 - c27)
211-
- Code(Counter(28)) at (prev + 1, 21) to (start + 0, 27)
211+
- Code(Zero) at (prev + 1, 21) to (start + 0, 27)
212212
- Code(Expression(63, Sub)) at (prev + 2, 21) to (start + 0, 27)
213-
= ((c26 - c27) - c28)
213+
= ((c26 - c27) - Zero)
214214
- Code(Expression(61, Sub)) at (prev + 4, 13) to (start + 0, 19)
215-
= ((c28 + ((c26 - c27) - c28)) - c30)
215+
= ((Zero + ((c26 - c27) - Zero)) - c30)
216216
- Code(Counter(31)) at (prev + 3, 9) to (start + 0, 25)
217217
- Code(Expression(59, Sub)) at (prev + 2, 5) to (start + 0, 15)
218-
= ((c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - c31)
218+
= ((c29 + ((Zero + ((c26 - c27) - Zero)) - c30)) - c31)
219219
- Code(Expression(58, Sub)) at (prev + 3, 9) to (start + 0, 34)
220-
= (((c29 + ((c28 + ((c26 - c27) - c28)) - c30)) - c31) - Zero)
220+
= (((c29 + ((Zero + ((c26 - c27) - Zero)) - c30)) - c31) - Zero)
221221
- Code(Zero) at (prev + 2, 5) to (start + 0, 15)
222222
- Code(Zero) at (prev + 3, 9) to (start + 0, 44)
223223
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)

‎tests/coverage/try_error_result.cov-map

Lines changed: 103 additions & 134 deletions
Large diffs are not rendered by default.

‎tests/coverage/yield.cov-map

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Function name: yield::main
2-
Raw bytes (106): 0x[01, 01, 0b, 05, 09, 0d, 11, 22, 15, 0d, 11, 11, 15, 22, 15, 0d, 11, 22, 15, 0d, 11, 19, 1d, 25, 29, 10, 01, 07, 01, 01, 16, 01, 06, 0b, 00, 2e, 0d, 01, 27, 00, 29, 03, 01, 0e, 00, 34, 0d, 02, 0b, 00, 2e, 22, 01, 22, 00, 27, 1e, 00, 2c, 00, 2e, 13, 01, 0e, 00, 34, 1e, 03, 09, 00, 16, 1e, 07, 0b, 00, 2e, 21, 01, 27, 00, 29, 27, 01, 0e, 00, 34, 21, 02, 0b, 00, 2e, 2d, 01, 27, 00, 29, 2b, 01, 0e, 00, 34, 2d, 02, 01, 00, 02]
2+
Raw bytes (106): 0x[01, 01, 0b, 05, 00, 0d, 11, 22, 15, 0d, 11, 11, 15, 22, 15, 0d, 11, 22, 15, 0d, 11, 19, 1d, 25, 29, 10, 01, 07, 01, 01, 16, 01, 06, 0b, 00, 2e, 0d, 01, 27, 00, 29, 03, 01, 0e, 00, 34, 0d, 02, 0b, 00, 2e, 22, 01, 22, 00, 27, 1e, 00, 2c, 00, 2e, 13, 01, 0e, 00, 34, 1e, 03, 09, 00, 16, 1e, 07, 0b, 00, 2e, 21, 01, 27, 00, 29, 27, 01, 0e, 00, 34, 21, 02, 0b, 00, 2e, 2d, 01, 27, 00, 29, 2b, 01, 0e, 00, 34, 2d, 02, 01, 00, 02]
33
Number of files: 1
44
- file 0 => global file 1
55
Number of expressions: 11
6-
- expression 0 operands: lhs = Counter(1), rhs = Counter(2)
6+
- expression 0 operands: lhs = Counter(1), rhs = Zero
77
- expression 1 operands: lhs = Counter(3), rhs = Counter(4)
88
- expression 2 operands: lhs = Expression(8, Sub), rhs = Counter(5)
99
- expression 3 operands: lhs = Counter(3), rhs = Counter(4)
@@ -19,7 +19,7 @@ Number of file 0 mappings: 16
1919
- Code(Counter(0)) at (prev + 6, 11) to (start + 0, 46)
2020
- Code(Counter(3)) at (prev + 1, 39) to (start + 0, 41)
2121
- Code(Expression(0, Add)) at (prev + 1, 14) to (start + 0, 52)
22-
= (c1 + c2)
22+
= (c1 + Zero)
2323
- Code(Counter(3)) at (prev + 2, 11) to (start + 0, 46)
2424
- Code(Expression(8, Sub)) at (prev + 1, 34) to (start + 0, 39)
2525
= (c3 - c4)

‎tests/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff

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

‎tests/mir-opt/const_goto.rs

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

‎tests/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
- // MIR for `f` before JumpThreading
2+
+ // MIR for `f` after JumpThreading
3+
4+
fn f() -> u64 {
5+
let mut _0: u64;
6+
let mut _1: bool;
7+
8+
bb0: {
9+
StorageLive(_1);
10+
switchInt(const A) -> [1: bb2, 2: bb2, 3: bb2, otherwise: bb1];
11+
}
12+
13+
bb1: {
14+
_1 = const true;
15+
- goto -> bb3;
16+
+ goto -> bb7;
17+
}
18+
19+
bb2: {
20+
_1 = const B;
21+
goto -> bb3;
22+
}
23+
24+
bb3: {
25+
switchInt(_1) -> [0: bb5, otherwise: bb4];
26+
}
27+
28+
bb4: {
29+
_0 = const 2_u64;
30+
goto -> bb6;
31+
}
32+
33+
bb5: {
34+
_0 = const 1_u64;
35+
goto -> bb6;
36+
}
37+
38+
bb6: {
39+
StorageDead(_1);
40+
return;
41+
+ }
42+
+
43+
+ bb7: {
44+
+ goto -> bb4;
45+
}
46+
}
47+

‎tests/mir-opt/const_goto_const_eval_fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// compile-flags: -Zunsound-mir-opts
66

77
// If const eval fails, then don't crash
8-
// EMIT_MIR const_goto_const_eval_fail.f.ConstGoto.diff
8+
// EMIT_MIR const_goto_const_eval_fail.f.JumpThreading.diff
99
pub fn f<const A: i32, const B: bool>() -> u64 {
1010
match {
1111
match A {

‎tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff

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

‎tests/mir-opt/const_goto_storage.rs

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

‎tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,12 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
44
debug x => _1;
55
debug n => _2;
66
let mut _0: u32;
7-
scope 1 (inlined <u32 as Step>::forward) {
8-
debug start => _1;
9-
debug n => _2;
10-
let _3: std::option::Option<u32>;
11-
let mut _4: &std::option::Option<u32>;
12-
let mut _7: bool;
13-
let mut _8: u32;
14-
scope 2 {
15-
}
16-
scope 3 (inlined Option::<u32>::is_none) {
17-
debug self => _4;
18-
let mut _6: bool;
19-
scope 4 (inlined Option::<u32>::is_some) {
20-
debug self => _4;
21-
let mut _5: isize;
22-
}
23-
}
24-
scope 5 (inlined core::num::<impl u32>::wrapping_add) {
25-
debug self => _1;
26-
debug rhs => _8;
27-
}
28-
}
297

308
bb0: {
31-
StorageLive(_7);
32-
StorageLive(_4);
33-
StorageLive(_3);
34-
_3 = <u32 as Step>::forward_checked(_1, _2) -> [return: bb1, unwind continue];
9+
_0 = <u32 as Step>::forward(move _1, move _2) -> [return: bb1, unwind continue];
3510
}
3611

3712
bb1: {
38-
_4 = &_3;
39-
StorageLive(_6);
40-
StorageLive(_5);
41-
_5 = discriminant(_3);
42-
_6 = Eq(_5, const 1_isize);
43-
StorageDead(_5);
44-
_7 = Not(move _6);
45-
StorageDead(_6);
46-
switchInt(move _7) -> [0: bb2, otherwise: bb3];
47-
}
48-
49-
bb2: {
50-
StorageDead(_3);
51-
StorageDead(_4);
52-
goto -> bb4;
53-
}
54-
55-
bb3: {
56-
StorageDead(_3);
57-
StorageDead(_4);
58-
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb4, unwind continue];
59-
}
60-
61-
bb4: {
62-
StorageDead(_7);
63-
StorageLive(_8);
64-
_8 = _2 as u32 (IntToInt);
65-
_0 = Add(_1, _8);
66-
StorageDead(_8);
6713
return;
6814
}
6915
}

‎tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ fn int_range(_1: usize, _2: usize) -> () {
77
let mut _3: std::ops::Range<usize>;
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: &mut std::ops::Range<usize>;
10-
let mut _11: std::option::Option<usize>;
11-
let mut _14: isize;
12-
let _16: ();
10+
let mut _13: std::option::Option<usize>;
11+
let _15: ();
1312
scope 1 {
1413
debug iter => _4;
15-
let _15: usize;
14+
let _14: usize;
1615
scope 2 {
17-
debug i => _15;
16+
debug i => _14;
1817
}
1918
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
2019
debug self => _5;
@@ -23,10 +22,10 @@ fn int_range(_1: usize, _2: usize) -> () {
2322
let mut _6: &usize;
2423
let mut _7: &usize;
2524
let mut _10: bool;
26-
let _12: usize;
27-
let mut _13: usize;
25+
let _11: usize;
26+
let mut _12: usize;
2827
scope 6 {
29-
debug old => _12;
28+
debug old => _11;
3029
scope 7 {
3130
}
3231
}
@@ -51,9 +50,9 @@ fn int_range(_1: usize, _2: usize) -> () {
5150
}
5251

5352
bb1: {
54-
StorageLive(_11);
53+
StorageLive(_13);
5554
_5 = &mut _4;
56-
StorageLive(_12);
55+
StorageLive(_11);
5756
StorageLive(_10);
5857
StorageLive(_6);
5958
_6 = &(_4.0: usize);
@@ -72,53 +71,33 @@ fn int_range(_1: usize, _2: usize) -> () {
7271
bb2: {
7372
StorageDead(_7);
7473
StorageDead(_6);
75-
_11 = const Option::<usize>::None;
76-
goto -> bb5;
74+
StorageDead(_10);
75+
StorageDead(_11);
76+
StorageDead(_13);
77+
StorageDead(_4);
78+
return;
7779
}
7880

7981
bb3: {
8082
StorageDead(_7);
8183
StorageDead(_6);
82-
_12 = (_4.0: usize);
83-
StorageLive(_13);
84-
_13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb4, unwind continue];
84+
_11 = (_4.0: usize);
85+
StorageLive(_12);
86+
_12 = <usize as Step>::forward_unchecked(_11, const 1_usize) -> [return: bb4, unwind continue];
8587
}
8688

8789
bb4: {
88-
(_4.0: usize) = move _13;
89-
StorageDead(_13);
90-
_11 = Option::<usize>::Some(_12);
91-
goto -> bb5;
92-
}
93-
94-
bb5: {
95-
StorageDead(_10);
90+
(_4.0: usize) = move _12;
9691
StorageDead(_12);
97-
_14 = discriminant(_11);
98-
switchInt(move _14) -> [0: bb6, 1: bb7, otherwise: bb9];
99-
}
100-
101-
bb6: {
92+
_13 = Option::<usize>::Some(_11);
93+
StorageDead(_10);
10294
StorageDead(_11);
103-
StorageDead(_4);
104-
return;
105-
}
106-
107-
bb7: {
108-
_15 = ((_11 as Some).0: usize);
109-
_16 = opaque::<usize>(move _15) -> [return: bb8, unwind continue];
95+
_14 = ((_13 as Some).0: usize);
96+
_15 = opaque::<usize>(move _14) -> [return: bb5, unwind continue];
11097
}
11198

112-
bb8: {
113-
StorageDead(_11);
99+
bb5: {
100+
StorageDead(_13);
114101
goto -> bb1;
115102
}
116-
117-
bb9: {
118-
unreachable;
119-
}
120-
}
121-
122-
ALLOC0 (size: 16, align: 8) {
123-
00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
124103
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// MIR for `issue_77355_opt` after PreCodegen
2+
3+
fn issue_77355_opt(_1: Foo) -> u64 {
4+
debug num => _1;
5+
let mut _0: u64;
6+
let mut _2: isize;
7+
8+
bb0: {
9+
_2 = discriminant(_1);
10+
switchInt(move _2) -> [1: bb1, 2: bb1, otherwise: bb2];
11+
}
12+
13+
bb1: {
14+
_0 = const 23_u64;
15+
return;
16+
}
17+
18+
bb2: {
19+
_0 = const 42_u64;
20+
return;
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This test verifies that the MIR we output using the `matches!()` macro is close
2+
// to the MIR for an `if let` branch.
3+
4+
pub enum Foo {
5+
A,
6+
B,
7+
C,
8+
D,
9+
E,
10+
F,
11+
}
12+
13+
// EMIT_MIR matches_macro.issue_77355_opt.PreCodegen.after.mir
14+
fn issue_77355_opt(num: Foo) -> u64 {
15+
// CHECK-LABEL: fn issue_77355_opt(
16+
// CHECK: switchInt({{.*}}) -> [1: bb1, 2: bb1, otherwise: bb2];
17+
// CHECK: bb1: {
18+
// CHECK-NEXT: _0 = const 23_u64;
19+
// CHECK-NEXT: return;
20+
// CHECK: bb2: {
21+
// CHECK-NEXT: _0 = const 42_u64;
22+
// CHECK-NEXT: return;
23+
if matches!(num, Foo::B | Foo::C) { 23 } else { 42 }
24+
}
25+
fn main() {
26+
issue_77355_opt(Foo::A);
27+
}

‎tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
88
let mut _4: std::ops::Range<u32>;
99
let mut _5: std::ops::Range<u32>;
1010
let mut _6: &mut std::ops::Range<u32>;
11-
let mut _12: std::option::Option<u32>;
12-
let mut _15: isize;
13-
let mut _17: &impl Fn(u32);
14-
let mut _18: (u32,);
15-
let _19: ();
11+
let mut _14: std::option::Option<u32>;
12+
let mut _16: &impl Fn(u32);
13+
let mut _17: (u32,);
14+
let _18: ();
1615
scope 1 {
1716
debug iter => _5;
18-
let _16: u32;
17+
let _15: u32;
1918
scope 2 {
20-
debug x => _16;
19+
debug x => _15;
2120
}
2221
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
2322
debug self => _6;
@@ -26,10 +25,10 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
2625
let mut _7: &u32;
2726
let mut _8: &u32;
2827
let mut _11: bool;
29-
let _13: u32;
30-
let mut _14: u32;
28+
let _12: u32;
29+
let mut _13: u32;
3130
scope 6 {
32-
debug old => _13;
31+
debug old => _12;
3332
scope 7 {
3433
}
3534
}
@@ -54,9 +53,9 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
5453
}
5554

5655
bb1: {
57-
StorageLive(_12);
56+
StorageLive(_14);
5857
_6 = &mut _5;
59-
StorageLive(_13);
58+
StorageLive(_12);
6059
StorageLive(_11);
6160
StorageLive(_7);
6261
_7 = &(_5.0: u32);
@@ -69,69 +68,49 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
6968
_11 = Lt(move _9, move _10);
7069
StorageDead(_10);
7170
StorageDead(_9);
72-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
71+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
7372
}
7473

7574
bb2: {
7675
StorageDead(_8);
7776
StorageDead(_7);
78-
_12 = const Option::<u32>::None;
79-
goto -> bb5;
77+
StorageDead(_11);
78+
StorageDead(_12);
79+
StorageDead(_14);
80+
StorageDead(_5);
81+
drop(_3) -> [return: bb3, unwind unreachable];
8082
}
8183

8284
bb3: {
83-
StorageDead(_8);
84-
StorageDead(_7);
85-
_13 = (_5.0: u32);
86-
StorageLive(_14);
87-
_14 = <u32 as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind unreachable];
85+
return;
8886
}
8987

9088
bb4: {
91-
(_5.0: u32) = move _14;
92-
StorageDead(_14);
93-
_12 = Option::<u32>::Some(_13);
94-
goto -> bb5;
89+
StorageDead(_8);
90+
StorageDead(_7);
91+
_12 = (_5.0: u32);
92+
StorageLive(_13);
93+
_13 = <u32 as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind unreachable];
9594
}
9695

9796
bb5: {
98-
StorageDead(_11);
97+
(_5.0: u32) = move _13;
9998
StorageDead(_13);
100-
_15 = discriminant(_12);
101-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
102-
}
103-
104-
bb6: {
99+
_14 = Option::<u32>::Some(_12);
100+
StorageDead(_11);
105101
StorageDead(_12);
106-
StorageDead(_5);
107-
drop(_3) -> [return: bb7, unwind unreachable];
108-
}
109-
110-
bb7: {
111-
return;
112-
}
113-
114-
bb8: {
115-
_16 = ((_12 as Some).0: u32);
102+
_15 = ((_14 as Some).0: u32);
103+
StorageLive(_16);
104+
_16 = &_3;
116105
StorageLive(_17);
117-
_17 = &_3;
118-
StorageLive(_18);
119-
_18 = (_16,);
120-
_19 = <impl Fn(u32) as Fn<(u32,)>>::call(move _17, move _18) -> [return: bb9, unwind unreachable];
106+
_17 = (_15,);
107+
_18 = <impl Fn(u32) as Fn<(u32,)>>::call(move _16, move _17) -> [return: bb6, unwind unreachable];
121108
}
122109

123-
bb9: {
124-
StorageDead(_18);
110+
bb6: {
125111
StorageDead(_17);
126-
StorageDead(_12);
112+
StorageDead(_16);
113+
StorageDead(_14);
127114
goto -> bb1;
128115
}
129-
130-
bb10: {
131-
unreachable;
132-
}
133-
}
134-
135-
ALLOC0 (size: 8, align: 4) {
136-
00 00 00 00 __ __ __ __ │ ....░░░░
137116
}

‎tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
88
let mut _4: std::ops::Range<u32>;
99
let mut _5: std::ops::Range<u32>;
1010
let mut _6: &mut std::ops::Range<u32>;
11-
let mut _12: std::option::Option<u32>;
12-
let mut _15: isize;
13-
let mut _17: &impl Fn(u32);
14-
let mut _18: (u32,);
15-
let _19: ();
11+
let mut _14: std::option::Option<u32>;
12+
let mut _16: &impl Fn(u32);
13+
let mut _17: (u32,);
14+
let _18: ();
1615
scope 1 {
1716
debug iter => _5;
18-
let _16: u32;
17+
let _15: u32;
1918
scope 2 {
20-
debug x => _16;
19+
debug x => _15;
2120
}
2221
scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
2322
debug self => _6;
@@ -26,10 +25,10 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
2625
let mut _7: &u32;
2726
let mut _8: &u32;
2827
let mut _11: bool;
29-
let _13: u32;
30-
let mut _14: u32;
28+
let _12: u32;
29+
let mut _13: u32;
3130
scope 6 {
32-
debug old => _13;
31+
debug old => _12;
3332
scope 7 {
3433
}
3534
}
@@ -54,9 +53,9 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
5453
}
5554

5655
bb1: {
57-
StorageLive(_12);
56+
StorageLive(_14);
5857
_6 = &mut _5;
59-
StorageLive(_13);
58+
StorageLive(_12);
6059
StorageLive(_11);
6160
StorageLive(_7);
6261
_7 = &(_5.0: u32);
@@ -69,77 +68,57 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
6968
_11 = Lt(move _9, move _10);
7069
StorageDead(_10);
7170
StorageDead(_9);
72-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
71+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
7372
}
7473

7574
bb2: {
7675
StorageDead(_8);
7776
StorageDead(_7);
78-
_12 = const Option::<u32>::None;
79-
goto -> bb5;
77+
StorageDead(_11);
78+
StorageDead(_12);
79+
StorageDead(_14);
80+
StorageDead(_5);
81+
drop(_3) -> [return: bb3, unwind continue];
8082
}
8183

8284
bb3: {
83-
StorageDead(_8);
84-
StorageDead(_7);
85-
_13 = (_5.0: u32);
86-
StorageLive(_14);
87-
_14 = <u32 as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind: bb11];
85+
return;
8886
}
8987

9088
bb4: {
91-
(_5.0: u32) = move _14;
92-
StorageDead(_14);
93-
_12 = Option::<u32>::Some(_13);
94-
goto -> bb5;
89+
StorageDead(_8);
90+
StorageDead(_7);
91+
_12 = (_5.0: u32);
92+
StorageLive(_13);
93+
_13 = <u32 as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind: bb7];
9594
}
9695

9796
bb5: {
98-
StorageDead(_11);
97+
(_5.0: u32) = move _13;
9998
StorageDead(_13);
100-
_15 = discriminant(_12);
101-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
102-
}
103-
104-
bb6: {
99+
_14 = Option::<u32>::Some(_12);
100+
StorageDead(_11);
105101
StorageDead(_12);
106-
StorageDead(_5);
107-
drop(_3) -> [return: bb7, unwind continue];
108-
}
109-
110-
bb7: {
111-
return;
112-
}
113-
114-
bb8: {
115-
_16 = ((_12 as Some).0: u32);
102+
_15 = ((_14 as Some).0: u32);
103+
StorageLive(_16);
104+
_16 = &_3;
116105
StorageLive(_17);
117-
_17 = &_3;
118-
StorageLive(_18);
119-
_18 = (_16,);
120-
_19 = <impl Fn(u32) as Fn<(u32,)>>::call(move _17, move _18) -> [return: bb9, unwind: bb11];
106+
_17 = (_15,);
107+
_18 = <impl Fn(u32) as Fn<(u32,)>>::call(move _16, move _17) -> [return: bb6, unwind: bb7];
121108
}
122109

123-
bb9: {
124-
StorageDead(_18);
110+
bb6: {
125111
StorageDead(_17);
126-
StorageDead(_12);
112+
StorageDead(_16);
113+
StorageDead(_14);
127114
goto -> bb1;
128115
}
129116

130-
bb10: {
131-
unreachable;
117+
bb7 (cleanup): {
118+
drop(_3) -> [return: bb8, unwind terminate(cleanup)];
132119
}
133120

134-
bb11 (cleanup): {
135-
drop(_3) -> [return: bb12, unwind terminate(cleanup)];
136-
}
137-
138-
bb12 (cleanup): {
121+
bb8 (cleanup): {
139122
resume;
140123
}
141124
}
142-
143-
ALLOC0 (size: 8, align: 4) {
144-
00 00 00 00 __ __ __ __ │ ....░░░░
145-
}

‎tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: std::ops::Range<usize>;
1010
let mut _6: &mut std::ops::Range<usize>;
11-
let mut _12: std::option::Option<usize>;
12-
let mut _15: isize;
13-
let mut _17: usize;
14-
let mut _18: bool;
15-
let mut _20: &impl Fn(usize, &T);
16-
let mut _21: (usize, &T);
17-
let _22: ();
11+
let mut _14: std::option::Option<usize>;
12+
let mut _16: usize;
13+
let mut _17: bool;
14+
let mut _19: &impl Fn(usize, &T);
15+
let mut _20: (usize, &T);
16+
let _21: ();
1817
scope 1 {
1918
debug iter => _5;
20-
let _16: usize;
19+
let _15: usize;
2120
scope 2 {
22-
debug i => _16;
23-
let _19: &T;
21+
debug i => _15;
22+
let _18: &T;
2423
scope 3 {
25-
debug x => _19;
24+
debug x => _18;
2625
}
2726
}
2827
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
@@ -32,10 +31,10 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
3231
let mut _7: &usize;
3332
let mut _8: &usize;
3433
let mut _11: bool;
35-
let _13: usize;
36-
let mut _14: usize;
34+
let _12: usize;
35+
let mut _13: usize;
3736
scope 7 {
38-
debug old => _13;
37+
debug old => _12;
3938
scope 8 {
4039
}
4140
}
@@ -63,9 +62,9 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
6362
}
6463

6564
bb1: {
66-
StorageLive(_12);
65+
StorageLive(_14);
6766
_6 = &mut _5;
68-
StorageLive(_13);
67+
StorageLive(_12);
6968
StorageLive(_11);
7069
StorageLive(_7);
7170
_7 = &(_5.0: usize);
@@ -78,76 +77,56 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
7877
_11 = Lt(move _9, move _10);
7978
StorageDead(_10);
8079
StorageDead(_9);
81-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
80+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
8281
}
8382

8483
bb2: {
8584
StorageDead(_8);
8685
StorageDead(_7);
87-
_12 = const Option::<usize>::None;
88-
goto -> bb5;
86+
StorageDead(_11);
87+
StorageDead(_12);
88+
StorageDead(_14);
89+
StorageDead(_5);
90+
drop(_2) -> [return: bb3, unwind unreachable];
8991
}
9092

9193
bb3: {
92-
StorageDead(_8);
93-
StorageDead(_7);
94-
_13 = (_5.0: usize);
95-
StorageLive(_14);
96-
_14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind unreachable];
94+
return;
9795
}
9896

9997
bb4: {
100-
(_5.0: usize) = move _14;
101-
StorageDead(_14);
102-
_12 = Option::<usize>::Some(_13);
103-
goto -> bb5;
98+
StorageDead(_8);
99+
StorageDead(_7);
100+
_12 = (_5.0: usize);
101+
StorageLive(_13);
102+
_13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind unreachable];
104103
}
105104

106105
bb5: {
107-
StorageDead(_11);
106+
(_5.0: usize) = move _13;
108107
StorageDead(_13);
109-
_15 = discriminant(_12);
110-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb11];
111-
}
112-
113-
bb6: {
108+
_14 = Option::<usize>::Some(_12);
109+
StorageDead(_11);
114110
StorageDead(_12);
115-
StorageDead(_5);
116-
drop(_2) -> [return: bb7, unwind unreachable];
117-
}
118-
119-
bb7: {
120-
return;
121-
}
122-
123-
bb8: {
124-
_16 = ((_12 as Some).0: usize);
125-
_17 = Len((*_1));
126-
_18 = Lt(_16, _17);
127-
assert(move _18, "index out of bounds: the length is {} but the index is {}", move _17, _16) -> [success: bb9, unwind unreachable];
111+
_15 = ((_14 as Some).0: usize);
112+
_16 = Len((*_1));
113+
_17 = Lt(_15, _16);
114+
assert(move _17, "index out of bounds: the length is {} but the index is {}", move _16, _15) -> [success: bb6, unwind unreachable];
128115
}
129116

130-
bb9: {
131-
_19 = &(*_1)[_16];
117+
bb6: {
118+
_18 = &(*_1)[_15];
119+
StorageLive(_19);
120+
_19 = &_2;
132121
StorageLive(_20);
133-
_20 = &_2;
134-
StorageLive(_21);
135-
_21 = (_16, _19);
136-
_22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb10, unwind unreachable];
122+
_20 = (_15, _18);
123+
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb7, unwind unreachable];
137124
}
138125

139-
bb10: {
140-
StorageDead(_21);
126+
bb7: {
141127
StorageDead(_20);
142-
StorageDead(_12);
128+
StorageDead(_19);
129+
StorageDead(_14);
143130
goto -> bb1;
144131
}
145-
146-
bb11: {
147-
unreachable;
148-
}
149-
}
150-
151-
ALLOC0 (size: 16, align: 8) {
152-
00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
153132
}

‎tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
88
let mut _4: std::ops::Range<usize>;
99
let mut _5: std::ops::Range<usize>;
1010
let mut _6: &mut std::ops::Range<usize>;
11-
let mut _12: std::option::Option<usize>;
12-
let mut _15: isize;
13-
let mut _17: usize;
14-
let mut _18: bool;
15-
let mut _20: &impl Fn(usize, &T);
16-
let mut _21: (usize, &T);
17-
let _22: ();
11+
let mut _14: std::option::Option<usize>;
12+
let mut _16: usize;
13+
let mut _17: bool;
14+
let mut _19: &impl Fn(usize, &T);
15+
let mut _20: (usize, &T);
16+
let _21: ();
1817
scope 1 {
1918
debug iter => _5;
20-
let _16: usize;
19+
let _15: usize;
2120
scope 2 {
22-
debug i => _16;
23-
let _19: &T;
21+
debug i => _15;
22+
let _18: &T;
2423
scope 3 {
25-
debug x => _19;
24+
debug x => _18;
2625
}
2726
}
2827
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
@@ -32,10 +31,10 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
3231
let mut _7: &usize;
3332
let mut _8: &usize;
3433
let mut _11: bool;
35-
let _13: usize;
36-
let mut _14: usize;
34+
let _12: usize;
35+
let mut _13: usize;
3736
scope 7 {
38-
debug old => _13;
37+
debug old => _12;
3938
scope 8 {
4039
}
4140
}
@@ -63,9 +62,9 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
6362
}
6463

6564
bb1: {
66-
StorageLive(_12);
65+
StorageLive(_14);
6766
_6 = &mut _5;
68-
StorageLive(_13);
67+
StorageLive(_12);
6968
StorageLive(_11);
7069
StorageLive(_7);
7170
_7 = &(_5.0: usize);
@@ -78,84 +77,64 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
7877
_11 = Lt(move _9, move _10);
7978
StorageDead(_10);
8079
StorageDead(_9);
81-
switchInt(move _11) -> [0: bb2, otherwise: bb3];
80+
switchInt(move _11) -> [0: bb2, otherwise: bb4];
8281
}
8382

8483
bb2: {
8584
StorageDead(_8);
8685
StorageDead(_7);
87-
_12 = const Option::<usize>::None;
88-
goto -> bb5;
86+
StorageDead(_11);
87+
StorageDead(_12);
88+
StorageDead(_14);
89+
StorageDead(_5);
90+
drop(_2) -> [return: bb3, unwind continue];
8991
}
9092

9193
bb3: {
92-
StorageDead(_8);
93-
StorageDead(_7);
94-
_13 = (_5.0: usize);
95-
StorageLive(_14);
96-
_14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind: bb12];
94+
return;
9795
}
9896

9997
bb4: {
100-
(_5.0: usize) = move _14;
101-
StorageDead(_14);
102-
_12 = Option::<usize>::Some(_13);
103-
goto -> bb5;
98+
StorageDead(_8);
99+
StorageDead(_7);
100+
_12 = (_5.0: usize);
101+
StorageLive(_13);
102+
_13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb5, unwind: bb8];
104103
}
105104

106105
bb5: {
107-
StorageDead(_11);
106+
(_5.0: usize) = move _13;
108107
StorageDead(_13);
109-
_15 = discriminant(_12);
110-
switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb11];
111-
}
112-
113-
bb6: {
108+
_14 = Option::<usize>::Some(_12);
109+
StorageDead(_11);
114110
StorageDead(_12);
115-
StorageDead(_5);
116-
drop(_2) -> [return: bb7, unwind continue];
117-
}
118-
119-
bb7: {
120-
return;
121-
}
122-
123-
bb8: {
124-
_16 = ((_12 as Some).0: usize);
125-
_17 = Len((*_1));
126-
_18 = Lt(_16, _17);
127-
assert(move _18, "index out of bounds: the length is {} but the index is {}", move _17, _16) -> [success: bb9, unwind: bb12];
111+
_15 = ((_14 as Some).0: usize);
112+
_16 = Len((*_1));
113+
_17 = Lt(_15, _16);
114+
assert(move _17, "index out of bounds: the length is {} but the index is {}", move _16, _15) -> [success: bb6, unwind: bb8];
128115
}
129116

130-
bb9: {
131-
_19 = &(*_1)[_16];
117+
bb6: {
118+
_18 = &(*_1)[_15];
119+
StorageLive(_19);
120+
_19 = &_2;
132121
StorageLive(_20);
133-
_20 = &_2;
134-
StorageLive(_21);
135-
_21 = (_16, _19);
136-
_22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb10, unwind: bb12];
122+
_20 = (_15, _18);
123+
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb7, unwind: bb8];
137124
}
138125

139-
bb10: {
140-
StorageDead(_21);
126+
bb7: {
141127
StorageDead(_20);
142-
StorageDead(_12);
128+
StorageDead(_19);
129+
StorageDead(_14);
143130
goto -> bb1;
144131
}
145132

146-
bb11: {
147-
unreachable;
133+
bb8 (cleanup): {
134+
drop(_2) -> [return: bb9, unwind terminate(cleanup)];
148135
}
149136

150-
bb12 (cleanup): {
151-
drop(_2) -> [return: bb13, unwind terminate(cleanup)];
152-
}
153-
154-
bb13 (cleanup): {
137+
bb9 (cleanup): {
155138
resume;
156139
}
157140
}
158-
159-
ALLOC0 (size: 16, align: 8) {
160-
00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
161-
}

‎tests/mir-opt/pre-codegen/try_identity.new.PreCodegen.after.mir

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,51 @@ fn new(_1: Result<T, E>) -> Result<T, E> {
66
let mut _2: isize;
77
let _3: T;
88
let mut _4: std::ops::ControlFlow<E, T>;
9-
let _5: E;
10-
let mut _6: isize;
11-
let _7: T;
12-
let _8: E;
9+
let _5: T;
10+
let _6: E;
11+
let _7: E;
1312
scope 1 {
1413
debug v => _3;
1514
}
1615
scope 2 {
17-
debug e => _5;
16+
debug e => _6;
1817
}
1918
scope 3 {
20-
debug v => _7;
19+
debug v => _5;
2120
}
2221
scope 4 {
23-
debug e => _8;
22+
debug e => _7;
2423
}
2524

2625
bb0: {
2726
StorageLive(_4);
2827
_2 = discriminant(_1);
29-
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb7];
28+
switchInt(move _2) -> [0: bb1, 1: bb2, otherwise: bb4];
3029
}
3130

3231
bb1: {
3332
_3 = move ((_1 as Ok).0: T);
3433
_4 = ControlFlow::<E, T>::Continue(_3);
34+
_5 = move ((_4 as Continue).0: T);
35+
_0 = Result::<T, E>::Ok(_5);
36+
StorageDead(_4);
3537
goto -> bb3;
3638
}
3739

3840
bb2: {
39-
_5 = move ((_1 as Err).0: E);
40-
_4 = ControlFlow::<E, T>::Break(_5);
41+
_6 = move ((_1 as Err).0: E);
42+
_4 = ControlFlow::<E, T>::Break(_6);
43+
_7 = move ((_4 as Break).0: E);
44+
_0 = Result::<T, E>::Err(_7);
45+
StorageDead(_4);
4146
goto -> bb3;
4247
}
4348

4449
bb3: {
45-
_6 = discriminant(_4);
46-
switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb7];
47-
}
48-
49-
bb4: {
50-
_7 = move ((_4 as Continue).0: T);
51-
_0 = Result::<T, E>::Ok(_7);
52-
StorageDead(_4);
53-
goto -> bb6;
54-
}
55-
56-
bb5: {
57-
_8 = move ((_4 as Break).0: E);
58-
_0 = Result::<T, E>::Err(_8);
59-
StorageDead(_4);
60-
goto -> bb6;
61-
}
62-
63-
bb6: {
6450
return;
6551
}
6652

67-
bb7: {
53+
bb4: {
6854
unreachable;
6955
}
7056
}

‎tests/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff renamed to ‎tests/mir-opt/separate_const_switch.identity.JumpThreading.diff

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `identity` before SeparateConstSwitch
2-
+ // MIR for `identity` after SeparateConstSwitch
1+
- // MIR for `identity` before JumpThreading
2+
+ // MIR for `identity` after JumpThreading
33

44
fn identity(_1: Result<i32, i32>) -> Result<i32, i32> {
55
debug x => _1;
@@ -79,7 +79,8 @@
7979
StorageDead(_8);
8080
StorageDead(_3);
8181
_4 = discriminant(_2);
82-
switchInt(move _4) -> [0: bb1, 1: bb2, otherwise: bb6];
82+
- switchInt(move _4) -> [0: bb1, 1: bb2, otherwise: bb6];
83+
+ goto -> bb1;
8384
}
8485

8586
bb4: {
@@ -88,7 +89,8 @@
8889
_11 = Result::<Infallible, i32>::Err(_10);
8990
_2 = ControlFlow::<Result<Infallible, i32>, i32>::Break(move _11);
9091
StorageDead(_11);
91-
goto -> bb3;
92+
- goto -> bb3;
93+
+ goto -> bb7;
9294
}
9395

9496
bb5: {
@@ -99,6 +101,15 @@
99101

100102
bb6: {
101103
unreachable;
104+
+ }
105+
+
106+
+ bb7: {
107+
+ StorageDead(_10);
108+
+ StorageDead(_9);
109+
+ StorageDead(_8);
110+
+ StorageDead(_3);
111+
+ _4 = discriminant(_2);
112+
+ goto -> bb2;
102113
}
103114
}
104115

‎tests/mir-opt/separate_const_switch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use std::ops::ControlFlow;
88

9-
// EMIT_MIR separate_const_switch.too_complex.SeparateConstSwitch.diff
9+
// EMIT_MIR separate_const_switch.too_complex.JumpThreading.diff
1010
fn too_complex(x: Result<i32, usize>) -> Option<i32> {
1111
// The pass should break the outer match into
1212
// two blocks that only have one parent each.
@@ -23,7 +23,7 @@ fn too_complex(x: Result<i32, usize>) -> Option<i32> {
2323
}
2424
}
2525

26-
// EMIT_MIR separate_const_switch.identity.SeparateConstSwitch.diff
26+
// EMIT_MIR separate_const_switch.identity.JumpThreading.diff
2727
fn identity(x: Result<i32, i32>) -> Result<i32, i32> {
2828
Ok(x?)
2929
}

‎tests/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff renamed to ‎tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `too_complex` before SeparateConstSwitch
2-
+ // MIR for `too_complex` after SeparateConstSwitch
1+
- // MIR for `too_complex` before JumpThreading
2+
+ // MIR for `too_complex` after JumpThreading
33

44
fn too_complex(_1: Result<i32, usize>) -> Option<i32> {
55
debug x => _1;
@@ -33,7 +33,8 @@
3333
bb1: {
3434
_5 = ((_1 as Err).0: usize);
3535
_2 = ControlFlow::<usize, i32>::Break(_5);
36-
goto -> bb3;
36+
- goto -> bb3;
37+
+ goto -> bb8;
3738
}
3839

3940
bb2: {
@@ -44,7 +45,8 @@
4445

4546
bb3: {
4647
_6 = discriminant(_2);
47-
switchInt(move _6) -> [0: bb5, 1: bb4, otherwise: bb7];
48+
- switchInt(move _6) -> [0: bb5, 1: bb4, otherwise: bb7];
49+
+ goto -> bb5;
4850
}
4951

5052
bb4: {
@@ -68,6 +70,11 @@
6870

6971
bb7: {
7072
unreachable;
73+
+ }
74+
+
75+
+ bb8: {
76+
+ _6 = discriminant(_2);
77+
+ goto -> bb4;
7178
}
7279
}
7380

0 commit comments

Comments
 (0)
Please sign in to comment.