different test to catch the bug in the implementation...
[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 shr1(int x) {
103         return -(x >> 31);
104 }
105
106 int shrs1(unsigned x) {
107         return -(x >> 31);
108 }
109
110 int demorgan1(int a, int b) {
111         return (~a) & (~b);
112 }
113
114 int demorgan2(int a, int b) {
115         return (~a) | (~b);
116 }
117
118 int eor1(int a, int b) {
119         return a & (a ^ b);
120 }
121
122 int main(void)
123 {
124 #define TU(func,x,expect) \
125         printf("%s(%d) = %d (should be %d)\n", #func, x, func(x), expect);
126 #define TB(func,x,y,expect) \
127         printf("%s(%d,%d) = %d (should be %d)\n", #func, x, y, func(x,y), expect);
128 #define TT(func,x,y,z,expect) \
129         printf("%s(%d,%d,%d) = %d (should be %d)\n", #func, x, y, z, func(x,y,z), expect);
130
131         TU(mul0, 3, -126);
132         TB(mul1, 20, 3, 60);
133         TT(mul2, 9, 2, 5, 27);
134         TT(mul3, 5, 2, 9, 27);
135         TT(sub0, 42, 17, 59, 84);
136         TB(sub1, 23, 17, -691);
137         TB(sub2, 42, 17, 59);
138         TB(sub3, 42, 17, -59);
139         TU(sub4, 42, 49);
140         TB(cmp1, 42, 17, 0);
141         TB(cmp2, 42, 17, 1);
142         TB(cmp3, 42, 17, 0);
143         TB(cmp4, 42, 17, 1);
144         TT(cmp5, 42, 17, -4, 0);
145         TT(cmp6, 42, 17, -4, 1);
146         TT(cmp7, 42, 17, -4, 0);
147         TT(cmp8, 42, 17, -4, 1);
148         TU(cmp9, -3, 1);
149         TU(cmp10, -3, 0);
150         TB(and1, 42, 17, 42);
151         TB(and2, 42, 17, 42^17);
152         TU(add1, -3, -1);
153         TU(shr1, -3, 1);
154         TU(shrs1, -3, -1);
155         TB(demorgan1, 42, 17, ~(42|17));
156         TB(demorgan2, 42, 17, ~(42&17));
157         TB(eor1, 42, 44, 42&~44);
158 }