[PATCH] D14071: [FPEnv Core 06/14] Do not fold constants on reading in IR asm/bitcode

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 27 10:59:53 PDT 2015


majnemer added a comment.

In http://reviews.llvm.org/D14071#275272, @sdmitrouk wrote:

> In http://reviews.llvm.org/D14071#275229, @majnemer wrote:
>
> > Why are we making this assumption?  It seems strange to assume that all constant expressions infer KeepExceptions and KeepRounding.
>
>
> Constant expressions do not have fast-math flags, the sole purpose of setting them here is to prevent any kind of folding. As there is no way to specify flags, assuming FPEnv access should work for all cases.


That sounds like an oversight.  We have overflow flags (`nsw`/`nuw`) for integer math.

> I don't think anything should be folded in any reader or writer. Without this patch `<input> != write(read(<input>))` for constant expressions, which is a problem in case of preserving side-effects, but is also an odd behaviour in general.

> 

> In http://reviews.llvm.org/D14071#275229, @majnemer wrote:

> 

> > Also, shouldn't we be folding these to SNaN if KeepExceptions is true?

> 

> 

> If you're talking about examples in test, then probably not, they return infinity or a number, SNaN is not equivalent to those values.


I am not, I am thinking about the general case.  It sounds reasonable to transform floating-point divide by zero into SNaN when fp-exceptions are enabled.

In http://reviews.llvm.org/D14071#276298, @sdmitrouk wrote:

> In http://reviews.llvm.org/D14071#275275, @majnemer wrote:
>
> > That sounds like an oversight.  We have overflow flags (`nsw`/`nuw`) for integer math.
>
>
> Actually I asked about this last year, but it appeared that there is not much use of fast-math flags for constant expressions.
>  See it on the list <http://lists.llvm.org/pipermail/llvm-dev/2014-December/079242.html>.
>
> > I am not, I am thinking about the general case.  It sounds reasonable to transform floating-point divide by zero into SNaN when fp-exceptions are enabled.
>
>
> As it can yield infinity, I'm not sure whether SNaN is a good replacement for it. It would nice to do not fold anything in some case, maybe when both flags are given, not sure if "exceptions" or "rounding" is good choice on their own.


I meant the more specific case where we are trying to fold `0.0/0.0`.

It seems to me that there are three cases:

- No flags on the constant expression: we can perform whatever folding we like
- Exception flag is present: we need to fold to a new constant. Perhaps we could name it `DynamicNaN`.  The job of `DynamicNaN` is to model the fact that expressions like `0.0/0.0` may or may not trap at runtime depending on how the program uses runtime calls like `fegetexceptflag` and `fesetexceptflag`.
- Rounding flag is present: we cannot fold unless there is an unambiguous result.


Repository:
  rL LLVM

http://reviews.llvm.org/D14071





More information about the llvm-commits mailing list