@@ -146,24 +146,6 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
146146 }
147147 }
148148 }
149-
150- // Generate sideeffect intrinsic if jumping to any of the targets can form
151- // a loop.
152- fn maybe_sideeffect < Bx : BuilderMethods < ' a , ' tcx > > (
153- & self ,
154- mir : & ' tcx mir:: Body < ' tcx > ,
155- bx : & mut Bx ,
156- targets : & [ mir:: BasicBlock ] ,
157- ) {
158- if bx. tcx ( ) . sess . opts . debugging_opts . insert_sideeffect {
159- if targets. iter ( ) . any ( |& target| {
160- target <= self . bb
161- && target. start_location ( ) . is_predecessor_of ( self . bb . start_location ( ) , mir)
162- } ) {
163- bx. sideeffect ( false ) ;
164- }
165- }
166- }
167149}
168150
169151/// Codegen implementations for some terminator variants.
@@ -198,8 +180,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
198180 let discr = self . codegen_operand ( & mut bx, & discr) ;
199181 // `switch_ty` is redundant, sanity-check that.
200182 assert_eq ! ( discr. layout. ty, switch_ty) ;
201- helper. maybe_sideeffect ( self . mir , & mut bx, targets. all_targets ( ) ) ;
202-
203183 let mut target_iter = targets. iter ( ) ;
204184 if target_iter. len ( ) == 1 {
205185 // If there are two targets (one conditional, one fallback), emit br instead of switch
@@ -308,7 +288,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
308288
309289 if let ty:: InstanceDef :: DropGlue ( _, None ) = drop_fn. def {
310290 // we don't actually need to drop anything.
311- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
312291 helper. funclet_br ( self , & mut bx, target) ;
313292 return ;
314293 }
@@ -337,7 +316,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
337316 }
338317 _ => ( bx. get_fn_addr ( drop_fn) , FnAbi :: of_instance ( & bx, drop_fn, & [ ] ) ) ,
339318 } ;
340- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
341319 helper. do_call (
342320 self ,
343321 & mut bx,
@@ -379,7 +357,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
379357
380358 // Don't codegen the panic block if success if known.
381359 if const_cond == Some ( expected) {
382- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
383360 helper. funclet_br ( self , & mut bx, target) ;
384361 return ;
385362 }
@@ -390,7 +367,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
390367 // Create the failure block and the conditional branch to it.
391368 let lltarget = helper. llblock ( self , target) ;
392369 let panic_block = self . new_block ( "panic" ) ;
393- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
394370 if expected {
395371 bx. cond_br ( cond, lltarget, panic_block. llbb ( ) ) ;
396372 } else {
@@ -491,9 +467,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
491467 let fn_abi = FnAbi :: of_instance ( bx, instance, & [ ] ) ;
492468 let llfn = bx. get_fn_addr ( instance) ;
493469
494- if let Some ( ( _, target) ) = destination. as_ref ( ) {
495- helper. maybe_sideeffect ( self . mir , bx, & [ * target] ) ;
496- }
497470 // Codegen the actual panic invoke/call.
498471 helper. do_call (
499472 self ,
@@ -507,7 +480,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
507480 } else {
508481 // a NOP
509482 let target = destination. as_ref ( ) . unwrap ( ) . 1 ;
510- helper. maybe_sideeffect ( self . mir , bx, & [ target] ) ;
511483 helper. funclet_br ( self , bx, target)
512484 }
513485 true
@@ -551,7 +523,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
551523 if let Some ( ty:: InstanceDef :: DropGlue ( _, None ) ) = def {
552524 // Empty drop glue; a no-op.
553525 let & ( _, target) = destination. as_ref ( ) . unwrap ( ) ;
554- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
555526 helper. funclet_br ( self , & mut bx, target) ;
556527 return ;
557528 }
@@ -586,7 +557,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
586557 if let Some ( destination_ref) = destination. as_ref ( ) {
587558 let & ( dest, target) = destination_ref;
588559 self . codegen_transmute ( & mut bx, & args[ 0 ] , dest) ;
589- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
590560 helper. funclet_br ( self , & mut bx, target) ;
591561 } else {
592562 // If we are trying to transmute to an uninhabited type,
@@ -634,8 +604,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
634604 location. val . store ( & mut bx, tmp) ;
635605 }
636606 self . store_return ( & mut bx, ret_dest, & fn_abi. ret , location. immediate ( ) ) ;
637-
638- helper. maybe_sideeffect ( self . mir , & mut bx, & [ * target] ) ;
639607 helper. funclet_br ( self , & mut bx, * target) ;
640608 }
641609 return ;
@@ -700,7 +668,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
700668 }
701669
702670 if let Some ( ( _, target) ) = * destination {
703- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
704671 helper. funclet_br ( self , & mut bx, target) ;
705672 } else {
706673 bx. unreachable ( ) ;
@@ -817,9 +784,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
817784 _ => span_bug ! ( span, "no llfn for call" ) ,
818785 } ;
819786
820- if let Some ( ( _, target) ) = destination. as_ref ( ) {
821- helper. maybe_sideeffect ( self . mir , & mut bx, & [ * target] ) ;
822- }
823787 helper. do_call (
824788 self ,
825789 & mut bx,
@@ -969,22 +933,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
969933
970934 mir:: TerminatorKind :: Goto { target } => {
971935 if bb == target {
972- // This is an unconditional branch back to this same basic
973- // block. That means we have something like a `loop {}`
974- // statement. Currently LLVM miscompiles this because it
975- // assumes forward progress. We want to prevent this in all
976- // cases, but that has a fairly high cost to compile times
977- // currently. Instead, try to handle this specific case
978- // which comes up commonly in practice (e.g., in embedded
979- // code).
936+ // This is an unconditional branch back to this same basic block. That means we
937+ // have something like a `loop {}` statement. LLVM versions before 12.0
938+ // miscompile this because they assume forward progress. For older versions
939+ // try to handle just this specific case which comes up commonly in practice
940+ // (e.g., in embedded code).
980941 //
981- // The `true` here means we insert side effects regardless
982- // of -Zinsert-sideeffect being passed on unconditional
983- // branching to the same basic block.
984- bx. sideeffect ( true ) ;
985- } else {
986- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
942+ // NB: the `sideeffect` currently checks for the LLVM version used internally.
943+ bx. sideeffect ( ) ;
987944 }
945+
988946 helper. funclet_br ( self , & mut bx, target) ;
989947 }
990948
0 commit comments