@@ -169,6 +169,12 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
169
169
crate :: optimize:: optimize_function ( tcx, instance, context, & cold_blocks, & mut clif_comments) ;
170
170
} ) ;
171
171
172
+ // If the return block is not reachable, then the SSA builder may have inserted a `iconst.i128`
173
+ // instruction, which doesn't have an encoding.
174
+ context. compute_cfg ( ) ;
175
+ context. compute_domtree ( ) ;
176
+ context. eliminate_unreachable_code ( cx. module . isa ( ) ) . unwrap ( ) ;
177
+
172
178
// Define function
173
179
let module = & mut cx. module ;
174
180
tcx. sess . time (
@@ -265,6 +271,23 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
265
271
266
272
match & bb_data. terminator ( ) . kind {
267
273
TerminatorKind :: Goto { target } => {
274
+ if let TerminatorKind :: Return = fx. mir [ * target] . terminator ( ) . kind {
275
+ let mut can_immediately_return = true ;
276
+ for stmt in & fx. mir [ * target] . statements {
277
+ if let StatementKind :: StorageDead ( _) = stmt. kind {
278
+ } else {
279
+ // FIXME Can sometimes happen, see rust-lang/rust#70531
280
+ can_immediately_return = false ;
281
+ break ;
282
+ }
283
+ }
284
+
285
+ if can_immediately_return {
286
+ crate :: abi:: codegen_return ( fx) ;
287
+ continue ;
288
+ }
289
+ }
290
+
268
291
let block = fx. get_block ( * target) ;
269
292
fx. bcx . ins ( ) . jump ( block, & [ ] ) ;
270
293
}
0 commit comments