File: ppc-pair-mma-types.c

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-16
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,496,368 kB
  • sloc: cpp: 5,593,980; ansic: 986,873; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,547; xml: 953; cs: 573; fortran: 567
file content (358 lines) | stat: -rw-r--r-- 13,120 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -fsyntax-only \
// RUN:   -target-cpu pwr10 %s -verify
// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -fsyntax-only \
// RUN:   -target-cpu pwr10 %s -verify

// The use of PPC MMA types is strongly restricted. Non-pointer MMA variables
// can only be declared in functions and a limited number of operations are
// supported on these types. This test case checks that invalid uses of MMA
// types are correctly prevented.

// vector quad

// typedef
typedef __vector_quad vq_t;
void testVQTypedef(int *inp, int *outp) {
  vq_t *vqin = (vq_t *)inp;
  vq_t *vqout = (vq_t *)outp;
  *vqout = *vqin;
}

// function argument
void testVQArg1(__vector_quad vq, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = vq;
}

void testVQArg2(const __vector_quad vq, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = vq;
}

void testVQArg3(__vector_quad *vq, int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = *vq;
}

void testVQArg4(const __vector_quad *const vq, int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = *vq;
}

void testVQArg5(__vector_quad vqa[], int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = vqa[0];
}

void testVQArg6(const vq_t vq, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = vq;
}

void testVQArg7(const vq_t *vq, int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  *vqp = *vq;
}

// function return
__vector_quad testVQRet1(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_quad *vqp = (__vector_quad *)ptr;
  return *vqp; // expected-error {{invalid use of PPC MMA type}}
}

__vector_quad *testVQRet2(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  return vqp + 2;
}

const __vector_quad *testVQRet3(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  return vqp + 2;
}

const vq_t testVQRet4(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_quad *vqp = (__vector_quad *)ptr;
  return *vqp; // expected-error {{invalid use of PPC MMA type}}
}

const vq_t *testVQRet5(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  return vqp + 2;
}

// global
__vector_quad globalvq;        // expected-error {{invalid use of PPC MMA type}}
const __vector_quad globalvq2; // expected-error {{invalid use of PPC MMA type}}
__vector_quad *globalvqp;
const __vector_quad *const globalvqp2;
vq_t globalvq_t; // expected-error {{invalid use of PPC MMA type}}

// local
void testVQLocal(int *ptr, vector unsigned char vc) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  __vector_quad vq1 = *vqp;
  __vector_quad vq2;
  __builtin_mma_xxsetaccz(&vq2);
  __vector_quad vq3;
  __builtin_mma_xvi4ger8(&vq3, vc, vc);
  *vqp = vq3;
}

// struct field
struct TestVQStruct {
  int a;
  float b;
  __vector_quad c; // expected-error {{invalid use of PPC MMA type}}
  __vector_quad *vq;
};

// sizeof / alignof
int testVQSizeofAlignof(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  __vector_quad vq = *vqp;
  unsigned sizet = sizeof(__vector_quad);
  unsigned alignt = __alignof__(__vector_quad);
  unsigned sizev = sizeof(vq);
  unsigned alignv = __alignof__(vq);
  return sizet + alignt + sizev + alignv;
}

// operators
int testVQOperators1(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  __vector_quad vq1 = *(vqp + 0);
  __vector_quad vq2 = *(vqp + 1);
  __vector_quad vq3 = *(vqp + 2);
  if (vq1) // expected-error {{statement requires expression of scalar type ('__vector_quad' invalid)}}
    *(vqp + 10) = vq1;
  if (!vq2) // expected-error {{invalid argument type '__vector_quad' to unary expression}}
    *(vqp + 11) = vq3;
  int c1 = vq1 && vq2; // expected-error {{invalid operands to binary expression ('__vector_quad' and '__vector_quad')}}
  int c2 = vq2 == vq3; // expected-error {{invalid operands to binary expression ('__vector_quad' and '__vector_quad')}}
  int c3 = vq2 < vq1;  // expected-error {{invalid operands to binary expression ('__vector_quad' and '__vector_quad')}}
  return c1 || c2 || c3;
}

