From 87dc3ea290a4ba75f153c5bb8b9fb87ec548e64f Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Mon, 21 Nov 2022 14:08:08 +0100 Subject: [PATCH] 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. --- rega.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rega.c b/rega.c index dd77a75..c97d1e1 100644 --- a/rega.c +++ b/rega.c @@ -359,8 +359,6 @@ doblk(Blk *b, RMap *cur) Mem *m; Ref *ra[4]; - for (r=0; bsiter(b->out, &r) && rjmp.arg) == RTmp) b->jmp.arg = ralloc(cur, b->jmp.arg.val); curi = &insb[NIns]; @@ -534,6 +532,8 @@ rega(Fn *fn) rl[j] = t; } } + for (r=0; bsiter(b->out, &r) && r