[PATCH] D144454: Add builtin for llvm set rounding

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 1 10:23:16 PST 2023


rjmccall added a comment.

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).



================
Comment at: clang/test/CodeGen/builtins.c:283
+  res = __builtin_flt_rounds_set(1);
+  // CHECK: call void @llvm.set.rounding(
 }
----------------
xiongji90 wrote:
> rjmccall wrote:
> > Just for completeness, please test that this gets the result of the expression.
> Hi, @rjmccall 
> I updated the test to check "llvm.set.rounding" string with input, does it meet your requirement?
> Thanks very much.
Yes, thank you.


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