From 61367525aea8f3f11c29e628fe49768dda959cef Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 19 Jun 2023 22:33:35 +0200 Subject: backend: compile comparison instrs and branches --- regalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'regalloc.c') diff --git a/regalloc.c b/regalloc.c index a8980cf..c3afe70 100644 --- a/regalloc.c +++ b/regalloc.c @@ -242,7 +242,9 @@ use(struct rega *ra, struct block *blk, int curi, enum op op, int hint, union re vpush(&ra->freestk, s); } } - *ref = mkref(RREG, ins->reg-1); + /* do not patch ref if it's cond branch arg, emit() wants to know what instr it is */ + if (ref != blk->jmp.arg || blk->jmp.t != Jb) + *ref = mkref(RREG, ins->reg-1); } void @@ -273,6 +275,9 @@ regalloc(struct function *fn) do { for (int i = 0; i < 2; ++i) { if (!blk->jmp.arg[i].t) break; + /* do not allocate a reg for a cmp op used a branch argument, since it's a pseudo op */ + if (blk->jmp.t == Jb && blk->jmp.arg[i].t == RTMP && oiscmp(instrtab[blk->jmp.arg[i].i].op)) + break; use(&ra, blk, blk->ins.n-1, (blk->jmp.t != Jb) - 1, blk->jmp.t == Jret ? fn->abiret[i].reg : -1, &blk->jmp.arg[i], blk->jmp.arg[!i]); -- cgit v1.2.3