4 * Register allocator tests.
9 public static int Main (String[] args) {
10 return TestDriver.RunTests (typeof (Tests));
13 static void call_clobber_inner () {
16 public static int test_15_clobber_1 () {
19 for (int i = 0; i < 10; ++i)
21 for (int i = 0; i < 5; ++i)
24 // clob == '1' and dreg == sreg2
29 public static int test_15_clobber_1_fp () {
32 for (int i = 0; i < 10; ++i)
34 for (int i = 0; i < 5; ++i)
37 // clob == '1' and dreg == sreg2
42 public static int test_5_call_clobber () {
43 // A call clobbers some registers so variables in those registers need to be spilled
44 // and later reloaded to a register
48 call_clobber_inner ();
53 static int call_clobber_inner2 () {
57 public static int test_7_call_clobber_dreg () {
58 // A call doesn't clobber its dreg
62 a = call_clobber_inner2 ();
67 public static int test_9_spill_if_then_else () {
68 // Spilling variables in one branch of an if-then-else
74 call_clobber_inner ();
80 public static int test_3_spill_reload_if_then_else () {
81 // Spilling and reloading variables in one branch of an if-then-else
88 call_clobber_inner ();
95 public static int test_5_spill_loop () {
98 for (i = 0; i < 5; ++i)
99 call_clobber_inner ();
104 public unsafe static int test_0_volatile () {
124 public unsafe static int test_0_volatile_unused () {
134 public unsafe static int test_0_volatile_unused_2 () {
145 static int ref_int (int i, ref int b, int j) {
151 public static int test_0_volatile_unused_3 () {
152 // b's def has no use so its interval is split at a position not covered by the interval
154 if (ref_int (99, ref b, 100) != 42)
157 if (ref_int (99, ref b, 100) != 43)
164 static int ref_bool (int i, ref bool b1, ref bool b2, ref bool b3) {
172 public static int test_0_volatile_regress_1 () {
173 // Spill stores should precede spill loads at a given position
174 for (int i = 0; i < 8; i++) {
175 bool b1 = (i & 4) != 0;
176 bool b2 = (i & 2) != 0;
177 bool b3 = (i & 1) != 0;
178 bool orig_b1 = b1, orig_b2 = b2, orig_b3 = b3;
179 if (ref_bool(i, ref b1, ref b2, ref b3) != 0)
192 public static int test_0_clobber_regress_1 () {
193 object[] a11 = new object [10];
194 object o = new Object ();
195 // A spill load is inserted before the backward branch, clobbering one of the
196 // registers used in the comparison
197 for (int i = 0; i < 10; ++i)
203 static int return_arg (int i) {
207 public static int test_0_spill_regress_1 () {
209 for (int i = 0; i < 3; i++) {
210 // i is spilled by the call, then reloaded for the loop check
211 // make sure the move from its first reg to its second is inserted in the
212 // if body bblock, not the for body bblock
215 if (return_arg (j) != 5)
223 public static int test_0_spill_regress_2 () {
224 double[] temporaries = new double[3];
225 for (int i = 0; i < 3; i++) {
226 // i and temporaries are spilled by the call, then reloaded after the call
227 // make sure the two moves inserted in the if bblock are in the proper order
230 temporaries [i] = return_arg (i);
237 static int many_args_unused (int i, int j, int k, int l, int m, int n, int p, int q) {
241 public static int test_0_unused_args () {
242 return many_args_unused (0, 1, 2, 3, 4, 5, 6, 7);
245 public unsafe void ClearBuffer (byte *buffer, int i) {
247 byte *b = stackalloc byte [4];
250 public unsafe bool instance_method_1 (string s, string target, int start, int length, int opt) {
251 byte* alwaysMatchFlags = stackalloc byte [16];
252 byte* neverMatchFlags = stackalloc byte [16];
253 byte* targetSortKey = stackalloc byte [4];
254 byte* sk1 = stackalloc byte [4];
255 byte* sk2 = stackalloc byte [4];
256 ClearBuffer (alwaysMatchFlags, 16);
257 ClearBuffer (neverMatchFlags, 16);
258 ClearBuffer (targetSortKey, 4);
259 ClearBuffer (sk1, 4);
260 ClearBuffer (sk2, 4);
262 return this == null && s == target && start == length && length == opt && alwaysMatchFlags == neverMatchFlags && neverMatchFlags == targetSortKey && sk1 == sk2;
265 public static int test_0_spill_regress_3 () {
266 new Tests ().instance_method_1 (null, null, 0, 0, 0);
270 unsafe bool MatchesBackward (string s, ref int idx, int end, int orgStart, int ti, byte* sortkey, bool noLv4, ref object ctx) {
272 byte *b = stackalloc byte [4];
275 throw new Exception ();
281 unsafe int LastIndexOfSortKey (string s, int start, int orgStart, int length, byte* sortkey, int ti, bool noLv4, ref object ctx)
283 // ctx is initially allocated to the stack, when it is reloaded before the call,
284 // %rax is spilled to free up the register, then ctx is allocated to %rax for its
285 // whole lifetime, but %rax is not available for this since it is clobbered by the
287 int end = start - length;
291 if (MatchesBackward (s, ref idx, end, orgStart,
292 ti, sortkey, noLv4, ref ctx))
298 public unsafe static int test_0_spill_regress_4 () {
299 object o = new Object ();
300 new Tests ().LastIndexOfSortKey ("", 10, 0, 5, null, 0, false, ref o);