[PATCH] D93624: [RISCV] Fix rounding mode in lowering of float operations

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 02:35:59 PST 2021


sepavloff added a comment.

In D93624#2465934 <https://reviews.llvm.org/D93624#2465934>, @jrtc27 wrote:

> I have a feeling that a lot of code out there uses `fesetround` without changing compiler flags, and probably "works" on x86 because everything uses the dynamic rounding mode.

I think you are right. Using dynamic rounding mode, the fact that `fesetround` is an external function (thus may have side effect which restricts code reordering) and special care taken by compilers to limit optimizations of FP operations allow the generated code to work in many cases. Another possible reason of "working" may be related to previous unavailability of `#pragma STDC FENV_ACCESS`. People that used `fesetround` understand that they should use this pragma but it was unsupported, so they try to use workarounds instead of complaining.

> Can we not just always use the dynamic rounding mode to be more friendly to users, and say that if you change the rounding mode you should have told the compiler about it (but you'll get behaviour approximately like what you asked for)? What do other backends do?

If only rounding mode was an issue, probably yes. There is however dependency on another FP register, `fflags`. More detailed consideration is make in D94163 <https://reviews.llvm.org/D94163>.

> FWIW, the Clang documentation just says:
>
>> The option -fno-rounding-math allows the compiler to assume that the rounding mode is set to FE_TONEAREST. This is the default.
>
> So this revision should only make a difference when people violate the documented assumptions of their compiler.

If only the default mode were needed, this change were useless. This is a step toward support of non-default FP environments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93624



More information about the llvm-commits mailing list