[PATCH] D106362: [FPEnv][InstSimplify] Enable more folds for constrained fadd

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 23:18:59 PDT 2021


sepavloff added a comment.

In D106362#3034097 <https://reviews.llvm.org/D106362#3034097>, @spatel wrote:

> In D106362#3034000 <https://reviews.llvm.org/D106362#3034000>, @sepavloff wrote:
>
>> In D106362#3033765 <https://reviews.llvm.org/D106362#3033765>, @spatel wrote:
>>
>>> In D106362#3033555 <https://reviews.llvm.org/D106362#3033555>, @sepavloff wrote:
>>>
>>>>>> Here is the sample program: https://godbolt.org/z/ssYs6ez91
>>>>>> Hardware converts `SNaN + 0` into QNaN.
>>>
>>> This is cherry-picking the example to try to prove your point; gcc does not behave as you are suggesting in general. Here is a counter-example based on the first transform (fadd X, -0.0) affected by this patch:
>>> https://godbolt.org/z/qj9Meavnd
>>
>> In this case no `add` instruction is generated, so it does not demonstrate hardware behavior. It is (incorrect) constant folding. ICC does not do such transformation. Could you please file a bug in GCC bug tracker?
>
> Apologies to this patch review for being off-topic again, but the answer is no. 
> I think you know that's not a standalone folding bug. It's intentional behavior in both compilers which you can easily show with a number of similar examples...
> https://godbolt.org/z/fT1j8YPK6

I tried opening a bug against GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102549) and got recommendation to use `-fsignaling-nans`. There is no such option in clang but gcc manual says that it implies `ftrapping-math` and the latter is a synonym of `-ffp-exception-behavior=strict` in clang.

So, you are right. Ignoring peculiarities of SNaN is by design in GCC and IEEE-754 conformant behavior is only possible in strict FP mode. Conformant behavior of GCC for `X + 0.0` looks accidental. As this behavior opens optimization possibilities it is reasonable to use it.

Thank you for the discussion!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106362/new/

https://reviews.llvm.org/D106362



More information about the llvm-commits mailing list