From b94fe89c9ddfcb85dcddebfd218fa7f00b8e6608 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 26 Jun 2023 00:29:07 +0200 Subject: backend: fix mem2reg & regalloc they were broken, especially for unstructured control flow. most significant fix is to register allocator for temporaries that are used before the first definition in the source order, e.g.: @1: %x = add %y, 1 b @3 @2 %y = ... b @1 it's legal for %x to use %y there (assuming @2 dominates @1) but from the point of view of the register allocator %y is defined and freed and then used again, which broke things. the fix is to introduce phis for this situation: @1: %y.1 = phi @2 %y %x = add %y.1, 1 b @3 @2 %y = ... b @1 then regalloc phi handling code makes it work --- main.c | 1 + 1 file changed, 1 insertion(+) (limited to 'main.c') diff --git a/main.c b/main.c index 6f9e0dc..35d25ac 100644 --- a/main.c +++ b/main.c @@ -116,6 +116,7 @@ optparse(char **args) case 'p': ccopt.dbg.p = 1; break; case 'a': ccopt.dbg.a = 1; break; case 'i': ccopt.dbg.i = 1; break; + case 'l': ccopt.dbg.l = 1; break; case 'r': ccopt.dbg.r = 1; break; case 'm': ccopt.dbg.m = 1; break; default: warn(NULL, "-d: invalid debug flag %'c", *arg); -- cgit v1.2.3