Skip to content

Commit 6d35464

Browse files
committed
Auto merge of rust-lang#130387 - workingjubilee:rollup-1k3g708, r=workingjubilee
Rollup of 3 pull requests Successful merges: - rust-lang#130295 (Fix target-cpu fpu features on Armv8-R.) - rust-lang#130325 (Use -0.0 in `intrinsics::simd::reduce_add_unordered`) - rust-lang#130371 (Correctly account for niche-optimized tags in rustc_transmute) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bc486f3 + e5c03c2 commit 6d35464

File tree

6 files changed

+78
-40
lines changed

6 files changed

+78
-40
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2066,14 +2066,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20662066
};
20672067
}
20682068

2069-
arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, 0.0);
2069+
arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, -0.0);
20702070
arith_red!(simd_reduce_mul_ordered: vector_reduce_mul, vector_reduce_fmul, true, mul, 1.0);
20712071
arith_red!(
20722072
simd_reduce_add_unordered: vector_reduce_add,
20732073
vector_reduce_fadd_reassoc,
20742074
false,
20752075
add,
2076-
0.0
2076+
-0.0
20772077
);
20782078
arith_red!(
20792079
simd_reduce_mul_unordered: vector_reduce_mul,

compiler/rustc_target/src/spec/targets/armv8r_none_eabihf.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ pub(crate) fn target() -> Target {
2121
linker: Some("rust-lld".into()),
2222
relocation_model: RelocModel::Static,
2323
panic_strategy: PanicStrategy::Abort,
24-
// The Cortex-R52 has two variants with respect to floating-point support:
25-
// 1. fp-armv8, SP-only, with 16 DP (32 SP) registers
26-
// 2. neon-fp-armv8, SP+DP, with 32 DP registers
27-
// Use the lesser of these two options as the default, as it will produce code
28-
// compatible with either variant.
24+
// Armv8-R requires a minimum set of floating-point features equivalent to:
25+
// fp-armv8, SP-only, with 16 DP (32 SP) registers
26+
// LLVM defines Armv8-R to include these features automatically.
27+
//
28+
// The Cortex-R52 supports these default features and optionally includes:
29+
// neon-fp-armv8, SP+DP, with 32 DP registers
2930
//
3031
// Reference:
3132
// Arm Cortex-R52 Processor Technical Reference Manual
3233
// - Chapter 15 Advanced SIMD and floating-point support
33-
features: "+fp-armv8,-fp64,-d32".into(),
3434
max_atomic_width: Some(64),
3535
emit_debug_gdb_scripts: false,
3636
// GCC defaults to 8 for arm-none here.

compiler/rustc_transmute/src/layout/tree.rs

+25-10
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub(crate) mod rustc {
175175
use rustc_middle::ty::{self, AdtDef, AdtKind, List, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
176176
use rustc_span::ErrorGuaranteed;
177177
use rustc_target::abi::{
178-
FieldIdx, FieldsShape, Layout, Size, TyAndLayout, VariantIdx, Variants,
178+
FieldIdx, FieldsShape, Layout, Size, TagEncoding, TyAndLayout, VariantIdx, Variants,
179179
};
180180

181181
use super::Tree;
@@ -319,11 +319,17 @@ pub(crate) mod rustc {
319319
assert!(def.is_enum());
320320

321321
// Computes the variant of a given index.
322-
let layout_of_variant = |index| {
322+
let layout_of_variant = |index, encoding: Option<TagEncoding<VariantIdx>>| {
323323
let tag = cx.tcx.tag_for_variant((cx.tcx.erase_regions(ty), index));
324324
let variant_def = Def::Variant(def.variant(index));
325325
let variant_layout = ty_variant(cx, (ty, layout), index);
326-
Self::from_variant(variant_def, tag, (ty, variant_layout), layout.size, cx)
326+
Self::from_variant(
327+
variant_def,
328+
tag.map(|tag| (tag, index, encoding.unwrap())),
329+
(ty, variant_layout),
330+
layout.size,
331+
cx,
332+
)
327333
};
328334

329335
// We consider three kinds of enums, each demanding a different
@@ -345,9 +351,9 @@ pub(crate) mod rustc {
345351
Variants::Single { index } => {
346352
// `Variants::Single` on enums with variants denotes that
347353
// the enum delegates its layout to the variant at `index`.
348-
layout_of_variant(*index)
354+
layout_of_variant(*index, None)
349355
}
350-
Variants::Multiple { tag_field, .. } => {
356+
Variants::Multiple { tag, tag_encoding, tag_field, .. } => {
351357
// `Variants::Multiple` denotes an enum with multiple
352358
// variants. The layout of such an enum is the disjunction
353359
// of the layouts of its tagged variants.
@@ -359,7 +365,7 @@ pub(crate) mod rustc {
359365
let variants = def.discriminants(cx.tcx()).try_fold(
360366
Self::uninhabited(),
361367
|variants, (idx, ref discriminant)| {
362-
let variant = layout_of_variant(idx)?;
368+
let variant = layout_of_variant(idx, Some(tag_encoding.clone()))?;
363369
Result::<Self, Err>::Ok(variants.or(variant))
364370
},
365371
)?;
@@ -380,7 +386,7 @@ pub(crate) mod rustc {
380386
/// `0`.
381387
fn from_variant(
382388
def: Def<'tcx>,
383-
tag: Option<ScalarInt>,
389+
tag: Option<(ScalarInt, VariantIdx, TagEncoding<VariantIdx>)>,
384390
(ty, layout): (Ty<'tcx>, Layout<'tcx>),
385391
total_size: Size,
386392
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
@@ -400,9 +406,18 @@ pub(crate) mod rustc {
400406
let mut struct_tree = Self::def(def);
401407

402408
// If a `tag` is provided, place it at the start of the layout.
403-
if let Some(tag) = tag {
404-
size += tag.size();
405-
struct_tree = struct_tree.then(Self::from_tag(tag, cx.tcx));
409+
if let Some((tag, index, encoding)) = &tag {
410+
match encoding {
411+
TagEncoding::Direct => {
412+
size += tag.size();
413+
}
414+
TagEncoding::Niche { niche_variants, .. } => {
415+
if !niche_variants.contains(index) {
416+
size += tag.size();
417+
}
418+
}
419+
}
420+
struct_tree = struct_tree.then(Self::from_tag(*tag, cx.tcx));
406421
}
407422

408423
// Append the fields, in memory order, to the layout.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ revisions: x86_64 x86_64-avx2 aarch64
2+
//@ assembly-output: emit-asm
3+
//@ compile-flags: --crate-type=lib -O
4+
//@[aarch64] only-aarch64
5+
//@[x86_64] only-x86_64
6+
//@[x86_64-avx2] only-x86_64
7+
//@[x86_64-avx2] compile-flags: -Ctarget-cpu=x86-64-v3
8+
#![feature(portable_simd)]
9+
#![feature(core_intrinsics)]
10+
use std::intrinsics::simd as intrinsics;
11+
use std::simd::*;
12+
// Regression test for https://github.com/rust-lang/rust/issues/130028
13+
// This intrinsic produces much worse code if you use +0.0 instead of -0.0 because
14+
// +0.0 isn't as easy to algebraically reassociate, even using LLVM's reassoc attribute!
15+
// It would emit about an extra fadd, depending on the architecture.
16+
17+
// CHECK-LABEL: reduce_fadd_negative_zero
18+
pub unsafe fn reduce_fadd_negative_zero(v: f32x4) -> f32 {
19+
// x86_64: addps
20+
// x86_64-NEXT: movaps
21+
// x86_64-NEXT: shufps
22+
// x86_64-NEXT: addss
23+
// x86_64-NOT: xorps
24+
25+
// x86_64-avx2: vaddps
26+
// x86_64-avx2-NEXT: vmovshdup
27+
// x86_64-avx2-NEXT: vaddss
28+
// x86_64-avx2-NOT: vxorps
29+
30+
// aarch64: faddp
31+
// aarch64-NEXT: faddp
32+
33+
// CHECK-NOT: {{f?}}add{{p?s*}}
34+
// CHECK: ret
35+
intrinsics::simd_reduce_add_unordered(v)
36+
}

tests/crashes/123693.rs

-22
This file was deleted.

tests/ui/transmutability/enums/niche_optimization.rs

+9
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,12 @@ fn no_niche() {
154154
assert::is_transmutable::<Pair<V1, MaybeUninit<u8>>, OptionLike>();
155155
assert::is_transmutable::<Pair<V2, MaybeUninit<u8>>, OptionLike>();
156156
}
157+
158+
fn niche_fields() {
159+
enum Kind {
160+
A(bool, bool),
161+
B(bool),
162+
}
163+
164+
assert::is_maybe_transmutable::<u16, Kind>();
165+
}

0 commit comments

Comments
 (0)