blob: ea03b55b9a63ec339c06fe1dc71c300107c79e48 [file] [log] [blame]
Matt Arsenault9c47dd52016-02-11 06:02:01 +00001; RUN: llc -march=amdgcn -mattr=-fp32-denormals -verify-machineinstrs -enable-unsafe-fp-math < %s | FileCheck -check-prefix=SI-UNSAFE -check-prefix=SI %s
2; RUN: llc -march=amdgcn -mattr=-fp32-denormals -verify-machineinstrs < %s | FileCheck -check-prefix=SI-SAFE -check-prefix=SI %s
Matt Arsenault15130462014-06-05 00:15:55 +00003
Matt Arsenault9c47dd52016-02-11 06:02:01 +00004declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
Matt Arsenault15130462014-06-05 00:15:55 +00005declare float @llvm.sqrt.f32(float) nounwind readnone
6declare double @llvm.sqrt.f64(double) nounwind readnone
7
Tom Stellard79243d92014-10-01 17:15:17 +00008; SI-LABEL: {{^}}rsq_f32:
Tom Stellard326d6ec2014-11-05 14:50:53 +00009; SI: v_rsq_f32_e32
10; SI: s_endpgm
Matt Arsenault15130462014-06-05 00:15:55 +000011define void @rsq_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in) nounwind {
David Blaikiea79ac142015-02-27 21:17:42 +000012 %val = load float, float addrspace(1)* %in, align 4
Matt Arsenault15130462014-06-05 00:15:55 +000013 %sqrt = call float @llvm.sqrt.f32(float %val) nounwind readnone
14 %div = fdiv float 1.0, %sqrt
15 store float %div, float addrspace(1)* %out, align 4
16 ret void
17}
18
Tom Stellard79243d92014-10-01 17:15:17 +000019; SI-LABEL: {{^}}rsq_f64:
Tom Stellard326d6ec2014-11-05 14:50:53 +000020; SI-UNSAFE: v_rsq_f64_e32
21; SI-SAFE: v_sqrt_f64_e32
22; SI: s_endpgm
Matt Arsenault15130462014-06-05 00:15:55 +000023define void @rsq_f64(double addrspace(1)* noalias %out, double addrspace(1)* noalias %in) nounwind {
David Blaikiea79ac142015-02-27 21:17:42 +000024 %val = load double, double addrspace(1)* %in, align 4
Matt Arsenault15130462014-06-05 00:15:55 +000025 %sqrt = call double @llvm.sqrt.f64(double %val) nounwind readnone
26 %div = fdiv double 1.0, %sqrt
27 store double %div, double addrspace(1)* %out, align 4
28 ret void
29}
Matt Arsenault49dd4282014-09-15 17:15:02 +000030
Tom Stellard79243d92014-10-01 17:15:17 +000031; SI-LABEL: {{^}}rsq_f32_sgpr:
Tom Stellard326d6ec2014-11-05 14:50:53 +000032; SI: v_rsq_f32_e32 {{v[0-9]+}}, {{s[0-9]+}}
33; SI: s_endpgm
Matt Arsenault49dd4282014-09-15 17:15:02 +000034define void @rsq_f32_sgpr(float addrspace(1)* noalias %out, float %val) nounwind {
35 %sqrt = call float @llvm.sqrt.f32(float %val) nounwind readnone
36 %div = fdiv float 1.0, %sqrt
37 store float %div, float addrspace(1)* %out, align 4
38 ret void
39}
Matt Arsenaulte93d06a2015-01-13 20:53:18 +000040
41; Recognize that this is rsqrt(a) * rcp(b) * c,
42; not 1 / ( 1 / sqrt(a)) * rcp(b) * c.
43
44; SI-LABEL: @rsqrt_fmul
45; SI-DAG: buffer_load_dword [[A:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
46; SI-DAG: buffer_load_dword [[B:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:4
47; SI-DAG: buffer_load_dword [[C:v[0-9]+]], {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64 offset:8
48
49; SI-UNSAFE-DAG: v_rsq_f32_e32 [[RSQA:v[0-9]+]], [[A]]
50; SI-UNSAFE-DAG: v_rcp_f32_e32 [[RCPB:v[0-9]+]], [[B]]
51; SI-UNSAFE-DAG: v_mul_f32_e32 [[TMP:v[0-9]+]], [[RCPB]], [[RSQA]]
52; SI-UNSAFE: v_mul_f32_e32 [[RESULT:v[0-9]+]], [[TMP]], [[C]]
53; SI-UNSAFE: buffer_store_dword [[RESULT]]
54
55; SI-SAFE-NOT: v_rsq_f32
56
57; SI: s_endpgm
58define void @rsqrt_fmul(float addrspace(1)* %out, float addrspace(1)* %in) {
Matt Arsenault9c47dd52016-02-11 06:02:01 +000059 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
David Blaikie79e6c742015-02-27 19:29:02 +000060 %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
61 %gep.0 = getelementptr float, float addrspace(1)* %in, i32 %tid
62 %gep.1 = getelementptr float, float addrspace(1)* %gep.0, i32 1
63 %gep.2 = getelementptr float, float addrspace(1)* %gep.0, i32 2
Matt Arsenaulte93d06a2015-01-13 20:53:18 +000064
David Blaikiea79ac142015-02-27 21:17:42 +000065 %a = load float, float addrspace(1)* %gep.0
66 %b = load float, float addrspace(1)* %gep.1
67 %c = load float, float addrspace(1)* %gep.2
Matt Arsenaulte93d06a2015-01-13 20:53:18 +000068
69 %x = call float @llvm.sqrt.f32(float %a)
70 %y = fmul float %x, %b
71 %z = fdiv float %c, %y
72 store float %z, float addrspace(1)* %out.gep
73 ret void
74}