@@ -60,10 +60,20 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
60
60
61
61
fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , _location : Location ) {
62
62
match rvalue {
63
- Rvalue :: NullaryOp ( NullOp :: UbChecks , ..) if !self . tcx . sess . ub_checks ( ) => {
63
+ Rvalue :: NullaryOp ( NullOp :: UbChecks , ..)
64
+ if self
65
+ . tcx
66
+ . sess
67
+ . opts
68
+ . unstable_opts
69
+ . inline_mir_preserve_debug
70
+ . unwrap_or ( !self . tcx . sess . ub_checks ( ) ) =>
71
+ {
64
72
// If this is in optimized MIR it's because it's used later,
65
73
// so if we don't need UB checks this session, give a bonus
66
74
// here to offset the cost of the call later.
75
+ // But if we're building std, give it the bonus regardless of the
76
+ // current configuration so we get consistent inlining.
67
77
self . bonus += CALL_PENALTY ;
68
78
}
69
79
// These are essentially constants that didn't end up in an Operand,
@@ -111,12 +121,19 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
111
121
}
112
122
}
113
123
TerminatorKind :: Assert { unwind, msg, .. } => {
114
- self . penalty +=
115
- if msg. is_optional_overflow_check ( ) && !self . tcx . sess . overflow_checks ( ) {
116
- INSTR_COST
117
- } else {
118
- CALL_PENALTY
119
- } ;
124
+ self . penalty += if msg. is_optional_overflow_check ( )
125
+ && self
126
+ . tcx
127
+ . sess
128
+ . opts
129
+ . unstable_opts
130
+ . inline_mir_preserve_debug
131
+ . unwrap_or ( !self . tcx . sess . overflow_checks ( ) )
132
+ {
133
+ INSTR_COST
134
+ } else {
135
+ CALL_PENALTY
136
+ } ;
120
137
if let UnwindAction :: Cleanup ( _) = unwind {
121
138
self . penalty += LANDINGPAD_PENALTY ;
122
139
}
0 commit comments