This is an archive of the discontinued LLVM Phabricator instance.

Do not translate rint into nearbyint, but truncate it like nearbyint
ClosedPublic

Authored by joerg on Mar 31 2017, 6:52 AM.

Details

Reviewers
scanon
arsenm
Summary

A common way to implement nearbyint is by fiddling with the floating point environment and calling rint. This is used at least by the BSD libm and musl. As such, canonicalizing the latter to the former will create infinite loops for libm and generally pessimize performance, at least when the generic C versions are used. This patch preserves the rint in the libcall translation and also handle the domain truncation logic, so that rint with float argument will be reduced to rintf etc.

Diff Detail

Repository
rL LLVM

Event Timeline

joerg created this revision.Mar 31 2017, 6:52 AM
scanon accepted this revision.Mar 31 2017, 6:56 AM

LGTM.

This revision is now accepted and ready to land.Mar 31 2017, 6:56 AM
arsenm accepted this revision.Mar 31 2017, 11:02 AM

LGTM

If rint() is faster than nearbyint(), should we canonicalize nearbyint()->rint()?

If rint() is faster than nearbyint(), should we canonicalize nearbyint()->rint()?

nearbyint( ) is not allowed to raise inexact. rint( ) is. Replacing nearbyint( ) with rint( ) requires that we support the FENV_ACCESS pragma (and only do the transformation when FENV_ACCESS is off).

Also, this is relatively low-value, because on newer platforms there's no difference; e.g. SSE4.1 and armv8 have single instruction implementations for both.

joerg closed this revision.Mar 31 2017, 1:10 PM

r299247.