[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 10:06:33 PDT 2021


sepavloff added a comment.

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?

>> As for llvm langref, I think the following statement is cited here: https://llvm.org/docs/LangRef.html#floating-point-environment:
>>
>>   The default LLVM floating-point environment assumes that floating-point instructions do not have side effects. Results assume the round-to-nearest rounding mode. No floating-point exception state is maintained in this environment. Therefore, there is no attempt to create or preserve invalid operation (SNaN) or division-by-zero exceptions.
>>
>> This sentence is about **exceptions** but not the results of operations. So actually nothing in the langref justifies this transformation.
>
> The wording could be made more explicit, but as I suggested in my comment from Aug 6 in this review: the default LLVM FP env ignores exceptions, so citing the IEEE-754 clause that begins with "under default exception handling" to describe SNAN->QNAN behavior is not applicable.

This is peculiarities of IEEE-754 language. `Exception handling` in this context is what to do if exceptional situation occurs. In 7.1 there is a description of the `default exception handling`:

  This clause also specifies default non-stop exception handling for exception signals, which is to deliver a
  default result, continue execution, and raise the corresponding status flag (except in the case of exact
  underflow, see 7.5).

This is exactly the way the exceptions are handled in the default FP environment. Exception must be handled in some way because hardware always signals them if exceptional situation occurs.


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

https://reviews.llvm.org/D106362



More information about the llvm-commits mailing list