summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-21 09:43:33 +0000
committerbors <bors@rust-lang.org>2024-02-21 09:43:33 +0000
commitbb8b11e67dd5833e503d47694d815eec41418675 (patch)
treeb21f60156d6e725c5311316e2c7b4677c45f2ee3 /tests/codegen
parent7168c13579a550f2c47f7eea22f5e226a436cd00 (diff)
parentcc73b71e8e568c6421a23fc2954a86e1947aac66 (diff)
downloadrust-bb8b11e67dd5833e503d47694d815eec41418675.tar.gz
rust-bb8b11e67dd5833e503d47694d815eec41418675.zip
Auto merge of #120718 - saethlin:reasonable-fast-math, r=nnethercote
Add "algebraic" fast-math intrinsics, based on fast-math ops that cannot return poison

Setting all of LLVM's fast-math flags makes our fast-math intrinsics very dangerous, because some inputs are UB. This set of flags permits common algebraic transformations, but according to the [LangRef](https://llvm.org/docs/LangRef.html#fastmath), only the flags `nnan` (no nans) and `ninf` (no infs) can produce poison.

And this uses the algebraic float ops to fix https://github.com/rust-lang/rust/issues/120720

cc `@orlp`
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/simd/issue-120720-reduce-nan.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/codegen/simd/issue-120720-reduce-nan.rs b/tests/codegen/simd/issue-120720-reduce-nan.rs
new file mode 100644
index 00000000000..233131aa01c
--- /dev/null
+++ b/tests/codegen/simd/issue-120720-reduce-nan.rs
@@ -0,0 +1,22 @@
+// compile-flags: -C opt-level=3 -C target-cpu=cannonlake
+// only-x86_64
+
+// In a previous implementation, _mm512_reduce_add_pd did the reduction with all fast-math flags
+// enabled, making it UB to reduce a vector containing a NaN.
+
+#![crate_type = "lib"]
+#![feature(stdarch_x86_avx512, avx512_target_feature)]
+use std::arch::x86_64::*;
+
+// CHECK-label: @demo(
+#[no_mangle]
+#[target_feature(enable = "avx512f")] // Function-level target feature mismatches inhibit inlining
+pub unsafe fn demo() -> bool {
+    // CHECK: %0 = tail call reassoc nsz arcp contract double @llvm.vector.reduce.fadd.v8f64(
+    // CHECK: %_0.i = fcmp uno double %0, 0.000000e+00
+    // CHECK: ret i1 %_0.i
+    let res = unsafe {
+        _mm512_reduce_add_pd(_mm512_set_pd(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, f64::NAN))
+    };
+    res.is_nan()
+}