[flang-commits] [PATCH] D88981: [flang] Rework host runtime folding and enable REAL(2) folding with it.

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Oct 13 09:37:17 PDT 2020


jeanPerier added a comment.

In D88981#2321900 <https://reviews.llvm.org/D88981#2321900>, @PeteSteinfeld wrote:

> 



> Where do things stand on 80 bit and 128 bit REALs?

I have updated the patch to allow using IEEE 128bits to fold 80 bits (X87) floats when IEEE 128 bits is available but not X87.
However 80/128 bits folding that require host runtime is currently not expected to work on all host at all (hence I did not add tests yet).
The folding code is designed to take advantage of when 80/128bits can be safely folded using `long double` without assuming too much about the platform. It is also designed to allow platform where 80/128bits cannot be safely folded to still compile/run flang normally and only refuse to compile programs that require such host folding. More precisely:

- 80 bits folding works if the host `long double` is the X87 or IEEE 128bits float (for this last case we would convert 80bits to 128bits before folding).
- 128 bits folding works if the host `long double` is the IEEE 128 bits.
- When the host long double type does not allow folding 80bits/128bits, Fold() will return the original expressions, and a warning message (non fatal) saying " intrinsic acos(real(kind=16)) cannot be folded on host". If the expressions must be a constant, compilation should then failed complaining it did not get a constant after Fold() calls. Otherwise, compilation will continue normally (leaving the expression unfolded since we do not have to, but warning the user that we could not fold it due to host limitation).

Hosts that needs to fold 80bits/128bits  will need to modify host.h to map some non standard types (e.g. __float128) in host.h provided the c++ standard math library works with them (or they will need to provide an ad-hoc runtime with it in intrinsics-library.cpp).

I tested that 80 bits folding works OK on X86-64 linux. I expect 80bits and 128bits folding to work on Aarch64, but did not test it. On Power8/9, I think that depends on how the OS is compiled there. By default `long double` maps to IBM double double format, but the OS/libc/gcc... can also be compiled to map long double to IEEE 128bits in which case folding 80bits and 128bits should work. As you see, all this is very dependent on the platform.

Note that this only applies to folding intrinsics for which there is no abstract implementation in `include/flang/Evaluate/real.h` and for which we have to resort to host runtime, otherwise all REALs can be folded regardless of the platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88981



More information about the flang-commits mailing list