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: [email protected]
Reporter: [email protected]
CC: [email protected]
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs