[PATCH] D69272: Enable '#pragma STDC FENV_ACCESS' in frontend

Melanie Blower via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 14 11:03:48 PDT 2020


mibintc added a comment.

In D69272#2271338 <https://reviews.llvm.org/D69272#2271338>, @sepavloff wrote:

> In D69272#2268337 <https://reviews.llvm.org/D69272#2268337>, @mibintc wrote:
>
>> I am working on a task to ensure that clang is doing floating point constant folding correctly.
>
> Could you please share your plans on it? I recently also started implementing constant folding in `ExprConstant.cpp`. I have not made anything substantial yet, so I can easily switch to another task. Do you have any estimation when you could prepare the first version of the patch?

I've been given a vague assignment, something along the lines "investigate floating point constant folding and make sure that the semantics are correct. " In the Intel ICL compiler, there were some circumstances of the semantics not being correct.  I saw Richard's comments in this review, and Intel also needs FENV_ACCESS implemented so I thought I'd start here.  I'm not a floating point expert, but of course some of my colleagues at Intel are!  I am pretty slow but it's my area of focus.

>> But sometimes, if the floating point semantics are set to 'strict', even tho' folding has occurred successfully in ExprConstant.cpp, when i look at emit-llvm, there is arithmetic emitted for the floating point expression;
>
> I used a bit different approach, may be it could be useful for you too. An initializer for global variable must be a constant, so things like `const xxx = 1.0 + 2.0` are evaluated. No llvm arithmetic occurs in the resulting ll file. Using `pragma STDC FENV_ROUND` floating point environment may be set to non-default state, which constant evaluator must use.

When I implemented clang #pragma float_control, I noticed that initialization expressions in classes were not subject to the pragma's that are active in the source file. Those expressions are pulled out and processed differently than the function bodies. I'll upload later today a patch that uses Expr->getFPFeaturesInEffect() to inhibit constant folding in ExprConstant.cpp.

> In D69272#2268387 <https://reviews.llvm.org/D69272#2268387>, @kpn wrote:
>
>> Say, in D80952 <https://reviews.llvm.org/D80952> I added support for disabling strictfp support when a target doesn't support it. But it only applies to command line arguments.
>>
>> Is there any chance at all that relevant pragmas can also be disabled with the warning in the same cases?
>
> This is definitely a good idea.

I'll look into it, thank you


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69272



More information about the cfe-commits mailing list