File: loop-25.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (128 lines) | stat: -rw-r--r-- 2,028 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-profile_estimate" } */

int foo(void);
void bla(void);
void bar(void);

void test1 (void)
{
  unsigned i;

  /* Only one loop should be found here.  */
  i = 0;
  while (1)
    {
      i++;
      if (i == 100)
	break;

      if (foo ())
	bla ();
      else
	bar ();
    }
}

void test2 (void)
{
  unsigned i, j;

  /* Two loops should be found, in this case.  */
  i = j = 0;
  while (1)
    {
      j++;
      foo ();
      if (j < 100)
	continue;

      i++;
      j = 0;
      if (i == 100)
	break;
    }
}

void test3 (void)
{
  unsigned i, j, k;

  /* Three loops.  */
  i = j = k = 0;
  while (1)
    {
      j++;
      foo ();
      if (j < 100)
	continue;

      j = 0;
      k++;
      if (k < 100)
	continue;

      k = 0;
      i++;
      if (i == 100)
	break;
    }
}

void test4 (void)
{
  unsigned i, j, k;

  /* Two loops with a nested subloop.  */
  i = j = 0;
  while (1)
    {
      j++;
      foo ();
      for (k = 0; k < 100; k++)
	foo ();

      if (j < 100)
	continue;

      i++;
      j = 0;
      if (i == 100)
	break;
    }
}


void test5 (void)
{
  unsigned i, j;

  /* Both subloop and non-subloop back edges.  */
  i = j = 0;
  while (1)
    {
      j++;
      foo ();
      if (j < 100)
	continue;
      j = 0;

      i++;
      if (i == 100)
	break;

      if (foo ())
	bla ();
      else
	bar ();
    }
}

/* { dg-final { scan-tree-dump-times "Disambiguating loop" 5 "profile_estimate" } } */
/* For the following xfail marks, see PR35629.  */
/* { dg-final { scan-tree-dump-times "Found latch edge" 5 "profile_estimate" { xfail *-*-* } } } */
/* { dg-final { scan-tree-dump-times "Merged latch edges" 2 "profile_estimate" { xfail *-*-* } } } */
/* { dg-final { scan-tree-dump-times "4 loops found" 2 "profile_estimate" { xfail *-*-* } } } */
/* { dg-final { scan-tree-dump-times "3 loops found" 2 "profile_estimate" { xfail *-*-* } } } */
/* { dg-final { scan-tree-dump-times "2 loops found" 1 "profile_estimate" { xfail *-*-* } } } */