Debian Codegraph @

clang/test/Headers/__clang_hip_cmath.hip

raw
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2 // REQUIRES: amdgpu-registered-target
3
4 // RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
5 // RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
6 // RUN: -internal-isystem %S/Inputs/include \
7 // RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
8 // RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -O1 -o - \
9 // RUN: -D__HIPCC_RTC__ | FileCheck -check-prefixes=DEFAULT,CORRECT-DIV-SQRT %s
10
11 // Check that we end up with fast math flags set on intrinsic calls
12 // RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
13 // RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
14 // RUN: -internal-isystem %S/Inputs/include \
15 // RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
16 // RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -O1 -menable-no-infs \
17 // RUN: -menable-no-nans -o - \
18 // RUN: -D__HIPCC_RTC__ | FileCheck -check-prefix=FINITEONLY %s
19
20 // Check that we end up with fpmath metadata set on sqrt calls
21 // RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
22 // RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
23 // RUN: -internal-isystem %S/Inputs/include \
24 // RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
25 // RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -O1 \
26 // RUN: -fno-hip-fp32-correctly-rounded-divide-sqrt -o - \
27 // RUN: -D__HIPCC_RTC__ | FileCheck -check-prefixes=DEFAULT,NO-CORRECT-DIV-SQRT %s
28
29 // DEFAULT-LABEL: @test_fma_f16(
30 // DEFAULT-NEXT: entry:
31 // DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract noundef half @llvm.fma.f16(half [[X:%.*]], half [[Y:%.*]], half [[Z:%.*]])
32 // DEFAULT-NEXT: ret half [[TMP0]]
33 //
34 // FINITEONLY-LABEL: @test_fma_f16(
35 // FINITEONLY-NEXT: entry:
36 // FINITEONLY-NEXT: [[TMP0:%.*]] = tail call nnan ninf contract noundef half @llvm.fma.f16(half nofpclass(nan inf) [[X:%.*]], half nofpclass(nan inf) [[Y:%.*]], half nofpclass(nan inf) [[Z:%.*]])
37 // FINITEONLY-NEXT: ret half [[TMP0]]
38 //
39 extern "C" __device__ _Float16 test_fma_f16(_Float16 x, _Float16 y,
40 _Float16 z) {
41 return fma(x, y, z);
42 }
43
44 // DEFAULT-LABEL: @test_pow_f16(
45 // DEFAULT-NEXT: entry:
46 // DEFAULT-NEXT: [[CALL_I:%.*]] = tail call contract noundef half @__ocml_pown_f16(half noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR9:[0-9]+]]
47 // DEFAULT-NEXT: ret half [[CALL_I]]
48 //
49 // FINITEONLY-LABEL: @test_pow_f16(
50 // FINITEONLY-NEXT: entry:
51 // FINITEONLY-NEXT: [[CALL_I:%.*]] = tail call nnan ninf contract noundef nofpclass(nan inf) half @__ocml_pown_f16(half noundef nofpclass(nan inf) [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR9:[0-9]+]]
52 // FINITEONLY-NEXT: ret half [[CALL_I]]
53 //
54 extern "C" __device__ _Float16 test_pow_f16(_Float16 x, int y) {
55 return pow(x, y);
56 }
57
58 // DEFAULT-LABEL: @test_fabs_f32(
59 // DEFAULT-NEXT: entry:
60 // DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract noundef float @llvm.fabs.f32(float [[X:%.*]])
61 // DEFAULT-NEXT: ret float [[TMP0]]
62 //
63 // FINITEONLY-LABEL: @test_fabs_f32(
64 // FINITEONLY-NEXT: entry:
65 // FINITEONLY-NEXT: [[TMP0:%.*]] = tail call nnan ninf contract noundef float @llvm.fabs.f32(float nofpclass(nan inf) [[X:%.*]])
66 // FINITEONLY-NEXT: ret float [[TMP0]]
67 //
68 extern "C" __device__ float test_fabs_f32(float x) {
69 return fabs(x);
70 }
71
72 // DEFAULT-LABEL: @test_sin_f32(
73 // DEFAULT-NEXT: entry:
74 // DEFAULT-NEXT: [[CALL_I1:%.*]] = tail call contract noundef float @__ocml_sin_f32(float noundef [[X:%.*]]) #[[ATTR10:[0-9]+]]
75 // DEFAULT-NEXT: ret float [[CALL_I1]]
76 //
77 // FINITEONLY-LABEL: @test_sin_f32(
78 // FINITEONLY-NEXT: entry:
79 // FINITEONLY-NEXT: [[CALL_I1:%.*]] = tail call nnan ninf contract noundef nofpclass(nan inf) float @__ocml_sin_f32(float noundef nofpclass(nan inf) [[X:%.*]]) #[[ATTR10:[0-9]+]]
80 // FINITEONLY-NEXT: ret float [[CALL_I1]]
81 //
82 extern "C" __device__ float test_sin_f32(float x) {
83 return sin(x);
84 }
85
86 // DEFAULT-LABEL: @test_cos_f32(
87 // DEFAULT-NEXT: entry:
88 // DEFAULT-NEXT: [[CALL_I1:%.*]] = tail call contract noundef float @__ocml_cos_f32(float noundef [[X:%.*]]) #[[ATTR10]]
89 // DEFAULT-NEXT: ret float [[CALL_I1]]
90 //
91 // FINITEONLY-LABEL: @test_cos_f32(
92 // FINITEONLY-NEXT: entry:
93 // FINITEONLY-NEXT: [[CALL_I1:%.*]] = tail call nnan ninf contract noundef nofpclass(nan inf) float @__ocml_cos_f32(float noundef nofpclass(nan inf) [[X:%.*]]) #[[ATTR10]]
94 // FINITEONLY-NEXT: ret float [[CALL_I1]]
95 //
96 extern "C" __device__ float test_cos_f32(float x) {
97 return cos(x);
98 }
99
100 // Check user defined type which can be converted to float and double but not
101 // specializes __numeric_type will not cause ambiguity diagnostics.
102 struct user_bfloat16 {
103 __host__ __device__ user_bfloat16(float);
104 operator float();
105 operator double();
106 };
107
108 namespace user_namespace {
109 // DEFAULT-LABEL: @_ZN14user_namespace3fmaE13user_bfloat16S0_S0_(
110 // DEFAULT-NEXT: entry:
111 // DEFAULT-NEXT: ret void
112 //
113 // FINITEONLY-LABEL: @_ZN14user_namespace3fmaE13user_bfloat16S0_S0_(
114 // FINITEONLY-NEXT: entry:
115 // FINITEONLY-NEXT: ret void
116 //
117 __device__ user_bfloat16 fma(const user_bfloat16 a, const user_bfloat16 b, const user_bfloat16 c) {
118 return a;
119 }
120
121 // DEFAULT-LABEL: @_ZN14user_namespace8test_fmaEv(
122 // DEFAULT-NEXT: entry:
123 // DEFAULT-NEXT: [[A:%.*]] = alloca [[STRUCT_USER_BFLOAT16:%.*]], align 1, addrspace(5)
124 // DEFAULT-NEXT: [[B:%.*]] = alloca [[STRUCT_USER_BFLOAT16]], align 1, addrspace(5)
125 // DEFAULT-NEXT: [[A_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A]] to ptr
126 // DEFAULT-NEXT: [[B_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[B]] to ptr
127 // DEFAULT-NEXT: call void @llvm.lifetime.start.p5(ptr addrspace(5) [[A]]) #[[ATTR11:[0-9]+]]
128 // DEFAULT-NEXT: call void @_ZN13user_bfloat16C1Ef(ptr noundef nonnull align 1 dereferenceable(1) [[A_ASCAST]], float noundef 1.000000e+00) #[[ATTR10]]
129 // DEFAULT-NEXT: call void @llvm.lifetime.start.p5(ptr addrspace(5) [[B]]) #[[ATTR11]]
130 // DEFAULT-NEXT: call void @_ZN13user_bfloat16C1Ef(ptr noundef nonnull align 1 dereferenceable(1) [[B_ASCAST]], float noundef 2.000000e+00) #[[ATTR10]]
131 // DEFAULT-NEXT: call void @llvm.lifetime.end.p5(ptr addrspace(5) [[B]]) #[[ATTR11]]
132 // DEFAULT-NEXT: call void @llvm.lifetime.end.p5(ptr addrspace(5) [[A]]) #[[ATTR11]]
133 // DEFAULT-NEXT: ret void
134 //
135 // FINITEONLY-LABEL: @_ZN14user_namespace8test_fmaEv(
136 // FINITEONLY-NEXT: entry:
137 // FINITEONLY-NEXT: [[A:%.*]] = alloca [[STRUCT_USER_BFLOAT16:%.*]], align 1, addrspace(5)
138 // FINITEONLY-NEXT: [[B:%.*]] = alloca [[STRUCT_USER_BFLOAT16]], align 1, addrspace(5)
139 // FINITEONLY-NEXT: [[A_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A]] to ptr
140 // FINITEONLY-NEXT: [[B_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[B]] to ptr
141 // FINITEONLY-NEXT: call void @llvm.lifetime.start.p5(ptr addrspace(5) [[A]]) #[[ATTR11:[0-9]+]]
142 // FINITEONLY-NEXT: call void @_ZN13user_bfloat16C1Ef(ptr noundef nonnull align 1 dereferenceable(1) [[A_ASCAST]], float noundef nofpclass(nan inf) 1.000000e+00) #[[ATTR10]]
143 // FINITEONLY-NEXT: call void @llvm.lifetime.start.p5(ptr addrspace(5) [[B]]) #[[ATTR11]]
144 // FINITEONLY-NEXT: call void @_ZN13user_bfloat16C1Ef(ptr noundef nonnull align 1 dereferenceable(1) [[B_ASCAST]], float noundef nofpclass(nan inf) 2.000000e+00) #[[ATTR10]]
145 // FINITEONLY-NEXT: call void @llvm.lifetime.end.p5(ptr addrspace(5) [[B]]) #[[ATTR11]]
146 // FINITEONLY-NEXT: call void @llvm.lifetime.end.p5(ptr addrspace(5) [[A]]) #[[ATTR11]]
147 // FINITEONLY-NEXT: ret void
148 //
149 __global__ void test_fma() {
150 user_bfloat16 a = 1.0f, b = 2.0f;
151 fma(a, b, b);
152 }
153 }
154
155 // CORRECT-DIV-SQRT-LABEL: @test_sqrt_f32(
156 // CORRECT-DIV-SQRT-NEXT: entry:
157 // CORRECT-DIV-SQRT-NEXT: [[TMP0:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[X:%.*]])
158 // CORRECT-DIV-SQRT-NEXT: ret float [[TMP0]]
159 //
160 // FINITEONLY-LABEL: @test_sqrt_f32(
161 // FINITEONLY-NEXT: entry:
162 // FINITEONLY-NEXT: [[TMP0:%.*]] = tail call nnan ninf contract noundef float @llvm.sqrt.f32(float nofpclass(nan inf) [[X:%.*]])
163 // FINITEONLY-NEXT: ret float [[TMP0]]
164 //
165 // NO-CORRECT-DIV-SQRT-LABEL: @test_sqrt_f32(
166 // NO-CORRECT-DIV-SQRT-NEXT: entry:
167 // NO-CORRECT-DIV-SQRT-NEXT: [[TMP0:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[X:%.*]]), !fpmath [[META4:![0-9]+]]
168 // NO-CORRECT-DIV-SQRT-NEXT: ret float [[TMP0]]
169 //
170 extern "C" __device__ float test_sqrt_f32(float x) {
171 return sqrt(x);
172 }
173
174 // DEFAULT-LABEL: @test_sqrt_f64(
175 // DEFAULT-NEXT: entry:
176 // DEFAULT-NEXT: [[TMP0:%.*]] = tail call contract noundef double @llvm.sqrt.f64(double [[X:%.*]])
177 // DEFAULT-NEXT: ret double [[TMP0]]
178 //
179 // FINITEONLY-LABEL: @test_sqrt_f64(
180 // FINITEONLY-NEXT: entry:
181 // FINITEONLY-NEXT: [[TMP0:%.*]] = tail call nnan ninf contract noundef double @llvm.sqrt.f64(double nofpclass(nan inf) [[X:%.*]])
182 // FINITEONLY-NEXT: ret double [[TMP0]]
183 //
184 extern "C" __device__ double test_sqrt_f64(double x) {
185 return sqrt(x);
186 }