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`
This commit is contained in:
commit
709c00a047
@ -1152,17 +1152,26 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
|||||||
ret.write_cvalue(fx, ret_val);
|
ret.write_cvalue(fx, ret_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::fadd_fast | sym::fsub_fast | sym::fmul_fast | sym::fdiv_fast | sym::frem_fast => {
|
sym::fadd_fast
|
||||||
|
| sym::fsub_fast
|
||||||
|
| sym::fmul_fast
|
||||||
|
| sym::fdiv_fast
|
||||||
|
| sym::frem_fast
|
||||||
|
| sym::fadd_algebraic
|
||||||
|
| sym::fsub_algebraic
|
||||||
|
| sym::fmul_algebraic
|
||||||
|
| sym::fdiv_algebraic
|
||||||
|
| sym::frem_algebraic => {
|
||||||
intrinsic_args!(fx, args => (x, y); intrinsic);
|
intrinsic_args!(fx, args => (x, y); intrinsic);
|
||||||
|
|
||||||
let res = crate::num::codegen_float_binop(
|
let res = crate::num::codegen_float_binop(
|
||||||
fx,
|
fx,
|
||||||
match intrinsic {
|
match intrinsic {
|
||||||
sym::fadd_fast => BinOp::Add,
|
sym::fadd_fast | sym::fadd_algebraic => BinOp::Add,
|
||||||
sym::fsub_fast => BinOp::Sub,
|
sym::fsub_fast | sym::fsub_algebraic => BinOp::Sub,
|
||||||
sym::fmul_fast => BinOp::Mul,
|
sym::fmul_fast | sym::fmul_algebraic => BinOp::Mul,
|
||||||
sym::fdiv_fast => BinOp::Div,
|
sym::fdiv_fast | sym::fdiv_algebraic => BinOp::Div,
|
||||||
sym::frem_fast => BinOp::Rem,
|
sym::frem_fast | sym::frem_algebraic => BinOp::Rem,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
x,
|
x,
|
||||||
|
Loading…
Reference in New Issue
Block a user