1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -verify-machineinstrs < %s | FileCheck -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=SI -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]+}}, {{v[0-9]+}}, |{{s[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]+}}, {{v[0-9]+}}, -|{{s[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 define amdgpu_kernel void @fneg_fabs_free_f32(float addrspace(1)* %out, i32 %in) {
39 %bc = bitcast i32 %in to float
40 %fabs = call float @llvm.fabs.f32(float %bc)
41 %fsub = fsub float -0.000000e+00, %fabs
42 store float %fsub, float addrspace(1)* %out
46 ; FUNC-LABEL: {{^}}fneg_fabs_fn_free_f32:
48 ; R600: |PV.{{[XYZW]}}|
51 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, 0x80000000
52 define amdgpu_kernel void @fneg_fabs_fn_free_f32(float addrspace(1)* %out, i32 %in) {
53 %bc = bitcast i32 %in to float
54 %fabs = call float @fabs(float %bc)
55 %fsub = fsub float -0.000000e+00, %fabs
56 store float %fsub, float addrspace(1)* %out
60 ; FUNC-LABEL: {{^}}fneg_fabs_f32:
61 ; SI: s_or_b32 s{{[0-9]+}}, s{{[0-9]+}}, 0x80000000
62 define amdgpu_kernel void @fneg_fabs_f32(float addrspace(1)* %out, float %in) {
63 %fabs = call float @llvm.fabs.f32(float %in)
64 %fsub = fsub float -0.000000e+00, %fabs
65 store float %fsub, float addrspace(1)* %out, align 4
69 ; FUNC-LABEL: {{^}}v_fneg_fabs_f32:
70 ; SI: v_or_b32_e32 v{{[0-9]+}}, 0x80000000, v{{[0-9]+}}
71 define amdgpu_kernel void @v_fneg_fabs_f32(float addrspace(1)* %out, float addrspace(1)* %in) {
72 %val = load float, float addrspace(1)* %in, align 4
73 %fabs = call float @llvm.fabs.f32(float %val)
74 %fsub = fsub float -0.000000e+00, %fabs
75 store float %fsub, float addrspace(1)* %out, align 4
79 ; FUNC-LABEL: {{^}}fneg_fabs_v2f32:
80 ; R600: |{{(PV|T[0-9])\.[XYZW]}}|
82 ; R600: |{{(PV|T[0-9])\.[XYZW]}}|
85 ; FIXME: In this case two uses of the constant should be folded
86 ; SI: s_brev_b32 [[SIGNBITK:s[0-9]+]], 1{{$}}
87 ; SI: v_or_b32_e32 v{{[0-9]+}}, [[SIGNBITK]], v{{[0-9]+}}
88 ; SI: v_or_b32_e32 v{{[0-9]+}}, [[SIGNBITK]], v{{[0-9]+}}
89 define amdgpu_kernel void @fneg_fabs_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %in) {
90 %fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %in)
91 %fsub = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, %fabs
92 store <2 x float> %fsub, <2 x float> addrspace(1)* %out
96 ; FUNC-LABEL: {{^}}fneg_fabs_v4f32:
97 ; SI: s_brev_b32 [[SIGNBITK:s[0-9]+]], 1{{$}}
98 ; SI: v_or_b32_e32 v{{[0-9]+}}, [[SIGNBITK]], v{{[0-9]+}}
99 ; SI: v_or_b32_e32 v{{[0-9]+}}, [[SIGNBITK]], v{{[0-9]+}}
100 ; SI: v_or_b32_e32 v{{[0-9]+}}, [[SIGNBITK]], v{{[0-9]+}}
101 ; SI: v_or_b32_e32 v{{[0-9]+}}, [[SIGNBITK]], v{{[0-9]+}}
102 define amdgpu_kernel void @fneg_fabs_v4f32(<4 x float> addrspace(1)* %out, <4 x float> %in) {
103 %fabs = call <4 x float> @llvm.fabs.v4f32(<4 x float> %in)
104 %fsub = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, %fabs
105 store <4 x float> %fsub, <4 x float> addrspace(1)* %out
109 declare float @fabs(float) readnone
110 declare float @llvm.fabs.f32(float) readnone
111 declare <2 x float> @llvm.fabs.v2f32(<2 x float>) readnone
112 declare <4 x float> @llvm.fabs.v4f32(<4 x float>) readnone