[llvm-dev] uitofp always evaluates to 0 under certain conditions

Andrew Adams via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 29 17:26:48 PDT 2015


Hi all,

This is a bug I reported a few weeks ago. It just bit us in production code
so I thought I'd raise it on the mailing list for some extra visibility:
https://llvm.org/bugs/show_bug.cgi?id=24512

The issue is that on x86 without avx, there's no native way to convert a
vector of uint32 to a vector of float. So llvm emulates it with a sequence
of floating point math and bit tricks (lowerUINT_TO_FP_vXi32 in
X86ISelLowering.cpp). Unfortunately the method used is numerically
unstable, so if unsafe-fp-math is on and reassociation is deemed
profitable, it turns into code that just throws away the bottom bits of the
input. So, for example, casting a vector of ones to float gives you a
vector of zeros.

I know unsafe-fp-math is a license to do a lot of shady stuff, but breaking
uitofp entirely doesn't seem like fair game :)

We have a workaround downstream (
https://github.com/halide/Halide/commit/5e976ba50f68873b43e97c427c68421fddc5c01d),
so there's no urgency, but someone else is probably going to hit this too
so I thought I'd re-raise the issue.

Thanks,

- Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150929/e1f85e0e/attachment.html>


More information about the llvm-dev mailing list