Skip to content

Commit

Permalink
Use -0.0 in intrinsics::simd::reduce_add_unordered
Browse files Browse the repository at this point in the history
-0.0 is the actual neutral additive float, not +0.0, and this matters to codegen.
  • Loading branch information
workingjubilee committed Sep 13, 2024
1 parent 0307e40 commit f23173b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2090,14 +2090,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
};
}

arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, 0.0);
arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, -0.0);
arith_red!(simd_reduce_mul_ordered: vector_reduce_mul, vector_reduce_fmul, true, mul, 1.0);
arith_red!(
simd_reduce_add_unordered: vector_reduce_add,
vector_reduce_fadd_reassoc,
false,
add,
0.0
-0.0
);
arith_red!(
simd_reduce_mul_unordered: vector_reduce_mul,
Expand Down
16 changes: 16 additions & 0 deletions tests/assembly/aarch64-reduce-add-unordered.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ assembly-output: emit-asm
//@ compile-flags: --crate-type=lib -O
//@ only-aarch64
#![feature(portable_simd)]
#![feature(core_intrinsics)]
use std::intrinsics::simd as intrinsics;
use std::simd::*;

// CHECK-LABEL: reduce_fadd_negative_zero
pub unsafe fn reduce_fadd_negative_zero(v: f32x4) -> f32 {
// CHECK-NEXT: ldr
// CHECK-NEXT: faddp
// CHECK-NEXT: faddp
// CHECK-NEXT: ret
intrinsics::simd_reduce_add_unordered(v)
}

0 comments on commit f23173b

Please sign in to comment.