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

Ahmed Bougacha via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 29 17:56:43 PDT 2015


On Tue, Sep 29, 2015 at 5:26 PM, Andrew Adams via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> 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

> 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
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>


More information about the llvm-dev mailing list