aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-10-19 11:07:07 +0200
committerlemon <lsof@mailbox.org>2025-10-19 11:07:07 +0200
commitb6afdd647ce394dc7e1281cc42c05b6981cd62b2 (patch)
tree1375d2f278441d8c094acefb50c282cd20322bdd
parent9bf5c97d3b5391c6cf3757629d09a53403a64f45 (diff)
codegen bugfixes
-rw-r--r--ir/abi0.c9
-rw-r--r--ir/regalloc.c10
2 files changed, 16 insertions, 3 deletions
diff --git a/ir/abi0.c b/ir/abi0.c
index 82d10a5..9e30ab7 100644
--- a/ir/abi0.c
+++ b/ir/abi0.c
@@ -249,6 +249,7 @@ abi0_call(struct function *fn, struct instr *ins, struct block *blk, int *curi)
}
for (int i = 0; i < nret; ++i) {
struct instr store = {0};
+ int iref;
/* XXX this can generate unaligned stores */
switch (call->abiret[i].ty.cls) {
default: assert(0);
@@ -264,6 +265,14 @@ abi0_call(struct function *fn, struct instr *ins, struct block *blk, int *curi)
}
store.r = r[i];
insertinstr(blk, ++*curi, store);
+ iref = retmem.i;
+ if (instrnuse[iref] > 1) {
+ /* make store the first use */
+ struct use tmp = instruse[iref][instrnuse[iref - 1]];
+ for (int i = instrnuse[iref] - 1; i > 0; --i)
+ instruse[iref][i] = instruse[iref][i-1];
+ instruse[iref][0] = tmp;
+ }
}
}
}
diff --git a/ir/regalloc.c b/ir/regalloc.c
index 64dcfac..1e23a8a 100644
--- a/ir/regalloc.c
+++ b/ir/regalloc.c
@@ -1026,7 +1026,8 @@ devirt(struct rega *ra, struct block *blk)
insertinstr(blk, ++curi, mkinstr(store, 0, .r = mkref(RREG, reg))).i,
alloc->a*8);
}
- } else if (!ins->reg && insrescls(*ins) && ins->op != Omove && !ins->keep) {
+ }
+ if (!ins->reg && insrescls(*ins) && ins->op != Omove && !ins->keep) {
/* dead */
Nop:
ins->op = Onop;
@@ -1036,12 +1037,15 @@ devirt(struct rega *ra, struct block *blk)
} else if (ins->op == Ocopy && ins->l.t == RREG && ins->reg-1 == ins->l.i) {
/* r1 = copy r2 / r1=r2 */
goto Nop;
- } else if (ins->inplace && ins->l.t == RREG && ins->reg && ins->reg-1 != ins->l.i) {
+ } else if (ins->op != Onop) {
+ allnops = 0;
+ }
+ if (ins->inplace && ins->l.t == RREG && ins->reg && ins->reg-1 != ins->l.i) {
/* fixup in-place (two-address) instructions */
allnops = 0;
insertinstr(blk, curi++, mkmove(ins->cls, ins->reg-1, ins->l.i));
ins->l.i = ins->reg-1;
- } else if (ins->op != Onop) allnops = 0;
+ }
}
return allnops;