[libc-commits] [libc] [libc][math] Prevent spurious floating-point exceptions in fdim (PR #228749)

Chen Miao via libc-commits libc-commits at lists.llvm.org
Wed Oct 7 10:50:04 PDT 2026


================

----------------
ChenMiaoi wrote:

This version appears to work without optimization, but at `-O2` and `-O3`, Clang still emits an unconditional subtraction, as shown here:

https://godbolt.org/z/TY53Gdx46

``` asm
movaps  xmm2, xmm0
subss   xmm2, xmm1
cmpnless        xmm0, xmm1
```

I initially considered this approach too, but the original issue also notes that replacing the conditional operator with an `if-statement` is brittle and can still produce the same problematic assembly.

So I don’t think switching to an `if-statement` alone is a reliable fix, and I believe we still need `LIBC_FENV_ACCESS_ON` on targets that support it.

https://github.com/llvm/llvm-project/pull/228749


More information about the libc-commits mailing list