Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ad726ca
Do not suggest `as_deref` for a slice pattern on `Err`
lapla-cogito Nov 3, 2026
3d486d0
prevent optimization for input in benchmarks
ywxt Nov 11, 2026
499332a
avoid redundant scans when extracting stage0 archives
TaKO8Ki Nov 11, 2026
832e0f3
prepare stage0 directories before parallel extraction
TaKO8Ki Nov 12, 2026
b0b3bfd
Preserve equality when relating binder regions
Dnreikronos Oct 11, 2026
1773f53
Test equality and variance across binder boundaries
Dnreikronos Oct 11, 2026
211e160
Enhance documentation for try_clone File implementation
MarioIlRosso Nov 13, 2026
33726d1
`rustc_hir_typeck::upvar`: replace for loop with `.any()`
Jules-Bertholet Nov 13, 2026
016e281
Merge `type_bf16()` with `type_f16b()`
beetrees Nov 13, 2026
0df9784
windows: use io::const_error in get_access_mode
seritools Nov 13, 2026
a6b77dd
Tweak wording of missing `core` note
estebank Nov 13, 2026
8bb9cef
PassWrapper: adapt for latest round of LLVM codegen flag refactor
durin42 Nov 14, 2026
9f9ec71
cranelift: use fallbacks for abs f16, f128
N1ark Sep 6, 2026
624e461
Make `copysign` generic
N1ark Sep 6, 2026
268bdaa
Make minimum/maximum generic
N1ark Sep 6, 2026
cc56d88
Replace float bound impls with a macro
N1ark Sep 7, 2026
6054bc3
De-constify the `FloatPrimitive` sealed trait
N1ark Sep 7, 2026
4b1ebeb
Add test
N1ark Sep 7, 2026
8b24bbd
Improve collapsed suggestions for trait impls tuples
rperier Oct 7, 2026
e8c680b
Document wide pointers in core::ptr module
MarioIlRosso Nov 14, 2026
5e71be3
Mention `#![doc = include_str!(...)]` trick in intro page
MarioIlRosso Nov 14, 2026
2c79d71
do not panic on non-UTF-8 arguments in `install_ice_hook`
TaKO8Ki Nov 15, 2026
84661ca
add a regression test for non-UTF-8 command-line arguments
TaKO8Ki Nov 15, 2026
dcf41ce
pipe_subprocess test: use libtest harness
RalfJung Nov 15, 2026
f4e35f8
Fix(docs): Correct discard behavior in datagram peek docs
Suryansh-Dey Nov 15, 2026
8cdd0bf
Do not include context span when source is unavailable to render
estebank Oct 6, 2026
e0c8da3
Rollup merge of #165819 - TaKO8Ki:avoid-stage0-archive-rescans, r=Mar…
Zalathar Nov 16, 2026
dc8bcda
Rollup merge of #157984 - Dnreikronos:trait_solver/binder_region_cons…
Zalathar Nov 16, 2026
1e65848
Rollup merge of #162414 - N1ark:const-unstable-float-generics, r=Ralf…
Zalathar Nov 16, 2026
633654c
Rollup merge of #163891 - estebank:tweak-context-unavailable, r=Muscraft
Zalathar Nov 16, 2026
b95da3b
Rollup merge of #164156 - rperier:fix_better_suggestions_for_trait_im…
Zalathar Nov 16, 2026
feddf11
Rollup merge of #165900 - estebank:issue-91459, r=nnethercote
Zalathar Nov 16, 2026
3a24dfc
Rollup merge of #165978 - MarioIlRosso:issue-148592-fix, r=notriddle
Zalathar Nov 16, 2026
76e8776
Rollup merge of #165406 - lapla-cogito:issue_165365, r=dianne,adwinwhite
Zalathar Nov 16, 2026
c09171e
Rollup merge of #165792 - ywxt:ascii-bench, r=JohnTitor
Zalathar Nov 16, 2026
e87f645
Rollup merge of #165936 - MarioIlRosso:issue-77520-fix, r=Noratrieb
Zalathar Nov 16, 2026
1a38037
Rollup merge of #165938 - Jules-Bertholet:mini-refactor, r=jieyouxu
Zalathar Nov 16, 2026
4532ee7
Rollup merge of #165941 - beetrees:merge-type-bf16-f16b, r=folkertdev
Zalathar Nov 16, 2026
681c181
Rollup merge of #165942 - rust9x:windows-io-const-error, r=clarfonthey
Zalathar Nov 16, 2026
b24dcf8
Rollup merge of #165946 - durin42:llvm-24-more-flag-stuff, r=Zalathar
Zalathar Nov 16, 2026
6a12ac7
Rollup merge of #165956 - MarioIlRosso:issue-164818-fix, r=maxdexh
Zalathar Nov 16, 2026
d027c8f
Rollup merge of #165987 - TaKO8Ki:ice-hook-non-utf8-args, r=workingju…
Zalathar Nov 16, 2026
b5fb2f9
Rollup merge of #165993 - RalfJung:pipe-subprocess, r=JohnTitor
Zalathar Nov 16, 2026
22cdd17
Rollup merge of #165996 - Suryansh-Dey:peek_docs, r=JohnTitor
Zalathar Nov 16, 2026
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
366 changes: 105 additions & 261 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Large diffs are not rendered by default.

