insert storageDead for not equal temp
This commit is contained in:
parent
2530274023
commit
118aae2af1
@ -46,27 +46,32 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
||||
|
||||
for opt_to_apply in opts_to_apply {
|
||||
trace!("SUCCESS: found optimization possibility to apply: {:?}", &opt_to_apply);
|
||||
// create the patch using MirPatch
|
||||
let mut patch = MirPatch::new(body);
|
||||
|
||||
// create temp to store second discriminant in
|
||||
let discr_type = opt_to_apply.infos[0].second_switch_info.discr_ty;
|
||||
let discr_span = opt_to_apply.infos[0].second_switch_info.discr_source_info.span;
|
||||
let temp = patch.new_temp(discr_type, discr_span);
|
||||
let statements_before =
|
||||
body.basic_blocks()[opt_to_apply.basic_block_first_switch].statements.len();
|
||||
let end_of_block_location = Location {
|
||||
block: opt_to_apply.basic_block_first_switch,
|
||||
statement_index: statements_before,
|
||||
};
|
||||
patch.add_statement(end_of_block_location, StatementKind::StorageLive(temp));
|
||||
|
||||
let mut patch = MirPatch::new(body);
|
||||
|
||||
// create temp to store second discriminant in
|
||||
let discr_type = opt_to_apply.infos[0].second_switch_info.discr_ty;
|
||||
let discr_span = opt_to_apply.infos[0].second_switch_info.discr_source_info.span;
|
||||
let second_discriminant_temp = patch.new_temp(discr_type, discr_span);
|
||||
|
||||
patch.add_statement(
|
||||
end_of_block_location,
|
||||
StatementKind::StorageLive(second_discriminant_temp),
|
||||
);
|
||||
|
||||
// create assignment of discriminant
|
||||
let place_of_adt_to_get_discriminant_of =
|
||||
opt_to_apply.infos[0].second_switch_info.place_of_adt_discr_read;
|
||||
patch.add_assign(
|
||||
end_of_block_location,
|
||||
Place::from(temp),
|
||||
Place::from(second_discriminant_temp),
|
||||
Rvalue::Discriminant(place_of_adt_to_get_discriminant_of),
|
||||
);
|
||||
|
||||
@ -81,7 +86,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
||||
opt_to_apply.infos[0].first_switch_info.discr_used_in_switch;
|
||||
let not_equal_rvalue = Rvalue::BinaryOp(
|
||||
not_equal,
|
||||
Operand::Copy(Place::from(temp)),
|
||||
Operand::Copy(Place::from(second_discriminant_temp)),
|
||||
Operand::Copy(Place::from(first_descriminant_place)),
|
||||
);
|
||||
patch.add_statement(
|
||||
@ -126,8 +131,19 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
||||
),
|
||||
);
|
||||
|
||||
// generate StorageDead for the temp not in use anymore. We use the not_equal_temp in the switch, so we can't mark that dead
|
||||
patch.add_statement(end_of_block_location, StatementKind::StorageDead(temp));
|
||||
// generate StorageDead for the second_discriminant_temp not in use anymore
|
||||
patch.add_statement(
|
||||
end_of_block_location,
|
||||
StatementKind::StorageDead(second_discriminant_temp),
|
||||
);
|
||||
|
||||
// Generate a StorageDead for not_equal_temp in each of the targets, since we moved it into the switch
|
||||
for bb in [false_case, true_case].iter() {
|
||||
patch.add_statement(
|
||||
Location { block: *bb, statement_index: 0 },
|
||||
StatementKind::StorageDead(not_equal_temp),
|
||||
);
|
||||
}
|
||||
|
||||
patch.apply(body);
|
||||
}
|
||||
|
@ -40,6 +40,7 @@
|
||||
}
|
||||
|
||||
bb1: {
|
||||
+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15
|
||||
_0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15
|
||||
goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6
|
||||
}
|
||||
@ -70,6 +71,7 @@
|
||||
+ }
|
||||
+
|
||||
+ bb6: {
|
||||
+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26
|
||||
+ switchInt(_7) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@
|
||||
}
|
||||
|
||||
bb2: {
|
||||
+ StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15
|
||||
_0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15
|
||||
goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6
|
||||
}
|
||||
@ -81,6 +82,7 @@
|
||||
+ }
|
||||
+
|
||||
+ bb8: {
|
||||
+ StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20
|
||||
+ switchInt(_8) -> [0_isize: bb5, 1_isize: bb4, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,8 @@
|
||||
}
|
||||
|
||||
bb1: {
|
||||
+ StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15
|
||||
+ StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15
|
||||
_0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15
|
||||
goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6
|
||||
}
|
||||
@ -95,10 +97,12 @@
|
||||
+ }
|
||||
+
|
||||
+ bb7: {
|
||||
+ StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26
|
||||
+ switchInt(_10) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26
|
||||
+ }
|
||||
+
|
||||
+ bb8: {
|
||||
+ StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35
|
||||
+ switchInt(_9) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@
|
||||
}
|
||||
|
||||
bb2: {
|
||||
+ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:25: 24:27
|
||||
StorageLive(_33); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:25: 24:27
|
||||
((_0 as Err).0: ()) = const (); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:21: 24:28
|
||||
discriminant(_0) = 1; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:21: 24:28
|
||||
@ -207,6 +208,7 @@
|
||||
+ }
|
||||
+
|
||||
+ bb13: {
|
||||
+ StorageDead(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:20:21: 20:30
|
||||
+ switchInt(_11) -> [0_isize: bb6, 1_isize: bb7, 2_isize: bb8, 3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:20:21: 20:30
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user