Debian Codegraph @

gcc/testsuite/gcc.dg/loop-unswitch-14.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -funswitch-loops -fdump-tree-unswitch-optimized --param=max-unswitch-insns=1000" } */
3 /* { dg-require-effective-target size32plus } */
4
5 int
6 __attribute__((noipa))
7 foo(double *a, double *b, double *c, double *d, double *r, int size, int order)
8 {
9 for (int i = 0; i < size; i++)
10 {
11 double tmp, tmp2;
12
13 if (order <= 0)
14 tmp = 123;
15
16 switch(order)
17 {
18 case 0:
19 tmp += -8 * a[i];
20 tmp2 = 2 * b[i];
21 break;
22 case 1:
23 tmp = 3 * a[i] - 2 * b[i];
24 tmp2 = 5 * b[i] - 2 * c[i];
25 break;
26 case 2:
27 tmp = 9 * a[i] + 2 * b[i] + c[i];
28 tmp2 = 4 * b[i] + 2 * c[i] + 8 * d[i];
29 break;
30 case 3:
31 tmp = 3 * a[i] + 2 * b[i] - c[i];
32 tmp2 = b[i] - 2 * c[i] + 8 * d[i];
33 break;
34 default:
35 __builtin_unreachable ();
36 }
37
38 double x = 3 * tmp + d[i] + tmp;
39 double y = 3.4f * tmp + d[i] + tmp2;
40 r[i] = x + y;
41 }
42
43 return 0;
44 }
45
46 #define N 16 * 1024
47 double aa[N], bb[N], cc[N], dd[N], rr[N];
48
49 int main()
50 {
51 for (int i = 0; i < 100 * 1000; i++)
52 foo (aa, bb, cc, dd, rr, N, i % 4);
53 }
54
55
56 /* Test that we actually unswitched something. */
57 /* { dg-final { scan-tree-dump-times "unswitching loop . on .switch. with condition: order.* <= 0" 1 "unswitch" } } */
58 /* { dg-final { scan-tree-dump-times "unswitching loop . on .switch. with condition: order.* == 0" 1 "unswitch" } } */
59 /* { dg-final { scan-tree-dump-times "unswitching loop . on .switch. with condition: order.* == 1" 1 "unswitch" } } */
60 /* { dg-final { scan-tree-dump-times "unswitching loop . on .switch. with condition: order.* == 2" 1 "unswitch" } } */
61 /* { dg-final { scan-tree-dump-times "unswitching loop . on .switch. with condition: order.* == 3" 1 "unswitch" } } */