1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI -check-prefix=FUNC %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI -check-prefix=FUNC %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=R600 -check-prefix=FUNC %s
5 ; FUNC-LABEL: {{^}}fneg_fabs_fadd_f32:
7 ; SI: v_sub_f32_e64 {{v[0-9]+}}, {{s[0-9]+}}, |{{v[0-9]+}}|
8 define amdgpu_kernel void @fneg_fabs_fadd_f32(float addrspace(1)* %out, float %x, float %y) {
9 %fabs = call float @llvm.fabs.f32(float %x)
10 %fsub = fsub float -0.000000e+00, %fabs
11 %fadd = fadd float %y, %fsub
12 store float %fadd, float addrspace(1)* %out, align 4
16 ; FUNC-LABEL: {{^}}fneg_fabs_fmul_f32:
18 ; SI: v_mul_f32_e64 {{v[0-9]+}}, {{s[0-9]+}}, -|{{v[0-9]+}}|
20 define amdgpu_kernel void @fneg_fabs_fmul_f32(float addrspace(1)* %out, float %x, float %y) {
21 %fabs = call float @llvm.fabs.f32(float %x)
22 %fsub = fsub float -0.000000e+00, %fabs
23 %fmul = fmul float %y, %fsub
24 store float %fmul, float addrspace(1)* %out, align 4
28 ; DAGCombiner will transform:
29 ; (fabs (f32 bitcast (i32 a))) => (f32 bitcast (and (i32 a), 0x7FFFFFFF))
30 ; unless isFabsFree returns true
32 ; FUNC-LABEL: {{^}}fneg_fabs_free_f32:
34 ; R600: |PV.{{[XYZW]}}|
37 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, 0x80000000
38 ; VI: s_bitset1_b32 s{{[0-9]+}}, 31
39 define amdgpu_kernel void @fneg_fabs_free_f32(float addrspace(1)* %out, i32 %in) {
40 %bc = bitcast i32 %in to float
41 %fabs = call float @llvm.fabs.f32(float %bc)
42 %fsub = fsub float -0.000000e+00, %fabs
43 store float %fsub, float addrspace(1)* %out
47 ; FUNC-LABEL: {{^}}fneg_fabs_fn_free_f32:
49 ; R600: |PV.{{[XYZW]}}|
52 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, 0x80000000
53 define amdgpu_kernel void @fneg_fabs_fn_free_f32(float addrspace(1)* %out, i32 %in) {
54 %bc = bitcast i32 %in to float
55 %fabs = call float @fabs(float %bc)
56 %fsub = fsub float -0.000000e+00, %fabs
57 store float %fsub, float addrspace(1)* %out
61 ; FUNC-LABEL: {{^}}fneg_fabs_f32:
62 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, 0x80000000
63 define amdgpu_kernel void @fneg_fabs_f32(float addrspace(1)* %out, float %in) {
64 %fabs = call float @llvm.fabs.f32(float %in)
65 %fsub = fsub float -0.000000e+00, %fabs
66 store float %fsub, float addrspace(1)* %out, align 4
70 ; FUNC-LABEL: {{^}}v_fneg_fabs_f32:
71 ; SI: v_or_b32_e32 v{{[0-9]+}}, 0x80000000, v{{[0-9]+}}
72 define amdgpu_kernel void @v_fneg_fabs_f32(float addrspace(1)* %out, float addrspace(1)* %in) {
73 %val = load float, float addrspace(1)* %in, align 4
74 %fabs = call float @llvm.fabs.f32(float %val)
75 %fsub = fsub float -0.000000e+00, %fabs
76 store float %fsub, float addrspace(1)* %out, align 4
80 ; FUNC-LABEL: {{^}}fneg_fabs_v2f32:
81 ; R600: |{{(PV|T[0-9])\.[XYZW]}}|
83 ; R600: |{{(PV|T[0-9])\.[XYZW]}}|
86 ; FIXME: In this case two uses of the constant should be folded
87 ; SI: s_brev_b32 [[SIGNBITK:s[0-9]+]], 1{{$}}
88 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, [[SIGNBITK]]
89 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, [[SIGNBITK]]
90 define amdgpu_kernel void @fneg_fabs_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %in) {
91 %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %in)
92 %fsub = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, %fabs
93 store <2 x float> %fsub, <2 x float> addrspace(1)* %out
97 ; FUNC-LABEL: {{^}}fneg_fabs_v4f32:
98 ; SI: s_brev_b32 [[SIGNBITK:s[0-9]+]], 1{{$}}
99 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, [[SIGNBITK]]
100 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, [[SIGNBITK]]
101 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, [[SIGNBITK]]
102 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, [[SIGNBITK]]
103 define amdgpu_kernel void @fneg_fabs_v4f32(<4 x float> addrspace(1)* %out, <4 x float> %in) {
104 %fabs = call <4 x float> @llvm.fabs.v4f32(<4 x float> %in)
105 %fsub = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %fabs
106 store <4 x float> %fsub, <4 x float> addrspace(1)* %out
110 declare float @fabs(float) readnone
111 declare float @llvm.fabs.f32(float) readnone
112 declare <2 x float> @llvm.fabs.v2f32(<2 x float>) readnone
113 declare <4 x float> @llvm.fabs.v4f32(<4 x float>) readnone