Skip to content

Commit 9d84f8d

Browse files
committed
clang: Add __builtin_elementwise_rint and nearbyint
These are basically the same thing and only differ for strictfp, so add both for future proofing. Note all the elementwise functions are currently broken for strictfp, and use non-constrained ops. Add a test that demonstrates this, but doesn't attempt to fix it.
1 parent abe34ce commit 9d84f8d

9 files changed

+344
-2
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,19 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in
651651
exceptions.
652652
T __builtin_elementwise_trunc(T x) return the integral value nearest to but no larger in floating point types
653653
magnitude than x
654+
655+
T __builtin_elementwise_nearbyint(T x) round x to the nearest integer value in floating point format, floating point types
656+
rounding according to the current rounding direction.
657+
May not raise the inexact floating-point exception. This is
658+
treated the same as ``__builtin_elementwise_rint`` unless
659+
:ref:`FENV_ACCESS is enabled <floating-point-environment>`.
660+
661+
T __builtin_elementwise_rint(T x) round x to the nearest integer value in floating point format, floating point types
662+
rounding according to the current rounding
663+
direction. May raise floating-point exceptions. This is treated
664+
the same as ``__builtin_elementwise_nearbyint`` unless
665+
:ref:`FENV_ACCESS is enabled <floating-point-environment>`.
666+
654667
T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types
655668
of a floating-point number
656669
T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y. floating point types

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ Non-comprehensive list of changes in this release
231231
- Added ``__builtin_elementwise_round`` for builtin for floating
232232
point types. This allows access to ``llvm.round`` for
233233
arbitrary floating-point and vector of floating-point types.
234-
234+
- Added ``__builtin_elementwise_rint`` for floating point types. This
235+
allows access to ``llvm.rint`` for arbitrary floating-point and
236+
vector of floating-point types.
237+
- Added ``__builtin_elementwise_nearbyint`` for floating point
238+
types. This allows access to ``llvm.nearbyint`` for arbitrary
239+
floating-point and vector of floating-point types.
235240

236241
New Compiler Flags
237242
------------------

