blob: a0fd3411ca05c03974e90e94ce734bda68345094 [file] [log] [blame]
Matt Arsenaultc1e6a452016-07-09 08:02:28 +00001; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=FUNC %s
Matt Arsenault7aad8fd2017-01-24 22:02:15 +00002; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=FUNC %s
Matt Arsenaultc1e6a452016-07-09 08:02:28 +00003; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=R600 -check-prefix=FUNC %s
4
Matt Arsenaulte93d06a2015-01-13 20:53:18 +00005
6; Run with unsafe-fp-math to make sure nothing tries to turn this into 1 / rsqrt(x)
Tom Stellard8ed7b452013-07-12 18:15:13 +00007
Matt Arsenaultc1e6a452016-07-09 08:02:28 +00008; FUNC-LABEL: {{^}}v_safe_fsqrt_f32:
9; GCN: v_sqrt_f32_e32 {{v[0-9]+, v[0-9]+}}
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000010define amdgpu_kernel void @v_safe_fsqrt_f32(float addrspace(1)* %out, float addrspace(1)* %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000011 %r0 = load float, float addrspace(1)* %in
12 %r1 = call float @llvm.sqrt.f32(float %r0)
13 store float %r1, float addrspace(1)* %out
14 ret void
Tom Stellard8ed7b452013-07-12 18:15:13 +000015}
16
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000017; FUNC-LABEL: {{^}}v_unsafe_fsqrt_f32:
18; GCN: v_sqrt_f32_e32 {{v[0-9]+, v[0-9]+}}
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000019define amdgpu_kernel void @v_unsafe_fsqrt_f32(float addrspace(1)* %out, float addrspace(1)* %in) #2 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000020 %r0 = load float, float addrspace(1)* %in
21 %r1 = call float @llvm.sqrt.f32(float %r0)
22 store float %r1, float addrspace(1)* %out
23 ret void
Tom Stellard8ed7b452013-07-12 18:15:13 +000024}
25
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000026
27; FUNC-LABEL: {{^}}s_sqrt_f32:
28; GCN: v_sqrt_f32_e32
29
30; R600: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[2].Z
31; R600: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[2].Z, PS
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000032define amdgpu_kernel void @s_sqrt_f32(float addrspace(1)* %out, float %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000033entry:
34 %fdiv = call float @llvm.sqrt.f32(float %in)
35 store float %fdiv, float addrspace(1)* %out
36 ret void
37}
38
39; FUNC-LABEL: {{^}}s_sqrt_v2f32:
40; GCN: v_sqrt_f32_e32
41; GCN: v_sqrt_f32_e32
42
43; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[2].W
44; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[2].W, PS
45; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].X
46; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].X, PS
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000047define amdgpu_kernel void @s_sqrt_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000048entry:
49 %fdiv = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %in)
50 store <2 x float> %fdiv, <2 x float> addrspace(1)* %out
51 ret void
52}
53
54; FUNC-LABEL: {{^}}s_sqrt_v4f32:
55; GCN: v_sqrt_f32_e32
56; GCN: v_sqrt_f32_e32
57; GCN: v_sqrt_f32_e32
58; GCN: v_sqrt_f32_e32
59
60; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].Y
61; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].Y, PS
62; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].Z
63; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].Z, PS
64; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[3].W
65; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[3].W, PS
66; R600-DAG: RECIPSQRT_CLAMPED * T{{[0-9]\.[XYZW]}}, KC0[4].X
67; R600-DAG: MUL NON-IEEE T{{[0-9]\.[XYZW]}}, KC0[4].X, PS
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000068define amdgpu_kernel void @s_sqrt_v4f32(<4 x float> addrspace(1)* %out, <4 x float> %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000069entry:
70 %fdiv = call <4 x float> @llvm.sqrt.v4f32(<4 x float> %in)
71 store <4 x float> %fdiv, <4 x float> addrspace(1)* %out
72 ret void
73}
74
75; FUNC-LABEL: {{^}}elim_redun_check_neg0:
76; GCN: v_sqrt_f32_e32
77; GCN-NOT: v_cndmask
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000078define amdgpu_kernel void @elim_redun_check_neg0(float addrspace(1)* %out, float %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000079entry:
80 %sqrt = call float @llvm.sqrt.f32(float %in)
81 %cmp = fcmp olt float %in, -0.000000e+00
82 %res = select i1 %cmp, float 0x7FF8000000000000, float %sqrt
83 store float %res, float addrspace(1)* %out
84 ret void
85}
86
87; FUNC-LABEL: {{^}}elim_redun_check_pos0:
88; GCN: v_sqrt_f32_e32
89; GCN-NOT: v_cndmask
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000090define amdgpu_kernel void @elim_redun_check_pos0(float addrspace(1)* %out, float %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +000091entry:
92 %sqrt = call float @llvm.sqrt.f32(float %in)
93 %cmp = fcmp olt float %in, 0.000000e+00
94 %res = select i1 %cmp, float 0x7FF8000000000000, float %sqrt
95 store float %res, float addrspace(1)* %out
96 ret void
97}
98
99; FUNC-LABEL: {{^}}elim_redun_check_ult:
100; GCN: v_sqrt_f32_e32
101; GCN-NOT: v_cndmask
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000102define amdgpu_kernel void @elim_redun_check_ult(float addrspace(1)* %out, float %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +0000103entry:
104 %sqrt = call float @llvm.sqrt.f32(float %in)
105 %cmp = fcmp ult float %in, -0.000000e+00
106 %res = select i1 %cmp, float 0x7FF8000000000000, float %sqrt
107 store float %res, float addrspace(1)* %out
108 ret void
109}
110
111; FUNC-LABEL: {{^}}elim_redun_check_v2:
112; GCN: v_sqrt_f32_e32
113; GCN: v_sqrt_f32_e32
114; GCN-NOT: v_cndmask
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000115define amdgpu_kernel void @elim_redun_check_v2(<2 x float> addrspace(1)* %out, <2 x float> %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +0000116entry:
117 %sqrt = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %in)
118 %cmp = fcmp olt <2 x float> %in, <float -0.000000e+00, float -0.000000e+00>
119 %res = select <2 x i1> %cmp, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> %sqrt
120 store <2 x float> %res, <2 x float> addrspace(1)* %out
121 ret void
122}
123
124; FUNC-LABEL: {{^}}elim_redun_check_v2_ult
125; GCN: v_sqrt_f32_e32
126; GCN: v_sqrt_f32_e32
127; GCN-NOT: v_cndmask
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000128define amdgpu_kernel void @elim_redun_check_v2_ult(<2 x float> addrspace(1)* %out, <2 x float> %in) #1 {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +0000129entry:
130 %sqrt = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %in)
131 %cmp = fcmp ult <2 x float> %in, <float -0.000000e+00, float -0.000000e+00>
132 %res = select <2 x i1> %cmp, <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> %sqrt
133 store <2 x float> %res, <2 x float> addrspace(1)* %out
134 ret void
135}
136
137declare float @llvm.sqrt.f32(float %in) #0
138declare <2 x float> @llvm.sqrt.v2f32(<2 x float> %in) #0
139declare <4 x float> @llvm.sqrt.v4f32(<4 x float> %in) #0
140
141attributes #0 = { nounwind readnone }
142attributes #1 = { nounwind "unsafe-fp-math"="false" }
143attributes #2 = { nounwind "unsafe-fp-math"="true" }