108 changes: 29 additions & 79 deletions compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,20 @@ use crate::context::CodegenCx;
use crate::intrinsic::simd::generic_simd_intrinsic;
use crate::type_of::LayoutGccExt;

fn float_intrinsic<'gcc, 'tcx>(
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
fn binop_libcall<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
typ: Type<'gcc>,
name: &str,
) -> Option<Function<'gcc>> {
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
Some(cx.context.new_function(
) -> Function<'gcc> {
cx.context.new_function(
None,
FunctionType::Extern,
typ,
&[cx.context.new_parameter(None, typ, "a"), cx.context.new_parameter(None, typ, "b")],
name,
false,
))
}

fn get_simple_intrinsic<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
name: Symbol,
) -> Option<Function<'gcc>> {
let gcc_name = match name {
sym::minimumf32 => return float_intrinsic(cx, cx.type_f32(), "fminimumf"),
sym::minimumf64 => return float_intrinsic(cx, cx.type_f64(), "fminimum"),
sym::minimumf128 => return float_intrinsic(cx, cx.type_f128(), "fminimumf128"),
sym::maximumf32 => return float_intrinsic(cx, cx.type_f32(), "fmaximumf"),
sym::maximumf64 => return float_intrinsic(cx, cx.type_f64(), "fmaximum"),
sym::maximumf128 => return float_intrinsic(cx, cx.type_f128(), "fmaximumf128"),
sym::copysignf32 => "copysignf",
sym::copysignf64 => "copysign",
_ => return None,
};
Some(cx.context.get_builtin_function(gcc_name))
)
}

