more test added
[libfirm] / ir / be / test / localopts.c
1 /*$ -fno-inline $*/
2 #include <stdio.h>
3
4 #define CONST 42
5
6 int mul0(int x)
7 {
8         return -x * CONST;
9 }
10
11 int mul1(int x, int y)
12 {
13         return -x * -y;
14 }
15
16 int mul2(int x, int y, int z)
17 {
18         return -x * (y - z);
19 }
20
21 int mul3(int x, int y, int z)
22 {
23         return (x - y) * z;
24 }
25
26 int sub0(int x, int y, int z)
27 {
28         return x - (y - z);
29 }
30
31 int sub1(int x, int y)
32 {
33         return x - (y * CONST);
34 }
35
36 int sub2(int x, int y)
37 {
38         return x - -y;
39 }
40
41 int sub3(int x, int y)
42 {
43         return -x - y;
44 }
45
46 int sub4(int x) {
47         return 6 - ~x;
48 }
49
50 int cmp1(int x, int y) {
51         return -x == -y;
52 }
53
54 int cmp2(int x, int y) {
55         return -x != -y;
56 }
57
58 int cmp3(int x, int y) {
59         return ~x == ~y;
60 }
61
62 int cmp4(int x, int y) {
63         return ~x != ~y;
64 }
65
66 int cmp5(int x, int y, int z) {
67         return x + z == z + y;
68 }
69
70 int cmp6(int x, int y, int z) {
71         return x + z != y + z;
72 }
73
74 int cmp7(int x, int y, int z) {
75         return x - z == y - z;
76 }
77
78 int cmp8(int x, int y, int z) {
79         return z -x != z - y;
80 }
81
82 int cmp9(int x) {
83         return -x == 3;
84 }
85
86 int cmp10(int x) {
87         return -x != 3;
88 }
89
90 int and1(int a, int b) {
91         return (a|b)&a;
92 }
93
94 int and2(int a, int b) {
95         return (a|b) & ~(a&b);
96 }
97
98 int add1(int x) {
99         return x + ~x;
100 }
101
102 int main(void)
103 {
104 #define TU(func,x,expect) \
105         printf("%s(%d) = %d (should be %d)\n", #func, x, func(x), expect);
106 #define TB(func,x,y,expect) \
107         printf("%s(%d,%d) = %d (should be %d)\n", #func, x, y, func(x,y), expect);
108 #define TT(func,x,y,z,expect) \
109         printf("%s(%d,%d,%d) = %d (should be %d)\n", #func, x, y, z, func(x,y,z), expect);
110
111         TU(mul0, 3, -126);
112         TB(mul1, 20, 3, 60);
113         TT(mul2, 9, 2, 5, 27);
114         TT(mul3, 5, 2, 9, 27);
115         TT(sub0, 42, 17, 59, 84);
116         TB(sub1, 23, 17, -691);
117         TB(sub2, 42, 17, 59);
118         TB(sub3, 42, 17, -59);
119         TU(sub4, 42, 49);
120         TB(cmp1, 42, 17, 0);
121         TB(cmp2, 42, 17, 1);
122         TB(cmp3, 42, 17, 0);
123         TB(cmp4, 42, 17, 1);
124         TT(cmp5, 42, 17, -4, 0);
125         TT(cmp6, 42, 17, -4, 1);
126         TT(cmp7, 42, 17, -4, 0);
127         TT(cmp8, 42, 17, -4, 1);
128         TU(cmp9, -3, 1);
129         TU(cmp10, -3, 0);
130         TB(and1, 42, 17, 42);
131         TB(and2, 42, 17, 42^17);
132         TU(add1, -3, -1);
133 }