1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -enable-var-scope -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, !fpmath !0
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, !fpmath !0
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:
65 define amdgpu_kernel void @safe_rsq_rcp_pat_f32(float addrspace(1)* %out, float %src) #1 {
66 %sqrt = call float @llvm.sqrt.f32(float %src)
67 %rcp = call float @llvm.amdgcn.rcp.f32(float %sqrt)
68 store float %rcp, float addrspace(1)* %out, align 4
72 ; FUNC-LABEL: {{^}}unsafe_rsq_rcp_pat_f32:
74 define amdgpu_kernel void @unsafe_rsq_rcp_pat_f32(float addrspace(1)* %out, float %src) #2 {
75 %sqrt = call float @llvm.sqrt.f32(float %src)
76 %rcp = call float @llvm.amdgcn.rcp.f32(float %sqrt)
77 store float %rcp, float addrspace(1)* %out, align 4
81 ; FUNC-LABEL: {{^}}rcp_f64:
82 ; SI: v_rcp_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
84 ; SI: buffer_store_dwordx2 [[RESULT]]
85 define amdgpu_kernel void @rcp_f64(double addrspace(1)* %out, double %src) #1 {
86 %rcp = call double @llvm.amdgcn.rcp.f64(double %src)
87 store double %rcp, double addrspace(1)* %out, align 8
91 ; FUNC-LABEL: {{^}}unsafe_rcp_f64:
92 ; SI: v_rcp_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
94 ; SI: buffer_store_dwordx2 [[RESULT]]
95 define amdgpu_kernel void @unsafe_rcp_f64(double addrspace(1)* %out, double %src) #2 {
96 %rcp = call double @llvm.amdgcn.rcp.f64(double %src)
97 store double %rcp, double addrspace(1)* %out, align 8
101 ; FUNC-LABEL: {{^}}rcp_pat_f64:
102 ; SI: v_div_scale_f64
103 define amdgpu_kernel void @rcp_pat_f64(double addrspace(1)* %out, double %src) #1 {
104 %rcp = fdiv double 1.0, %src
105 store double %rcp, double addrspace(1)* %out, align 8
109 ; FUNC-LABEL: {{^}}unsafe_rcp_pat_f64:
117 define amdgpu_kernel void @unsafe_rcp_pat_f64(double addrspace(1)* %out, double %src) #2 {
118 %rcp = fdiv double 1.0, %src
119 store double %rcp, double addrspace(1)* %out, align 8
123 ; FUNC-LABEL: {{^}}safe_rsq_rcp_pat_f64:
124 ; SI-NOT: v_rsq_f64_e32
127 define amdgpu_kernel void @safe_rsq_rcp_pat_f64(double addrspace(1)* %out, double %src) #1 {
128 %sqrt = call double @llvm.sqrt.f64(double %src)
129 %rcp = call double @llvm.amdgcn.rcp.f64(double %sqrt)
130 store double %rcp, double addrspace(1)* %out, align 8
134 ; FUNC-LABEL: {{^}}unsafe_rsq_rcp_pat_f64:
135 ; SI: v_sqrt_f64_e32 [[SQRT:v\[[0-9]+:[0-9]+\]]], s{{\[[0-9]+:[0-9]+\]}}
136 ; SI: v_rcp_f64_e32 [[RESULT:v\[[0-9]+:[0-9]+\]]], [[SQRT]]
137 ; SI: buffer_store_dwordx2 [[RESULT]]
138 define amdgpu_kernel void @unsafe_rsq_rcp_pat_f64(double addrspace(1)* %out, double %src) #2 {
139 %sqrt = call double @llvm.sqrt.f64(double %src)
140 %rcp = call double @llvm.amdgcn.rcp.f64(double %sqrt)
141 store double %rcp, double addrspace(1)* %out, align 8
145 attributes #0 = { nounwind readnone }
146 attributes #1 = { nounwind "unsafe-fp-math"="false" "denormal-fp-math-f32"="preserve-sign,preserve-sign" }
147 attributes #2 = { nounwind "unsafe-fp-math"="true" "denormal-fp-math-f32"="preserve-sign,preserve-sign" }
148 attributes #3 = { nounwind "unsafe-fp-math"="false" "denormal-fp-math-f32"="ieee,ieee" }
149 attributes #4 = { nounwind "unsafe-fp-math"="true" "denormal-fp-math-f32"="ieee,ieee" }
151 !0 = !{float 2.500000e+00}