Debian Codegraph @

gcc/testsuite/g++.dg/vect/simd-1.cc

raw
1 // { dg-require-effective-target vect_simd_clones }
2 // { dg-additional-options "-fopenmp-simd" }
3 // { dg-additional-options "-mavx" { target avx_runtime } }
4
5 #include "../../gcc.dg/vect/tree-vect.h"
6
7 int w;
8 struct S {
9 int s, &t;
10 int *p;
11 S (int *x) : s (0), t (w), p (x) {};
12 void foo (short &, int &);
13 void bar (short &, int &);
14 void baz (short &, int &);
15 void qux (short &, int &);
16 };
17
18 __attribute__((noipa)) void
19 S::foo (short &x, int &y)
20 {
21 int *q = this->p;
22 #pragma omp simd lastprivate (x, s, t) private (y)
23 for (int i = 0; i < 1025; ++i)
24 {
25 y = q[i];
26 x = y;
27 q[i] = y * 2;
28 s = q[i] + 3;
29 t = q[i] + 6;
30 }
31 }
32
33 __attribute__((noipa)) void
34 S::bar (short &x, int &y)
35 {
36 #pragma omp simd linear (x) linear (s, t: 2) private (y)
37 for (int i = 0; i < 1025; ++i)
38 {
39 y = p[i];
40 x += y - 2 * i + 1;
41 p[i] = y * 2;
42 s += 2 * y - 4 * i + 2;
43 t += 2 * y - 4 * i + 2;
44 }
45 }
46
47 __attribute__((noipa)) void
48 S::baz (short &x, int &y)
49 {
50 int *q = this->p;
51 #pragma omp simd lastprivate (x, s, t) private (y) if (simd: 0)
52 for (int i = 0; i < 1025; ++i)
53 {
54 y = q[i];
55 x = y;
56 q[i] = y * 2;
57 s = q[i] + 3;
58 t = q[i] + 6;
59 }
60 }
61
62 __attribute__((noipa)) void
63 S::qux (short &x, int &y)
64 {
65 #pragma omp simd linear (x) linear (s, t: 2) private (y) simdlen (1)
66 for (int i = 0; i < 1025; ++i)
67 {
68 y = p[i];
69 x += y - 2 * i + 1;
70 p[i] = y * 2;
71 s += 2 * y - 4 * i + 2;
72 t += 2 * y - 4 * i + 2;
73 }
74 }
75
76 int
77 main ()
78 {
79 short x;
80 int a[1025], y;
81 check_vect ();
82 S s = a;
83 for (int i = 0; i < 1025; ++i)
84 {
85 a[i] = i;
86 asm volatile ("" : "+g" (i));
87 }
88 s.foo (x, y);
89 if (x != 1024 || s.s != 2051 || s.t != 2054)
90 abort ();
91 #pragma GCC novector
92 for (int i = 0; i < 1025; ++i)
93 if (a[i] != 2 * i)
94 abort ();
95 s.bar (x, y);
96 if (x != 2049 || s.s != 4101 || s.t != 4104)
97 abort ();
98 #pragma GCC novector
99 for (int i = 0; i < 1025; ++i)
100 if (a[i] != 4 * i)
101 abort ();
102 else
103 a[i] = i;
104 s.baz (x, y);
105 if (x != 1024 || s.s != 2051 || s.t != 2054)
106 abort ();
107 #pragma GCC novector
108 for (int i = 0; i < 1025; ++i)
109 if (a[i] != 2 * i)
110 abort ();
111 s.qux (x, y);
112 if (x != 2049 || s.s != 4101 || s.t != 4104)
113 abort ();
114 #pragma GCC novector
115 for (int i = 0; i < 1025; ++i)
116 if (a[i] != 4 * i)
117 abort ();
118 }