PR libfortran/64770 Segfault when trying to open existing file with status="new".
[official-gcc.git] / gcc / testsuite / gcc.dg / ipa / ipa-icf-13.c
blobe409ee496b18ac93186a051277560ab2495aa1ff
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -fdump-ipa-icf" } */
4 #include <stdlib.h>
5 #include <stdio.h>
7 int gcd(int x, int y) __attribute__ ((pure));
9 __attribute__ ((noinline))
10 int gcd(int x, int y)
12 int swap;
14 if(x <= 0 || y <= 0)
15 return 0;
17 if(x < y)
19 swap = x;
20 x = y;
21 y = swap;
24 while(x != y)
26 x = x - y;
28 if(y > x)
30 swap = x;
31 x = y;
32 y = swap;
36 return x;
39 int nsd(int x, int y) __attribute__ ((pure));
41 __attribute__ ((noinline))
42 int nsd(int x, int y)
44 int swap;
46 if(x <= 0 || y <= 0)
47 return 0;
49 if(x < y)
51 swap = x;
52 x = y;
53 y = swap;
56 while(x != y)
58 x = x - y;
60 if(y > x)
62 swap = x;
63 x = y;
64 y = swap;
68 return x;
71 int nsd_different_result(int x, int y) __attribute__ ((pure));
73 __attribute__ ((noinline))
74 int nsd_different_result(int x, int y)
76 int pes;
78 if(x <= 0 || y <= 0)
79 return 1;
81 if(x < 10)
82 y = 12;
83 else if(x == 44)
84 y = 124;
85 else
86 y = 1111;
88 if(x < y)
90 pes = x;
91 x = y;
92 y = pes;
95 while(x != y)
97 x = x - y;
99 if(y > x)
101 pes = x;
102 x = y;
103 y = pes;
107 return x;
110 int nsd_different_result2(int x, int y) __attribute__ ((pure));
112 __attribute__ ((noinline))
113 int nsd_different_result2(int x, int y)
115 int pes;
117 if(x <= 0 || y <= 0)
118 return 1;
120 if(x < 10)
121 y = 12;
122 else if(x == 44)
123 y = 124;
124 else
125 y = 1111;
127 if(x < y)
129 pes = x;
130 x = y;
131 y = pes;
134 while(x != y)
136 x = x - y;
138 if(y > x)
140 pes = x;
141 x = y;
142 y = pes;
146 return x;
149 __attribute__ ((noinline))
150 int s1(int x)
152 switch (x)
154 case 10:
155 case 11:
156 return 2;
157 case 12:
158 return 123;
159 default:
160 return x + 2;
164 __attribute__ ((noinline))
165 int s2(int x)
167 switch (x)
169 case 10:
170 case 11:
171 return 2;
172 case 12:
173 return 123;
174 default:
175 return x + 2;
178 int main(int argc, char **argv)
180 if(argc < 3)
181 return 1;
183 int a = atoi(argv[1]);
184 int b = atoi(argv[2]);
186 printf("Test1: %d, %d, gdc: %d\n", a, b, gcd(a, b));
187 printf("Test2: %d, %d, gdc: %d\n", a, b, nsd(a, b));
190 /* { dg-final { scan-ipa-dump "Semantic equality hit:s2->s1" "icf" } } */
191 /* { dg-final { scan-ipa-dump "Semantic equality hit:nsd_different_result2->nsd_different_result" "icf" } } */
192 /* { dg-final { scan-ipa-dump "Semantic equality hit:nsd->gcd" "icf" } } */
193 /* { dg-final { scan-ipa-dump "Equal symbols: 3" "icf" } } */
194 /* { dg-final { cleanup-ipa-dump "icf" } } */