fn get_simple_function_f128<'gcc, 'tcx>(
Expand All @@ -76,6 +58,7 @@ fn get_simple_function_f128<'gcc, 'tcx>(
) -> Function<'gcc> {
let f128_type = cx.type_f128();
let (func_name, args): (&str, &[gccjit::Type<'_>]) = match name {
sym::copysign => ("copysignf128", &[f128_type, f128_type]),
sym::ceil => ("ceilf128", &[f128_type]),
sym::cos => ("cosf128", &[f128_type]),
sym::fabs => ("fabsf128", &[f128_type]),
Expand All @@ -92,6 +75,8 @@ fn get_simple_function_f128<'gcc, 'tcx>(
sym::sqrt => ("sqrtf128", &[f128_type]),
sym::powf => ("powf128", &[f128_type, f128_type]),
sym::fma => ("fmaf128", &[f128_type, f128_type, f128_type]),
sym::minimum => ("fminimumf128", &[f128_type, f128_type]),
sym::maximum => ("fmaximumf128", &[f128_type, f128_type]),
_ => span_bug!(span, "used get_simple_function_f128 for unsupported f128 intrinsic"),
};
let args: Vec<_> = args
Expand All @@ -110,7 +95,7 @@ fn f16_builtin<'gcc, 'tcx>(
let f32_type = cx.type_f32();
let builtin_name = match name {
sym::ceil => "__builtin_ceilf",
sym::copysignf16 => "__builtin_copysignf",
sym::copysign => "__builtin_copysignf",
sym::cos => "cosf",
sym::exp => "expf",
sym::exp2 => "exp2f",
Expand Down Expand Up @@ -152,60 +137,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
let name_str = name.as_str();
let fn_args = instance.args;

let simple = get_simple_intrinsic(self, name);

let value = match name {
_ if let Some(func) = simple => self.cx.context.new_call(
self.location,
func,
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
),
// FIXME(antoyo): We can probably remove these and use the fallback intrinsic implementation.
sym::minimumf32 | sym::minimumf64 | sym::maximumf32 | sym::maximumf64 => {
let (ty, func_name) = match name {
sym::minimumf32 => (self.cx.float_type, "fminimumf"),
sym::maximumf32 => (self.cx.float_type, "fmaximumf"),
sym::minimumf64 => (self.cx.double_type, "fminimum"),
sym::maximumf64 => (self.cx.double_type, "fmaximum"),
_ => unreachable!(),
};
let func = self.cx.context.new_function(
None,
FunctionType::Extern,
ty,
&[
self.cx.context.new_parameter(None, ty, "a"),
self.cx.context.new_parameter(None, ty, "b"),
],
func_name,
false,
);
self.cx.context.new_call(
self.location,
func,
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
)
}
sym::copysignf16 => f16_builtin(self, name, args),
sym::copysignf128 if self.cx.supports_f128_type => {
let f128_type = self.cx.type_f128();
let func = self.cx.context.new_function(
None,
FunctionType::Extern,
f128_type,
&[
self.cx.context.new_parameter(None, f128_type, "a"),
self.cx.context.new_parameter(None, f128_type, "b"),
],
"copysignf128",
false,
);
self.cx.context.new_call(
self.location,
func,
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
)
}
sym::is_val_statically_known => {
let a = args[0].immediate();
let builtin = self.context.get_builtin_function("__builtin_constant_p");
Expand Down Expand Up @@ -317,7 +249,10 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
}
}
}
sym::fabs
sym::copysign
| sym::fabs
| sym::minimum
| sym::maximum
| sym::sqrt
| sym::powf
| sym::fma
Expand All @@ -337,13 +272,28 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
| sym::powi => 'float_op: {
let ty = args[0].layout.ty;
let ty::Float(float_ty) = *ty.kind() else {
span_bug!(span, "expected float type for fabs intrinsic: {:?}", ty);
span_bug!(span, "expected float type for {:?} intrinsic: {:?}", name, ty);
};
use ty::FloatTy::*;
let func = match (name, float_ty) {
(sym::copysign, F32) => self.context.get_builtin_function("copysignf"),
(sym::copysign, F64) => self.context.get_builtin_function("copysign"),

(sym::fabs, F32) => self.context.get_builtin_function("fabsf"),
(sym::fabs, F64) => self.context.get_builtin_function("fabs"),

// FIXME(antoyo): We can probably remove these and use the fallback intrinsic implementation.
(sym::minimum, F32) => binop_libcall(self, self.type_f32(), "fminimumf"),
(sym::minimum, F64) => binop_libcall(self, self.type_f64(), "fminimum"),
(sym::maximum, F32) => binop_libcall(self, self.type_f32(), "fmaximumf"),
(sym::maximum, F64) => binop_libcall(self, self.type_f64(), "fmaximum"),

// `f16` has no builtin for these, use the intrinsic fallback bodies instead.
(sym::minimum | sym::maximum, F16) => {
let fallback = Instance::new_raw(instance.def_id(), instance.args);
return IntrinsicResult::Fallback(fallback);
}

(sym::sqrt, F32) => self.context.get_builtin_function("sqrtf"),
(sym::sqrt, F64) => self.context.get_builtin_function("sqrt"),

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/llvm_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl CodegenBackend for LlvmCodegenBackend {
sym::round, sym::round_ties_even,
sym::fma,

sym::copysignf16, sym::copysignf32, sym::copysignf64, sym::copysignf128,
sym::copysign,
];

will_not_use_fallback
Expand Down
72 changes: 22 additions & 50 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,6 @@ use crate::llvm::{self, Attribute, AttributePlace, Metadata, Type, TypeKind, Val
use crate::type_of::LayoutLlvmExt;
use crate::va_arg::emit_va_arg;

fn call_simple_intrinsic<'ll, 'tcx>(
bx: &mut Builder<'_, 'll, 'tcx>,
name: Symbol,
args: &[OperandRef<'tcx, Value<'ll>>],
) -> Option<Value<'ll>> {
let llvm_version = crate::llvm_util::get_version();
// minimum/maximum were broken for f64/f128 before
// <https://github.com/llvm/llvm-project/commit/56385af687c3a7a1f67716fb3f819336789a8cab>.
// We use the fallback body there.
let fixed_minmax = llvm_version >= (23, 0, 0);

let (base_name, type_params): (&'static str, &[Type<'ll>]) = match name {
sym::minimumf16 => ("llvm.minimum", &[bx.type_f16()]),
sym::minimumf32 => ("llvm.minimum", &[bx.type_f32()]),
sym::minimumf64 if fixed_minmax => ("llvm.minimum", &[bx.type_f64()]),
sym::minimumf128 if fixed_minmax => ("llvm.minimum", &[bx.type_f128()]),

sym::maximumf16 => ("llvm.maximum", &[bx.type_f16()]),
sym::maximumf32 => ("llvm.maximum", &[bx.type_f32()]),
sym::maximumf64 if fixed_minmax => ("llvm.maximum", &[bx.type_f64()]),
sym::maximumf128 if fixed_minmax => ("llvm.maximum", &[bx.type_f128()]),

sym::copysignf16 => ("llvm.copysign", &[bx.type_f16()]),
sym::copysignf32 => ("llvm.copysign", &[bx.type_f32()]),
sym::copysignf64 => ("llvm.copysign", &[bx.type_f64()]),
sym::copysignf128 => ("llvm.copysign", &[bx.type_f128()]),

_ => return None,
};
Some(bx.call_intrinsic(
base_name,
type_params,
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
))
}

impl<'ll, 'tcx> Builder<'_, 'll, 'tcx> {
fn black_box(&mut self, result: PlaceRef<'tcx, Value<'ll>>, span: Span) {
let result_val_span = [result.val.llval];
Expand Down Expand Up @@ -135,18 +99,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
let name = tcx.item_name(instance.def_id());
let fn_args = instance.args;

let simple = call_simple_intrinsic(self, name, args);
let llval = match name {
_ if simple.is_some() => simple.unwrap(),
sym::minimum_number_nsz_f16
| sym::minimum_number_nsz_f32
| sym::minimum_number_nsz_f64
| sym::minimum_number_nsz_f128
| sym::maximum_number_nsz_f16
| sym::maximum_number_nsz_f32
| sym::maximum_number_nsz_f64
| sym::maximum_number_nsz_f128 => {
let intrinsic_name = if name.as_str().starts_with("min") {
sym::minimum_number_nsz | sym::maximum_number_nsz => {
let intrinsic_name = if name == sym::minimum_number_nsz {
"llvm.minimumnum"
} else {
"llvm.maximumnum"
Expand Down Expand Up @@ -503,7 +458,8 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
}
}

sym::fabs
sym::copysign
| sym::fabs
| sym::sqrt
| sym::powf
| sym::fma
Expand All @@ -520,7 +476,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
| sym::log2
| sym::sin
| sym::cos
| sym::powi => {
| sym::powi
| sym::minimum
| sym::maximum => {
let ty = args[0].layout.ty;
let ty::Float(f) = ty.kind() else {
span_bug!(
Expand All @@ -532,6 +490,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
};
let llty = self.type_float_from_ty(*f);
let llvm_name = match name {
sym::copysign => "llvm.copysign",
sym::fabs => "llvm.fabs",
sym::sqrt => "llvm.sqrt",
sym::powf => "llvm.pow",
Expand All @@ -555,6 +514,19 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
sym::cos => "llvm.cos",
sym::powi => "llvm.powi",

// minimum/maximum were broken for f64/f128 before
// <https://github.com/llvm/llvm-project/commit/56385af687c3a7a1f67716fb3f819336789a8cab>.
// We use the fallback body there.
sym::minimum | sym::maximum
if llvm_version < (23, 0, 0)
&& matches!(f, ty::FloatTy::F64 | ty::FloatTy::F128) =>
{
let fallback = ty::Instance::new_raw(instance.def_id(), instance.args);
return IntrinsicResult::Fallback(fallback);
}
sym::minimum => "llvm.minimum",
sym::maximum => "llvm.maximum",

_ => bug!(),
};

Expand Down Expand Up @@ -1086,7 +1058,7 @@ fn can_autocast<'ll>(cx: &CodegenCx<'ll, '_>, rust_ty: Type<'ll>, llvm_ty: Type<
_ if let Some((llvm_element_ty, element_count)) =
cx.vector_element_type_and_length(llvm_ty) =>
{
if llvm_element_ty == cx.type_bf16() {
if llvm_element_ty == cx.type_f16b() {
rust_ty == cx.type_vector(cx.type_i16(), element_count)
} else if llvm_element_ty == cx.type_i1() {
let int_width = element_count.next_power_of_two().max(8);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,6 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
}
}

pub(crate) fn type_bf16(&self) -> Type<'ll> {
unsafe { llvm::LLVMBFloatTypeInContext(self.llcx()) }
}

pub(crate) fn type_array(&self, ty: Type<'ll>, len: u64) -> Type<'ll> {
unsafe { llvm::LLVMArrayType2(ty, len) }
}
Expand Down
Loading
Loading