Skip to content

Commit 1df8efa

Browse files
committed
[SelectionDAG][X86] Support f16 in getReciprocalOpName.
If the "reciprocal-estimates" attribute is present and it doesn't contain "all", "none", or "default", we previously crashed on f16 operations. This patch addes an 'h' suffix' to prevent the crash. I've added simple tests that just enable the estimate for all vec-sqrt and one test case that explicitly tests the new 'h' suffix to override the default steps. There may be some frontend change needed to, but I haven't checked that yet. Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D120158
1 parent 3915171 commit 1df8efa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,9 +2072,11 @@ static std::string getReciprocalOpName(bool IsSqrt, EVT VT) {
20722072

20732073
Name += IsSqrt ? "sqrt" : "div";
20742074

2075-
// TODO: Handle "half" or other float types?
2075+
// TODO: Handle other float types?
20762076
if (VT.getScalarType() == MVT::f64) {
20772077
Name += "d";
2078+
} else if (VT.getScalarType() == MVT::f16) {
2079+
Name += "h";
20782080
} else {
20792081
assert(VT.getScalarType() == MVT::f32 &&
20802082
"Unexpected FP type for reciprocal estimate");

llvm/test/CodeGen/X86/avx512fp16-intrinsics.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,32 @@ define <32 x half> @test_sqrt_ph_512_fast(<32 x half> %a0, <32 x half> %a1) {
3535
ret <32 x half> %2
3636
}
3737

38+
define <32 x half> @test_sqrt_ph_512_fast_estimate_attribute(<32 x half> %a0, <32 x half> %a1) "reciprocal-estimates"="vec-sqrt" {
39+
; CHECK-LABEL: test_sqrt_ph_512_fast_estimate_attribute:
40+
; CHECK: # %bb.0:
41+
; CHECK-NEXT: vrsqrtph %zmm0, %zmm0
42+
; CHECK-NEXT: vmulph %zmm0, %zmm1, %zmm0
43+
; CHECK-NEXT: retq
44+
%1 = call fast <32 x half> @llvm.sqrt.v32f16(<32 x half> %a0)
45+
%2 = fdiv fast <32 x half> %a1, %1
46+
ret <32 x half> %2
47+
}
48+
49+
define <32 x half> @test_sqrt_ph_512_fast_estimate_attribute_2(<32 x half> %a0, <32 x half> %a1) "reciprocal-estimates"="vec-sqrth:1" {
50+
; CHECK-LABEL: test_sqrt_ph_512_fast_estimate_attribute_2:
51+
; CHECK: # %bb.0:
52+
; CHECK-NEXT: vrsqrtph %zmm0, %zmm2
53+
; CHECK-NEXT: vmulph %zmm2, %zmm0, %zmm0
54+
; CHECK-NEXT: vfmadd213ph {{\.?LCPI[0-9]+_[0-9]+}}(%rip){1to32}, %zmm2, %zmm0
55+
; CHECK-NEXT: vmulph {{\.?LCPI[0-9]+_[0-9]+}}(%rip){1to32}, %zmm2, %zmm2
56+
; CHECK-NEXT: vmulph %zmm1, %zmm0, %zmm0
57+
; CHECK-NEXT: vmulph %zmm0, %zmm2, %zmm0
58+
; CHECK-NEXT: retq
59+
%1 = call fast <32 x half> @llvm.sqrt.v32f16(<32 x half> %a0)
60+
%2 = fdiv fast <32 x half> %a1, %1
61+
ret <32 x half> %2
62+
}
63+
3864
define <32 x half> @test_mask_sqrt_ph_512(<32 x half> %a0, <32 x half> %passthru, i32 %mask) {
3965
; CHECK-LABEL: test_mask_sqrt_ph_512:
4066
; CHECK: # %bb.0:

0 commit comments

Comments
 (0)