From e4f8fc6306cc14edd600d7691142e21af711f603 Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 21 Nov 2025 09:38:15 +0100 Subject: cfg: sortrpo delete unreachable blocks with allocas by hoisting them to the entry block --- ir/cfg.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'ir') diff --git a/ir/cfg.c b/ir/cfg.c index 8e86cb2..e79dc63 100644 --- a/ir/cfg.c +++ b/ir/cfg.c @@ -14,7 +14,7 @@ void sortrpo(struct function *fn) { static struct block **rpobuf; - struct block **rpoend, **rpo; + struct block **rpoend, **rpo, *blk, *next; int i, ndead; xbgrow(&rpobuf, fn->nblk); @@ -24,19 +24,20 @@ sortrpo(struct function *fn) fn->entry->id = 0; porec(&rpo, fn->entry); ndead = rpo - rpobuf; - for (struct block *blk = fn->entry->lprev, *next; blk != fn->entry; blk = next) { + if (ndead > 0) for (blk = fn->entry->lprev; blk != fn->entry; blk = next) { next = blk->lprev; if (!wasvisited(blk)) { for (int i = 0; i < blk->ins.n; ++i) { - /* don't delete unreachable blocks with alloca pseudo-instrs */ - if (oisalloca(instrtab[blk->ins.p[i]].op)) - goto Next; + /* if unreachable block has alloca pseudo-instrs, move them to the entry + * to be able to delete it */ + if (oisalloca(instrtab[blk->ins.p[i]].op)) { + vpush(&fn->entry->ins, blk->ins.p[i]); + } } for (int i = 0; i < blk->npred; ++i) assert(!wasvisited(blkpred(blk, i))); freeblk(fn, blk); --ndead; - Next:; } } for (i = 1, ++rpo; rpo < rpoend; ++rpo, ++i) { -- cgit v1.2.3