void testVQOperators2(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  __vector_quad vq1 = *(vqp + 0);
  __vector_quad vq2 = *(vqp + 1);
  __vector_quad vq3 = *(vqp + 2);
  vq1 = -vq1;      // expected-error {{invalid argument type '__vector_quad' to unary expression}}
  vq2 = vq1 + vq3; // expected-error {{invalid operands to binary expression ('__vector_quad' and '__vector_quad')}}
  vq2 = vq2 * vq3; // expected-error {{invalid operands to binary expression ('__vector_quad' and '__vector_quad')}}
  vq3 = vq3 | vq3; // expected-error {{invalid operands to binary expression ('__vector_quad' and '__vector_quad')}}
  vq3 = vq3 << 2;  // expected-error {{invalid operands to binary expression ('__vector_quad' and 'int')}}
  *(vqp + 10) = vq1;
  *(vqp + 11) = vq2;
  *(vqp + 12) = vq3;
}

vector unsigned char testVQOperators3(int *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  __vector_quad vq1 = *(vqp + 0);
  __vector_quad vq2 = *(vqp + 1);
  __vector_quad vq3 = *(vqp + 2);
  vq1 ? *(vqp + 10) = vq2 : *(vqp + 11) = vq3; // expected-error {{used type '__vector_quad' where arithmetic or pointer type is required}}
  vq2 = vq3;
  return vq2[1]; // expected-error {{subscripted value is not an array, pointer, or vector}}
}

void testVQOperators4(int v, void *ptr) {
  __vector_quad *vqp = (__vector_quad *)ptr;
  __vector_quad vq1 = (__vector_quad)v;   // expected-error {{used type '__vector_quad' where arithmetic or pointer type is required}}
  __vector_quad vq2 = (__vector_quad)vqp; // expected-error {{used type '__vector_quad' where arithmetic or pointer type is required}}
}

// vector pair

// typedef
typedef __vector_pair vp_t;
void testVPTypedef(int *inp, int *outp) {
  vp_t *vpin = (vp_t *)inp;
  vp_t *vpout = (vp_t *)outp;
  *vpout = *vpin;
}

// function argument
void testVPArg1(__vector_pair vp, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = vp;
}

void testVPArg2(const __vector_pair vp, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = vp;
}

void testVPArg3(__vector_pair *vp, int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = *vp;
}

void testVPArg4(const __vector_pair *const vp, int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = *vp;
}

void testVPArg5(__vector_pair vpa[], int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = vpa[0];
}

void testVPArg6(const vp_t vp, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = vp;
}

void testVPArg7(const vp_t *vp, int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  *vpp = *vp;
}

// function return
__vector_pair testVPRet1(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_pair *vpp = (__vector_pair *)ptr;
  return *vpp; // expected-error {{invalid use of PPC MMA type}}
}

__vector_pair *testVPRet2(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  return vpp + 2;
}

const __vector_pair *testVPRet3(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  return vpp + 2;
}

const vp_t testVPRet4(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
  __vector_pair *vpp = (__vector_pair *)ptr;
  return *vpp; // expected-error {{invalid use of PPC MMA type}}
}

const vp_t *testVPRet5(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  return vpp + 2;
}

// global
__vector_pair globalvp;        // expected-error {{invalid use of PPC MMA type}}
const __vector_pair globalvp2; // expected-error {{invalid use of PPC MMA type}}
__vector_pair *globalvpp;
const __vector_pair *const globalvpp2;
vp_t globalvp_t; // expected-error {{invalid use of PPC MMA type}}

// local
void testVPLocal(int *ptr, vector unsigned char vc) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  __vector_pair vp1 = *vpp;
  __vector_pair vp2;
  __builtin_vsx_assemble_pair(&vp2, vc, vc);
  __builtin_vsx_build_pair(&vp2, vc, vc);
  __vector_pair vp3;
  __vector_quad vq;
  __builtin_mma_xvf64ger(&vq, vp3, vc);
  *vpp = vp3;
}

// struct field
struct TestVPStruct {
  int a;
  float b;
  __vector_pair c; // expected-error {{invalid use of PPC MMA type}}
  __vector_pair *vp;
};

// sizeof / alignof
int testVPSizeofAlignof(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  __vector_pair vp = *vpp;
  unsigned sizet = sizeof(__vector_pair);
  unsigned alignt = __alignof__(__vector_pair);
  unsigned sizev = sizeof(vp);
  unsigned alignv = __alignof__(vp);
  return sizet + alignt + sizev + alignv;
}

