aboutsummaryrefslogtreecommitdiffhomepage
path: root/optmem.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-09-15 17:11:05 +0200
committerlemon <lsof@mailbox.org>2025-09-15 17:11:46 +0200
commitb8ae5b14c7bbe28161ea83f4c10045f8af5b766a (patch)
treeb53e99abf48f82435220aecea86c5569b85a74e6 /optmem.c
parentbdf9776b0b127b53a34be07f8adc0541df78654e (diff)
mem2reg: fix deltrivialphis bug
Diffstat (limited to 'optmem.c')
-rw-r--r--optmem.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/optmem.c b/optmem.c
index 00be3a0..9e8d1c6 100644
--- a/optmem.c
+++ b/optmem.c
@@ -43,17 +43,15 @@ deltrivialphis(struct ssabuilder *sb, struct block *blk, union ref phiref)
assert(instrtab[phiref.i].op == Ophi);
- if (phiref.i == 4)
- efmt("");
-
for (int i = 0; i < blk->npred; ++i) {
- if (args[i].bits == same.bits || args[i].bits == phiref.bits)
+ if (args[i].bits == same.bits || args[i].bits == phiref.bits) {
continue; /* unique value or self-reference */
- if (same.bits != 0) {
+ } if (same.bits != 0) {
return phiref; /* non-trivial */
}
same = args[i];
}
+
if (same.bits == 0)
same = UNDREF; /* the phi is unreachable or in the start block */
@@ -78,6 +76,7 @@ Redo:
union ref vphi2 = deltrivialphis(sb, use->blk, it);
if (vphi2.bits != it.bits) {
/* deletion happened so phiref use may have changed */
+ if (same.bits == it.bits) same.bits = vphi2.bits;
goto Redo;
}
}
@@ -106,6 +105,7 @@ writevar(struct ssabuilder *sb, int var, struct block *blk, union ref val)
if (!(pcurdefs = imap_get(&sb->curdefs, var))) {
pcurdefs = imap_set(&sb->curdefs, var, xcalloc(sb->nblk * sizeof(union ref)));
}
+ if (val.t == RTMP) assert(instrtab[val.i].op != Onop);
(*pcurdefs)[blk->id] = val;
}
@@ -144,6 +144,7 @@ trysealrec(struct ssabuilder *sb, struct block *blk)
{
vec_of(struct pendingphi) *pending;
+Recur:
if (bstest(sb->sealed, blk->id)) return 1;
if (blk->id > sb->lastvisit) return 0;
markvisited(blk);
@@ -160,8 +161,14 @@ trysealrec(struct ssabuilder *sb, struct block *blk)
mkref(RTMP, pending->p[i].phi));
}
vfree(pending);
- if (blk->s1) trysealrec(sb, blk->s1);
- if (blk->s2) trysealrec(sb, blk->s2);
+ if (blk->s1 && !blk->s2) {
+ blk = blk->s1;
+ goto Recur;
+ } else if (blk->s1 && blk->s2) {
+ trysealrec(sb, blk->s1);
+ blk = blk->s2;
+ goto Recur;
+ }
return 1;
}