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