[llvm-dev] Should rint and nearbyint be always constrained?

Serge Pavlov via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 2 08:10:17 PST 2020


>
> I'm not sure why this is an issue.  Yes, these two intrinsics depend
> on the current rounding mode according to the C standard, and yes,
> LLVM in default mode assumes that the current rounding mode is the
> default rounding mode.  But the same holds true for many other
> intrinsics and even the arithmetic IR operations like add.


Any other intrinsic, like `floor`, `round` etc has meaning at default
rounding mode. But use of `rint` or `nearbyint` in default FP environment
is strange, `roundeven` can be used instead. We could use more general
intrinsics in all cases, as the special case of default environment is not
of practical interest.

There is another reason for special handling. Set of intrinsics includes
things like `x86_sse_cvtss2si`. It is unlikely that all of them eventually
get constrained counterpart. It looks more natural that such intrinsics are
defined as accessing FP environment and can be optimized if the latter is
default. These two intrinsics could be a good model for such cases. IIUC,
splitting entities into constrained or non-constrained is a temporary
solution, ideally they will merge into one entity. We could do it for some
intrinsics now.

Thanks,
--Serge


On Mon, Mar 2, 2020 at 8:58 PM Ulrich Weigand <Ulrich.Weigand at de.ibm.com>
wrote:

> Serge Pavlov <sepavloff at gmail.com> wrote on 02.03.2020 14:38:48:
>
> > This approach has issues when applied to the intrinsics `rint` and
> > `nearbyint`. Value returned by either of these intrinsics depends on
> > current rounding mode. If they are considered as operation in
> > default environment, they would round only to nearest. It is by far
> > not the meaning of the standard C functions that these intrinsics
> represent.
>
> I'm not sure why this is an issue.  Yes, these two intrinsics depend
> on the current rounding mode according to the C standard, and yes,
> LLVM in default mode assumes that the current rounding mode is the
> default rounding mode.  But the same holds true for many other
> intrinsics and even the arithmetic IR operations like add.
>
> If you want to stop clang from making the default rounding mode
> assumption, you need to use the -frounding-math option (or one
> of its equivalents), which will cause clang to emit the corresponding
> constrained intrinsics instead, for those two as well all other
> affected intrinsics.
>
> I don't see why it would make sense to add another special case
> just for those two intrinsics ...
>
>
> Bye,
> Ulrich
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200302/6fef3cf6/attachment.html>


More information about the llvm-dev mailing list