Skip to content

Commit e8e59d1

Browse files
committed
Auto merge of #154514 - JonathanBrouwer:rollup-ZLbqtwS, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - #147811 (naked functions: respect `function-sections`) - #153834 (Merge `fabsf16/32/64/128` into `fabs::<F>`) - #154043 (simd_fmin/fmax: make semantics and name consistent with scalar intrinsics) - #154494 (triagebot: add reminder for bumping CI LLVM stamp) - #153374 (Fix LegacyKeyValueFormat report from docker build: dist-x86_64) - #154320 (`trim_prefix` for paths) - #154453 (Fix ice in rustdoc of private reexport)
2 parents fb27476 + dd1ba42 commit e8e59d1

48 files changed

Lines changed: 504 additions & 313 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_codegen_cranelift/example/float-minmax-pass.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ fn main() {
3333
let n = f32x4([nan, nan, nan, nan]);
3434

3535
unsafe {
36-
let min0 = simd_fmin(x, y);
37-
let min1 = simd_fmin(y, x);
36+
let min0 = simd_minimum_number_nsz(x, y);
37+
let min1 = simd_minimum_number_nsz(y, x);
3838
assert_eq!(min0.into_array(), min1.into_array());
3939
let e = f32x4([1.0, 1.0, 3.0, 3.0]);
4040
assert_eq!(min0.into_array(), e.into_array());
41-
let minn = simd_fmin(x, n);
41+
let minn = simd_minimum_number_nsz(x, n);
4242
assert_eq!(minn.into_array(), x.into_array());
43-
let minn = simd_fmin(y, n);
43+
let minn = simd_minimum_number_nsz(y, n);
4444
assert_eq!(minn.into_array(), y.into_array());
4545

46-
let max0 = simd_fmax(x, y);
47-
let max1 = simd_fmax(y, x);
46+
let max0 = simd_maximum_number_nsz(x, y);
47+
let max1 = simd_maximum_number_nsz(y, x);
4848
assert_eq!(max0.into_array(), max1.into_array());
4949
let e = f32x4([2.0, 2.0, 4.0, 4.0]);
5050
assert_eq!(max0.into_array(), e.into_array());
51-
let maxn = simd_fmax(x, n);
51+
let maxn = simd_maximum_number_nsz(x, n);
5252
assert_eq!(maxn.into_array(), x.into_array());
53-
let maxn = simd_fmax(y, n);
53+
let maxn = simd_maximum_number_nsz(y, n);
5454
assert_eq!(maxn.into_array(), y.into_array());
5555
}
5656
}

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,6 @@ fn codegen_float_intrinsic_call<'tcx>(
346346
sym::log10f32 => ("log10f", 1, fx.tcx.types.f32, types::F32),
347347
sym::log10f64 => ("log10", 1, fx.tcx.types.f64, types::F64),
348348
sym::log10f128 => ("log10f128", 1, fx.tcx.types.f128, types::F128),
349-
sym::fabsf16 => ("fabsf16", 1, fx.tcx.types.f16, types::F16),
350-
sym::fabsf32 => ("fabsf", 1, fx.tcx.types.f32, types::F32),
351-
sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64, types::F64),
352-
sym::fabsf128 => ("fabsf128", 1, fx.tcx.types.f128, types::F128),
353349
sym::fmaf16 => ("fmaf16", 3, fx.tcx.types.f16, types::F16),
354350
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32),
355351
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64),
@@ -441,11 +437,7 @@ fn codegen_float_intrinsic_call<'tcx>(
441437
sym::copysignf32 | sym::copysignf64 => {
442438
CValue::by_val(fx.bcx.ins().fcopysign(args[0], args[1]), layout)
443439
}
444-
sym::fabsf16 => CValue::by_val(codegen_f16_f128::abs_f16(fx, args[0]), layout),
445-
sym::fabsf128 => CValue::by_val(codegen_f16_f128::abs_f128(fx, args[0]), layout),
446-
sym::fabsf32
447-
| sym::fabsf64
448-
| sym::floorf32
440+
sym::floorf32
449441
| sym::floorf64
450442
| sym::ceilf32
451443
| sym::ceilf64
@@ -456,7 +448,6 @@ fn codegen_float_intrinsic_call<'tcx>(
456448
| sym::sqrtf32
457449
| sym::sqrtf64 => {
458450
let val = match intrinsic {
459-
sym::fabsf32 | sym::fabsf64 => fx.bcx.ins().fabs(args[0]),
460451
sym::floorf32 | sym::floorf64 => fx.bcx.ins().floor(args[0]),
461452
sym::ceilf32 | sym::ceilf64 => fx.bcx.ins().ceil(args[0]),
462453
sym::truncf32 | sym::truncf64 => fx.bcx.ins().trunc(args[0]),
@@ -1179,6 +1170,28 @@ fn codegen_regular_intrinsic_call<'tcx>(
11791170
ret.write_cvalue(fx, old);
11801171
}
11811172

1173+
sym::fabs => {
1174+
intrinsic_args!(fx, args => (arg); intrinsic);
1175+
let layout = arg.layout();
1176+
let ty::Float(float_ty) = layout.ty.kind() else {
1177+
span_bug!(
1178+
source_info.span,
1179+
"expected float type for fabs intrinsic: {:?}",
1180+
layout.ty
1181+
);
1182+
};
1183+
let x = arg.load_scalar(fx);
1184+
let val = match float_ty {
1185+
FloatTy::F32 | FloatTy::F64 => fx.bcx.ins().fabs(x),
1186+
// FIXME(bytecodealliance/wasmtime#8312): Use `fabsf16` once Cranelift
1187+
// backend lowerings are implemented.
1188+
FloatTy::F16 => codegen_f16_f128::abs_f16(fx, x),
1189+
FloatTy::F128 => codegen_f16_f128::abs_f128(fx, x),
1190+
};
1191+
let val = CValue::by_val(val, layout);
1192+
ret.write_cvalue(fx, val);
1193+
}
1194+
11821195
sym::minimumf16 => {
11831196
intrinsic_args!(fx, args => (a, b); intrinsic);
11841197
let a = a.load_scalar(fx);

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
493493
}
494494
}
495495

