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