1 /* { dg-do run } */
2 /* { dg-additional-options "-msse2" { target sse2_runtime } } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4
5 extern void abort ();
6 int a[1024] __attribute__((aligned (32))) = { 1 };
7 int b[1024] __attribute__((aligned (32))) = { 1 };
8 unsigned char c[1024] __attribute__((aligned (32))) = { 1 };
9 int k, m;
10 __UINTPTR_TYPE__ u, u2, u3;
11
12 __attribute__((noinline, noclone)) int
foo(int * p)13 foo (int *p)
14 {
15 int i, s = 0, s2 = 0, t, t2;
16 #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s) \
17 lastprivate (t2)
18 for (i = 0; i < 512; i++)
19 {
20 a[i] *= p[i];
21 t2 = k + p[i];
22 k += m + 1;
23 s += p[i] + k;
24 c[i]++;
25 }
26 #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s2) \
27 lastprivate (t, u, u2, u3)
28 for (i = 512; i < 1024; i++)
29 {
30 a[i] *= p[i];
31 k += m + 1;
32 t = k + p[i];
33 u = (__UINTPTR_TYPE__) &k;
34 u2 = (__UINTPTR_TYPE__) &s2;
35 u3 = (__UINTPTR_TYPE__) &t;
36 s2 += t;
37 c[i]++;
38 }
39 return s + s2 + t + t2;
40 }
41
42 __attribute__((noinline, noclone)) long int
bar(int * p,long int n,long int o)43 bar (int *p, long int n, long int o)
44 {
45 long int i, s = 0, s2 = 0, t, t2;
46 #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s) \
47 lastprivate (t2)
48 for (i = 0; i < n; i++)
49 {
50 a[i] *= p[i];
51 t2 = k + p[i];
52 k += m + 1;
53 s += p[i] + k;
54 c[i]++;
55 }
56 #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s2) \
57 lastprivate (t, u, u2, u3)
58 for (i = n; i < o; i++)
59 {
60 a[i] *= p[i];
61 k += m + 1;
62 t = k + p[i];
63 u = (__UINTPTR_TYPE__) &k;
64 u2 = (__UINTPTR_TYPE__) &s2;
65 u3 = (__UINTPTR_TYPE__) &t;
66 s2 += t;
67 c[i]++;
68 }
69 return s + s2 + t + t2;
70 }
71
72 int
main()73 main ()
74 {
75 #if __SIZEOF_INT__ >= 4
76 int i;
77 k = 4;
78 m = 2;
79 for (i = 0; i < 1024; i++)
80 {
81 a[i] = i - 512;
82 b[i] = (i - 51) % 39;
83 c[i] = (unsigned char) i;
84 }
85 int s = foo (b);
86 for (i = 0; i < 1024; i++)
87 {
88 if (b[i] != (i - 51) % 39
89 || a[i] != (i - 512) * b[i]
90 || c[i] != (unsigned char) (i + 1))
91 abort ();
92 a[i] = i - 512;
93 }
94 if (k != 4 + 3 * 1024
95 || s != 1596127 + (4 + 3 * 511 + b[511]) + (4 + 3 * 1024 + b[1023]))
96 abort ();
97 k = 4;
98 s = bar (b, 512, 1024);
99 for (i = 0; i < 1024; i++)
100 {
101 if (b[i] != (i - 51) % 39
102 || a[i] != (i - 512) * b[i]
103 || c[i] != (unsigned char) (i + 2))
104 abort ();
105 a[i] = i - 512;
106 }
107 if (k != 4 + 3 * 1024
108 || s != 1596127 + (4 + 3 * 511 + b[511]) + (4 + 3 * 1024 + b[1023]))
109 abort ();
110 k = 4;
111 s = bar (b, 511, 1021);
112 for (i = 0; i < 1021; i++)
113 {
114 if (b[i] != (i - 51) % 39
115 || a[i] != (i - 512) * b[i]
116 || c[i] != (unsigned char) (i + 3))
117 abort ();
118 a[i] = i - 512;
119 }
120 for (i = 1021; i < 1024; i++)
121 if (b[i] != (i - 51) % 39
122 || a[i] != i - 512
123 || c[i] != (unsigned char) (i + 2))
124 abort ();
125 if (k != 4 + 3 * 1021
126 || s != 1586803 + (4 + 3 * 510 + b[510]) + (4 + 3 * 1021 + b[1020]))
127 abort ();
128 #endif
129 return 0;
130 }
131