Skip to content

Commit 709c00a

Browse files
committed
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 rust-lang/rust#120720 cc `@orlp`
2 parents 4f23c24 + 968e795 commit 709c00a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/intrinsics/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1152,17 +1152,26 @@ fn codegen_regular_intrinsic_call<'tcx>(
11521152
ret.write_cvalue(fx, ret_val);
11531153
}
11541154

1155-
sym::fadd_fast | sym::fsub_fast | sym::fmul_fast | sym::fdiv_fast | sym::frem_fast => {
1155+
sym::fadd_fast
1156+
| sym::fsub_fast
1157+
| sym::fmul_fast
1158+
| sym::fdiv_fast
1159+
| sym::frem_fast
1160+
| sym::fadd_algebraic
1161+
| sym::fsub_algebraic
1162+
| sym::fmul_algebraic
1163+
| sym::fdiv_algebraic
1164+
| sym::frem_algebraic => {
11561165
intrinsic_args!(fx, args => (x, y); intrinsic);
11571166

11581167
let res = crate::num::codegen_float_binop(
11591168
fx,
11601169
match intrinsic {
1161-
sym::fadd_fast => BinOp::Add,
1162-
sym::fsub_fast => BinOp::Sub,
1163-
sym::fmul_fast => BinOp::Mul,
1164-
sym::fdiv_fast => BinOp::Div,
1165-
sym::frem_fast => BinOp::Rem,
1170+
sym::fadd_fast | sym::fadd_algebraic => BinOp::Add,
1171+
sym::fsub_fast | sym::fsub_algebraic => BinOp::Sub,
1172+
sym::fmul_fast | sym::fmul_algebraic => BinOp::Mul,
1173+
sym::fdiv_fast | sym::fdiv_algebraic => BinOp::Div,
1174+
sym::frem_fast | sym::frem_algebraic => BinOp::Rem,
11661175
_ => unreachable!(),
11671176
},
11681177
x,

0 commit comments

Comments
 (0)