llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[X86] bf16 to float conversion fails to stay on FPU

Open RKSimon opened this issue 1 year ago • 4 comments

https://godbolt.org/z/qTasEq77v

define float @src(bfloat %a0) {
  %res = fpext bfloat %a0 to float
  ret float %res
}
src: # @src
  pextrw $0, %xmm0, %eax
  shll $16, %eax
  movd %eax, %xmm0
  retq

This could be handled as:

src: # @src
  pmovzxwd %xmm0, %xmm0 ; UNPCKLWD pre-SSE41
  pslld $16, %xmm0
  retq

Hopefully we can handle this generically instead of handling it in explicit fpext lowering

RKSimon avatar Aug 25 '25 16:08 RKSimon

@llvm/issue-subscribers-backend-x86

Author: Simon Pilgrim (RKSimon)

https://godbolt.org/z/qTasEq77v
define float @<!-- -->src(bfloat %a0) {
  %res = fpext bfloat %a0 to float
  ret float %res
}
src: # @<!-- -->src
  pextrw $0, %xmm0, %eax
  shll $16, %eax
  movd %eax, %xmm0
  retq

This could be handled as:

src: # @<!-- -->src
  pmovzxwd %xmm0, %xmm0 ; UNPCKLWD pre-SSE41
  pslld $16, %xmm0
  retq

Hopefully we can handle this generically instead of handling it in explicit fpext lowering

llvmbot avatar Aug 25 '25 16:08 llvmbot

Hi Simon (@RKSimon), I would like to take a crack at this. Would you help assign it to me please? Thanks!

ningxinr avatar Aug 25 '25 20:08 ningxinr

@ningxinr, there were some bugs with bfloat16 on x86 that were reported at https://github.com/llvm/llvm-project/issues/151692 and https://github.com/llvm/llvm-project/issues/134222, along with a draft pull request at https://github.com/llvm/llvm-project/pull/134859 to improve bfloat16 code generation on X86.

johnplatts avatar Sep 10 '25 12:09 johnplatts

@ningxinr, there were some bugs with bfloat16 on x86 that were reported at #151692 and #134222, along with a draft pull request at #134859 to improve bfloat16 code generation on X86.

Thank you, John! I will try #134859 locally

ningxinr avatar Sep 10 '25 19:09 ningxinr