Skip to content

Commit f879fcb

Browse files
committed
Try an inliner tweak
1 parent 557d607 commit f879fcb

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

compiler/rustc_mir_transform/src/cost_checker.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_middle::bug;
22
use rustc_middle::mir::visit::*;
33
use rustc_middle::mir::*;
44
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
5+
use rustc_span::sym;
56

67
const INSTR_COST: usize = 5;
78
const CALL_PENALTY: usize = 25;
@@ -127,14 +128,24 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
127128
}
128129
}
129130
TerminatorKind::Call { func, unwind, .. } => {
130-
self.penalty += if let Some((def_id, ..)) = func.const_fn_def()
131-
&& self.tcx.intrinsic(def_id).is_some()
132-
{
133-
// Don't give intrinsics the extra penalty for calls
134-
INSTR_COST
135-
} else {
136-
CALL_PENALTY
137-
};
131+
let mut is_intrinsic = false;
132+
let mut is_ubcheck = false;
133+
if let Some((def_id, ..)) = func.const_fn_def() {
134+
if self.tcx.intrinsic(def_id).is_some() {
135+
is_intrinsic = true;
136+
}
137+
if self.tcx.has_attr(def_id, sym::rustc_no_mir_inline) {
138+
is_ubcheck = true;
139+
}
140+
}
141+
if !is_ubcheck {
142+
self.penalty += if is_intrinsic {
143+
// Don't give intrinsics the extra penalty for calls
144+
INSTR_COST
145+
} else {
146+
CALL_PENALTY
147+
};
148+
}
138149
if let UnwindAction::Cleanup(_) = unwind {
139150
self.penalty += LANDINGPAD_PENALTY;
140151
}

0 commit comments

Comments
 (0)