@@ -60,7 +60,27 @@ impl<'b, 'tcx> CostChecker<'b, 'tcx> {
6060}
6161
6262impl < ' tcx > Visitor < ' tcx > for CostChecker < ' _ , ' tcx > {
63- fn visit_statement ( & mut self , statement : & Statement < ' tcx > , _: Location ) {
63+ fn visit_operand ( & mut self , operand : & Operand < ' tcx > , _: Location ) {
64+ match operand {
65+ Operand :: RuntimeChecks ( RuntimeChecks :: UbChecks ) => {
66+ if !self
67+ . tcx
68+ . sess
69+ . opts
70+ . unstable_opts
71+ . inline_mir_preserve_debug
72+ . unwrap_or ( self . tcx . sess . ub_checks ( ) )
73+ {
74+ // If this is in optimized MIR it's because it's used later, so if we don't need UB
75+ // checks this session, give a bonus here to offset the cost of the call later.
76+ self . bonus += CALL_PENALTY ;
77+ }
78+ }
79+ _ => { }
80+ }
81+ }
82+
83+ fn visit_statement ( & mut self , statement : & Statement < ' tcx > , loc : Location ) {
6484 // Most costs are in rvalues and terminators, not in statements.
6585 match statement. kind {
6686 StatementKind :: Intrinsic ( ref ndi) => {
@@ -72,9 +92,10 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
7292 StatementKind :: Assign ( ..) => self . penalty += INSTR_COST ,
7393 _ => { }
7494 }
95+ self . super_statement ( statement, loc)
7596 }
7697
77- fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , _ : Location ) {
98+ fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , loc : Location ) {
7899 match & terminator. kind {
79100 TerminatorKind :: Drop { place, unwind, .. } => {
80101 // If the place doesn't actually need dropping, treat it like a regular goto.
@@ -151,6 +172,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
151172 bug ! ( "{kind:?} should not be in runtime MIR" ) ;
152173 }
153174 }
175+ self . super_terminator ( terminator, loc)
154176 }
155177}
156178
0 commit comments