Skip to content

Commit 6642b85

Browse files
committed
Auto merge of rust-lang#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 rust-lang#120720 cc `@orlp`
2 parents 2b3ae2a + e0cc93e commit 6642b85

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

core/src/intrinsics.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,46 @@ extern "rust-intrinsic" {
18981898
#[rustc_nounwind]
18991899
pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
19001900

1901+
/// Float addition that allows optimizations based on algebraic rules.
1902+
///
1903+
/// This intrinsic does not have a stable counterpart.
1904+
#[rustc_nounwind]
1905+
#[rustc_safe_intrinsic]
1906+
#[cfg(not(bootstrap))]
1907+
pub fn fadd_algebraic<T: Copy>(a: T, b: T) -> T;
1908+
1909+
/// Float subtraction that allows optimizations based on algebraic rules.
1910+
///
1911+
/// This intrinsic does not have a stable counterpart.
1912+
#[rustc_nounwind]
1913+
#[rustc_safe_intrinsic]
1914+
#[cfg(not(bootstrap))]
1915+
pub fn fsub_algebraic<T: Copy>(a: T, b: T) -> T;
1916+
1917+
/// Float multiplication that allows optimizations based on algebraic rules.
1918+
///
1919+
/// This intrinsic does not have a stable counterpart.
1920+
#[rustc_nounwind]
1921+
#[rustc_safe_intrinsic]
1922+
#[cfg(not(bootstrap))]
1923+
pub fn fmul_algebraic<T: Copy>(a: T, b: T) -> T;
1924+
1925+
/// Float division that allows optimizations based on algebraic rules.
1926+
///
1927+
/// This intrinsic does not have a stable counterpart.
1928+
#[rustc_nounwind]
1929+
#[rustc_safe_intrinsic]
1930+
#[cfg(not(bootstrap))]
1931+
pub fn fdiv_algebraic<T: Copy>(a: T, b: T) -> T;
1932+
1933+
/// Float remainder that allows optimizations based on algebraic rules.
1934+
///
1935+
/// This intrinsic does not have a stable counterpart.
1936+
#[rustc_nounwind]
1937+
#[rustc_safe_intrinsic]
1938+
#[cfg(not(bootstrap))]
1939+
pub fn frem_algebraic<T: Copy>(a: T, b: T) -> T;
1940+
19011941
/// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
19021942
/// (<https://github.com/rust-lang/rust/issues/10184>)
19031943
///

0 commit comments

Comments
 (0)