diff options
| author | 2026-01-08 12:21:40 +0100 | |
|---|---|---|
| committer | 2026-01-08 12:21:40 +0100 | |
| commit | 2769a58ab256522eafec1f833676ceffb4baff24 (patch) | |
| tree | 6c76f99d14598d7cf0a93a08a8dcd714752236f2 | |
| parent | 45036f2a6f612d8bbe071d332c5a0baf92783044 (diff) | |
codegen: eliminate redudant consecutive ret sequences
| -rw-r--r-- | ir/regalloc.c | 1 | ||||
| -rw-r--r-- | x86_64/emit.c | 2 |
2 files changed, 3 insertions, 0 deletions
diff --git a/ir/regalloc.c b/ir/regalloc.c index 14dfafc..9057d43 100644 --- a/ir/regalloc.c +++ b/ir/regalloc.c @@ -1197,6 +1197,7 @@ devirt(struct rega *ra, struct block *blk) } } + if (allnops) vfree(&blk->ins); return allnops; } diff --git a/x86_64/emit.c b/x86_64/emit.c index 783ea20..17ea1f3 100644 --- a/x86_64/emit.c +++ b/x86_64/emit.c @@ -1372,6 +1372,8 @@ emitbin(struct function *fn) emitinstr(pcode, fn, blk, i, &instrtab[blk->ins.p[i]]); if (blk->jmp.t == Jret) { + if (blk->lnext != fn->entry && blk->lnext->jmp.t == Jret && blk->lnext->ins.n == 0) + continue; /* fallthru to next blk's RET */ /* epilogue */ if (fn->stksiz && (saverestore || !usebp)) Xadd(pcode, KPTR, mkoper(OREG, .reg = RSP), mkoper(OIMM, .imm = fn->stksiz)); |