This patch teaches the backend how to custom lower a 'fp_to_fp16' node that performs a double-to-half conversion.
Under fast-math, if the target has F16C, the backend can expand a double-to-half conversion into a double-to-float conversion immediately followed by a float-to-half conversion. Before this patch, a double-to-half conversion was always expanded into a library call even under fast-math.
Example:
\code
define zeroext i16 @func(double %d) #0 {
entry:
%0 = tail call i16 @llvm.convert.to.fp16.f64(double %d) ret i16 %0
}
attributes #0 = { "unsafe-fp-math=true" "use-soft-float"="false" }
\code end
Before this patch (with -mattr=+f16c), the conversion from double to fp16 was expanded into a library call to function '__truncdfhf2'.
With this patch, the double-to-half conversion is now expanded into the sequence:
vcvtsd2ss %xmm0, %xmm0, %xmm0 vcvtps2ph $0, %xmm0, %xmm0
Note that this patch also handles 'long double'-to-half conversions.
This patch doesn't add custom lowering rules for 'fp16_to_fp' dag nodes. The reason why we don't need those rules is because LegalizeDAG (see around lines 3532:3546) already knows how to expand a half-to-double conversion into a 'FP16_TO_FP' plus 'FP_EXTEND'.
Please let me know if ok to submit.
Thanks!
Andrea
Not very important, but add a check for fp80->fp32, perhaps?