[llvm-dev] [FPEnv] FNEG instruction

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 29 09:16:06 PDT 2018


On Wed, 29 Aug 2018 at 07:51, Cameron McInally via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> The current thinking is that FNEG(X) and FSUB(-0.0, X) are not the same operation when X is a NaN or 0.

Do you mean denormals (when flushed) rather than 0 there? AFAIK it's
OK for 0 itself.

> So, the xforms in question should only be valid under Fast-Math conditions.

We could probably also "fix" the issue by taking the view that LLVM's
fsub provides extra guarantees for NaN over the IEEE-754 one. I.e.
that "fsub -0.0, x" behaves as negate. I believe that would still be
conformant to IEEE-754 and not require any actual changes in LLVM
(since it's what CPUs would do anyway).

I think that's uglier than adding FNEG though.

> Is correcting this behavior something that the general LLVM population would like? If not, we can create constrained intrinsics for the FPEnv project.

I'm in favour of FNEG too. I remember the fsub trick being confusing
when I first encountered it.

Cheers.

Tim.


More information about the llvm-dev mailing list