Debian Codegraph @

libgomp/testsuite/libgomp.c/scan-23.c

raw
1 /* { dg-require-effective-target size32plus } */
2 /* Same as scan-9.c, instead of using { ... } it simply uses multiple
3 executable stmt before 'omp scan'. */
4
5 extern void abort (void);
6 int r, a[1024], b[1024], x, y, z;
7
8 __attribute__((noipa)) void
9 foo (int *a, int *b)
10 {
11 #pragma omp for reduction (inscan, +:r) lastprivate (conditional: z) firstprivate (x) private (y)
12 for (int i = 0; i < 1024; i++)
13 {
14 y = a[i];
15 r += y + x + 12;
16 #pragma omp scan inclusive(r)
17 b[i] = r;
18 if ((i & 1) == 0 && i < 937)
19 z = r;
20 }
21 }
22
23 __attribute__((noipa)) int
24 bar (void)
25 {
26 int s = 0;
27 #pragma omp parallel
28 #pragma omp for reduction (inscan, +:s) firstprivate (x) private (y) lastprivate (z)
29 for (int i = 0; i < 1024; i++)
30 {
31 y = 2 * a[i]; s += y; z = y;
32 #pragma omp scan inclusive(s)
33 y = s; b[i] = y + x + 12;
34 }
35 return s;
36 }
37
38 __attribute__((noipa)) void
39 baz (int *a, int *b)
40 {
41 #pragma omp parallel for reduction (inscan, +:r) firstprivate (x) lastprivate (x)
42 for (int i = 0; i < 1024; i++)
43 {
44 r += a[i] + x + 12; if (i == 1023) x = 29;
45 #pragma omp scan inclusive(r)
46 b[i] = r;
47 }
48 }
49
50 __attribute__((noipa)) int
51 qux (void)
52 {
53 int s = 0;
54 #pragma omp parallel for reduction (inscan, +:s) lastprivate (conditional: x, y)
55 for (int i = 0; i < 1024; i++)
56 {
57 s += 2 * a[i]; if ((a[i] & 1) == 1 && i < 825) x = a[i];
58 #pragma omp scan inclusive(s)
59 b[i] = s; if ((a[i] & 1) == 0 && i < 829) y = a[i];
60 }
61 return s;
62 }
63
64 int
65 main ()
66 {
67 int s = 0;
68 x = -12;
69 for (int i = 0; i < 1024; ++i)
70 {
71 a[i] = i;
72 b[i] = -1;
73 asm ("" : "+g" (i));
74 }
75 #pragma omp parallel
76 foo (a, b);
77 if (r != 1024 * 1023 / 2 || x != -12 || z != b[936])
78 abort ();
79 for (int i = 0; i < 1024; ++i)
80 {
81 s += i;
82 if (b[i] != s)
83 abort ();
84 else
85 b[i] = 25;
86 }
87 if (bar () != 1024 * 1023 || x != -12 || z != 2 * 1023)
88 abort ();
89 s = 0;
90 for (int i = 0; i < 1024; ++i)
91 {
92 s += 2 * i;
93 if (b[i] != s)
94 abort ();
95 else
96 b[i] = -1;
97 }
98 r = 0;
99 baz (a, b);
100 if (r != 1024 * 1023 / 2 || x != 29)
101 abort ();
102 s = 0;
103 for (int i = 0; i < 1024; ++i)
104 {
105 s += i;
106 if (b[i] != s)
107 abort ();
108 else
109 b[i] = -25;
110 }
111 if (qux () != 1024 * 1023 || x != 823 || y != 828)
112 abort ();
113 s = 0;
114 for (int i = 0; i < 1024; ++i)
115 {
116 s += 2 * i;
117 if (b[i] != s)
118 abort ();
119 }
120 return 0;
121 }