496-
sym::simd_fmin | sym::simd_fmax => {
496+
sym::simd_minimum_number_nsz | sym::simd_maximum_number_nsz => {
497497
intrinsic_args!(fx, args => (x, y); intrinsic);
498498

499499
if !x.layout().ty.is_simd() {
@@ -508,8 +508,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
508508
_ => unreachable!("{:?}", lane_ty),
509509
}
510510
match intrinsic {
511-
sym::simd_fmin => crate::num::codegen_float_min(fx, x_lane, y_lane),
512-
sym::simd_fmax => crate::num::codegen_float_max(fx, x_lane, y_lane),
511+
sym::simd_minimum_number_nsz => {
512+
crate::num::codegen_float_min(fx, x_lane, y_lane)
513+
}
514+
sym::simd_maximum_number_nsz => {
515+
crate::num::codegen_float_max(fx, x_lane, y_lane)
516+
}
513517
_ => unreachable!(),
514518
}
515519
});

compiler/rustc_codegen_cranelift/src/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ fn codegen_ptr_binop<'tcx>(
500500

501501
// In Rust floating point min and max don't propagate NaN (not even SNaN). In Cranelift they do
502502
// however. For this reason it is necessary to use `a.is_nan() ? b : (a >= b ? b : a)` for
503-
// `minnumf*` and `a.is_nan() ? b : (a <= b ? b : a)` for `maxnumf*`. NaN checks are done by
504-
// comparing a float against itself. Only in case of NaN is it not equal to itself.
503+
// `minimum_number_nsz` and `a.is_nan() ? b : (a <= b ? b : a)` for `maximum_number_nsz`. NaN checks
504+
// are done by comparing a float against itself. Only in case of NaN is it not equal to itself.
505505
pub(crate) fn codegen_float_min(fx: &mut FunctionCx<'_, '_, '_>, a: Value, b: Value) -> Value {
506506
// FIXME(bytecodealliance/wasmtime#8312): Replace with Cranelift `fcmp` once
507507
// `f16`/`f128` backend lowerings have been added to Cranelift.

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
22782278
})
22792279
}
22802280

2281+
/// Emits a SIMD min/max operation for floats. The semantics for each lane are: if one
2282+
/// side is NaN (QNaN or SNaN), the other side is returned.
22812283
fn vector_extremum(
22822284
&mut self,
22832285
a: RValue<'gcc>,
@@ -2286,8 +2288,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
22862288
) -> RValue<'gcc> {
22872289
let vector_type = a.get_type();
22882290

2289-
// mask out the NaNs in b and replace them with the corresponding lane in a, so when a and
2290-
// b get compared & spliced together, we get the numeric values instead of NaNs.
2291+
// Mask out the NaNs (both QNaN and SNaN) in b and replace them with the corresponding lane
2292+
// in a, so when a and b get compared & spliced together, we get the numeric values instead
2293+
// of NaNs.
22912294
let b_nan_mask = self.context.new_comparison(self.location, ComparisonOp::NotEquals, b, b);
22922295
let mask_type = b_nan_mask.get_type();
22932296
let b_nan_mask_inverted =
@@ -2309,7 +2312,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
23092312
self.context.new_bitcast(self.location, res, vector_type)
23102313
}
23112314

