libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / loop-unswitch-14.c
blobe1225f6890f4a4c543c02421542d1282d385fbff
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 } */
5 int
6 __attribute__((noipa))
7 foo(double *a, double *b, double *c, double *d, double *r, int size, int order)
9 for (int i = 0; i < size; i++)
11 double tmp, tmp2;
13 if (order <= 0)
14 tmp = 123;
16 switch(order)
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 ();
38 double x = 3 * tmp + d[i] + tmp;
39 double y = 3.4f * tmp + d[i] + tmp2;
40 r[i] = x + y;
43 return 0;
46 #define N 16 * 1024
47 double aa[N], bb[N], cc[N], dd[N], rr[N];
49 int main()
51 for (int i = 0; i < 100 * 1000; i++)
52 foo (aa, bb, cc, dd, rr, N, i % 4);
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" } } */