Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions compiler/rustc_mir_transform/src/cross_crate_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_middle::mir::*;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{InliningThreshold, OptLevel};
use rustc_span::bug;
use rustc_span::{bug, sym};

use crate::{inline, pass_manager as pm};

Expand Down Expand Up @@ -64,13 +64,19 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
return true;
}

let sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip();
for ty in sig.inputs().skip_binder().iter().chain(std::iter::once(&sig.output().skip_binder()))
{
// FIXME(f16_f128): in order to avoid crashes building `core`, always inline to skip
// codegen if the function is not used.
if ty == &tcx.types.f16 || ty == &tcx.types.f128 {
return true;
let reliable_f16 = tcx.sess.config.contains(&(sym::target_has_reliable_f16, None));
let reliable_f128 = tcx.sess.config.contains(&(sym::target_has_reliable_f128, None));
if !reliable_f16 || !reliable_f128 {
let sig = tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip();
for ty in
sig.inputs().skip_binder().iter().chain(std::iter::once(&sig.output().skip_binder()))
{
// FIXME(f16,f128): in order to avoid crashes building `core`, inline on targets that
// have issues to skip codegen if the function is not used.
if (!reliable_f16 && ty == &tcx.types.f16) || (!reliable_f128 && ty == &tcx.types.f128)
{
return true;
}
}
}

Expand Down
91 changes: 73 additions & 18 deletions tests/codegen-llvm/float/f16-f128-inline.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,84 @@
//@ revisions: default nopt
//@[nopt] compile-flags: -Copt-level=0 -Zcross-crate-inline-threshold=never -Zmir-opt-level=0 -Cno-prepopulate-passes
//@ revisions: DEFAULT NOPT
//@[NOPT] compile-flags: -Copt-level=0 -Zcross-crate-inline-threshold=never -Zmir-opt-level=0 -Cno-prepopulate-passes

// Ensure that functions using `f16` and `f128` are always inlined to avoid crashes
// when the backend does not support these types.
// Ensure that functions using `f16` and `f128` are always inlined when the backend does not
// support these types, to avoid crashes.

#![crate_type = "lib"]
#![feature(f128)]
#![feature(f16)]
#![feature(cfg_target_has_reliable_f16_f128)]

pub fn f16_arg(_a: f16) {
// CHECK-NOT: f16_arg
todo!()
}
// This test does some tricky things. On `target_has_reliable_*` platforms:
//
// * `*_on_reliable` functions should always show up in codegen since they are not auto-inlined
// (the default),
// * `*_on_not_reliable` functions aren't defined at all, so `CHECK-NOT` passes.
//
// On non-`target_has_reliable_*` platforms:
//
// * `*_on_reliable` functions are dummies so they always show up in codegen.
// * `*_on_not_reliable` functions should be auto-inlined and thus not show up in codegen.
//
// `*_on_reliable` is only checked with NOPT since otherwise they may hit auto-inlining thresholds
// unrelated to the type signature.

pub fn f16_ret() -> f16 {
// CHECK-NOT: f16_ret
todo!()
}
// NOPT: f16_arg_on_reliable
// NOPT: f16_ret_on_reliable
// CHECK-NOT: f16_arg_on_not_reliable
// CHECK-NOT: f16_ret_on_not_reliable
cfg_select! {
target_has_reliable_f16 => {
pub fn f16_arg_on_reliable(_a: f16) {
todo!()
}

pub fn f16_ret_on_reliable() -> f16 {
todo!()
}
}
_ => {
pub fn f16_arg_on_not_reliable(_a: f16) {
todo!()
}

pub fn f16_ret_on_not_reliable() -> f16 {
todo!()
}

pub fn f128_arg(_a: f128) {
// CHECK-NOT: f128_arg
todo!()
#[unsafe(no_mangle)]
pub fn f16_arg_on_reliable() {}
#[unsafe(no_mangle)]
pub fn f16_ret_on_reliable() {}
}
}

pub fn f128_ret() -> f128 {
// CHECK-NOT: f128_ret
todo!()
// NOPT: f128_arg_on_reliable
// NOPT: f128_ret_on_reliable
// CHECK-NOT: f128_arg_on_not_reliable
// CHECK-NOT: f128_ret_on_not_reliable
cfg_select! {
target_has_reliable_f128 => {
pub fn f128_arg_on_reliable(_a: f128) {
todo!()
}

pub fn f128_ret_on_reliable() -> f128 {
todo!()
}
}
_ => {
pub fn f128_arg_on_not_reliable(_a: f128) {
todo!()
}

pub fn f128_ret_on_not_reliable() -> f128 {
todo!()
}

#[unsafe(no_mangle)]
pub fn f128_arg_on_reliable() {}
#[unsafe(no_mangle)]
pub fn f128_ret_on_reliable() {}
}
}
Loading