clang/include/clang/Basic/Builtins.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ BUILTIN(__builtin_elementwise_log2, "v.", "nct")
688688
BUILTIN(__builtin_elementwise_log10, "v.", "nct")
689689
BUILTIN(__builtin_elementwise_roundeven, "v.", "nct")
690690
BUILTIN(__builtin_elementwise_round, "v.", "nct")
691+
BUILTIN(__builtin_elementwise_rint, "v.", "nct")
692+
BUILTIN(__builtin_elementwise_nearbyint, "v.", "nct")
691693
BUILTIN(__builtin_elementwise_sin, "v.", "nct")
692694
BUILTIN(__builtin_elementwise_trunc, "v.", "nct")
693695
BUILTIN(__builtin_elementwise_canonicalize, "v.", "nct")

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
31973197
case Builtin::BI__builtin_elementwise_round:
31983198
return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::round,
31993199
"elt.round"));
3200+
case Builtin::BI__builtin_elementwise_rint:
3201+
return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::rint,
3202+
"elt.rint"));
3203+
case Builtin::BI__builtin_elementwise_nearbyint:
3204+
return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::nearbyint,
3205+
"elt.nearbyint"));
32003206
case Builtin::BI__builtin_elementwise_sin:
32013207
return RValue::get(
32023208
emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
26372637
case Builtin::BI__builtin_elementwise_log10:
26382638
case Builtin::BI__builtin_elementwise_roundeven:
26392639
case Builtin::BI__builtin_elementwise_round:
2640+
case Builtin::BI__builtin_elementwise_rint:
2641+
case Builtin::BI__builtin_elementwise_nearbyint:
26402642
case Builtin::BI__builtin_elementwise_sin:
26412643
case Builtin::BI__builtin_elementwise_trunc:
26422644
case Builtin::BI__builtin_elementwise_canonicalize: {

clang/test/CodeGen/builtins-elementwise-math.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,38 @@ void test_builtin_elementwise_round(float f1, float f2, double d1, double d2,
484484
vf2 = __builtin_elementwise_round(vf1);
485485
}
486486

487+
void test_builtin_elementwise_rint(float f1, float f2, double d1, double d2,
488+
float4 vf1, float4 vf2) {
489+
// CHECK-LABEL: define void @test_builtin_elementwise_rint(
490+
// CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
491+
// CHECK-NEXT: call float @llvm.rint.f32(float [[F1]])
492+
f2 = __builtin_elementwise_rint(f1);
493+
494+
// CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
495+
// CHECK-NEXT: call double @llvm.rint.f64(double [[D1]])
496+
d2 = __builtin_elementwise_rint(d1);
497+
498+
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
499+
// CHECK-NEXT: call <4 x float> @llvm.rint.v4f32(<4 x float> [[VF1]])
500+
vf2 = __builtin_elementwise_rint(vf1);
501+
}
502+
503+
void test_builtin_elementwise_nearbyint(float f1, float f2, double d1, double d2,
504+
float4 vf1, float4 vf2) {
505+
// CHECK-LABEL: define void @test_builtin_elementwise_nearbyint(
506+
// CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
507+
// CHECK-NEXT: call float @llvm.nearbyint.f32(float [[F1]])
508+
f2 = __builtin_elementwise_nearbyint(f1);
509+
510+
// CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
511+
// CHECK-NEXT: call double @llvm.nearbyint.f64(double [[D1]])
512+
d2 = __builtin_elementwise_nearbyint(d1);
513+
514+
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
515+
// CHECK-NEXT: call <4 x float> @llvm.nearbyint.v4f32(<4 x float> [[VF1]])
516+
vf2 = __builtin_elementwise_nearbyint(vf1);
517+
}
518+
487519
void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2,
488520
float4 vf1, float4 vf2) {
489521
// CHECK-LABEL: define void @test_builtin_elementwise_sin(
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
2+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -frounding-math -ffp-exception-behavior=strict -O2 -emit-llvm -o - %s | FileCheck %s
3+
4+
// FIXME: This demonstrates elementwise builtins are broken for strictfp and
5+
// produce unconstrained intrinsics
6+
7+
typedef float float4 __attribute__((ext_vector_type(4)));
8+
9+
// Sanity check we're getting constrained ops for a non-builtin.
10+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z11strict_faddDv4_fS_
11+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
12+
// CHECK-NEXT: entry:
13+
// CHECK-NEXT: [[ADD:%.*]] = tail call <4 x float> @llvm.experimental.constrained.fadd.v4f32(<4 x float> [[A]], <4 x float> [[B]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4:[0-9]+]]
14+
// CHECK-NEXT: ret <4 x float> [[ADD]]
15+
//
16+
float4 strict_fadd(float4 a, float4 b) {
17+
return a + b;
18+
}
19+
20+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_absDv4_f
21+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
22+
// CHECK-NEXT: entry:
23+
// CHECK-NEXT: [[ELT_ABS:%.*]] = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> [[A]]) #[[ATTR4]]
24+
// CHECK-NEXT: ret <4 x float> [[ELT_ABS]]
25+
//
26+
float4 strict_elementwise_abs(float4 a) {
27+
return __builtin_elementwise_abs(a);
28+
}
29+
30+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_maxDv4_fS_
31+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
32+
// CHECK-NEXT: entry:
33+
// CHECK-NEXT: [[ELT_MAX:%.*]] = tail call <4 x float> @llvm.maxnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
34+
// CHECK-NEXT: ret <4 x float> [[ELT_MAX]]
35+
//
36+
float4 strict_elementwise_max(float4 a, float4 b) {
37+
return __builtin_elementwise_max(a, b);
38+
}
39+
40+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_minDv4_fS_
41+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
42+
// CHECK-NEXT: entry:
43+
// CHECK-NEXT: [[ELT_MIN:%.*]] = tail call <4 x float> @llvm.minnum.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
44+
// CHECK-NEXT: ret <4 x float> [[ELT_MIN]]
45+
//
46+
float4 strict_elementwise_min(float4 a, float4 b) {
47+
return __builtin_elementwise_min(a, b);
48+
}
49+
50+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_ceilDv4_f
51+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
52+
// CHECK-NEXT: entry:
53+
// CHECK-NEXT: [[ELT_CEIL:%.*]] = tail call <4 x float> @llvm.ceil.v4f32(<4 x float> [[A]]) #[[ATTR4]]
54+
// CHECK-NEXT: ret <4 x float> [[ELT_CEIL]]
55+
//
56+
float4 strict_elementwise_ceil(float4 a) {
57+
return __builtin_elementwise_ceil(a);
58+
}
59+
60+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_cosDv4_f
61+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
62+
// CHECK-NEXT: entry:
63+
// CHECK-NEXT: [[ELT_COS:%.*]] = tail call <4 x float> @llvm.cos.v4f32(<4 x float> [[A]]) #[[ATTR4]]
64+
// CHECK-NEXT: ret <4 x float> [[ELT_COS]]
65+
//
66+
float4 strict_elementwise_cos(float4 a) {
67+
return __builtin_elementwise_cos(a);
68+
}
69+
70+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_expDv4_f
71+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
72+
// CHECK-NEXT: entry:
73+
// CHECK-NEXT: [[ELT_EXP:%.*]] = tail call <4 x float> @llvm.exp.v4f32(<4 x float> [[A]]) #[[ATTR4]]
74+
// CHECK-NEXT: ret <4 x float> [[ELT_EXP]]
75+
//
76+
float4 strict_elementwise_exp(float4 a) {
77+
return __builtin_elementwise_exp(a);
78+
}
79+
80+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_exp2Dv4_f
81+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
82+
// CHECK-NEXT: entry:
83+
// CHECK-NEXT: [[ELT_EXP2:%.*]] = tail call <4 x float> @llvm.exp2.v4f32(<4 x float> [[A]]) #[[ATTR4]]
84+
// CHECK-NEXT: ret <4 x float> [[ELT_EXP2]]
85+
//
86+
float4 strict_elementwise_exp2(float4 a) {
87+
return __builtin_elementwise_exp2(a);
88+
}
89+
90+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_floorDv4_f
91+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
92+
// CHECK-NEXT: entry:
93+
// CHECK-NEXT: [[ELT_FLOOR:%.*]] = tail call <4 x float> @llvm.floor.v4f32(<4 x float> [[A]]) #[[ATTR4]]
94+
// CHECK-NEXT: ret <4 x float> [[ELT_FLOOR]]
95+
//
96+
float4 strict_elementwise_floor(float4 a) {
97+
return __builtin_elementwise_floor(a);
98+
}
99+
100+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_logDv4_f
101+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
102+
// CHECK-NEXT: entry:
103+
// CHECK-NEXT: [[ELT_LOG:%.*]] = tail call <4 x float> @llvm.log.v4f32(<4 x float> [[A]]) #[[ATTR4]]
104+
// CHECK-NEXT: ret <4 x float> [[ELT_LOG]]
105+
//
106+
float4 strict_elementwise_log(float4 a) {
107+
return __builtin_elementwise_log(a);
108+
}
109+
110+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_log2Dv4_f
111+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
112+
// CHECK-NEXT: entry:
113+
// CHECK-NEXT: [[ELT_LOG2:%.*]] = tail call <4 x float> @llvm.log2.v4f32(<4 x float> [[A]]) #[[ATTR4]]
114+
// CHECK-NEXT: ret <4 x float> [[ELT_LOG2]]
115+
//
116+
float4 strict_elementwise_log2(float4 a) {
117+
return __builtin_elementwise_log2(a);
118+
}
119+
120+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_log10Dv4_f
121+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
122+
// CHECK-NEXT: entry:
123+
// CHECK-NEXT: [[ELT_LOG2:%.*]] = tail call <4 x float> @llvm.log2.v4f32(<4 x float> [[A]]) #[[ATTR4]]
124+
// CHECK-NEXT: ret <4 x float> [[ELT_LOG2]]
125+
//
126+
float4 strict_elementwise_log10(float4 a) {
127+
return __builtin_elementwise_log2(a);
128+
}
129+
130+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z28strict_elementwise_roundevenDv4_f
131+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
132+
// CHECK-NEXT: entry:
133+
// CHECK-NEXT: [[ELT_ROUNDEVEN:%.*]] = tail call <4 x float> @llvm.roundeven.v4f32(<4 x float> [[A]]) #[[ATTR4]]
134+
// CHECK-NEXT: ret <4 x float> [[ELT_ROUNDEVEN]]
135+
//
136+
float4 strict_elementwise_roundeven(float4 a) {
137+
return __builtin_elementwise_roundeven(a);
138+
}
139+
140+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_roundDv4_f
141+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
142+
// CHECK-NEXT: entry:
143+
// CHECK-NEXT: [[ELT_ROUND:%.*]] = tail call <4 x float> @llvm.round.v4f32(<4 x float> [[A]]) #[[ATTR4]]
144+
// CHECK-NEXT: ret <4 x float> [[ELT_ROUND]]
145+
//
146+
float4 strict_elementwise_round(float4 a) {
147+
return __builtin_elementwise_round(a);
148+
}
149+
150+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z23strict_elementwise_rintDv4_f
151+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
152+
// CHECK-NEXT: entry:
153+
// CHECK-NEXT: [[ELT_RINT:%.*]] = tail call <4 x float> @llvm.rint.v4f32(<4 x float> [[A]]) #[[ATTR4]]
154+
// CHECK-NEXT: ret <4 x float> [[ELT_RINT]]
155+
//
156+
float4 strict_elementwise_rint(float4 a) {
157+
return __builtin_elementwise_rint(a);
158+
}
159+
160+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z28strict_elementwise_nearbyintDv4_f
161+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
162+
// CHECK-NEXT: entry:
163+
// CHECK-NEXT: [[ELT_NEARBYINT:%.*]] = tail call <4 x float> @llvm.nearbyint.v4f32(<4 x float> [[A]]) #[[ATTR4]]
164+
// CHECK-NEXT: ret <4 x float> [[ELT_NEARBYINT]]
165+
//
166+
float4 strict_elementwise_nearbyint(float4 a) {
167+
return __builtin_elementwise_nearbyint(a);
168+
}
169+
170+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_sinDv4_f
171+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
172+
// CHECK-NEXT: entry:
173+
// CHECK-NEXT: [[ELT_SIN:%.*]] = tail call <4 x float> @llvm.sin.v4f32(<4 x float> [[A]]) #[[ATTR4]]
174+
// CHECK-NEXT: ret <4 x float> [[ELT_SIN]]
175+
//
176+
float4 strict_elementwise_sin(float4 a) {
177+
return __builtin_elementwise_sin(a);
178+
}
179+
180+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_truncDv4_f
181+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
182+
// CHECK-NEXT: entry:
183+
// CHECK-NEXT: [[ELT_TRUNC:%.*]] = tail call <4 x float> @llvm.trunc.v4f32(<4 x float> [[A]]) #[[ATTR4]]
184+
// CHECK-NEXT: ret <4 x float> [[ELT_TRUNC]]
185+
//
186+
float4 strict_elementwise_trunc(float4 a) {
187+
return __builtin_elementwise_trunc(a);
188+
}
189+
190+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z31strict_elementwise_canonicalizeDv4_f
191+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
192+
// CHECK-NEXT: entry:
193+
// CHECK-NEXT: [[ELT_CANONICALIZE:%.*]] = tail call <4 x float> @llvm.canonicalize.v4f32(<4 x float> [[A]]) #[[ATTR4]]
194+
// CHECK-NEXT: ret <4 x float> [[ELT_CANONICALIZE]]
195+
//
196+
float4 strict_elementwise_canonicalize(float4 a) {
197+
return __builtin_elementwise_canonicalize(a);
198+
}
199+
200+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z27strict_elementwise_copysignDv4_fS_
201+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) local_unnamed_addr #[[ATTR2]] {
202+
// CHECK-NEXT: entry:
203+
// CHECK-NEXT: [[TMP0:%.*]] = tail call <4 x float> @llvm.copysign.v4f32(<4 x float> [[A]], <4 x float> [[B]]) #[[ATTR4]]
204+
// CHECK-NEXT: ret <4 x float> [[TMP0]]
205+
//
206+
float4 strict_elementwise_copysign(float4 a, float4 b) {
207+
return __builtin_elementwise_copysign(a, b);
208+
}
209+
210+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z22strict_elementwise_fmaDv4_fS_S_
211+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]], <4 x float> noundef [[C:%.*]]) local_unnamed_addr #[[ATTR2]] {
212+
// CHECK-NEXT: entry:
213+
// CHECK-NEXT: [[TMP0:%.*]] = tail call <4 x float> @llvm.fma.v4f32(<4 x float> [[A]], <4 x float> [[B]], <4 x float> [[C]]) #[[ATTR4]]
214+
// CHECK-NEXT: ret <4 x float> [[TMP0]]
215+
//
216+
float4 strict_elementwise_fma(float4 a, float4 b, float4 c) {
217+
return __builtin_elementwise_fma(a, b, c);
218+
}
219+

