diff options
| author | bors <bors@rust-lang.org> | 2024-02-21 09:43:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-21 09:43:33 +0000 |
| commit | 7a991d522ab50e1de3ac9f4dd04be302a6471a8a (patch) | |
| tree | 9d4203abcfe72b5038cec5682ad8cb372f707280 | |
| parent | c350ae83e87519090f94e6a6d2f94ed5ca5f28ba (diff) | |
| parent | 6ff147b2050bc99f2bca7707e29052e7e4737912 (diff) | |
| download | rust-7a991d522ab50e1de3ac9f4dd04be302a6471a8a.tar.gz rust-7a991d522ab50e1de3ac9f4dd04be302a6471a8a.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`
| -rw-r--r-- | src/builder.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/builder.rs b/src/builder.rs index 42e61b3ccb5..5f1e4538376 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -705,6 +705,31 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { self.frem(lhs, rhs) } + fn fadd_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs + rhs + } + + fn fsub_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs - rhs + } + + fn fmul_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs * rhs + } + + fn fdiv_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + lhs / rhs + } + + fn frem_algebraic(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> { + // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC. + self.frem(lhs, rhs) + } + fn checked_binop(&mut self, oop: OverflowOp, typ: Ty<'_>, lhs: Self::Value, rhs: Self::Value) -> (Self::Value, Self::Value) { self.gcc_checked_binop(oop, typ, lhs, rhs) } |
