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