[X86] LLVM >= 17 generates call to __extendhfsf2
for bitcast -> and -> bitcast · Issue #104914 · llvm/llvm-project (original) (raw)
https://godbolt.org/z/exb7PbjnK
C++ code:
_Float16 fabsf16(_Float16 x) { return __builtin_bit_cast( _Float16, static_cast( __builtin_bit_cast(unsigned short, x) & 0x7fff ) ); }
IR:
define dso_local noundef half @fabsf16(_Float16)(half noundef %x) local_unnamed_addr { entry: %0 = bitcast half %x to i16 %1 = and i16 %0, 32767 %2 = bitcast i16 %1 to half ret half %2 }
Clang 16 output assembly with -O3
:
fabsf16(_Float16): pextrw eax, xmm0, 0 and eax, 32767 pinsrw xmm0, eax, 0 ret
Clang 17 output assembly with -O3
:
.LCPI0_0: .long 0x7fffffff .long 0x7fffffff .long 0x7fffffff .long 0x7fffffff fabsf16(_Float16): push rax call __extendhfsf2@PLT andps xmm0, xmmword ptr [rip + .LCPI0_0] call __truncsfhf2@PLT pop rax ret
Related: #104869 (comment).