uitofp always evaluates to 0 under certain conditions

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 :slight_smile:

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

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.

Ah, yes, we hit this too, and I was about to file a PR! Let's finish
this conversation there and quickly get this fixed.

-Ahmed