This is because the Sema::UsualUnaryConversions don't apply to VectorTypes (see Sema::CheckVectorOperands), so we never try to promote to v4f32 (as we would promote __fp16 to f32).
Even if we decide to reject that code and never do the implicit promotion, the alternative is also broken:
Even when "half" is used instead of i16 (AArch64, or after we migrate away from the convert intrinsics), we generate IR without the promotion:
%3 = fadd <4 x half> %1, %2
Relying on the backend to do the promotion.
However, this has slightly different semantics, because LLVM works at the instruction level, and clang at the expression level. Consider:
Doing the promotion in clang means the intermediate result is a v4f32. Doing it in LLVM means the intermediate result is truncated back to v4f16, before being extended again to v4f32.
This can give different result, and it's probably best to mirror the scalar clang behavior of promoting entire expressions.
Extended Description
__fp16 is a storage-only type, and there are two CodeGen variants:
In both cases, we don't do the right thing for vectors.
On X86, this:
generates the very broken:
This is because the Sema::UsualUnaryConversions don't apply to VectorTypes (see Sema::CheckVectorOperands), so we never try to promote to v4f32 (as we would promote __fp16 to f32).
Even if we decide to reject that code and never do the implicit promotion, the alternative is also broken:
Generates:
Even when "half" is used instead of i16 (AArch64, or after we migrate away from the convert intrinsics), we generate IR without the promotion:
Relying on the backend to do the promotion. However, this has slightly different semantics, because LLVM works at the instruction level, and clang at the expression level. Consider:
Doing the promotion in clang means the intermediate result is a v4f32. Doing it in LLVM means the intermediate result is truncated back to v4f16, before being extended again to v4f32.
This can give different result, and it's probably best to mirror the scalar clang behavior of promoting entire expressions.