aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-20 13:17:08 +0100
committerlemon <lsof@mailbox.org>2025-12-20 13:17:08 +0100
commitf123a0868ca44ca5fb5adf5c230ad03e5eb058b0 (patch)
tree9daef6ad2fce42fa30aba9f6e44514b75175e712
parentbad03d3c0ba2d438b067a9689c7544108f62289a (diff)
copyopt: optimize same-arg phis with multiple preds
-rw-r--r--ir/ssa.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ir/ssa.c b/ir/ssa.c
index 31cab4b..9d248f4 100644
--- a/ir/ssa.c
+++ b/ir/ssa.c
@@ -7,15 +7,19 @@ copyopt(struct function *fn)
FREQUIRE(FNUSE);
do {
- if (blk->npred == 1) for (int i = 0; i < blk->phi.n; ++i) {
- /* simplify 1-arg phi */
+ for (int i = 0; i < blk->phi.n; ++i) {
+ /* simplify same-arg phi */
int phi = blk->phi.p[i];
union ref *arg = phitab.p[instrtab[phi].l.i];
+ for (int j = 1; j < blk->npred; ++j) {
+ if (arg[j].bits != arg->bits) goto Next;
+ }
/* being conservative here because phis could have circular dependencies? */
if (arg->t != RTMP || instrtab[arg->i].op != Ophi) {
replcuses(mkref(RTMP, phi), *arg);
delphi(blk, i--);
}
+ Next:;
}
for (int i = 0; i < blk->ins.n; ++i) {
union ref var = mkref(RTMP, blk->ins.p[i]);