From 78d992ff3052db9dc98a3074e8a4423760c342f1 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 15 Apr 2024 03:08:34 +0300 Subject: fix insert_before/after + Hopefully for good, quite a lot of messing about with those functions --- src/regalloc.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/regalloc.c') diff --git a/src/regalloc.c b/src/regalloc.c index 8c42eab..cd21f5e 100644 --- a/src/regalloc.c +++ b/src/regalloc.c @@ -401,15 +401,24 @@ static void insn_insert_before_call(struct blk *b, struct insn save, { assert((insn_at(b->insns, pos)).type == CALL); struct insn setup; - do { - if (pos < 0) + while (1) { + if (pos < 0) { + pos = 0; break; + } setup = insn_at(b->insns, pos); - pos--; - } while (has_insn_flag(setup, CALL_SETUP)); + if (has_insn_flag(setup, CALL_SETUP)) { + pos--; + continue; + } + + /* we want to insert after this instruction */ + pos++; + break; + }; - insn_insert(b, save, pos + 1); + insn_insert(b, save, pos); } static void insn_insert_after_call(struct blk *b, struct insn restore, @@ -419,13 +428,18 @@ static void insn_insert_after_call(struct blk *b, struct insn restore, size_t max = vec_len(&b->insns); struct insn setup; - do { + while (1) { if (pos == max) break; setup = insn_at(b->insns, pos); - pos++; - } while (has_insn_flag(setup, CALL_TEARDOWN)); + if (has_insn_flag(setup, CALL_TEARDOWN)) { + pos++; + continue; + } + + break; + } insn_insert(b, restore, pos); } -- cgit v1.3