2312-
pub fn vector_fmin(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
2315+
pub fn vector_minimum_number_nsz(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
23132316
self.vector_extremum(a, b, ExtremumOperation::Min)
23142317
}
23152318

@@ -2341,7 +2344,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
23412344
unimplemented!();
23422345
}
23432346

2344-
pub fn vector_fmax(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
2347+
pub fn vector_maximum_number_nsz(&mut self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
23452348
self.vector_extremum(a, b, ExtremumOperation::Max)
23462349
}
23472350

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use rustc_codegen_ssa::traits::{
2323
IntrinsicCallBuilderMethods, LayoutTypeCodegenMethods,
2424
};
2525
use rustc_data_structures::fx::FxHashSet;
26-
use rustc_middle::bug;
2726
#[cfg(feature = "master")]
2827
use rustc_middle::ty::layout::FnAbiOf;
2928
use rustc_middle::ty::layout::LayoutOf;
3029
use rustc_middle::ty::{self, Instance, Ty};
30+
use rustc_middle::{bug, span_bug};
3131
use rustc_span::{Span, Symbol, sym};
3232
use rustc_target::callconv::{ArgAbi, PassMode};
3333

@@ -70,8 +70,6 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
7070
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
7171
sym::fmuladdf32 => "fmaf", // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f32
7272
sym::fmuladdf64 => "fma", // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f64
73-
sym::fabsf32 => "fabsf",
74-
sym::fabsf64 => "fabs",
7573
sym::minimumf32 => "fminimumf",
7674
sym::minimumf64 => "fminimum",
7775
sym::minimumf128 => {
@@ -194,58 +192,29 @@ fn get_simple_function<'gcc, 'tcx>(
194192
}
195193

196194
fn get_simple_function_f128<'gcc, 'tcx>(
195+
span: Span,
197196
cx: &CodegenCx<'gcc, 'tcx>,
198197
name: Symbol,
199-
) -> Option<Function<'gcc>> {
200-
if !cx.supports_f128_type {
201-
return None;
202-
}
203-
198+
) -> Function<'gcc> {
204199
let f128_type = cx.type_f128();
205200
let func_name = match name {
206201
sym::ceilf128 => "ceilf128",
207-
sym::fabsf128 => "fabsf128",
202+
sym::fabs => "fabsf128",
208203
sym::floorf128 => "floorf128",
209204
sym::truncf128 => "truncf128",
210205
sym::roundf128 => "roundf128",
211206
sym::round_ties_even_f128 => "roundevenf128",
212207
sym::sqrtf128 => "sqrtf128",
213-
_ => return None,
208+
_ => span_bug!(span, "used get_simple_function_f128 for non-unary f128 intrinsic"),
214209
};
215-
Some(cx.context.new_function(
210+
cx.context.new_function(
216211
None,
217212
FunctionType::Extern,
218213
f128_type,
219214
&[cx.context.new_parameter(None, f128_type, "a")],
220215
func_name,
221216
false,
222-
))
223-
}
224-
225-
fn get_simple_function_f128_2args<'gcc, 'tcx>(
226-
cx: &CodegenCx<'gcc, 'tcx>,
227-
name: Symbol,
228-
) -> Option<Function<'gcc>> {
229-
if !cx.supports_f128_type {
230-
return None;
231-
}
232-
233-
let f128_type = cx.type_f128();
234-
let func_name = match name {
235-
sym::copysignf128 => "copysignf128",
236-
_ => return None,
237-
};
238-
Some(cx.context.new_function(
239-
None,
240-
FunctionType::Extern,
241-
f128_type,
242-
&[
243-
cx.context.new_parameter(None, f128_type, "a"),
244-
cx.context.new_parameter(None, f128_type, "b"),
245-
],
246-
func_name,
247-
false,
248-
))
217+
)
249218
}
250219

