[LLVMbugs] [Bug 22944] New: simplifylibcalls should optimize various floating point rounding utilities like lround or lrintf

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 17 13:23:25 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=22944

            Bug ID: 22944
           Summary: simplifylibcalls should optimize various floating
                    point rounding utilities like lround or lrintf
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Quickly rounding a floating point value towards the nearest integer in the
positive direction is hard to do portably. The obvious code of (int)(f + 0.5)
does float to double promotion before rounding to the nearest int. It also
fails on some obscure edge cases, which aren't important. C99 has a whole
family of functions such as round(), lrintf(), nearbyint(), etc that we should
optimize down to a cvttss2si instruction. Today users have to write stuff like
this to get down to a single cvttss2i:

  int roundit(float f) { return _mm_cvt_ss2si(_mm_load_ss(&f)); }

This is hacky and not portable.

This transform may be tricky, since some functions like lrint are supposed to
respect the fenv rounding and error handling modes, which LLVM doesn't respect.
I think some libcalls like lround are specified to behave the same way, so if
we limit ourselves to that I'd be happy.

Alternatively, we could fix this in Clang IRgen, but I think simplifylibcalls
is more likely to be the right place.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150317/37954cd4/attachment.html>


More information about the llvm-bugs mailing list