llvm.fma.bf16
intrinsic is expanded incorrectly
#131531
Labels
llvm.fma.bf16
intrinsic is expanded incorrectly
#131531
Consider the following LLVM IR:
LLVM turns this into the equivalent of:
This is a miscompilation, however, as
float
does not have enough precision to do a fused-multiply-add forbfloat
without double rounding becoming an issue. For instance:do_fma(0x1.40p+127, 0x1.04p+0, 0x1.00p-133) = 0x1.46p+127
, but LLVM's lowering tofloat
FMA gives an incorrect result of0x1.44p+127
.Just using
double
instead offloat
would also not be a correct lowering: it would give the same incorrect result as the example above (using the reasoning from #128450 (comment), a 126 + 127 + 8 = 261-bit significand would be required for double rounding not to be a problem with this lowering). I suspect the best option here is to lower to a libcall instead.Closely related to #98389/#128450
The text was updated successfully, but these errors were encountered: