1; RUN: llc -march=amdgcn -mcpu=SI -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI -check-prefix=FUNC %s
2; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI -check-prefix=FUNC %s
3; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=R600 -check-prefix=FUNC %s
4
5
6; DAGCombiner will transform:
7; (fabs (f32 bitcast (i32 a))) => (f32 bitcast (and (i32 a), 0x7FFFFFFF))
8; unless isFabsFree returns true
9
10; FUNC-LABEL: {{^}}fabs_fn_free:
11; R600-NOT: AND
12; R600: |PV.{{[XYZW]}}|
13
14; GCN: v_and_b32
15
16define void @fabs_fn_free(float addrspace(1)* %out, i32 %in) {
17  %bc= bitcast i32 %in to float
18  %fabs = call float @fabs(float %bc)
19  store float %fabs, float addrspace(1)* %out
20  ret void
21}
22
23; FUNC-LABEL: {{^}}fabs_free:
24; R600-NOT: AND
25; R600: |PV.{{[XYZW]}}|
26
27; GCN: v_and_b32
28
29define void @fabs_free(float addrspace(1)* %out, i32 %in) {
30  %bc= bitcast i32 %in to float
31  %fabs = call float @llvm.fabs.f32(float %bc)
32  store float %fabs, float addrspace(1)* %out
33  ret void
34}
35
36; FUNC-LABEL: {{^}}fabs_f32:
37; R600: |{{(PV|T[0-9])\.[XYZW]}}|
38
39; GCN: v_and_b32
40define void @fabs_f32(float addrspace(1)* %out, float %in) {
41  %fabs = call float @llvm.fabs.f32(float %in)
42  store float %fabs, float addrspace(1)* %out
43  ret void
44}
45
46; FUNC-LABEL: {{^}}fabs_v2f32:
47; R600: |{{(PV|T[0-9])\.[XYZW]}}|
48; R600: |{{(PV|T[0-9])\.[XYZW]}}|
49
50; GCN: v_and_b32
51; GCN: v_and_b32
52define void @fabs_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %in) {
53  %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %in)
54  store <2 x float> %fabs, <2 x float> addrspace(1)* %out
55  ret void
56}
57
58; FUNC-LABEL: {{^}}fabs_v4f32:
59; R600: |{{(PV|T[0-9])\.[XYZW]}}|
60; R600: |{{(PV|T[0-9])\.[XYZW]}}|
61; R600: |{{(PV|T[0-9])\.[XYZW]}}|
62; R600: |{{(PV|T[0-9])\.[XYZW]}}|
63
64; GCN: v_and_b32
65; GCN: v_and_b32
66; GCN: v_and_b32
67; GCN: v_and_b32
68define void @fabs_v4f32(<4 x float> addrspace(1)* %out, <4 x float> %in) {
69  %fabs = call <4 x float> @llvm.fabs.v4f32(<4 x float> %in)
70  store <4 x float> %fabs, <4 x float> addrspace(1)* %out
71  ret void
72}
73
74; GCN-LABEL: {{^}}fabs_fn_fold:
75; SI: s_load_dword [[ABS_VALUE:s[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0xb
76; VI: s_load_dword [[ABS_VALUE:s[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0x2c
77; GCN-NOT: and
78; GCN: v_mul_f32_e64 v{{[0-9]+}}, |[[ABS_VALUE]]|, v{{[0-9]+}}
79define void @fabs_fn_fold(float addrspace(1)* %out, float %in0, float %in1) {
80  %fabs = call float @fabs(float %in0)
81  %fmul = fmul float %fabs, %in1
82  store float %fmul, float addrspace(1)* %out
83  ret void
84}
85
86; GCN-LABEL: {{^}}fabs_fold:
87; SI: s_load_dword [[ABS_VALUE:s[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0xb
88; VI: s_load_dword [[ABS_VALUE:s[0-9]+]], s[{{[0-9]+:[0-9]+}}], 0x2c
89; GCN-NOT: and
90; GCN: v_mul_f32_e64 v{{[0-9]+}}, |[[ABS_VALUE]]|, v{{[0-9]+}}
91define void @fabs_fold(float addrspace(1)* %out, float %in0, float %in1) {
92  %fabs = call float @llvm.fabs.f32(float %in0)
93  %fmul = fmul float %fabs, %in1
94  store float %fmul, float addrspace(1)* %out
95  ret void
96}
97
98declare float @fabs(float) readnone
99declare float @llvm.fabs.f32(float) readnone
100declare <2 x float> @llvm.fabs.v2f32(<2 x float>) readnone
101declare <4 x float> @llvm.fabs.v4f32(<4 x float>) readnone
102