// operators
int testVPOperators1(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  __vector_pair vp1 = *(vpp + 0);
  __vector_pair vp2 = *(vpp + 1);
  __vector_pair vp3 = *(vpp + 2);
  if (vp1) // expected-error {{statement requires expression of scalar type ('__vector_pair' invalid)}}
    *(vpp + 10) = vp1;
  if (!vp2) // expected-error {{invalid argument type '__vector_pair' to unary expression}}
    *(vpp + 11) = vp3;
  int c1 = vp1 && vp2; // expected-error {{invalid operands to binary expression ('__vector_pair' and '__vector_pair')}}
  int c2 = vp2 == vp3; // expected-error {{invalid operands to binary expression ('__vector_pair' and '__vector_pair')}}
  int c3 = vp2 < vp1;  // expected-error {{invalid operands to binary expression ('__vector_pair' and '__vector_pair')}}
  return c1 || c2 || c3;
}

void testVPOperators2(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  __vector_pair vp1 = *(vpp + 0);
  __vector_pair vp2 = *(vpp + 1);
  __vector_pair vp3 = *(vpp + 2);
  vp1 = -vp1;      // expected-error {{invalid argument type '__vector_pair' to unary expression}}
  vp2 = vp1 + vp3; // expected-error {{invalid operands to binary expression ('__vector_pair' and '__vector_pair')}}
  vp2 = vp2 * vp3; // expected-error {{invalid operands to binary expression ('__vector_pair' and '__vector_pair')}}
  vp3 = vp3 | vp3; // expected-error {{invalid operands to binary expression ('__vector_pair' and '__vector_pair')}}
  vp3 = vp3 << 2;  // expected-error {{invalid operands to binary expression ('__vector_pair' and 'int')}}
  *(vpp + 10) = vp1;
  *(vpp + 11) = vp2;
  *(vpp + 12) = vp3;
}

vector unsigned char testVPOperators3(int *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  __vector_pair vp1 = *(vpp + 0);
  __vector_pair vp2 = *(vpp + 1);
  __vector_pair vp3 = *(vpp + 2);
  vp1 ? *(vpp + 10) = vp2 : *(vpp + 11) = vp3; // expected-error {{used type '__vector_pair' where arithmetic or pointer type is required}}
  vp2 = vp3;
  return vp2[1]; // expected-error {{subscripted value is not an array, pointer, or vector}}
}

void testVPOperators4(int v, void *ptr) {
  __vector_pair *vpp = (__vector_pair *)ptr;
  __vector_pair vp1 = (__vector_pair)v;   // expected-error {{used type '__vector_pair' where arithmetic or pointer type is required}}
  __vector_pair vp2 = (__vector_pair)vpp; // expected-error {{used type '__vector_pair' where arithmetic or pointer type is required}}
}

void testBuiltinTypes1(const __vector_pair *vpp, const __vector_pair *vp2, float f) {
  __vector_pair vp = __builtin_vsx_lxvp(f, vpp); // expected-error {{passing 'float' to parameter of incompatible type 'long'}}
  __builtin_vsx_stxvp(vp, 32799, vp2);           // expected-error {{passing 'int' to parameter of incompatible type 'long'}}
}

void testBuiltinTypes2(__vector_pair *vpp, const __vector_pair *vp2, unsigned char c) {
  __vector_pair vp = __builtin_vsx_lxvp(6L, vpp); // expected-error {{passing '__vector_pair *' to parameter of incompatible type 'const __vector_pair *'}}
  __builtin_vsx_stxvp(vp, c, vp2);                // expected-error {{passing 'unsigned char' to parameter of incompatible type 'long'}}
}

void testBuiltinTypes3(vector int v, __vector_pair *vp2, signed long l, unsigned short s) {
  __vector_pair vp = __builtin_vsx_lxvp(l, v); // expected-error {{passing '__vector int' (vector of 4 'int' values) to parameter of incompatible type 'const __vector_pair *'}}
  __builtin_vsx_stxvp(vp, l, s);               // expected-error {{passing 'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
}

void testRestrictQualifiedPointer1(int *__restrict acc) {
  vector float arr[4];
  __builtin_mma_disassemble_acc(arr, acc); // expected-error {{passing 'int *restrict' to parameter of incompatible type '__vector_quad *'}}
}

void testRestrictQualifiedPointer2(__vector_quad *__restrict acc) {
  vector float arr[4];
  __builtin_mma_disassemble_acc(arr, acc);
}

void testVolatileQualifiedPointer1(int *__volatile acc) {
  vector float arr[4];
  __builtin_mma_disassemble_acc(arr, acc); // expected-error {{passing 'int *volatile' to parameter of incompatible type '__vector_quad *'}}
}

void testVolatileQualifiedPointer2(__vector_quad *__volatile acc) {
  vector float arr[4];
  __builtin_mma_disassemble_acc(arr, acc);
}