llvm.fma.f16
intrinsic is expanded incorrectly on targets without native half
FMA support
#98389
Labels
llvm.fma.f16
intrinsic is expanded incorrectly on targets without native half
FMA support
#98389
Consider the following LLVM IR:
On targets without native
half
FMA support, 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 forhalf
without double rounding becoming an issue. For instance (raw bits of eachhalf
are in brackets):do_fma(48.34375 (0x520b), 0.000013887882 (0x00e9), 0.12438965 (0x2ff6)) = 0.12512207 (0x3001)
, but LLVM's lowering tofloat
FMA gives an incorrect result of0.125 (0x3000)
.A correct lowering would need to use
double
(or larger): adouble
FMA is not required asdouble
is large enough to represent the result ofhalf * half
without any rounding. In summary, a correct lowering would look something like this:The text was updated successfully, but these errors were encountered: