OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [testsuite/] [gcc.dg/] [tree-ssa/] [tailrecursion-5.c] - Blame information for rev 338

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 298 jeremybenn
/* { dg-do run } */
2
/* { dg-options "-O1 -foptimize-sibling-calls -fdump-tree-optimized" } */
3
 
4
extern void abort (void);
5
extern void exit (int);
6
 
7
int sum (int n)
8
{
9
  if (n == 0)
10
    return 0;
11
 
12
  return n + sum (n - 1);
13
}
14
 
15
int fac (int n)
16
{
17
  if (n == 0)
18
    return 1;
19
 
20
  return n * fac (n - 1);
21
}
22
 
23
int sq_sum (int n)
24
{
25
  if (n == 0)
26
    return 0;
27
 
28
  return n * n + sq_sum (n - 1);
29
}
30
 
31
int pow2m1 (int n)
32
{
33
  if (n == 0)
34
    return 0;
35
 
36
  return 2 * pow2m1 (n - 1) + 1;
37
}
38
 
39
int fib (int n)
40
{
41
  if (n <= 1)
42
    return 1;
43
 
44
  return fib (n - 2) + fib (n - 1);
45
}
46
 
47
int main(void)
48
{
49
  if (sum (5) != 15)
50
    abort ();
51
 
52
  if (fac (5) != 120)
53
    abort ();
54
 
55
  if (sq_sum (5) != 55)
56
    abort ();
57
 
58
  if (pow2m1 (5) != 31)
59
    abort ();
60
 
61
  if (fib (5) != 8)
62
    abort ();
63
 
64
  exit (0);
65
}
66
 
67
/* There is one call of sum in main and then 2 instances of the word in
68
   ;; Function sum (sum) and one in the function header.  */
69
/* { dg-final { scan-tree-dump-times "\\msum\\M" 4 "optimized"} } */
70
/* { dg-final { scan-tree-dump-times "\\mfac\\M" 4 "optimized"} } */
71
/* { dg-final { scan-tree-dump-times "\\msq_sum\\M" 4 "optimized"} } */
72
/* { dg-final { scan-tree-dump-times "\\mpow2m1\\M" 4 "optimized"} } */
73
 
74
/* There is one recursive call to fib.  */
75
/* { dg-final { scan-tree-dump-times "\\mfib\\M" 5 "optimized"} } */
76
 
77
/* { dg-final { cleanup-tree-dump "optimized" } } */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.