- split get_pairidx_for_regidx(), always called with constant parameter
[libfirm] / ir / be / test / pbqpHeur2.c
1 /**
2  * This test case should provoke incompatible heuristical decision of the
3  * PBQP solver, which lead to infinity cost, i.e. no solution of the PBQP could
4  * found.
5  *
6  * It is necessary to manipulation some cost vectors to let the PBQP solver
7  * "crash". More details are shown below.
8  *
9  * This also seems more a missing feature of the PBQP solver than a counter
10  * example against the PBQP approach for instruction selection.
11  */
12
13 unsigned *block;
14 unsigned *block1, *block2, *block3, *block4, *block5, *block6;
15 unsigned *block7, *block8,*block9,*block10,*block11;
16 volatile unsigned arr[100];
17 unsigned b = 3008;
18 unsigned g1,g2,g3;
19 unsigned g4,g5,g6;
20 unsigned g7,g8;
21 unsigned h1,h2,h3;
22 unsigned h4,h5,h6;
23 unsigned h7,h8,h9;
24 unsigned k1,k2,k3;
25 unsigned k4,k5,k6;
26 unsigned kb1,kb2,kb3;
27 unsigned kc1,kc2,kc3;
28 unsigned kd1,kd2,kd3;
29 unsigned ke1,ke2,ke3;
30
31 unsigned k3_3(char* base, unsigned i1, unsigned i2, unsigned i3, unsigned k1, unsigned k2, unsigned k3)
32 {
33         char a1, a2, a3;
34         char b1, b2, b3;
35         char c1, c2, c3;
36
37         a1 = i1 + k1;
38         a2 = base[i2 + k1];
39         a3 = base[i3 + k1];
40
41         b1 = i1 + k2;
42         b2 = base[i2 + k2];
43         b3 = base[i3 + k2];
44
45         c1 = i1 + k3;
46         c2 = base[i2 + k3];
47         c3 = base[i3 + k3];
48
49         if (a1 != a2)
50                 return a3;
51         if (b1 != b2)
52                 return b3;
53         if (c1 != c2)
54                 return c3;
55
56         return 0;
57 }
58
59 unsigned k3_3_2(char* base, int i1, int i2, int i3, int k1, int k2, int k3)
60 {
61         char a1, a2, a3;
62         char b1, b2, b3;
63         char c1, c2, c3;
64
65         a1 = base[i1 + k1];
66         a2 = base[i2 + k1];
67         a3 = base[i3 + k1];
68
69         b1 = base[i1 + k2];
70         b2 = base[i2 + k2];
71         b3 = base[i3 + k2];
72
73         c1 = base[i1 + k3];
74         c2 = base[i2 + k3];
75         c3 = base[i3 + k3];
76
77         if (a1 != a2)
78                 return a3;
79         if (b1 != b2)
80                 return b3;
81         if (c1 != c2)
82                 return c3;
83
84         return 0;
85 }
86
87 unsigned k3_3_am(char* base, unsigned i1, unsigned i2, unsigned i3, unsigned k1, unsigned k2, unsigned k3)
88 {
89         char a1, a2, a3;
90         char b1, b2, b3;
91         char c1, c2, c3;
92
93         a1 = base[i1 + k1];
94         a2 = base[i2 + k1];
95         a3 = base[i3 + k1];
96
97         b1 = base[i1 + k2];
98         b2 = base[i2 + k2];
99         b3 = base[i3 + k2];
100
101         c1 = base[i1 + k3];
102         c2 = base[i2 + k3];
103         c3 = base[i3 + k3];
104
105         if (a1 != a2)
106                 return a3;
107         if (b1 != b2)
108                 return b3;
109         if (c1 != c2)
110                 return c3;
111
112         return 0;
113 }
114
115 void full_am(unsigned base, int index, unsigned base2, int index2, unsigned base3, int index3, unsigned base4, int index4, unsigned base5, int index5)
116 {
117         /*
118          * This is the core of this example.
119          * The following line can be done with one instruction
120          * (add with address mode) on x86.
121          * We provoke four heuristical decision on nodes of this address mode
122          * pattern. The mean idea is that the root (the add node) choose this
123          * pattern, but the decision on the shift const forbid these.
124          * To achieve this you have to manipulate the cost of the shift const by
125          * hand!
126          * The other two heuristical decision ensure, that the two heuristical
127          * decision above are separated, i.e. there are at least two irreducible
128          * nodes between them.
129          */
130         unsigned ca = arr[index] + base;
131
132         /*
133          * The following function ensure irreducible users of given nodes.
134          * All of these function have to be inlined.
135          */
136
137         /* users for shift const */
138         b = k3_3_am(block, h1, h2, h3, 2, 3, 4);
139         b = k3_3_am(block, h4, h5, h6, 2, 5, 6);
140         b = k3_3_am(block, h7, h8, h9, 2, 7, 8);
141
142         /* users for symconst */
143         unsigned cb = arr[index2] + base2;
144         b = k3_3(block1, cb, kb1, kb2, 101, 102, 103);
145         unsigned cc = arr[index3] + base3;
146         b = k3_3(block2, cc, kc1, kc2, 111, 112, 113);
147         unsigned cd = arr[index4] + base4;
148         b = k3_3(block3, cd, kd1, kd2, 121, 122, 123);
149         unsigned ce = arr[index5] + base5;
150         b = k3_3(block4, ce, ke1, ke2, 131, 132, 133);
151
152         /* users for offset */
153         b = k3_3_2(block5, 4 * index, g1, g2, 31, 32, 33);
154         b = k3_3_2(block6, 4 * index, g3, g4, 34, 35, 36);
155         b = k3_3_2(block7, 4 * index, g5, g6, 37, 38, 39);
156         b = k3_3_2(block8, 4 * index, g7, g8, 40, 41, 42);
157
158         /* users for computed value */
159         b = k3_3(block9, ca, k1, k2, 13, 14, 15);
160         b = k3_3(block10, ca, k3, k4, 16, 17, 18);
161         b = k3_3(block11, ca, k5, k6, 19, 20, 21);
162 }
163
164 int main(int argc, char **argv) {
165         return 0;
166 }