@@ -146,24 +146,6 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
146
146
}
147
147
}
148
148
}
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
- }
167
149
}
168
150
169
151
/// Codegen implementations for some terminator variants.
@@ -198,8 +180,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
198
180
let discr = self . codegen_operand ( & mut bx, & discr) ;
199
181
// `switch_ty` is redundant, sanity-check that.
200
182
assert_eq ! ( discr. layout. ty, switch_ty) ;
201
- helper. maybe_sideeffect ( self . mir , & mut bx, targets. all_targets ( ) ) ;
202
-
203
183
let mut target_iter = targets. iter ( ) ;
204
184
if target_iter. len ( ) == 1 {
205
185
// 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> {
308
288
309
289
if let ty:: InstanceDef :: DropGlue ( _, None ) = drop_fn. def {
310
290
// we don't actually need to drop anything.
311
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
312
291
helper. funclet_br ( self , & mut bx, target) ;
313
292
return ;
314
293
}
@@ -337,7 +316,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
337
316
}
338
317
_ => ( bx. get_fn_addr ( drop_fn) , FnAbi :: of_instance ( & bx, drop_fn, & [ ] ) ) ,
339
318
} ;
340
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
341
319
helper. do_call (
342
320
self ,
343
321
& mut bx,
@@ -379,7 +357,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
379
357
380
358
// Don't codegen the panic block if success if known.
381
359
if const_cond == Some ( expected) {
382
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
383
360
helper. funclet_br ( self , & mut bx, target) ;
384
361
return ;
385
362
}
@@ -390,7 +367,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
390
367
// Create the failure block and the conditional branch to it.
391
368
let lltarget = helper. llblock ( self , target) ;
392
369
let panic_block = self . new_block ( "panic" ) ;
393
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
394
370
if expected {
395
371
bx. cond_br ( cond, lltarget, panic_block. llbb ( ) ) ;
396
372
} else {
@@ -491,9 +467,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
491
467
let fn_abi = FnAbi :: of_instance ( bx, instance, & [ ] ) ;
492
468
let llfn = bx. get_fn_addr ( instance) ;
493
469
494
- if let Some ( ( _, target) ) = destination. as_ref ( ) {
495
- helper. maybe_sideeffect ( self . mir , bx, & [ * target] ) ;
496
- }
497
470
// Codegen the actual panic invoke/call.
498
471
helper. do_call (
499
472
self ,
@@ -507,7 +480,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
507
480
} else {
508
481
// a NOP
509
482
let target = destination. as_ref ( ) . unwrap ( ) . 1 ;
510
- helper. maybe_sideeffect ( self . mir , bx, & [ target] ) ;
511
483
helper. funclet_br ( self , bx, target)
512
484
}
513
485
true
@@ -551,7 +523,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
551
523
if let Some ( ty:: InstanceDef :: DropGlue ( _, None ) ) = def {
552
524
// Empty drop glue; a no-op.
553
525
let & ( _, target) = destination. as_ref ( ) . unwrap ( ) ;
554
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
555
526
helper. funclet_br ( self , & mut bx, target) ;
556
527
return ;
557
528
}
@@ -586,7 +557,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
586
557
if let Some ( destination_ref) = destination. as_ref ( ) {
587
558
let & ( dest, target) = destination_ref;
588
559
self . codegen_transmute ( & mut bx, & args[ 0 ] , dest) ;
589
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
590
560
helper. funclet_br ( self , & mut bx, target) ;
591
561
} else {
592
562
// 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> {
634
604
location. val . store ( & mut bx, tmp) ;
635
605
}
636
606
self . store_return ( & mut bx, ret_dest, & fn_abi. ret , location. immediate ( ) ) ;
637
-
638
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ * target] ) ;
639
607
helper. funclet_br ( self , & mut bx, * target) ;
640
608
}
641
609
return ;
@@ -700,7 +668,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
700
668
}
701
669
702
670
if let Some ( ( _, target) ) = * destination {
703
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
704
671
helper. funclet_br ( self , & mut bx, target) ;
705
672
} else {
706
673
bx. unreachable ( ) ;
@@ -817,9 +784,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
817
784
_ => span_bug ! ( span, "no llfn for call" ) ,
818
785
} ;
819
786
820
- if let Some ( ( _, target) ) = destination. as_ref ( ) {
821
- helper. maybe_sideeffect ( self . mir , & mut bx, & [ * target] ) ;
822
- }
823
787
helper. do_call (
824
788
self ,
825
789
& mut bx,
@@ -969,22 +933,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
969
933
970
934
mir:: TerminatorKind :: Goto { target } => {
971
935
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).
980
941
//
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 ( ) ;
987
944
}
945
+
988
946
helper. funclet_br ( self , & mut bx, target) ;
989
947
}
990
948
0 commit comments