Skip to content

Commit 25264cf

Browse files
committed
Don't codegen expect in opt-level=0
1 parent b286722 commit 25264cf

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
186186
Some(instance),
187187
)
188188
}
189-
sym::likely => {
190-
self.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(true)])
191-
}
189+
sym::likely => self.expect(args[0].immediate(), true),
192190
sym::is_val_statically_known => {
193191
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
194192
match self.type_kind(intrinsic_type) {
@@ -201,8 +199,8 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
201199
_ => self.const_bool(false),
202200
}
203201
}
204-
sym::unlikely => self
205-
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
202+
203+
sym::unlikely => self.expect(args[0].immediate(), false),
206204
sym::catch_unwind => {
207205
catch_unwind_intrinsic(
208206
self,
@@ -566,11 +564,17 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
566564
}
567565

568566
fn assume(&mut self, val: Self::Value) {
569-
self.call_intrinsic("llvm.assume", &[val]);
567+
if self.cx.sess().opts.optimize != rustc_session::config::OptLevel::No {
568+
self.call_intrinsic("llvm.assume", &[val]);
569+
}
570570
}
571571

572572
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value {
573-
self.call_intrinsic("llvm.expect.i1", &[cond, self.const_bool(expected)])
573+
if self.cx.sess().opts.optimize != rustc_session::config::OptLevel::No {
574+
self.call_intrinsic("llvm.expect.i1", &[cond, self.const_bool(expected)])
575+
} else {
576+
cond
577+
}
574578
}
575579

576580
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
332332
scalar: abi::Scalar,
333333
backend_ty: Bx::Type,
334334
) {
335-
if matches!(self.cx.sess().opts.optimize, OptLevel::No | OptLevel::Less)
335+
if matches!(self.cx.sess().opts.optimize, OptLevel::No)
336336
// For now, the critical niches are all over `Int`eger values.
337337
// Should floating-point values or pointers ever get more complex
338338
// niches, then this code will probably want to handle them too.

compiler/rustc_codegen_ssa/src/mir/statement.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6969
self.codegen_coverage(bx, kind, statement.source_info.scope);
7070
}
7171
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => {
72-
if !matches!(bx.tcx().sess.opts.optimize, OptLevel::No | OptLevel::Less) {
73-
let op_val = self.codegen_operand(bx, op);
74-
bx.assume(op_val.immediate());
75-
}
72+
let op_val = self.codegen_operand(bx, op);
73+
bx.assume(op_val.immediate());
7674
}
7775
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(
7876
mir::CopyNonOverlapping { ref count, ref src, ref dst },

0 commit comments

Comments
 (0)