Debian Codegraph @

clang/test/Sema/aarch64-incompat-sm-builtin-calls.cpp

raw
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2 // RUN: %clang_cc1 -std=c++23 -triple aarch64-none-linux-gnu -target-feature +sve \
3 // RUN: -target-feature +bf16 -target-feature +sve -target-feature +sme -target-feature +sme2 -target-feature +sve2 -target-feature +neon -Waarch64-sme-attributes -fsyntax-only -verify %s
4
5 // REQUIRES: aarch64-registered-target
6
7 #include "arm_neon.h"
8 #include "arm_sme.h"
9 #include "arm_sve.h"
10
11 int16x8_t incompat_neon_sm(int16x8_t splat) __arm_streaming {
12 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
13 return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, (int8x16_t)splat, 33);
14 }
15
16 __arm_locally_streaming int16x8_t incompat_neon_ls(int16x8_t splat) {
17 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
18 return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, (int8x16_t)splat, 33);
19 }
20
21 int16x8_t incompat_neon_smc(int16x8_t splat) __arm_streaming_compatible {
22 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
23 return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, (int8x16_t)splat, 33);
24 }
25
26 void incompat_sme_smc(svbool_t pg, void const *ptr) __arm_streaming_compatible __arm_inout("za") {
27 // expected-error@+1 {{builtin can only be called from a streaming function}}
28 return __builtin_sme_svld1_hor_za128(0, 0, pg, ptr);
29 }
30
31 float incomp_sve_sm_fadda_sm(void) __arm_streaming {
32 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
33 return svadda(svptrue_b32(), 0, svdup_f32(1));
34 }
35
36 float incomp_sve_sm_fadda_smc(void) __arm_streaming_compatible {
37 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
38 return svadda(svptrue_b32(), 0, svdup_f32(1));
39 }
40
41 svuint32_t incompat_sve_sm(svbool_t pg, svuint32_t a, int16_t b) __arm_streaming {
42 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
43 return __builtin_sve_svld1_gather_u32base_index_u32(pg, a, b);
44 }
45
46 // expected-warning@+2 {{returning a VL-dependent argument from a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
47 // expected-warning@+1 {{passing a VL-dependent argument to a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
48 __arm_locally_streaming svuint32_t incompat_sve_ls(svbool_t pg, svuint32_t a, int64_t b) {
49 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
50 return __builtin_sve_svld1_gather_u32base_index_u32(pg, a, b);
51 }
52
53 svuint32_t incompat_sve_smc(svbool_t pg, svuint32_t a, int64_t b) __arm_streaming_compatible {
54 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
55 return __builtin_sve_svld1_gather_u32base_index_u32(pg, a, b);
56 }
57
58 svuint32_t incompat_sve2_sm(svbool_t pg, svuint32_t a, int64_t b) __arm_streaming {
59 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
60 return __builtin_sve_svldnt1_gather_u32base_index_u32(pg, a, b);
61 }
62
63 // expected-warning@+2 {{returning a VL-dependent argument from a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
64 // expected-warning@+1 {{passing a VL-dependent argument to a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
65 __arm_locally_streaming svuint32_t incompat_sve2_ls(svbool_t pg, svuint32_t a, int64_t b) {
66 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
67 return __builtin_sve_svldnt1_gather_u32base_index_u32(pg, a, b);
68 }
69
70 svuint32_t incompat_sve2_smc(svbool_t pg, svuint32_t a, int64_t b) __arm_streaming_compatible {
71 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
72 return __builtin_sve_svldnt1_gather_u32base_index_u32(pg, a, b);
73 }
74
75 void incompat_sme_sm(svbool_t pn, svbool_t pm, svfloat32_t zn, svfloat32_t zm) __arm_inout("za") {
76 // expected-error@+1 {{builtin can only be called from a streaming function}}
77 svmops_za32_f32_m(0, pn, pm, zn, zm);
78 }
79
80 svfloat64_t streaming_caller_sve(svbool_t pg, svfloat64_t a, float64_t b) __arm_streaming {
81 return svadd_n_f64_m(pg, a, b);
82 }
83
84 // expected-warning@+2 {{returning a VL-dependent argument from a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
85 // expected-warning@+1 {{passing a VL-dependent argument to a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
86 __arm_locally_streaming svfloat64_t locally_streaming_caller_sve(svbool_t pg, svfloat64_t a, float64_t b) {
87 return svadd_n_f64_m(pg, a, b);
88 }
89
90 svfloat64_t streaming_compatible_caller_sve(svbool_t pg, svfloat64_t a, float64_t b) __arm_streaming_compatible {
91 return svadd_n_f64_m(pg, a, b);
92 }
93
94 svint16_t streaming_caller_sve2(svint16_t op1, svint16_t op2) __arm_streaming {
95 return svmul_lane_s16(op1, op2, 0);
96 }
97
98 // expected-warning@+2 {{returning a VL-dependent argument from a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
99 // expected-warning@+1 {{passing a VL-dependent argument to a locally streaming function is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
100 __arm_locally_streaming svint16_t locally_streaming_caller_sve2(svint16_t op1, svint16_t op2) {
101 return svmul_lane_s16(op1, op2, 0);
102 }
103
104 svint16_t streaming_compatible_caller_sve2(svint16_t op1, svint16_t op2) __arm_streaming_compatible {
105 return svmul_lane_s16(op1, op2, 0);
106 }
107
108 svbool_t streaming_caller_ptrue(void) __arm_streaming {
109 return svand_z(svptrue_b16(), svptrue_pat_b16(SV_ALL), svptrue_pat_b16(SV_VL4));
110 }
111
112 svint8_t missing_za(svint8_t zd, svbool_t pg, uint32_t slice_base) __arm_streaming {
113 // expected-warning@+1 {{builtin call is not valid when calling from a function without active ZA state}}
114 return svread_hor_za8_s8_m(zd, pg, 0, slice_base);
115 }
116
117 __arm_new("za")
118 svint8_t new_za(svint8_t zd, svbool_t pg, uint32_t slice_base) __arm_streaming {
119 return svread_hor_za8_s8_m(zd, pg, 0, slice_base);
120 }
121
122 void missing_zt0(void) __arm_streaming {
123 // expected-warning@+1 {{builtin call is not valid when calling from a function without active ZT0 state}}
124 svzero_zt(0);
125 }
126
127 __arm_new("zt0")
128 void new_zt0(void) __arm_streaming { svzero_zt(0); }
129
130 /// C++ lambda tests:
131
132 void use_streaming_builtin_in_lambda(uint32_t slice_base, svbool_t pg, const void *ptr) __arm_streaming __arm_out("za")
133 {
134 [&]{
135 /// The lambda is its own function and does not inherit the SME attributes (so this should error).
136 // expected-error@+1 {{builtin can only be called from a streaming function}}
137 svld1_hor_za64(0, slice_base, pg, ptr);
138 }();
139 }
140
141 void use_streaming_builtin(uint32_t slice_base, svbool_t pg, const void *ptr) __arm_streaming __arm_out("za")
142 {
143 /// Without the lambda the same builtin is okay (as the SME attributes apply).
144 svld1_hor_za64(0, slice_base, pg, ptr);
145 }
146
147 int16x8_t use_neon_builtin_sm(int16x8_t splat) __arm_streaming_compatible {
148 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
149 return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, (int8x16_t)splat, 33);
150 }
151
152 int16x8_t use_neon_builtin_sm_in_lambda(int16x8_t splat) __arm_streaming_compatible {
153 return [&]{
154 /// This should not error (as we switch out of streaming mode to execute the lambda).
155 /// Note: The result int16x8_t is spilled and reloaded as a q-register.
156 return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, (int8x16_t)splat, 33);
157 }();
158 }
159
160 float use_incomp_sve_builtin_sm() __arm_streaming {
161 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
162 return svadda(svptrue_b32(), 0, svdup_f32(1));
163 }
164
165 float incomp_sve_sm_fadda_sm_in_lambda(void) __arm_streaming {
166 return [&]{
167 /// This should work like the Neon builtin.
168 return svadda(svptrue_b32(), 0, svdup_f32(1));
169 }();
170 }
171
172 void use_streaming_builtin_in_streaming_lambda(uint32_t slice_base, const void *ptr)
173 {
174 [&] __arm_new("za") () __arm_streaming {
175 // Here the lambda is streaming with ZA state, so this is okay.
176 svld1_hor_za64(0, slice_base, svptrue_b64(), ptr);
177 }();
178 }
179
180 int16x8_t use_neon_builtin_in_streaming_lambda(int16x8_t splat) {
181 return [&]() __arm_streaming_compatible {
182 /// This should error as the lambda is streaming-compatible.
183 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
184 return (int16x8_t)__builtin_neon_vqaddq_v((int8x16_t)splat, (int8x16_t)splat, 33);
185 }();
186 }
187
188 float incomp_sve_fadda_in_streaming_lambda(void) {
189 return [&]() __arm_streaming {
190 // Should error (like the Neon case above).
191 // expected-error@+1 {{builtin can only be called from a non-streaming function}}
192 return svadda(svptrue_b32(), 0, svdup_f32(1));
193 }();
194 }