[PATCH] D144454: Add builtin for llvm set rounding

xiongji90 via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 1 19:54:53 PST 2023


xiongji90 added a comment.

In D144454#4162129 <https://reviews.llvm.org/D144454#4162129>, @rjmccall wrote:

> In D144454#4157717 <https://reviews.llvm.org/D144454#4157717>, @xiongji90 wrote:
>
>> In D144454#4142253 <https://reviews.llvm.org/D144454#4142253>, @rjmccall wrote:
>>
>>> New builtins should be documented in the user manual.
>>>
>>> There are standard pragmas for changing the rounding mode, right?  What's the interaction between the ability to set this dynamically with a builtin call and those pragmas?
>>
>> Hi, @rjmccall 
>> Current status is LLVM has added llvm.get.rounding and llvm.set.rounding intrinsic and has also added "__builtin_flt_rounds" for llvm.get.rounding but there is no corresponding for llvm.set.rounding intrinisc. According to original patch to add llvm.set.rounding: https://reviews.llvm.org/D74729 and LLVM document for this intrinsic: https://llvm.org/docs/LangRef.html#id1506
>> The introduction of llvm.set.rounding intrinsic can provide same functionality as C library function "fesetround" and avoid unnecessary dependency on C library. Currently, this intrinsic can't benefit C/C++ developers since we don't have a corresponding builtin and we even can't add a C/C++ test for this intrinsic.
>
> If this builtin is defined to have the same behavior as `fesetround`, the obvious name would be `__builtin_fesetround`.  You seem to have patterned it off of `__builtin_flt_rounds`, but that is not an arbitrarily-chosen name, it's taken from the standard `FLT_ROUNDS` macro and is expected to work as an implementation of it.
>
> We already understand how `fesetround` is supposed to interact with the standard pragmas about the FP environment, so that indirectly answers that part of my question.  I assume you've modeled your intrinsic correctly in LLVM so that the optimizer understands it can't reorder the environment-sensitive math intrinsics around calls to the new intrinsic?
>
> If this builtin is just an intrinsic implementation of `fesetround`, I don't think we need further documentation of it.
>
> I assume the intrinsic is only implemented on certain targets?  If so, we might need to restrict uses of the builtin as well (and make sure that `__has_builtin` only returns true on those targets).

Hi, @rjmccall 
"llvm.set.rounding" intrinsic will change default floating-point environment, so as same as explicit C library call to "fesetround", this intrinsic should work with "pragma std fenv_access on", then "strictfp" attr will be added and optimizer will honor it.
"llvm.set.rounding" shouldn't be a target-sepcific intrinsic and target backend should be responsible for supporting it. I didn't my local tests on x86/x86_64 hardware and I also searched tests related to "llvm.set.rounding", arm, aarch64, risc-v all include such tests, so this builtin should work for these targets too.
Thanks very much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144454



More information about the cfe-commits mailing list