@@ -128,36 +128,27 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
128128
129129 let mut patch = MirPatch :: new ( body) ;
130130
131- let ( second_discriminant_temp , second_operand) = if opt_data. need_hoist_discriminant {
131+ let second_operand = if opt_data. need_hoist_discriminant {
132132 // create temp to store second discriminant in, `_s` in example above
133133 let second_discriminant_temp =
134134 patch. new_temp ( opt_data. child_ty , opt_data. child_source . span ) ;
135135
136- patch. add_statement (
137- parent_end,
138- StatementKind :: StorageLive ( second_discriminant_temp) ,
139- ) ;
140-
141136 // create assignment of discriminant
142137 patch. add_assign (
143138 parent_end,
144139 Place :: from ( second_discriminant_temp) ,
145140 Rvalue :: Discriminant ( opt_data. child_place ) ,
146141 ) ;
147- (
148- Some ( second_discriminant_temp) ,
149- Operand :: Move ( Place :: from ( second_discriminant_temp) ) ,
150- )
142+ Operand :: Move ( Place :: from ( second_discriminant_temp) )
151143 } else {
152- ( None , Operand :: Copy ( opt_data. child_place ) )
144+ Operand :: Copy ( opt_data. child_place )
153145 } ;
154146
155147 // create temp to store inequality comparison between the two discriminants, `_t` in
156148 // example above
157149 let nequal = BinOp :: Ne ;
158150 let comp_res_type = nequal. ty ( tcx, parent_ty, opt_data. child_ty ) ;
159151 let comp_temp = patch. new_temp ( comp_res_type, opt_data. child_source . span ) ;
160- patch. add_statement ( parent_end, StatementKind :: StorageLive ( comp_temp) ) ;
161152
162153 // create inequality comparison
163154 let comp_rvalue =
@@ -193,42 +184,13 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch {
193184 let eq_bb = patch. new_block ( eq_switch) ;
194185
195186 // Jump to it on the basis of the inequality comparison
196- let mut true_case = opt_data. destination ;
197- let mut false_case = eq_bb;
198- // Create an indirect BB to add `StorageDead` If the jump target is itself.
199- for bb in [ & mut false_case, & mut true_case] . into_iter ( ) {
200- if * bb == parent {
201- * bb = patch. new_block ( BasicBlockData :: new (
202- Some ( Terminator {
203- kind : TerminatorKind :: Goto { target : parent } ,
204- source_info : bbs[ parent] . terminator ( ) . source_info ,
205- } ) ,
206- bbs[ parent] . is_cleanup ,
207- ) ) ;
208- }
209- }
187+ let true_case = opt_data. destination ;
188+ let false_case = eq_bb;
210189 patch. patch_terminator (
211190 parent,
212191 TerminatorKind :: if_ ( Operand :: Move ( Place :: from ( comp_temp) ) , true_case, false_case) ,
213192 ) ;
214193
215- if let Some ( second_discriminant_temp) = second_discriminant_temp {
216- // generate StorageDead for the second_discriminant_temp not in use anymore
217- patch. add_statement (
218- parent_end,
219- StatementKind :: StorageDead ( second_discriminant_temp) ,
220- ) ;
221- }
222-
223- // Generate a StorageDead for comp_temp in each of the targets, since we moved it into
224- // the switch
225- for bb in [ false_case, true_case] . into_iter ( ) {
226- patch. add_statement (
227- Location { block : bb, statement_index : 0 } ,
228- StatementKind :: StorageDead ( comp_temp) ,
229- ) ;
230- }
231-
232194 patch. apply ( body) ;
233195 }
234196
0 commit comments