Browse Source

fix allocation ordering bug in rega

When we process one block, we
start by allocating registers
for all the temporaries live
at the exit of the block.

Before this patch we processed
temps first, then in doblk() we
would mark globally live registers
allocated. This meant that temps
could get wrongly assigned a live
register.

The fix is simple: we now process
registers first at block exits,
then allocate temps.
Quentin Carbonneaux 3 years ago
parent
commit
87dc3ea290
1 changed files with 2 additions and 2 deletions
  1. 2 2
      rega.c

+ 2 - 2
rega.c

@@ -359,8 +359,6 @@ doblk(Blk *b, RMap *cur)
 	Mem *m;
 	Mem *m;
 	Ref *ra[4];
 	Ref *ra[4];
 
 
-	for (r=0; bsiter(b->out, &r) && r<Tmp0; r++)
-		radd(cur, r, r);
 	if (rtype(b->jmp.arg) == RTmp)
 	if (rtype(b->jmp.arg) == RTmp)
 		b->jmp.arg = ralloc(cur, b->jmp.arg.val);
 		b->jmp.arg = ralloc(cur, b->jmp.arg.val);
 	curi = &insb[NIns];
 	curi = &insb[NIns];
@@ -534,6 +532,8 @@ rega(Fn *fn)
 				rl[j] = t;
 				rl[j] = t;
 			}
 			}
 		}
 		}
+		for (r=0; bsiter(b->out, &r) && r<Tmp0; r++)
+			radd(&cur, r, r);
 		for (j=0; j<x; j++)
 		for (j=0; j<x; j++)
 			ralloctry(&cur, rl[j], 1);
 			ralloctry(&cur, rl[j], 1);
 		for (j=0; j<x; j++)
 		for (j=0; j<x; j++)