Debian Codegraph @

gcc/testsuite/g++.dg/ext/unroll-7.C

raw
1 // PR c++/112795
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-O2 -fdump-tree-cunrolli-details" }
4
5 void baz (int);
6 constexpr int n = 3;
7 constexpr int m = 7;
8
9 template <typename T>
10 void
11 foo (int (&a)[3], T b)
12 {
13 #pragma GCC unroll(n)
14 for (auto i : a)
15 baz (i);
16 #pragma GCC unroll(m)
17 for (auto i : b)
18 baz (i);
19 }
20
21 template <int N>
22 void
23 bar (int (&a)[N])
24 {
25 #pragma GCC unroll(N)
26 for (auto i : a)
27 baz (i);
28 }
29
30 void
31 qux ()
32 {
33 int a[3] = { 1, 2, 3 };
34 int b[7] = { 4, 5, 6, 7, 8, 9, 10 };
35 int c[6] = { 11, 12, 13, 14, 15, 16 };
36 int d[10] = { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
37 foo <int (&)[7]> (a, b);
38 bar <6> (c);
39 bar <10> (d);
40 }
41
42 // { dg-final { scan-tree-dump "loop with 3 iterations completely unrolled" "cunrolli" } }
43 // { dg-final { scan-tree-dump "loop with 6 iterations completely unrolled" "cunrolli" } }
44 // { dg-final { scan-tree-dump "loop with 7 iterations completely unrolled" "cunrolli" } }
45 // { dg-final { scan-tree-dump "loop with 10 iterations completely unrolled" "cunrolli" } }