Skip to content

Commit

Permalink
Auto merge of rust-lang#127087 - cjgillot:small-map, r=<try>
Browse files Browse the repository at this point in the history
Only track mentioned places for jump threading

This PR aims to reduce the state space size in jump threading and dataflow const-prop opts.

The current implementation walks the types of all locals, and creates a place for each possible projection. This can easily lead to a large number of places and tracked values, most being useless to the actual pass.

With this PR, we instead collect places that appear syntactically in the MIR (first commit). However, this is not sufficient (second commit), and we miss places that we could track in aggregate assignments. The third commit tracks such assignments to mirror place projections, see the inline comment.

This is complementary to rust-lang#127036

r? `@oli-obk`
  • Loading branch information
bors committed Jul 4, 2024
2 parents 486bc27 + 82b6247 commit 53ab1ce
Show file tree
Hide file tree
Showing 14 changed files with 615 additions and 271 deletions.
338 changes: 216 additions & 122 deletions compiler/rustc_mir_dataflow/src/value_analysis.rs

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'tcx> MirPass<'tcx> for DataflowConstProp {
}

struct ConstAnalysis<'a, 'tcx> {
map: Map,
map: Map<'tcx>,
tcx: TyCtxt<'tcx>,
local_decls: &'a LocalDecls<'tcx>,
ecx: InterpCx<'tcx, DummyMachine>,
Expand All @@ -78,7 +78,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {

const NAME: &'static str = "ConstAnalysis";

fn map(&self) -> &Map {
fn map(&self) -> &Map<'tcx> {
&self.map
}

Expand Down Expand Up @@ -330,7 +330,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
}

impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map) -> Self {
pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map<'tcx>) -> Self {
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
Self {
map,
Expand Down Expand Up @@ -560,12 +560,13 @@ impl<'tcx, 'locals> Collector<'tcx, 'locals> {
Self { patch: Patch::new(tcx), local_decls }
}

#[instrument(level = "trace", skip(self, ecx, map), ret)]
fn try_make_constant(
&self,
ecx: &mut InterpCx<'tcx, DummyMachine>,
place: Place<'tcx>,
state: &State<FlatSet<Scalar>>,
map: &Map,
map: &Map<'tcx>,
) -> Option<Const<'tcx>> {
let ty = place.ty(self.local_decls, self.patch.tcx).ty;
let layout = ecx.layout_of(ty).ok()?;
Expand Down Expand Up @@ -598,10 +599,11 @@ impl<'tcx, 'locals> Collector<'tcx, 'locals> {
}
}

#[instrument(level = "trace", skip(map), ret)]
fn propagatable_scalar(
place: PlaceIndex,
state: &State<FlatSet<Scalar>>,
map: &Map,
map: &Map<'_>,
) -> Option<Scalar> {
if let FlatSet::Elem(value) = state.get_idx(place, map)
&& value.try_to_scalar_int().is_ok()
Expand All @@ -613,14 +615,14 @@ fn propagatable_scalar(
}
}

#[instrument(level = "trace", skip(ecx, state, map))]
#[instrument(level = "trace", skip(ecx, state, map), ret)]
fn try_write_constant<'tcx>(
ecx: &mut InterpCx<'tcx, DummyMachine>,
dest: &PlaceTy<'tcx>,
place: PlaceIndex,
ty: Ty<'tcx>,
state: &State<FlatSet<Scalar>>,
map: &Map,
map: &Map<'tcx>,
) -> InterpResult<'tcx> {
let layout = ecx.layout_of(ty)?;

Expand Down Expand Up @@ -719,6 +721,7 @@ impl<'mir, 'tcx>
{
type FlowState = State<FlatSet<Scalar>>;

#[instrument(level = "trace", skip(self, results, statement))]
fn visit_statement_before_primary_effect(
&mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
Expand All @@ -740,6 +743,7 @@ impl<'mir, 'tcx>
}
}

