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

Jessica Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 07:00:02 PST 2020


jrtc27 added a comment.

In D93624#2465904 <https://reviews.llvm.org/D93624#2465904>, @sepavloff wrote:

> In D93624#2465776 <https://reviews.llvm.org/D93624#2465776>, @jrtc27 wrote:
>
>> Doesn't this render `fesetround` useless?
>
> No. `fesetround` sets dynamic rounding mode (register frm), which may be any mode. However in the case of non-default rounding mode (all other than RNE), floating operations must be represented by constrained intrinsics, for example `llvm.experimental.constrained.fadd` should be used instead of `fadd`.

Ah, I see, I need -ffp-strict (or an FENV_ACCESS pragma) if I want that behaviour. Though is that something people actually use? 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. 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?

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.


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