251220
fn f16_builtin<'gcc, 'tcx>(
@@ -257,7 +226,7 @@ fn f16_builtin<'gcc, 'tcx>(
257226
let builtin_name = match name {
258227
sym::ceilf16 => "__builtin_ceilf",
259228
sym::copysignf16 => "__builtin_copysignf",
260-
sym::fabsf16 => "fabsf",
229+
sym::fabs => "fabsf",
261230
sym::floorf16 => "__builtin_floorf",
262231
sym::fmaf16 => "fmaf",
263232
sym::powf16 => "__builtin_powf",
@@ -297,11 +266,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
297266
let fn_args = instance.args;
298267

299268
let simple = get_simple_intrinsic(self, name);
300-
// FIXME(antoyo): Only call get_simple_function_f128 and get_simple_function_f128_2args when
301-
// it is the symbols for the supported f128 builtins.
302-
let simple_func = get_simple_function(self, name)
303-
.or_else(|| get_simple_function_f128(self, name))
304-
.or_else(|| get_simple_function_f128_2args(self, name));
269+
let simple_func = get_simple_function(self, name);
305270

306271
let value = match name {
307272
_ if simple.is_some() => {
@@ -322,7 +287,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
322287
}
323288
sym::ceilf16
324289
| sym::copysignf16
325-
| sym::fabsf16
326290
| sym::floorf16
327291
| sym::fmaf16
328292
| sym::powf16
@@ -331,6 +295,40 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
331295
| sym::round_ties_even_f16
332296
| sym::sqrtf16
333297
| sym::truncf16 => f16_builtin(self, name, args),
298+
sym::ceilf128
299+
| sym::floorf128
300+
| sym::truncf128
301+
| sym::roundf128
302+
| sym::round_ties_even_f128
303+
| sym::sqrtf128
304+
if self.cx.supports_f128_type =>
305+
{
306+
let func = get_simple_function_f128(span, self, name);
307+
self.cx.context.new_call(
308+
self.location,
309+
func,
310+
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
311+
)
312+
}
313+
sym::copysignf128 if self.cx.supports_f128_type => {
314+
let f128_type = self.cx.type_f128();
315+
let func = self.cx.context.new_function(
316+
None,
317+
FunctionType::Extern,
318+
f128_type,
319+
&[
320+
self.cx.context.new_parameter(None, f128_type, "a"),
321+
self.cx.context.new_parameter(None, f128_type, "b"),
322+
],
323+
"copysignf128",
324+
false,
325+
);
326+
self.cx.context.new_call(
327+
self.location,
328+
func,
329+
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
330+
)
331+
}
334332
sym::fmaf128 => {
335333
let f128_type = self.cx.type_f128();
336334
let func = self.cx.context.new_function(
@@ -488,6 +486,23 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
488486
}
489487
}
490488
}
489+
sym::fabs => 'fabs: {
490+
let ty = args[0].layout.ty;
491+
let ty::Float(float_ty) = *ty.kind() else {
492+
span_bug!(span, "expected float type for fabs intrinsic: {:?}", ty);
493+
};
494+
let func = match float_ty {
495+
ty::FloatTy::F16 => break 'fabs f16_builtin(self, name, args),
496+
ty::FloatTy::F32 => self.context.get_builtin_function("fabsf"),
497+
ty::FloatTy::F64 => self.context.get_builtin_function("fabs"),
498+
ty::FloatTy::F128 => get_simple_function_f128(span, self, name),
499+
};
500+
self.cx.context.new_call(
501+
self.location,
502+
func,
503+
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
504+
)
505+
}
491506

492507
sym::raw_eq => {
493508
use rustc_abi::BackendRepr::*;

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
811811
}};
812812
}
813813
let ty::Float(ref f) = *in_elem.kind() else {
814-
return_error!(InvalidMonomorphization::FloatingPointType { span, name, in_ty });
814+
return_error!(InvalidMonomorphization::BasicFloatType { span, name, ty: in_ty });
815815
};
816816
let elem_ty = bx.cx.type_float_from_ty(*f);
817817
let (elem_ty_str, elem_ty, cast_type) = match f.bit_width() {
@@ -1222,8 +1222,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
12221222
simd_and: Uint, Int => and;
12231223
simd_or: Uint, Int => or; // FIXME(antoyo): calling `or` might not work on vectors.
12241224
simd_xor: Uint, Int => xor;
1225-
simd_fmin: Float => vector_fmin;
1226-
simd_fmax: Float => vector_fmax;
1225+
simd_minimum_number_nsz: Float => vector_minimum_number_nsz;
1226+
simd_maximum_number_nsz: Float => vector_maximum_number_nsz;
12271227
}
12281228

12291229
macro_rules! arith_unary {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,12 +1605,16 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16051605
*self = Self::build(self.cx, next_bb);
16061606
}
16071607

1608-
pub(crate) fn minnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
1609-
self.call_intrinsic("llvm.minnum", &[self.val_ty(lhs)], &[lhs, rhs])
1608+
pub(crate) fn minimum_number_nsz(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
1609+
let call = self.call_intrinsic("llvm.minimumnum", &[self.val_ty(lhs)], &[lhs, rhs]);
1610+
unsafe { llvm::LLVMRustSetNoSignedZeros(call) };
1611+
call
16101612
}
16111613

1612-
pub(crate) fn maxnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
1613-
self.call_intrinsic("llvm.maxnum", &[self.val_ty(lhs)], &[lhs, rhs])
1614+
pub(crate) fn maximum_number_nsz(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
1615+
let call = self.call_intrinsic("llvm.maximumnum", &[self.val_ty(lhs)], &[lhs, rhs]);
1616+
unsafe { llvm::LLVMRustSetNoSignedZeros(call) };
1617+
call
16141618
}
16151619

16161620
pub(crate) fn insert_element(

0 commit comments

Comments
 (0)