PR testsuite/52641
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / predcom-1.c
blobf1e52e5d8c2cb9823e9249fb54a0551eb6d9a7b4
1 /* { dg-do compile } */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -funroll-loops --param max-unroll-times=8 -fpredictive-commoning -fdump-tree-pcom-details" } */
5 void abort (void);
7 unsigned fib[1000];
9 __attribute__ ((noinline))
10 void count_fib(void)
12 int i;
14 fib[0] = 0;
15 fib[1] = 1;
16 for (i = 2; i < 1000; i++)
17 fib[i] = (fib[i-1] + fib[i - 2]) & 0xffff;
20 unsigned avg[1000];
22 __attribute__ ((noinline))
23 void count_averages(int n)
25 int i;
27 for (i = 1; i < n; i++)
28 avg[i] = (((unsigned long) fib[i - 1] + fib[i] + fib[i + 1]) / 3) & 0xffff;
31 int main(void)
33 count_fib ();
34 count_averages (999);
36 if (fib[19] != 4181 || avg[19] != 4510)
37 abort ();
39 if (fib[999] != 162 || avg[998] != 21953)
40 abort ();
42 return 0;
45 /* Verify that both loops were transformed and unrolled. */
46 /* { dg-final { scan-tree-dump-times "Unrolling 2 times." 2 "pcom"} } */
48 /* Also check that we undid the transformation previously made by PRE. */
49 /* { dg-final { scan-tree-dump-times "looparound ref" 1 "pcom"} } */
51 /* { dg-final { cleanup-tree-dump "pcom" } } */