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

Ulrich Weigand via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 2 05:57:50 PST 2020

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200302/5b63070f/attachment-0001.html>

More information about the llvm-dev mailing list