Skip to content

Commit a5065ab

Browse files
authored
[SYCL] Support LLVM FP intrinsic in llvm-spirv and FE (#2880)
Support LLVM FP intrinsic in llvm-spirv and enable the corresponding builtin in FE. Signed-off-by: gejin <[email protected]>
1 parent ac93d6f commit a5065ab

File tree

3 files changed

+67
-45
lines changed

3 files changed

+67
-45
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,38 +165,14 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
165165
case Builtin::BI__builtin_truncl:
166166
case Builtin::BIlroundl:
167167
case Builtin::BI__builtin_lroundl:
168-
case Builtin::BIcopysign:
169-
case Builtin::BI__builtin_copysign:
170-
case Builtin::BIfloor:
171-
case Builtin::BI__builtin_floor:
172168
case Builtin::BIfmax:
173169
case Builtin::BI__builtin_fmax:
174170
case Builtin::BIfmin:
175171
case Builtin::BI__builtin_fmin:
176-
case Builtin::BInearbyint:
177-
case Builtin::BI__builtin_nearbyint:
178-
case Builtin::BIrint:
179-
case Builtin::BI__builtin_rint:
180-
case Builtin::BIround:
181-
case Builtin::BI__builtin_round:
182-
case Builtin::BItrunc:
183-
case Builtin::BI__builtin_trunc:
184-
case Builtin::BIcopysignf:
185-
case Builtin::BI__builtin_copysignf:
186-
case Builtin::BIfloorf:
187-
case Builtin::BI__builtin_floorf:
188172
case Builtin::BIfmaxf:
189173
case Builtin::BI__builtin_fmaxf:
190174
case Builtin::BIfminf:
191175
case Builtin::BI__builtin_fminf:
192-
case Builtin::BInearbyintf:
193-
case Builtin::BI__builtin_nearbyintf:
194-
case Builtin::BIrintf:
195-
case Builtin::BI__builtin_rintf:
196-
case Builtin::BIroundf:
197-
case Builtin::BI__builtin_roundf:
198-
case Builtin::BItruncf:
199-
case Builtin::BI__builtin_truncf:
200176
case Builtin::BIlroundf:
201177
case Builtin::BI__builtin_lroundf:
202178
case Builtin::BI__builtin_fpclassify:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-strict -verify %s
2+
extern "C" float sinf(float);
3+
extern "C" float cosf(float);
4+
extern "C" float floorf(float);
5+
extern "C" float logf(float);
6+
extern "C" float nearbyintf(float);
7+
extern "C" float rintf(float);
8+
extern "C" float roundf(float);
9+
extern "C" float truncf(float);
10+
extern "C" float copysignf(float, float);
11+
extern "C" double sin(double);
12+
extern "C" double cos(double);
13+
extern "C" double floor(double);
14+
extern "C" double log(double);
15+
extern "C" double nearbyint(double);
16+
extern "C" double rint(double);
17+
extern "C" double round(double);
18+
extern "C" double trunc(double);
19+
extern "C" double copysign(double, double);
20+
template <typename name, typename Func>
21+
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
22+
kernelFunc();
23+
}
24+
25+
int main() {
26+
kernel<class kernel_function>([=]() {
27+
int acc[1] = {5};
28+
acc[0] *= 2;
29+
acc[0] += (int)truncf(1.0f); // expected-no-diagnostics
30+
acc[0] += (int)trunc(1.0); // expected-no-diagnostics
31+
acc[0] += (int)roundf(1.0f); // expected-no-diagnostics
32+
acc[0] += (int)round(1.0); // expected-no-diagnostics
33+
acc[0] += (int)rintf(1.0f); // expected-no-diagnostics
34+
acc[0] += (int)rint(1.0); // expected-no-diagnostics
35+
acc[0] += (int)nearbyintf(0.5f); // expected-no-diagnostics
36+
acc[0] += (int)nearbyint(0.5); // expected-no-diagnostics
37+
acc[0] += (int)floorf(0.5f); // expected-no-diagnostics
38+
acc[0] += (int)floor(0.5); // expected-no-diagnostics
39+
acc[0] += (int)copysignf(1.0f, -0.5f); // expected-no-diagnostics
40+
acc[0] += (int)copysign(1.0, -0.5); // expected-no-diagnostics
41+
acc[0] += (int)sinf(1.0f); // expected-no-diagnostics
42+
acc[0] += (int)sin(1.0); // expected-no-diagnostics
43+
acc[0] += (int)__builtin_sinf(1.0f); // expected-no-diagnostics
44+
acc[0] += (int)__builtin_sin(1.0); // expected-no-diagnostics
45+
acc[0] += (int)cosf(1.0f); // expected-no-diagnostics
46+
acc[0] += (int)cos(1.0); // expected-no-diagnostics
47+
acc[0] += (int)__builtin_cosf(1.0f); // expected-no-diagnostics
48+
acc[0] += (int)__builtin_cos(1.0); // expected-no-diagnostics
49+
acc[0] += (int)logf(1.0f); // expected-no-diagnostics
50+
acc[0] += (int)log(1.0); // expected-no-diagnostics
51+
acc[0] += (int)__builtin_truncf(1.0f); // expected-no-diagnostics
52+
acc[0] += (int)__builtin_trunc(1.0); // expected-no-diagnostics
53+
acc[0] += (int)__builtin_rintf(1.0f); // expected-no-diagnostics
54+
acc[0] += (int)__builtin_rint(1.0); // expected-no-diagnostics
55+
acc[0] += (int)__builtin_nearbyintf(0.5f); // expected-no-diagnostics
56+
acc[0] += (int)__builtin_nearbyint(0.5); // expected-no-diagnostics
57+
acc[0] += (int)__builtin_floorf(0.5f); // expected-no-diagnostics
58+
acc[0] += (int)__builtin_floor(0.5); // expected-no-diagnostics
59+
acc[0] += (int)__builtin_copysignf(1.0f, -0.5f); // expected-no-diagnostics
60+
acc[0] += (int)__builtin_logf(1.0f); // expected-no-diagnostics
61+
acc[0] += (int)__builtin_log(1.0); // expected-no-diagnostics
62+
});
63+
return 0;
64+
}
Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s
2-
extern "C" float sinf(float);
3-
extern "C" float cosf(float);
4-
extern "C" float logf(float);
5-
extern "C" double sin(double);
6-
extern "C" double cos(double);
7-
extern "C" double log(double);
82
template <typename name, typename Func>
93
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
104
kernelFunc();
@@ -14,21 +8,9 @@ int main() {
148
kernel<class kernel_function>([=]() {
159
int acc[1] = {5};
1610
acc[0] *= 2;
17-
acc[0] += (int)sinf(1.0f); // expected-no-error
18-
acc[0] += (int)sin(1.0); // expected-no-error
19-
acc[0] += (int)__builtin_sinf(1.0f); // expected-no-error
20-
acc[0] += (int)__builtin_sin(1.0); // expected-no-error
21-
acc[0] += (int)cosf(1.0f); // expected-no-error
22-
acc[0] += (int)cos(1.0); // expected-no-error
23-
acc[0] += (int)__builtin_cosf(1.0f); // expected-no-error
24-
acc[0] += (int)__builtin_cos(1.0); // expected-no-error
25-
acc[0] += (int)logf(1.0f); // expected-no-error
26-
acc[0] += (int)log(1.0); // expected-no-error
27-
acc[0] += (int)__builtin_logf(1.0f); // expected-no-error
28-
acc[0] += (int)__builtin_log(1.0); // expected-no-error
29-
acc[0] += (int)__builtin_fabsl(-1.0); // expected-error{{builtin is not supported on this target}}
30-
acc[0] += (int)__builtin_cosl(-1.0); // expected-error{{builtin is not supported on this target}}
31-
acc[0] += (int)__builtin_powl(-1.0, 10.0); // expected-error{{builtin is not supported on this target}}
11+
acc[0] += (int)__builtin_fabsl(-1.0); // expected-error{{builtin is not supported on this target}}
12+
acc[0] += (int)__builtin_cosl(-1.0); // expected-error{{builtin is not supported on this target}}
13+
acc[0] += (int)__builtin_powl(-1.0, 10.0); // expected-error{{builtin is not supported on this target}}
3214
});
3315
return 0;
3416
}

0 commit comments

Comments
 (0)