Auto merge of #121614 - clubby789:no-expect, r=saethlin
Don't emit `expect`/`assume` in opt-level=0 LLVM does not make use of expect/assume calls in `opt-level=0`, so we can simplify IR by not emitting them in this case.
This commit is contained in:
commit
54fdef7799
4 changed files with 14 additions and 14 deletions
|
@ -187,9 +187,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
Some(instance),
|
Some(instance),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
sym::likely => {
|
sym::likely => self.expect(args[0].immediate(), true),
|
||||||
self.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(true)])
|
|
||||||
}
|
|
||||||
sym::is_val_statically_known => {
|
sym::is_val_statically_known => {
|
||||||
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
|
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
|
||||||
let kind = self.type_kind(intrinsic_type);
|
let kind = self.type_kind(intrinsic_type);
|
||||||
|
@ -210,8 +208,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
self.const_bool(false)
|
self.const_bool(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym::unlikely => self
|
sym::unlikely => self.expect(args[0].immediate(), false),
|
||||||
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
|
|
||||||
sym::select_unpredictable => {
|
sym::select_unpredictable => {
|
||||||
let cond = args[0].immediate();
|
let cond = args[0].immediate();
|
||||||
assert_eq!(args[1].layout, args[2].layout);
|
assert_eq!(args[1].layout, args[2].layout);
|
||||||
|
@ -604,11 +601,17 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assume(&mut self, val: Self::Value) {
|
fn assume(&mut self, val: Self::Value) {
|
||||||
self.call_intrinsic("llvm.assume", &[val]);
|
if self.cx.sess().opts.optimize != rustc_session::config::OptLevel::No {
|
||||||
|
self.call_intrinsic("llvm.assume", &[val]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value {
|
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value {
|
||||||
self.call_intrinsic("llvm.expect.i1", &[cond, self.const_bool(expected)])
|
if self.cx.sess().opts.optimize != rustc_session::config::OptLevel::No {
|
||||||
|
self.call_intrinsic("llvm.expect.i1", &[cond, self.const_bool(expected)])
|
||||||
|
} else {
|
||||||
|
cond
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value {
|
fn type_test(&mut self, pointer: Self::Value, typeid: Self::Value) -> Self::Value {
|
||||||
|
|
|
@ -382,7 +382,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
scalar: abi::Scalar,
|
scalar: abi::Scalar,
|
||||||
backend_ty: Bx::Type,
|
backend_ty: Bx::Type,
|
||||||
) {
|
) {
|
||||||
if matches!(self.cx.sess().opts.optimize, OptLevel::No | OptLevel::Less)
|
if matches!(self.cx.sess().opts.optimize, OptLevel::No)
|
||||||
// For now, the critical niches are all over `Int`eger values.
|
// For now, the critical niches are all over `Int`eger values.
|
||||||
// Should floating-point values or pointers ever get more complex
|
// Should floating-point values or pointers ever get more complex
|
||||||
// niches, then this code will probably want to handle them too.
|
// niches, then this code will probably want to handle them too.
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use rustc_middle::mir::{self, NonDivergingIntrinsic};
|
use rustc_middle::mir::{self, NonDivergingIntrinsic};
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_session::config::OptLevel;
|
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use super::{FunctionCx, LocalRef};
|
use super::{FunctionCx, LocalRef};
|
||||||
|
@ -68,10 +67,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
self.codegen_coverage(bx, kind, statement.source_info.scope);
|
self.codegen_coverage(bx, kind, statement.source_info.scope);
|
||||||
}
|
}
|
||||||
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => {
|
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => {
|
||||||
if !matches!(bx.tcx().sess.opts.optimize, OptLevel::No | OptLevel::Less) {
|
let op_val = self.codegen_operand(bx, op);
|
||||||
let op_val = self.codegen_operand(bx, op);
|
bx.assume(op_val.immediate());
|
||||||
bx.assume(op_val.immediate());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(
|
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(
|
||||||
mir::CopyNonOverlapping { ref count, ref src, ref dst },
|
mir::CopyNonOverlapping { ref count, ref src, ref dst },
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//@ compile-flags: -C no-prepopulate-passes
|
//@ compile-flags: -C no-prepopulate-passes -Copt-level=1
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue