Open overmighty opened 2 months ago
Forming fabs is correct, the codegen is not. Promotion should bitcast to integer
@llvm/issue-subscribers-backend-x86
Author: OverMighty (overmighty)
The same bug exists for fneg and copysign, and this is repeated in the type legalizer and promotion action
Attaching partial patch. It's incomplete because it asserts on targets with legal f16, but no legal i16. I don't have the patience to fight with SelectionDAG's insistence that there can be no illegal types after type legalization
This isn't x86 specific; it affects FABS
and FNEG
for any target that uses TypeSoftPromoteHalf
. The issue is that the lowering uses the generic SoftPromoteHalfRes_UnaryOp
method. The resulting lowering is actually a miscompilation as __extendhfsf2
and __truncsfhf2
quieten signalling NaNs, whereas FABS
and FNEG
are defined as only affecting the sign bit (FCOPYSIGN
doesn't have this issue as its lowering in SoftPromoteHalfRes_FCOPYSIGN
doesn't convert to and from a f32
).
https://godbolt.org/z/on6Pj6Tsc
Starting from https://github.com/llvm/llvm-project/commit/5c0da5839de1bdc08f411a04305a9bdadf538ad5, InstCombine transforms this IR:
into:
On x86, when AVX-512 FP16 is not available, this generates something like:
whereas with LLVM 16,
bitcast
->and
->bitcast
generates something like:Related:
cc @arsenm @lntue