1 /* { dg-do compile } */
2 /* { dg-options "-O2 -fdump-tree-thread1-stats -fdump-tree-thread2-stats -fdump-tree-dom2-stats -fdump-tree-thread3-stats -fdump-tree-dom3-stats -fdump-tree-vrp2-stats -fno-guess-branch-probability" } */
3 /* { dg-final { scan-tree-dump "Jumps threaded: 16"  "thread1" } } */
4 /* { dg-final { scan-tree-dump "Jumps threaded: 9" "thread2" } } */
5 /* { dg-final { scan-tree-dump-not "Jumps threaded"  "dom2" } } */
6 /* aarch64 has the highest CASE_VALUES_THRESHOLD in GCC.  It's high enough
7    to change decisions in switch expansion which in turn can expose new
8    jump threading opportunities.  Skip the later tests on aarch64.  */
9 /* { dg-final { scan-tree-dump-not "Jumps threaded"  "dom3" { target { ! aarch64*-*-* } } } } */
10 /* { dg-final { scan-tree-dump-not "Jumps threaded"  "vrp2" { target { ! aarch64*-*-* } } } } */
11 
12 /* Most architectures get 3 threadable paths here, whereas aarch64 and
13    possibly others get 5.  We really should rewrite threading tests to
14    test a specific IL sequence, not gobs of code whose IL can vary
15    from architecture to architecture.  */
16 /* { dg-final { scan-tree-dump "Jumps threaded: \[35\]" "thread3" } } */
17 
18 enum STATE {
19   S0=0,
20   SI,
21   S1,
22   S2,
23   S3,
24   S4,
25   S5,
26   S6
27 };
28 
29 int bar (enum STATE s);
30 
foo(unsigned char ** y,unsigned * c)31 enum STATE foo (unsigned char **y, unsigned *c)
32 {
33   unsigned char *x = *y;
34   unsigned char n;
35   enum STATE s = S0;
36 
37   for( ; *x && s != SI; x++ )
38     {
39       n = *x;
40       if (n == 'x')
41 	{
42 	  x++;
43 	  break;
44 	}
45       switch(s)
46 	{
47 	case S0:
48 	  if(bar(n))
49 	    s = S3;
50 	  else if( n == 'a' || n == 'b' )
51 	    s = S1;
52 	  else if( n == 'c' )
53 	    s = S4;
54 	  else
55 	    {
56 	      s = SI;
57 	      c[SI]++;
58 	    }
59 	  c[S0]++;
60 	  break;
61 	case S1:
62 	  if(bar(n))
63 	    {
64 	      s = S3;
65 	      c[S1]++;
66 	    }
67 	  else if( n == 'c' )
68 	    {
69 	      s = S4;
70 	      c[S1]++;
71 	    }
72 	  else
73 	    {
74 	      s = SI;
75 	      c[S1]++;
76 	    }
77 	  break;
78 	case S3:
79 	  if( n == 'c' )
80 	    {
81 	      s = S4;
82 	      c[S3]++;
83 	    }
84 	  else if(!bar(n))
85 	    {
86 	      s = SI;
87 	      c[S3]++;
88 	    }
89 	  break;
90 	case S4:
91 	  if( n == 'E' || n == 'e' )
92 	    {
93 	      s = S2;
94 	      c[S4]++;
95 	    }
96 	  else if(!bar(n))
97 	    {
98 	      s = SI;
99 	      c[S4]++;
100 	    }
101 	  break;
102 	case S2:
103 	  if( n == 'a' || n == 'b' )
104 	    {
105 	      s = S5;
106 	      c[S2]++;
107 	    }
108 	  else
109 	    {
110 	      s = SI;
111 	      c[S2]++;
112 	    }
113 	  break;
114 	case S5:
115 	  if(bar(n))
116 	    {
117 	      s = S6;
118 	      c[S5]++;
119 	    }
120 	  else
121 	    {
122 	      s = SI;
123 	      c[S5]++;
124 	    }
125 	  break;
126 	case S6:
127 	  if(!bar(n))
128 	    {
129 	      s = SI;
130 	      c[SI]++;
131 	    }
132 	  break;
133 	default:
134 	  break;
135 	}
136     }
137   *y=x;
138   return s;
139 }
140