demonstartes a bug in the tarval module
[libfirm] / ir / be / test / rtsopt.c
1 #include <math.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 /* transform into Abs node, gcc(+), icc(+), cl(+) */
7 int test_abs(int a) {
8         return abs(a);
9 }
10
11 /* transform into Abs node, gcc(+), icc(+), cl(?) */
12 long test_labs(long a) {
13         return labs(a);
14 }
15
16 /* transform into Abs node, gcc(+), icc(+), cl(+) */
17 double test_fabs(double a) {
18         return fabs(a);
19 }
20
21 /* transform info memcpy(test + strlen(test), "ab", 2), gcc(+), icc(-), cl(-) */
22 char *test_strcat(void) {
23         static char test[10] = "ab";
24         return strcat(test, "bc");
25 }
26
27 /* evaluate, gcc(+), icc(-), cl(-) */
28 char *test_strchr(void) {
29         return strchr("abc", 'b');
30 }
31
32 /* evaluate, gcc(+), icc(-), cl(-) */
33 char *test_strrchr(void) {
34         return strrchr("abc", 'b');
35 }
36
37 /* evaluate into 0, gcc(+), icc(-), cl(-) */
38 int test_strcmp1(const char *s) {
39         return strcmp(s, s);
40 }
41
42 /* transform info -(*s), gcc(+), icc(-), cl(-) */
43 int test_strcmp2(const char *s) {
44         return strcmp("", s);
45 }
46
47 /* transform info *s, gcc(+), icc(-), cl(-) */
48 int test_strcmp3(const char *s) {
49         return strcmp(s, "");
50 }
51
52 /* evaluate, gcc(+), icc(-), cl(-) */
53 int test_strcmp4(void) {
54         return strcmp("ab", "cd");
55 }
56
57 /* evaluate into 0, gcc(+), icc(-), cl(-) */
58 int test_strncmp1(const char *s, int len) {
59         return strncmp(s, s, len);
60 }
61
62 /* transform info -(*s), gcc(+), icc(-), cl(-) */
63 int test_strncmp2(const char *s) {
64         return strncmp("", s, 1);
65 }
66
67 /* transform info *s, gcc(+), icc(-), cl(-) */
68 int test_strncmp3(const char *s) {
69         return strncmp(s, "", 1);
70 }
71
72 /* evaluate, gcc(+), cl(-) */
73 int test_strncmp4(void) {
74         return strncmp("ab", "cd", 2);
75 }
76
77 /* evaluate, gcc(+), cl(-) */
78 int test_strncmp5(char *a, char *b) {
79         return strncmp(a, b, 0);
80 }
81
82 /* transform into *s = '\0', s, gcc(+), icc(-), cl(+) */
83 char *test_strcpy1(char *s) {
84         return strcpy(s, "");
85 }
86
87 /* transform into memcpy(s, c, len(c)+1), gcc(+), icc(-), cl(+) */
88 char *test_strcpy2(char *s) {
89         return strcpy(s, "ab");
90 }
91
92 /* evaluate, gcc(+), icc(+), cl(+) */
93 int test_strlen(void) {
94         return strlen("ab");
95 }
96
97 /* transform into d, gcc(+), icc(+), cl(-) */
98 void *test_memcpy1(void *d, void *s) {
99         return memcpy(d, s, 0);
100 }
101
102 /* transform into *(char *)d = *(char *)s, d, gcc(+), icc(+), cl(+) */
103 void *test_memcpy2(void *d, void *s) {
104         return memcpy(d, s, 1);
105 }
106
107 /* transform into *(short *)d = *(short *)s, d, gcc(+), icc(+), cl(+) */
108 void *test_memcpy3(short *d, short *s) {
109         return memcpy(d, s, 2);
110 }
111
112 /* transform into *(int *)d = *(int *)s, d, gcc(+), icc(+), cl(+) */
113 void *test_memcpy4(int *d, int *s) {
114         return memcpy(d, s, 4);
115 }
116
117 /* transform into *(long long *)d = *(long long *)s, d, gcc(+), icc(+), cl(+) */
118 void *test_memcpy5(long long *d, long long *s) {
119         return memcpy(d, s, 8);
120 }
121
122 /* transform into d, gcc(+), icc(+), cl(-) */
123 void *test_memset1(void *d, int C) {
124         return memset(d, C, 0);
125 }
126
127 /* transform into *(char *)d = (char)C, d, gcc(+), icc(+), cl(+) */
128 void *test_memset2(void *d, int C) {
129         return memset(d, C, 1);
130 }
131
132 /* transform into *(short *)d = (short)((char)C * 0x0101), d, gcc(+), icc(+), cl(+) */
133 void *test_memset3(short *d, int C) {
134         return memset(d, C, 2);
135 }
136
137 /* transform into *(int *)d = (int)((char)C * 0x01010101), d, gcc(+), icc(+), cl(+) */
138 void *test_memset4(int *d, int C) {
139         return memset(d, C, 4);
140 }
141
142 /* transform into *(long long *)d = (long long)((char)C) * 0x0101010101010101, d, gcc(+), icc(+), cl(+) */
143 void *test_memset5(long long *d, int C) {
144         return memset(d, C, 8);
145 }
146
147 /* evaluate into 1.0, gcc(+), icc(-), cl(-) */
148 double test_pow1(double a) {
149         return pow(1.0, a);
150 }
151
152 /* evaluate into 1.0, gcc(+), icc(+), cl(-) */
153 double test_pow2(double a) {
154         return pow(a, 0.0);
155 }
156
157 /* transform into sqrt(a), gcc(-), icc(+), cl(-) */
158 double test_pow3(double a) {
159         return pow(a, 0.5);
160 }
161
162 /* evaluate into a, gcc(+), icc(+), cl(-) */
163 double test_pow4(double a) {
164         return pow(a, 1.0);
165 }
166
167 /* evaluate into 1.0/a. gcc(+), icc(+), cl(-) */
168 double test_pow5(double a) {
169         return pow(a, -1.0);
170 }
171
172 /* evaluate into 1.0 gcc(+), icc(+), cl(-) */
173 double test_exp1(void) {
174         return exp(0.0);
175 }
176
177 /* evaluate into M_E gcc(+), icc(-), cl(?) */
178 double test_exp2(void) {
179         return exp(1.0);
180 }
181
182 /* evaluate gcc(-), icc(-), cl(?) */
183 double test_exp3(void) {
184         return exp(7.3434);
185 }
186
187 /* evaluate into 0.0 gcc(+), icc(-), cl(?) */
188 double test_log1(void) {
189         return log(1.0);
190 }
191
192 /* evaluate into 0.0 gcc(+), icc(-), cl(?) */
193 double test_log2(void) {
194         return log2(1.0);
195 }
196
197 /* evaluate into 0.0 gcc(+), icc(-), cl(?) */
198 double test_log3(void) {
199         return log10(1.0);
200 }
201
202 /* evaluate into 0.0 gcc(+), icc(-), cl(?) */
203 double test_trunc1(void) {
204         return trunc(0.1);
205 }
206
207 /* evaluate into 0.0 gcc(+), icc(-), cl(?) */
208 double test_trunc2(void) {
209         return trunc(-8.9);
210 }
211
212 /* transform into putchar, gcc(+), icc(-), cl(-) */
213 void test_printf1() {
214         printf("\n");
215 }
216
217 /* transform into putchar(c), gcc(+), icc(+), cl(-) */
218 void test_printf2(char c) {
219         printf("%c", c);
220 }
221
222 /* transform into puts(s), gcc(+), icc(-), cl(-) */
223 void test_printf3(char *s) {
224         printf("%s\n", s);
225 }
226
227 /* transform into fwrite(s,strlen(s),f), gcc(+) OR fputs(s, f), icc(+), cl(-) */
228 void test_fprintf1(FILE *f) {
229         fprintf(f, "ab");
230 }
231
232 /* transform into fputc(c,f), gcc(+), icc(+), cl(-) */
233 void test_fprintf2(FILE *f, char c) {
234         fprintf(f, "%c", c);
235 }
236
237 /* transform into fputs(s,file), gcc(+), icc(+), cl(-) */
238 void test_fprintf3(FILE *f, char *s) {
239         fprintf(f, "%s", s);
240 }
241
242 /* transform into memcpy(d,s,strlen(s)+1,1), gcc(+), icc(-), cl(-) */
243 void test_sprintf1(char *d) {
244         sprintf(d, "ab");
245 }
246
247 /* transform into d[0] = c; d[1] = '\0';, gcc(-), icc(-), cl(-) */
248 void test_sprintf2(char *d, char c) {
249         sprintf(d, "%c", c);
250 }
251
252 /* transform into memcpy(d, s, strlen(s)+1, 1)), gcc(-), icc(-), cl(-) */
253 void test_sprintf3(char *d, char *s) {
254         sprintf(d, "%s", s);
255 }
256
257 /* transform fwrite(s,1,strlen(s),F), gcc(+), icc(-), cl(-) */
258 void test_fputs(FILE *f) {
259         fputs("abs", f);
260 }
261
262 /* evaluate to 0, gcc(-), icc(-), cl(-) */
263 int test_fwrite1(FILE *f, char *s, int l) {
264         return fwrite(s, 0, l, f);
265 }
266
267 /* evaluate to 0, gcc(-), icc(-), cl(-) */
268 int test_fwrite2(FILE *f, char *s, int l) {
269         return fwrite(s, l, 0, f);
270 }
271
272 /* transform into fputc(s[0],F) if this is usefull ..., gcc(-), icc(-), cl(-) */
273 int test_fwrite3(FILE *f, char *s, int l) {
274         return fwrite(s,1,1,f);
275 }
276
277 /* evaluate, gcc(+), cl(-) */
278 double test_sin1(void) {
279         return sin(0.0);
280 }
281
282 /* transform into fsin, gcc(+), cl(-) */
283 double test_sin2(double x) {
284         return sin(x);
285 }
286
287 /* transform into cos(x), gcc(+), icc(-), cl(-) */
288 double test_cos1(double x) {
289         return cos(-x);
290 }
291
292 /* evaluate, gcc(+), cl(-) */
293 double test_cos2(void) {
294         return cos(0.0);
295 }
296
297 /* transform into fcos, gcc(+), cl(-) */
298 double test_cos3(double x) {
299         return cos(x);
300 }
301
302 /* transform into cosf(x), gcc(+), icc(-), cl(-) */
303 float test_cosf1(float x) {
304         return cosf(-x);
305 }
306
307 #if 0
308 /* transform into cosl(x), gcc(+), icc(-), cl(-) */
309 long double test_cosl(long double x) {
310         return cosl(-x);
311 }
312 #endif
313
314 /* evaluate, gcc(+), cl(-) */
315 double test_tan1(void) {
316         return tan(0);
317 }
318
319 /* evaluate, gcc(-), cl(-) */
320 double test_asin1(void) {
321         return asin(0.0);
322 }
323
324 /* evaluate, gcc(-), cl(-) */
325 double test_acos1(void) {
326         return acos(1.0);
327 }
328
329 /* evaluate, gcc(+), cl(-) */
330 double test_atans1(void) {
331         return atan(0.0);
332 }
333
334 /* evaluate into 0.0, gcc(+), icc(+), cl(-) */
335 double test_sqrt1(void) {
336         return sqrt(0.0);
337 }
338
339 /* evaluate into 1.0, gcc(+), icc(+), cl(-) */
340 double test_sqrt2(void) {
341         return sqrt(1.0);
342 }
343
344 /* evaluate, gcc(+), icc(+), cl(-) */
345 double test_sqrt3(void) {
346         return sqrt(7.345);
347 }
348
349 /* evaluate into 0.0, gcc(+), icc(-), cl(?) */
350 double test_cbrt1(void) {
351         return cbrt(0.0);
352 }
353
354 /* evaluate into 1.0, gcc(+), icc(-), cl(?) */
355 double test_cbrt2(void) {
356         return cbrt(1.0);
357 }
358
359 /* evaluate into -1.0, gcc(+), icc(-), cl(?) */
360 double test_cbrt3(void) {
361         return cbrt(-1.0);
362 }
363
364 /* transform exit(3) into a return 3, gcc(-), icc(-), cl(-) */
365 int main() {
366         printf("%f\n", test_asin1());
367         printf("%f\n", test_acos1());
368         exit(0);
369         return 42;
370 }