diff options
| author | 2025-12-20 13:17:08 +0100 | |
|---|---|---|
| committer | 2025-12-20 13:17:08 +0100 | |
| commit | f123a0868ca44ca5fb5adf5c230ad03e5eb058b0 (patch) | |
| tree | 9daef6ad2fce42fa30aba9f6e44514b75175e712 /ir | |
| parent | bad03d3c0ba2d438b067a9689c7544108f62289a (diff) | |
copyopt: optimize same-arg phis with multiple preds
Diffstat (limited to 'ir')
| -rw-r--r-- | ir/ssa.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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]); |