Issue 126892
Summary [X86] Unnecessary promotion for fneg / fabs half calls
Labels good first issue, backend:X86, missed-optimization, llvm:SelectionDAG
Assignees
Reporter RKSimon
    https://gcc.godbolt.org/z/PGshMcsTY

```cpp
_Float16 fabs_f16(_Float16 x) {
    return static_cast<_Float16>(__builtin_elementwise_abs(x));
}
_Float16 fneg_f16(_Float16 x) {
    return static_cast<_Float16>(-(x));
}
```
These shouldn't require vcvtph2ps/vcvtps2ph or __extendhfsf2/__truncsfhf2 calls - we should be able to use the bitwise ops directly on the v8f16 type.
```asm
.LCPI0_0:
 .long 0x7fffffff # float NaN
  .long 0x7fffffff # float NaN
  .long 0x7fffffff # float NaN
  .long 0x7fffffff # float NaN
fabs_f16(_Float16): # @fabs_f16(_Float16)
# %bb.0: # %entry
  vcvtph2ps %xmm0, %xmm0
  vandps .LCPI0_0(%rip), %xmm0, %xmm0
  vcvtps2ph $4, %xmm0, %xmm0
  retq
  # -- End function
.LCPI1_0:
  .long 0x80000000 # float -0
  .long 0x80000000 # float -0
  .long 0x80000000 # float -0
  .long 0x80000000 # float -0
fneg_f16(_Float16): # @fneg_f16(_Float16)
# %bb.0: # %entry
  vcvtph2ps %xmm0, %xmm0
  vxorps .LCPI1_0(%rip), %xmm0, %xmm0
  vcvtps2ph $4, %xmm0, %xmm0
  retq
  # -- End function
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to