aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir/builder.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-24 12:58:46 +0100
committerlemon <lsof@mailbox.org>2025-11-24 12:58:46 +0100
commit5ba62d79923a48c1b1f6a8fc236650f5a8281844 (patch)
tree7edc0d8828e1e5b71eb194b03672665e89ce754d /ir/builder.c
parent31122c856c193085d427dc74459847a280728805 (diff)
ir: simplify some occurrences of single-argument phis
Diffstat (limited to 'ir/builder.c')
-rw-r--r--ir/builder.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/ir/builder.c b/ir/builder.c
index c793f80..4b25329 100644
--- a/ir/builder.c
+++ b/ir/builder.c
@@ -228,19 +228,18 @@ useblk(struct function *fn, struct block *blk)
union ref
addphi(struct function *fn, enum irclass cls, union ref *r)
{
- int new;
- struct instr ins = { Ophi, cls };
- union ref *refs = NULL;
+ assert(fn->curblk);
+ if (fn->curblk->npred == 0) return UNDREF;
+ if (fn->curblk->npred == 1) /* 1-argument phi is identity */
+ return *r;
+ union ref *refs = NULL;
xbgrow(&refs, fn->curblk->npred);
memcpy(refs, r, fn->curblk->npred * sizeof *r);
vpush(&phitab, refs);
- ins.l = mkref(RXXX, phitab.n-1);
-
- assert(fn->curblk != NULL);
/*assert(fn->curblk->ins.n == 0);*/
- new = allocinstr();
- instrtab[new] = ins;
+ int new = allocinstr();
+ instrtab[new] = mkinstr(Ophi, cls, .l.i = phitab.n-1);
for (int i = 0; i < fn->curblk->npred; ++i) {
adduse(fn->curblk, new, r[i]);
}