1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
3 declare float @llvm.amdgcn.rcp.f32(float) #0
4 declare double @llvm.amdgcn.rcp.f64(double) #0
6 declare double @llvm.sqrt.f64(double) #0
7 declare float @llvm.sqrt.f32(float) #0
9 ; FUNC-LABEL: {{^}}rcp_undef_f32:
11 define amdgpu_kernel void @rcp_undef_f32(float addrspace(1)* %out) #1 {
12 %rcp = call float @llvm.amdgcn.rcp.f32(float undef)
13 store float %rcp, float addrspace(1)* %out, align 4
17 ; FUNC-LABEL: {{^}}rcp_2_f32:
19 ; SI: v_mov_b32_e32 v{{[0-9]+}}, 0.5
20 define amdgpu_kernel void @rcp_2_f32(float addrspace(1)* %out) #1 {
21 %rcp = call float @llvm.amdgcn.rcp.f32(float 2.0)
22 store float %rcp, float addrspace(1)* %out, align 4
26 ; FUNC-LABEL: {{^}}rcp_10_f32:
28 ; SI: v_mov_b32_e32 v{{[0-9]+}}, 0x3dcccccd
29 define amdgpu_kernel void @rcp_10_f32(float addrspace(1)* %out) #1 {
30 %rcp = call float @llvm.amdgcn.rcp.f32(float 10.0)
31 store float %rcp, float addrspace(1)* %out, align 4
35 ; FUNC-LABEL: {{^}}safe_no_fp32_denormals_rcp_f32:
36 ; SI: v_rcp_f32_e32 [[RESULT:v[0-9]+]], s{{[0-9]+}}
38 ; SI: buffer_store_dword [[RESULT]]
39 define amdgpu_kernel void @safe_no_fp32_denormals_rcp_f32(float addrspace(1)* %out, float %src) #1 {
40 %rcp = fdiv float 1.0, %src
41 store float %rcp, float addrspace(1)* %out, align 4
45 ; FUNC-LABEL: {{^}}safe_f32_denormals_rcp_pat_f32:
46 ; SI: v_rcp_f32_e32 [[RESULT:v[0-9]+]], s{{[0-9]+}}
48 ; SI: buffer_store_dword [[RESULT]]
49 define amdgpu_kernel void @safe_f32_denormals_rcp_pat_f32(float addrspace(1)* %out, float %src) #4 {
50 %rcp = fdiv float 1.0, %src
51 store float %rcp, float addrspace(1)* %out, align 4
55 ; FUNC-LABEL: {{^}}unsafe_f32_denormals_rcp_pat_f32:
57 define amdgpu_kernel void @unsafe_f32_denormals_rcp_pat_f32(float addrspace(1)* %out, float %src) #3 {
58 %rcp = fdiv float 1.0, %src
59 store float %rcp, float addrspace(1)* %out, align 4
63 ; FUNC-LABEL: {{^}}safe_rsq_rcp_pat_f32:
66 define amdgpu_kernel void @safe_rsq_rcp_pat_f32(float addrspace(1)* %out, float %src) #1 {
67 %sqrt = call float @llvm.sqrt.f32(float %src)
68 %rcp = call float @llvm.amdgcn.rcp.f32(float %sqrt)
69 store float %rcp, float addrspace(1)* %out, align 4
73 ; FUNC-LABEL: {{^}}unsafe_rsq_rcp_pat_f32:
75 define amdgpu_kernel void @unsafe_rsq_rcp_pat_f32(float addrspace(1)* %out, float %src) #2 {
76 %sqrt = call float @llvm.sqrt.f32(float %src)
77 %rcp = call float @llvm.amdgcn.rcp.f32(float %sqrt)
78 store float %rcp, float addrspace(1)* %out, align 4
82 ; FUNC-LABEL: {{^}}rcp_f64:
83 ; SI: v_rcp_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
85 ; SI: buffer_store_dwordx2 [[RESULT]]
86 define amdgpu_kernel void @rcp_f64(double addrspace(1)* %out, double %src) #1 {
87 %rcp = call double @llvm.amdgcn.rcp.f64(double %src)
88 store double %rcp, double addrspace(1)* %out, align 8
92 ; FUNC-LABEL: {{^}}unsafe_rcp_f64:
93 ; SI: v_rcp_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
95 ; SI: buffer_store_dwordx2 [[RESULT]]
96 define amdgpu_kernel void @unsafe_rcp_f64(double addrspace(1)* %out, double %src) #2 {
97 %rcp = call double @llvm.amdgcn.rcp.f64(double %src)
98 store double %rcp, double addrspace(1)* %out, align 8
102 ; FUNC-LABEL: {{^}}rcp_pat_f64:
103 ; SI: v_div_scale_f64
104 define amdgpu_kernel void @rcp_pat_f64(double addrspace(1)* %out, double %src) #1 {
105 %rcp = fdiv double 1.0, %src
106 store double %rcp, double addrspace(1)* %out, align 8
110 ; FUNC-LABEL: {{^}}unsafe_rcp_pat_f64:
111 ; SI: v_rcp_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
113 ; SI: buffer_store_dwordx2 [[RESULT]]
114 define amdgpu_kernel void @unsafe_rcp_pat_f64(double addrspace(1)* %out, double %src) #2 {
115 %rcp = fdiv double 1.0, %src
116 store double %rcp, double addrspace(1)* %out, align 8
120 ; FUNC-LABEL: {{^}}safe_rsq_rcp_pat_f64:
121 ; SI-NOT: v_rsq_f64_e32
124 define amdgpu_kernel void @safe_rsq_rcp_pat_f64(double addrspace(1)* %out, double %src) #1 {
125 %sqrt = call double @llvm.sqrt.f64(double %src)
126 %rcp = call double @llvm.amdgcn.rcp.f64(double %sqrt)
127 store double %rcp, double addrspace(1)* %out, align 8
131 ; FUNC-LABEL: {{^}}unsafe_rsq_rcp_pat_f64:
132 ; SI: v_rsq_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
134 ; SI: buffer_store_dwordx2 [[RESULT]]
135 define amdgpu_kernel void @unsafe_rsq_rcp_pat_f64(double addrspace(1)* %out, double %src) #2 {
136 %sqrt = call double @llvm.sqrt.f64(double %src)
137 %rcp = call double @llvm.amdgcn.rcp.f64(double %sqrt)
138 store double %rcp, double addrspace(1)* %out, align 8
142 attributes #0 = { nounwind readnone }
143 attributes #1 = { nounwind "unsafe-fp-math"="false" "target-features"="-fp32-denormals" }
144 attributes #2 = { nounwind "unsafe-fp-math"="true" "target-features"="-fp32-denormals" }
145 attributes #3 = { nounwind "unsafe-fp-math"="false" "target-features"="+fp32-denormals" }
146 attributes #4 = { nounwind "unsafe-fp-math"="true" "target-features"="+fp32-denormals" }