#[instrument(level = "trace", skip(self, results, statement))]
fn visit_statement_after_primary_effect(
&mut self,
results: &mut Results<'tcx, ValueAnalysisWrapper<ConstAnalysis<'_, 'tcx>>>,
Expand Down Expand Up @@ -834,7 +838,7 @@ struct OperandCollector<'tcx, 'map, 'locals, 'a> {
state: &'a State<FlatSet<Scalar>>,
visitor: &'a mut Collector<'tcx, 'locals>,
ecx: &'map mut InterpCx<'tcx, DummyMachine>,
map: &'map Map,
map: &'map Map<'tcx>,
}

impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/jump_threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct TOFinder<'tcx, 'a> {
param_env: ty::ParamEnv<'tcx>,
ecx: InterpCx<'tcx, DummyMachine>,
body: &'a Body<'tcx>,
map: &'a Map,
map: &'a Map<'tcx>,
loop_headers: &'a BitSet<BasicBlock>,
/// We use an arena to avoid cloning the slices when cloning `state`.
arena: &'a DroplessArena,
Expand Down
199 changes: 114 additions & 85 deletions tests/coverage/try_error_result.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -81,101 +81,130 @@ Number of file 0 mappings: 11
= (((c4 + Zero) + Zero) + c3)

Function name: try_error_result::test2
Raw bytes (280): 0x[01, 01, 24, 01, 07, 00, 09, 03, 0d, 41, 00, 1e, 00, 41, 00, 1e, 00, 41, 00, 4a, 00, 4e, 00, 52, 41, 03, 0d, 52, 41, 03, 0d, 4e, 00, 52, 41, 03, 0d, 4a, 00, 4e, 00, 52, 41, 03, 0d, 66, 00, 45, 00, 45, 00, 66, 00, 45, 00, 7a, 00, 4d, 00, 4d, 00, 7a, 00, 4d, 00, 83, 01, 0d, 87, 01, 00, 00, 8b, 01, 8f, 01, 00, 19, 00, 28, 01, 3d, 01, 03, 17, 03, 08, 09, 00, 0e, 52, 02, 09, 04, 1a, 41, 06, 0d, 00, 2f, 00, 00, 2f, 00, 30, 1e, 00, 31, 03, 35, 00, 04, 11, 00, 12, 1a, 02, 11, 04, 12, 00, 05, 11, 00, 14, 1a, 00, 17, 00, 41, 19, 00, 41, 00, 42, 00, 00, 43, 00, 5f, 00, 00, 5f, 00, 60, 00, 01, 0d, 00, 20, 00, 01, 11, 00, 14, 00, 00, 17, 00, 41, 00, 00, 41, 00, 42, 00, 00, 43, 00, 60, 00, 00, 60, 00, 61, 00, 01, 0d, 00, 20, 46, 04, 11, 00, 14, 4e, 00, 17, 00, 42, 00, 00, 42, 00, 43, 4a, 00, 44, 00, 61, 00, 00, 61, 00, 62, 46, 01, 0d, 00, 20, 62, 01, 11, 00, 14, 45, 00, 17, 01, 36, 00, 01, 36, 00, 37, 66, 01, 12, 00, 2f, 00, 00, 2f, 00, 30, 62, 01, 0d, 00, 20, 76, 01, 11, 00, 14, 4d, 00, 17, 01, 36, 00, 02, 11, 00, 12, 7a, 01, 12, 00, 2f, 00, 01, 11, 00, 12, 76, 02, 0d, 00, 20, 0d, 03, 05, 00, 0b, 7f, 01, 01, 00, 02]
Raw bytes (358): 0x[01, 01, 3b, 01, 07, 05, 09, 03, 0d, 41, 11, 4a, 15, 41, 11, 42, 1d, 46, 19, 4a, 15, 41, 11, 4a, 15, 41, 11, 46, 19, 4a, 15, 41, 11, 42, 1d, 46, 19, 4a, 15, 41, 11, 5e, 25, 49, 21, 49, 21, 5e, 25, 49, 21, 8a, 01, 2d, 8e, 01, 29, 92, 01, 41, 03, 0d, 92, 01, 41, 03, 0d, 8e, 01, 29, 92, 01, 41, 03, 0d, 8a, 01, 2d, 8e, 01, 29, 92, 01, 41, 03, 0d, a6, 01, 35, 45, 31, 45, 31, a6, 01, 35, 45, 31, ba, 01, 3d, 4d, 39, 4d, 39, ba, 01, 3d, 4d, 39, c3, 01, 0d, c7, 01, db, 01, cb, 01, cf, 01, 11, 15, d3, 01, d7, 01, 19, 1d, 21, 25, df, 01, e3, 01, 29, 2d, e7, 01, eb, 01, 31, 35, 39, 3d, 28, 01, 3d, 01, 03, 17, 03, 08, 09, 00, 0e, 92, 01, 02, 09, 04, 1a, 41, 06, 0d, 00, 2f, 11, 00, 2f, 00, 30, 4a, 00, 31, 03, 35, 15, 04, 11, 00, 12, 46, 02, 11, 04, 12, 3e, 05, 11, 00, 14, 46, 00, 17, 00, 41, 19, 00, 41, 00, 42, 42, 00, 43, 00, 5f, 1d, 00, 5f, 00, 60, 3e, 01, 0d, 00, 20, 5a, 01, 11, 00, 14, 49, 00, 17, 00, 41, 21, 00, 41, 00, 42, 5e, 00, 43, 00, 60, 25, 00, 60, 00, 61, 5a, 01, 0d, 00, 20, 86, 01, 04, 11, 00, 14, 8e, 01, 00, 17, 00, 42, 29, 00, 42, 00, 43, 8a, 01, 00, 44, 00, 61, 2d, 00, 61, 00, 62, 86, 01, 01, 0d, 00, 20, a2, 01, 01, 11, 00, 14, 45, 00, 17, 01, 36, 31, 01, 36, 00, 37, a6, 01, 01, 12, 00, 2f, 35, 00, 2f, 00, 30, a2, 01, 01, 0d, 00, 20, b6, 01, 01, 11, 00, 14, 4d, 00, 17, 01, 36, 39, 02, 11, 00, 12, ba, 01, 01, 12, 00, 2f, 3d, 01, 11, 00, 12, b6, 01, 02, 0d, 00, 20, 0d, 03, 05, 00, 0b, bf, 01, 01, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 36
Number of expressions: 59
- expression 0 operands: lhs = Counter(0), rhs = Expression(1, Add)
- expression 1 operands: lhs = Zero, rhs = Counter(2)
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 3 operands: lhs = Counter(16), rhs = Zero
- expression 4 operands: lhs = Expression(7, Sub), rhs = Zero
- expression 5 operands: lhs = Counter(16), rhs = Zero
- expression 6 operands: lhs = Expression(7, Sub), rhs = Zero
- expression 7 operands: lhs = Counter(16), rhs = Zero
- expression 8 operands: lhs = Expression(18, Sub), rhs = Zero
- expression 9 operands: lhs = Expression(19, Sub), rhs = Zero
- expression 10 operands: lhs = Expression(20, Sub), rhs = Counter(16)
- expression 11 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 12 operands: lhs = Expression(20, Sub), rhs = Counter(16)
- expression 13 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 14 operands: lhs = Expression(19, Sub), rhs = Zero
- expression 15 operands: lhs = Expression(20, Sub), rhs = Counter(16)
- expression 16 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 17 operands: lhs = Expression(18, Sub), rhs = Zero
- expression 18 operands: lhs = Expression(19, Sub), rhs = Zero
- expression 19 operands: lhs = Expression(20, Sub), rhs = Counter(16)
- expression 20 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 21 operands: lhs = Expression(25, Sub), rhs = Zero
- expression 22 operands: lhs = Counter(17), rhs = Zero
- expression 23 operands: lhs = Counter(17), rhs = Zero
- expression 24 operands: lhs = Expression(25, Sub), rhs = Zero
- expression 25 operands: lhs = Counter(17), rhs = Zero
- expression 26 operands: lhs = Expression(30, Sub), rhs = Zero
- expression 27 operands: lhs = Counter(19), rhs = Zero
- expression 28 operands: lhs = Counter(19), rhs = Zero
- expression 29 operands: lhs = Expression(30, Sub), rhs = Zero
- expression 30 operands: lhs = Counter(19), rhs = Zero
- expression 31 operands: lhs = Expression(32, Add), rhs = Counter(3)
- expression 32 operands: lhs = Expression(33, Add), rhs = Zero
- expression 33 operands: lhs = Zero, rhs = Expression(34, Add)
- expression 34 operands: lhs = Expression(35, Add), rhs = Zero
- expression 35 operands: lhs = Counter(6), rhs = Zero
- expression 3 operands: lhs = Counter(16), rhs = Counter(4)
- expression 4 operands: lhs = Expression(18, Sub), rhs = Counter(5)
- expression 5 operands: lhs = Counter(16), rhs = Counter(4)
- expression 6 operands: lhs = Expression(16, Sub), rhs = Counter(7)
- expression 7 operands: lhs = Expression(17, Sub), rhs = Counter(6)
- expression 8 operands: lhs = Expression(18, Sub), rhs = Counter(5)
- expression 9 operands: lhs = Counter(16), rhs = Counter(4)
- expression 10 operands: lhs = Expression(18, Sub), rhs = Counter(5)
- expression 11 operands: lhs = Counter(16), rhs = Counter(4)
- expression 12 operands: lhs = Expression(17, Sub), rhs = Counter(6)
- expression 13 operands: lhs = Expression(18, Sub), rhs = Counter(5)
- expression 14 operands: lhs = Counter(16), rhs = Counter(4)
- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(7)
- expression 16 operands: lhs = Expression(17, Sub), rhs = Counter(6)
- expression 17 operands: lhs = Expression(18, Sub), rhs = Counter(5)
- expression 18 operands: lhs = Counter(16), rhs = Counter(4)
- expression 19 operands: lhs = Expression(23, Sub), rhs = Counter(9)
- expression 20 operands: lhs = Counter(18), rhs = Counter(8)
- expression 21 operands: lhs = Counter(18), rhs = Counter(8)
- expression 22 operands: lhs = Expression(23, Sub), rhs = Counter(9)
- expression 23 operands: lhs = Counter(18), rhs = Counter(8)
- expression 24 operands: lhs = Expression(34, Sub), rhs = Counter(11)
- expression 25 operands: lhs = Expression(35, Sub), rhs = Counter(10)
- expression 26 operands: lhs = Expression(36, Sub), rhs = Counter(16)
- expression 27 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 28 operands: lhs = Expression(36, Sub), rhs = Counter(16)
- expression 29 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 30 operands: lhs = Expression(35, Sub), rhs = Counter(10)
- expression 31 operands: lhs = Expression(36, Sub), rhs = Counter(16)
- expression 32 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 33 operands: lhs = Expression(34, Sub), rhs = Counter(11)
- expression 34 operands: lhs = Expression(35, Sub), rhs = Counter(10)
- expression 35 operands: lhs = Expression(36, Sub), rhs = Counter(16)
- expression 36 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 37 operands: lhs = Expression(41, Sub), rhs = Counter(13)
- expression 38 operands: lhs = Counter(17), rhs = Counter(12)
- expression 39 operands: lhs = Counter(17), rhs = Counter(12)
- expression 40 operands: lhs = Expression(41, Sub), rhs = Counter(13)
- expression 41 operands: lhs = Counter(17), rhs = Counter(12)
- expression 42 operands: lhs = Expression(46, Sub), rhs = Counter(15)
- expression 43 operands: lhs = Counter(19), rhs = Counter(14)
- expression 44 operands: lhs = Counter(19), rhs = Counter(14)
- expression 45 operands: lhs = Expression(46, Sub), rhs = Counter(15)
- expression 46 operands: lhs = Counter(19), rhs = Counter(14)
- expression 47 operands: lhs = Expression(48, Add), rhs = Counter(3)
- expression 48 operands: lhs = Expression(49, Add), rhs = Expression(54, Add)
- expression 49 operands: lhs = Expression(50, Add), rhs = Expression(51, Add)
- expression 50 operands: lhs = Counter(4), rhs = Counter(5)
- expression 51 operands: lhs = Expression(52, Add), rhs = Expression(53, Add)
- expression 52 operands: lhs = Counter(6), rhs = Counter(7)
- expression 53 operands: lhs = Counter(8), rhs = Counter(9)
- expression 54 operands: lhs = Expression(55, Add), rhs = Expression(56, Add)
- expression 55 operands: lhs = Counter(10), rhs = Counter(11)
- expression 56 operands: lhs = Expression(57, Add), rhs = Expression(58, Add)
- expression 57 operands: lhs = Counter(12), rhs = Counter(13)
- expression 58 operands: lhs = Counter(14), rhs = Counter(15)
Number of file 0 mappings: 40
- Code(Counter(0)) at (prev + 61, 1) to (start + 3, 23)
- Code(Expression(0, Add)) at (prev + 8, 9) to (start + 0, 14)
= (c0 + (Zero + c2))
- Code(Expression(20, Sub)) at (prev + 2, 9) to (start + 4, 26)
= ((c0 + (Zero + c2)) - c3)
= (c0 + (c1 + c2))
- Code(Expression(36, Sub)) at (prev + 2, 9) to (start + 4, 26)
= ((c0 + (c1 + c2)) - c3)
- Code(Counter(16)) at (prev + 6, 13) to (start + 0, 47)
- Code(Zero) at (prev + 0, 47) to (start + 0, 48)
- Code(Expression(7, Sub)) at (prev + 0, 49) to (start + 3, 53)
= (c16 - Zero)
- Code(Zero) at (prev + 4, 17) to (start + 0, 18)
- Code(Expression(6, Sub)) at (prev + 2, 17) to (start + 4, 18)
= ((c16 - Zero) - Zero)
- Code(Zero) at (prev + 5, 17) to (start + 0, 20)
- Code(Expression(6, Sub)) at (prev + 0, 23) to (start + 0, 65)
= ((c16 - Zero) - Zero)
- Code(Counter(4)) at (prev + 0, 47) to (start + 0, 48)
- Code(Expression(18, Sub)) at (prev + 0, 49) to (start + 3, 53)
= (c16 - c4)
- Code(Counter(5)) at (prev + 4, 17) to (start + 0, 18)
- Code(Expression(17, Sub)) at (prev + 2, 17) to (start + 4, 18)
= ((c16 - c4) - c5)
- Code(Expression(15, Sub)) at (prev + 5, 17) to (start + 0, 20)
= ((((c16 - c4) - c5) - c6) - c7)
- Code(Expression(17, Sub)) at (prev + 0, 23) to (start + 0, 65)
= ((c16 - c4) - c5)
- Code(Counter(6)) at (prev + 0, 65) to (start + 0, 66)
- Code(Zero) at (prev + 0, 67) to (start + 0, 95)
- Code(Zero) at (prev + 0, 95) to (start + 0, 96)
- Code(Zero) at (prev + 1, 13) to (start + 0, 32)
- Code(Zero) at (prev + 1, 17) to (start + 0, 20)
- Code(Zero) at (prev + 0, 23) to (start + 0, 65)
- Code(Zero) at (prev + 0, 65) to (start + 0, 66)
- Code(Zero) at (prev + 0, 67) to (start + 0, 96)
- Code(Zero) at (prev + 0, 96) to (start + 0, 97)
- Code(Zero) at (prev + 1, 13) to (start + 0, 32)
- Code(Expression(17, Sub)) at (prev + 4, 17) to (start + 0, 20)
= (((((c0 + (Zero + c2)) - c3) - c16) - Zero) - Zero)
- Code(Expression(19, Sub)) at (prev + 0, 23) to (start + 0, 66)
= (((c0 + (Zero + c2)) - c3) - c16)
- Code(Zero) at (prev + 0, 66) to (start + 0, 67)
- Code(Expression(18, Sub)) at (prev + 0, 68) to (start + 0, 97)
= ((((c0 + (Zero + c2)) - c3) - c16) - Zero)
- Code(Zero) at (prev + 0, 97) to (start + 0, 98)
- Code(Expression(17, Sub)) at (prev + 1, 13) to (start + 0, 32)
= (((((c0 + (Zero + c2)) - c3) - c16) - Zero) - Zero)
- Code(Expression(24, Sub)) at (prev + 1, 17) to (start + 0, 20)
= ((c17 - Zero) - Zero)
- Code(Expression(16, Sub)) at (prev + 0, 67) to (start + 0, 95)
= (((c16 - c4) - c5) - c6)
- Code(Counter(7)) at (prev + 0, 95) to (start + 0, 96)
- Code(Expression(15, Sub)) at (prev + 1, 13) to (start + 0, 32)
= ((((c16 - c4) - c5) - c6) - c7)
- Code(Expression(22, Sub)) at (prev + 1, 17) to (start + 0, 20)
= ((c18 - c8) - c9)
- Code(Counter(18)) at (prev + 0, 23) to (start + 0, 65)
- Code(Counter(8)) at (prev + 0, 65) to (start + 0, 66)
- Code(Expression(23, Sub)) at (prev + 0, 67) to (start + 0, 96)
= (c18 - c8)
- Code(Counter(9)) at (prev + 0, 96) to (start + 0, 97)
- Code(Expression(22, Sub)) at (prev + 1, 13) to (start + 0, 32)
= ((c18 - c8) - c9)
- Code(Expression(33, Sub)) at (prev + 4, 17) to (start + 0, 20)
= (((((c0 + (c1 + c2)) - c3) - c16) - c10) - c11)
- Code(Expression(35, Sub)) at (prev + 0, 23) to (start + 0, 66)
= (((c0 + (c1 + c2)) - c3) - c16)
- Code(Counter(10)) at (prev + 0, 66) to (start + 0, 67)
- Code(Expression(34, Sub)) at (prev + 0, 68) to (start + 0, 97)
= ((((c0 + (c1 + c2)) - c3) - c16) - c10)
- Code(Counter(11)) at (prev + 0, 97) to (start + 0, 98)
- Code(Expression(33, Sub)) at (prev + 1, 13) to (start + 0, 32)
= (((((c0 + (c1 + c2)) - c3) - c16) - c10) - c11)
- Code(Expression(40, Sub)) at (prev + 1, 17) to (start + 0, 20)
= ((c17 - c12) - c13)
- Code(Counter(17)) at (prev + 0, 23) to (start + 1, 54)
- Code(Zero) at (prev + 1, 54) to (start + 0, 55)
- Code(Expression(25, Sub)) at (prev + 1, 18) to (start + 0, 47)
= (c17 - Zero)
- Code(Zero) at (prev + 0, 47) to (start + 0, 48)
- Code(Expression(24, Sub)) at (prev + 1, 13) to (start + 0, 32)
= ((c17 - Zero) - Zero)
- Code(Expression(29, Sub)) at (prev + 1, 17) to (start + 0, 20)
= ((c19 - Zero) - Zero)
- Code(Counter(12)) at (prev + 1, 54) to (start + 0, 55)
- Code(Expression(41, Sub)) at (prev + 1, 18) to (start + 0, 47)
= (c17 - c12)
- Code(Counter(13)) at (prev + 0, 47) to (start + 0, 48)
- Code(Expression(40, Sub)) at (prev + 1, 13) to (start + 0, 32)
= ((c17 - c12) - c13)
- Code(Expression(45, Sub)) at (prev + 1, 17) to (start + 0, 20)
= ((c19 - c14) - c15)
- Code(Counter(19)) at (prev + 0, 23) to (start + 1, 54)
- Code(Zero) at (prev + 2, 17) to (start + 0, 18)
- Code(Expression(30, Sub)) at (prev + 1, 18) to (start + 0, 47)
= (c19 - Zero)
- Code(Zero) at (prev + 1, 17) to (start + 0, 18)
- Code(Expression(29, Sub)) at (prev + 2, 13) to (start + 0, 32)
= ((c19 - Zero) - Zero)
- Code(Counter(14)) at (prev + 2, 17) to (start + 0, 18)
- Code(Expression(46, Sub)) at (prev + 1, 18) to (start + 0, 47)
= (c19 - c14)
- Code(Counter(15)) at (prev + 1, 17) to (start + 0, 18)
- Code(Expression(45, Sub)) at (prev + 2, 13) to (start + 0, 32)
= ((c19 - c14) - c15)
- Code(Counter(3)) at (prev + 3, 5) to (start + 0, 11)
- Code(Expression(31, Add)) at (prev + 1, 1) to (start + 0, 2)
= (((Zero + ((c6 + Zero) + Zero)) + Zero) + c3)
- Code(Expression(47, Add)) at (prev + 1, 1) to (start + 0, 2)
= ((((c4 + c5) + ((c6 + c7) + (c8 + c9))) + ((c10 + c11) + ((c12 + c13) + (c14 + c15)))) + c3)

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
- // MIR for `foo` before DataflowConstProp
+ // MIR for `foo` after DataflowConstProp

fn foo() -> u32 {
let mut _0: u32;
let _1: (u32, u32);
let mut _4: bool;
let mut _5: u32;
scope 1 {
debug a => _1;
let _2: (u32, u32);
scope 2 {
debug b => _2;
let _3: u32;
scope 3 {
debug c => _3;
}
}
}

bb0: {
StorageLive(_1);
_1 = const Foo;
StorageLive(_2);
- _2 = _1;
+ _2 = const (5_u32, 3_u32);
StorageLive(_3);
- _3 = (_2.1: u32);
+ _3 = const 3_u32;
StorageLive(_4);
StorageLive(_5);
- _5 = _3;
- _4 = Ge(move _5, const 2_u32);
- switchInt(move _4) -> [0: bb2, otherwise: bb1];
+ _5 = const 3_u32;
+ _4 = const true;
+ switchInt(const true) -> [0: bb2, otherwise: bb1];
}

bb1: {
StorageDead(_5);
- _0 = (_2.0: u32);
+ _0 = const 5_u32;
goto -> bb3;
}

bb2: {
StorageDead(_5);
_0 = const 13_u32;
goto -> bb3;
}

bb3: {
StorageDead(_4);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
return;
}
+ }
+
+ ALLOC0 (size: 8, align: 4) {
+ 05 00 00 00 03 00 00 00 │ ........
}

Loading

0 comments on commit 53ab1ce

Please sign in to comment.