Should NaN payloads be preserved through compilation?

Hi everyone,

The WebAssembly backend recently had Bug 39448 filed against it because NaN payloads in floating-point immediates are not preserved through compilation on 32-bit builds. I took a look and the corruption takes place when the immediates are converted from APFloats to be stored as native doubles in MCOperand. I assume this bug only appears in 32-bit builds because they are using x87 doubles that happen to not preserve all possible NaN payloads.

There are two things we could do here: Change MCOperand to not store floating point immediates as native doubles, or explicitly accept that NaN payloads in immediates will not necessarily be preserved through compilation.

The ability to have custom NaN payloads in immediates could be useful to the WebAssembly community, but if the consensus is that LLVM should not guarantee their preservation, that’s fine too. What do you think?

Thomas

One issue is that currently none (except one I think I added) of the functions in APFloat properly preserve payload bits so I think the problem is bigger than late corruption if you are expecting these to behave as expected.

-Matt

Thanks, Matt, that’s good to know. If we only consider immediates that are not modified by optimization passes, perhaps the problem is more tractable. In my brief exploration, it appeared that the custom NaN payloads of the immediates were intact up until that conversion in the MC layer.

Our out-of-tree compiler encodes information into the mantissa of a NaN. E.g. what caused the NaN to be created. This helps us track down the problematic code and has been useful in the past.

Seems fine, as long as you don't increase the size of MCOperand. (MachineOperand already uses ConstantFP, so it should be a tiny patch.)

-Eli

I think there are no guarantees for NaN preservation. See for example:

https://lists.llvm.org/pipermail/llvm-dev/2014-September/076783.html

That said I assume we will take patches that fix bugs in the area if they don’t cause any other problems.

  • Matthias