re PR tree-optimization/33291 (a+=2; a+=2 not simplified to a+=4; with -O3 ...
[gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / predcom-1.c
1 /* { dg-do compile } */
2 /* { dg-do run } */
3 /* { dg-options "-O2 -fpredictive-commoning -fdump-tree-pcom-details" } */
4
5 void abort (void);
6
7 unsigned fib[1000];
8
9 void count_fib(void)
10 {
11 int i;
12
13 fib[0] = 0;
14 fib[1] = 1;
15 for (i = 2; i < 1000; i++)
16 fib[i] = (fib[i-1] + fib[i - 2]) & 0xffff;
17 }
18
19 unsigned avg[1000];
20
21 void count_averages(int n)
22 {
23 int i;
24
25 for (i = 1; i < n; i++)
26 avg[i] = (((unsigned long) fib[i - 1] + fib[i] + fib[i + 1]) / 3) & 0xffff;
27 }
28
29 int main(void)
30 {
31 count_fib ();
32 count_averages (999);
33
34 if (fib[19] != 4181 || avg[19] != 4510)
35 abort ();
36
37 if (fib[999] != 162 || avg[998] != 21953)
38 abort ();
39
40 return 0;
41 }
42
43 /* Verify that both loops were transformed and unrolled. */
44 /* { dg-final { scan-tree-dump-times "Unrolling 2 times." 2 "pcom"} } */
45
46 /* Also check that we undid the transformation previously made by PRE. */
47 /* { dg-final { scan-tree-dump-times "looparound ref" 1 "pcom"} } */
48
49 /* { dg-final { cleanup-tree-dump "pcom" } } */