xref: /aosp_15_r20/external/llvm/test/CodeGen/AMDGPU/fract.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN-SAFE -check-prefix=GCN -check-prefix=SI %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck -check-prefix=GCN-SAFE -check-prefix=GCN -check-prefix=CI %s
3*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -check-prefix=GCN-SAFE -check-prefix=GCN -check-prefix=FUNC %s
4*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -verify-machineinstrs -enable-unsafe-fp-math < %s | FileCheck -check-prefix=GCN-UNSAFE -check-prefix=GCN %s
5*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs -enable-unsafe-fp-math < %s | FileCheck -check-prefix=GCN-UNSAFE -check-prefix=GCN %s
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workerdeclare float @llvm.fabs.f32(float) #0
8*9880d681SAndroid Build Coastguard Workerdeclare float @llvm.floor.f32(float) #0
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}fract_f32:
11*9880d681SAndroid Build Coastguard Worker; GCN-SAFE: v_floor_f32_e32 [[FLR:v[0-9]+]], [[INPUT:v[0-9]+]]
12*9880d681SAndroid Build Coastguard Worker; GCN-SAFE: v_subrev_f32_e32 [[RESULT:v[0-9]+]], [[FLR]], [[INPUT]]
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE: v_fract_f32_e32 [[RESULT:v[0-9]+]], [[INPUT:v[0-9]+]]
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword [[RESULT]]
17*9880d681SAndroid Build Coastguard Workerdefine void @fract_f32(float addrspace(1)* %out, float addrspace(1)* %src) #1 {
18*9880d681SAndroid Build Coastguard Worker  %x = load float, float addrspace(1)* %src
19*9880d681SAndroid Build Coastguard Worker  %floor.x = call float @llvm.floor.f32(float %x)
20*9880d681SAndroid Build Coastguard Worker  %fract = fsub float %x, %floor.x
21*9880d681SAndroid Build Coastguard Worker  store float %fract, float addrspace(1)* %out
22*9880d681SAndroid Build Coastguard Worker  ret void
23*9880d681SAndroid Build Coastguard Worker}
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}fract_f32_neg:
26*9880d681SAndroid Build Coastguard Worker; GCN-SAFE: v_floor_f32_e64 [[FLR:v[0-9]+]], -[[INPUT:v[0-9]+]]
27*9880d681SAndroid Build Coastguard Worker; GCN-SAFE: v_sub_f32_e64 [[RESULT:v[0-9]+]], -[[INPUT]], [[FLR]]
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE: v_fract_f32_e64 [[RESULT:v[0-9]+]], -[[INPUT:v[0-9]+]]
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword [[RESULT]]
32*9880d681SAndroid Build Coastguard Workerdefine void @fract_f32_neg(float addrspace(1)* %out, float addrspace(1)* %src) #1 {
33*9880d681SAndroid Build Coastguard Worker  %x = load float, float addrspace(1)* %src
34*9880d681SAndroid Build Coastguard Worker  %x.neg = fsub float -0.0, %x
35*9880d681SAndroid Build Coastguard Worker  %floor.x.neg = call float @llvm.floor.f32(float %x.neg)
36*9880d681SAndroid Build Coastguard Worker  %fract = fsub float %x.neg, %floor.x.neg
37*9880d681SAndroid Build Coastguard Worker  store float %fract, float addrspace(1)* %out
38*9880d681SAndroid Build Coastguard Worker  ret void
39*9880d681SAndroid Build Coastguard Worker}
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}fract_f32_neg_abs:
42*9880d681SAndroid Build Coastguard Worker; GCN-SAFE: v_floor_f32_e64 [[FLR:v[0-9]+]], -|[[INPUT:v[0-9]+]]|
43*9880d681SAndroid Build Coastguard Worker; GCN-SAFE: v_sub_f32_e64 [[RESULT:v[0-9]+]], -|[[INPUT]]|, [[FLR]]
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE: v_fract_f32_e64 [[RESULT:v[0-9]+]], -|[[INPUT:v[0-9]+]]|
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker; GCN: buffer_store_dword [[RESULT]]
48*9880d681SAndroid Build Coastguard Workerdefine void @fract_f32_neg_abs(float addrspace(1)* %out, float addrspace(1)* %src) #1 {
49*9880d681SAndroid Build Coastguard Worker  %x = load float, float addrspace(1)* %src
50*9880d681SAndroid Build Coastguard Worker  %abs.x = call float @llvm.fabs.f32(float %x)
51*9880d681SAndroid Build Coastguard Worker  %neg.abs.x = fsub float -0.0, %abs.x
52*9880d681SAndroid Build Coastguard Worker  %floor.neg.abs.x = call float @llvm.floor.f32(float %neg.abs.x)
53*9880d681SAndroid Build Coastguard Worker  %fract = fsub float %neg.abs.x, %floor.neg.abs.x
54*9880d681SAndroid Build Coastguard Worker  store float %fract, float addrspace(1)* %out
55*9880d681SAndroid Build Coastguard Worker  ret void
56*9880d681SAndroid Build Coastguard Worker}
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker; GCN-LABEL: {{^}}multi_use_floor_fract_f32:
59*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE-DAG: v_floor_f32_e32 [[FLOOR:v[0-9]+]], [[INPUT:v[0-9]+]]
60*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE-DAG: v_fract_f32_e32 [[FRACT:v[0-9]+]], [[INPUT:v[0-9]+]]
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE: buffer_store_dword [[FLOOR]]
63*9880d681SAndroid Build Coastguard Worker; GCN-UNSAFE: buffer_store_dword [[FRACT]]
64*9880d681SAndroid Build Coastguard Workerdefine void @multi_use_floor_fract_f32(float addrspace(1)* %out, float addrspace(1)* %src) #1 {
65*9880d681SAndroid Build Coastguard Worker  %x = load float, float addrspace(1)* %src
66*9880d681SAndroid Build Coastguard Worker  %floor.x = call float @llvm.floor.f32(float %x)
67*9880d681SAndroid Build Coastguard Worker  %fract = fsub float %x, %floor.x
68*9880d681SAndroid Build Coastguard Worker  store volatile float %floor.x, float addrspace(1)* %out
69*9880d681SAndroid Build Coastguard Worker  store volatile float %fract, float addrspace(1)* %out
70*9880d681SAndroid Build Coastguard Worker  ret void
71*9880d681SAndroid Build Coastguard Worker}
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind readnone }
74*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind }
75