From b6afdd647ce394dc7e1281cc42c05b6981cd62b2 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 19 Oct 2025 11:07:07 +0200 Subject: codegen bugfixes --- ir/abi0.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ir/abi0.c') 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; + } } } } -- cgit v1.2.3