clang/test/Sema/builtins-elementwise-math.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ void test_builtin_elementwise_roundeven(int i, float f, double d, float4 v, int3
460460
}
461461

462462
void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
463-
464463
struct Foo s = __builtin_elementwise_round(f);
465464
// expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
466465

@@ -485,6 +484,56 @@ void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv,
485484
// expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
486485
}
487486

487+
void test_builtin_elementwise_rint(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
488+
struct Foo s = __builtin_elementwise_rint(f);
489+
// expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
490+
491+
i = __builtin_elementwise_rint();
492+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
493+
494+
i = __builtin_elementwise_rint(i);
495+
// expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
496+
497+
i = __builtin_elementwise_rint(f, f);
498+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
499+
500+
u = __builtin_elementwise_rint(u);
501+
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
502+
503+
uv = __builtin_elementwise_rint(uv);
504+
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
505+
506+
// FIXME: Error should not mention integer
507+
_Complex float c1, c2;
508+
c1 = __builtin_elementwise_rint(c1);
509+
// expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
510+
}
511+
512+
void test_builtin_elementwise_nearbyint(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
513+
struct Foo s = __builtin_elementwise_nearbyint(f);
514+
// expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
515+
516+
i = __builtin_elementwise_nearbyint();
517+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
518+
519+
i = __builtin_elementwise_nearbyint(i);
520+
// expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
521+
522+
i = __builtin_elementwise_nearbyint(f, f);
523+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
524+
525+
u = __builtin_elementwise_nearbyint(u);
526+
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
527+
528+
uv = __builtin_elementwise_nearbyint(uv);
529+
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
530+
531+
// FIXME: Error should not mention integer
532+
_Complex float c1, c2;
533+
c1 = __builtin_elementwise_nearbyint(c1);
534+
// expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
535+
}
536+
488537
void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
489538

490539
struct Foo s = __builtin_elementwise_sin(f);

0 commit comments

Comments
 (0)