[PATCH] D151436: [compiler-rt][SelectionDAG] Add extendbfsf2 libcall and use it for bf16 extends with soft FP

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 08:46:27 PDT 2023


craig.topper added a comment.

> I'm not able to convince myself that the anyext+shift lowering is always identical to the more elaborate extension performed by the libcall in all cases (and if so, why do the trunc and extend libcalls even exist?). though I'm not sure I can convince myself. I know @craig.topper was involved in a previous discussion on this so I'd appreciate your view.

fp32 has more bits of mantissa than bfloat16 but they have the same number of exponent bits.

The trunc libcall exists because the extra bits of mantissa that exist in fp32 need to be rounded to convert to bfloat16. Also some f32 subnormal values can't be represented in bfloat16. So it can't be done as an integer truncate.

For extend, we should just need to add 0s to the end of the mantissa. The +0.0, -0.0 are encoded as all 0s in the mantissa and exponent in both encodings. infinity is encoded with a special exponent and all 0 mantissa in both formats. nan uses the same exponent as infinity but a non-zero mantissa. If the mantissa is already non-zero, adding more zeros doesn't change that. Adding zeros to the end of the mantissa for normals and denormals shouldn't change their value.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151436/new/

https://reviews.llvm.org/D151436



More information about the llvm-commits mailing list