[PATCH] D104854: Introduce intrinsic llvm.isnan
Kevin P. Neal via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 23 07:25:43 PDT 2021
kpn added a comment.
In D104854#2959680 <https://reviews.llvm.org/D104854#2959680>, @thopre wrote:
> In D104854#2957735 <https://reviews.llvm.org/D104854#2957735>, @kpn wrote:
>
>> In D104854#2957490 <https://reviews.llvm.org/D104854#2957490>, @lebedev.ri wrote:
>>
>>> In D104854#2957471 <https://reviews.llvm.org/D104854#2957471>, @sepavloff wrote:
>>>
>>>> In D104854#2957423 <https://reviews.llvm.org/D104854#2957423>, @spatel wrote:
>>>>
>>>>> Is it intentional that we are not canonicalizing the intrinsic call back to `fcmp uno` in the default FP environment?
>>>>
>>>> It is lowered to unordered comparison by default. Changing `llvm.isnan` to `fcmp uno` somewhere in IR would make it possible to optimize out the latter if fast-math mode is on. Preserving semantics of `isnan` when fast-math is in effect was one of the goals of this change.
>>>
>>> Eeek. Was there an RFC about this?
>>> This does not sound good to me at all,
>>> much like "let's not apply fast-math flags to x86 vector intrinsics".
>>
>> We can switch into and out of the default FP environment inside a single function.
>
> Really? The constrained intrinsic documentation claims the reverse (https://llvm.org/docs/LangRef.html#constrainedfp):
>
>> If any FP operation in a function is constrained then they all must be constrained. This is required for correct LLVM IR. Optimizations that move code around can create miscompiles if mixing of constrained and normal operations is done. The correct way to mix constrained and less constrained operations is to use the rounding mode and exception handling metadata to mark constrained intrinsics as having LLVM’s default behavior.
Use of constrained intrinsics does not mean that we are automatically in an alternate FP environment.
When constrained intrinsics are used and the metadata says the rounding mode is "tonearest" with exceptions set to "ignore" then that's the default FP environment. If, for example, #pragma STDC FENV_ACCESS is used in only a part of a function then the constrained intrinsics will be used in the entire function but the metadata will specify different exception or rounding behavior in the part covered by the FENV_ACCESS.
That the constrained intrinsics can state that they are in the default FP environment is what makes it safe for EarlyCSE to treat them the same as a normal FP instruction (which is assumed to be in the default FP environment). For example.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104854/new/
https://reviews.llvm.org/D104854
More information about the cfe-commits
mailing list