[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress
Melanie Blower via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 5 08:37:50 PDT 2020
mibintc added inline comments.
================
Comment at: clang/include/clang/Basic/LangOptions.h:410-411
setRoundingMode(LO.getFPRoundingMode());
+ // FENV access is true if rounding math is enabled.
+ setAllowFEnvAccess((getRoundingMode() == llvm::RoundingMode::Dynamic));
setFPExceptionMode(LO.getFPExceptionMode());
----------------
sepavloff wrote:
>
> I don't think this deduction is correct.
>
> `AllowFEnvAccess` implies that user can access FP environment in a way unknown to the compiler, for example by calling external functions or by using inline assembler. So if `AllowFEnvAccess` is set, the compiler must assume that rounding mode is dynamic, as user can set it to any value unknown to the compiler. Similarly, `FPExceptionMode` must be set to strict as user may read/write exception bits in any way or may associate them with traps. These deductions are valid and compiler must apply them.
>
> The reverse is not valid. `AllowFEnvAccess` is a very coarse instrument to manipulate FP environment, it prevents from many optimization techniques. In contrast, setting `RoundingMode` to dynamic means only that rounding mode may be different from the default value. If a user changes rounding mode by calls to external functions like `fesetmode` or by using some intrinsic, the compiler still can, for example, reorder FP operations, if `FPExceptionMode` is `ignore`. Impact of performance in this case can be minimized.
>
>
Thanks @sepavloff I'll make the change you recommend
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87528/new/
https://reviews.llvm.org/D87528
More information about the cfe-commits
mailing list