Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-simd-8.c

raw
1 /* { dg-require-effective-target size32plus } */
2 /* { dg-additional-options "-fopenmp-simd" } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4 /* { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 2 "vect" { target i?86-*-* x86_64-*-* } } } */
5
6 #ifndef main
7 #include "tree-vect.h"
8 #endif
9
10 int r, a[1024], b[1024];
11
12 __attribute__((noipa)) void
13 foo (int *a, int *b)
14 {
15 #pragma omp simd reduction (inscan, +:r)
16 for (int i = 0; i < 1024; i++)
17 {
18 r += a[i];
19 #pragma omp scan inclusive(r)
20 b[i] = r;
21 }
22 }
23
24 __attribute__((noipa)) int
25 bar (void)
26 {
27 int s = 0;
28 #pragma omp simd reduction (inscan, +:s)
29 for (int i = 0; i < 1024; i++)
30 {
31 s += 2 * a[i];
32 #pragma omp scan inclusive(s)
33 b[i] = s;
34 }
35 return s;
36 }
37
38 __attribute__((noipa)) void
39 baz (int *a, int *b)
40 {
41 #pragma omp simd reduction (inscan, +:r) if (simd: 0)
42 for (int i = 0; i < 1024; i++)
43 {
44 r += a[i];
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 simd reduction (inscan, +:s) simdlen (1)
55 for (int i = 0; i < 1024; i++)
56 {
57 s += 2 * a[i];
58 #pragma omp scan inclusive(s)
59 b[i] = s;
60 }
61 return s;
62 }
63
64 int
65 main ()
66 {
67 int s = 0;
68 #ifndef main
69 check_vect ();
70 #endif
71 for (int i = 0; i < 1024; ++i)
72 {
73 a[i] = i;
74 b[i] = -1;
75 asm ("" : "+g" (i));
76 }
77 foo (a, b);
78 if (r != 1024 * 1023 / 2)
79 abort ();
80 #pragma GCC novector
81 for (int i = 0; i < 1024; ++i)
82 {
83 s += i;
84 if (b[i] != s)
85 abort ();
86 else
87 b[i] = 25;
88 }
89 if (bar () != 1024 * 1023)
90 abort ();
91 s = 0;
92 #pragma GCC novector
93 for (int i = 0; i < 1024; ++i)
94 {
95 s += 2 * i;
96 if (b[i] != s)
97 abort ();
98 else
99 b[i] = -1;
100 }
101 r = 0;
102 baz (a, b);
103 if (r != 1024 * 1023 / 2)
104 abort ();
105 s = 0;
106 #pragma GCC novector
107 for (int i = 0; i < 1024; ++i)
108 {
109 s += i;
110 if (b[i] != s)
111 abort ();
112 else
113 b[i] = -25;
114 }
115 if (qux () != 1024 * 1023)
116 abort ();
117 s = 0;
118 #pragma GCC novector
119 for (int i = 0; i < 1024; ++i)
120 {
121 s += 2 * i;
122 if (b[i] != s)
123 abort ();
124 }
125 return 0;
126 }