Commit 88fd2a2
committed
hir: speculative cross-branch pure-call elimination
Recursive self-inlining leaves a redundancy dominator-CSE can't see: the
depth-1 inline of fib makes the fib(n-1) and fib(n-2) expansions each call
fib(n-3), but on separate base-case-guarded branches, so neither call
dominates the other.
pure_call_pre hoists the shared call to the nearest block dominating both
sites and rewrites both results to it, collapsing the recurrence base from
phi (1.618) to ~1.466 — the same transform LLVM's GVN performs, now on
every backend. Because the hoist target runs on more paths than the
original sites, the move is gated on speculation-safety: the callee must
be pure, non-faulting (no int div/rem), loop-free, and — if recursive —
structurally decreasing under a range base-guard, so it terminates on
every input including the speculated ones. speculation_safe_module
certifies this; anything unproven is left alone.
Cranelift-tier fib: 346ms -> 10.7ms (~32x), result unchanged. All other
kernels unchanged and correct. Gate off with ZYNTAX_DISABLE_PURE_CALL_PRE=1.1 parent 9248631 commit 88fd2a2
3 files changed
Lines changed: 996 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
1698 | 1699 | | |
1699 | 1700 | | |
1700 | 1701 | | |
| 1702 | + | |
1701 | 1703 | | |
1702 | 1704 | | |
1703 | 1705 | | |
| |||
1964 | 1966 | | |
1965 | 1967 | | |
1966 | 1968 | | |
1967 | | - | |
1968 | | - | |
1969 | | - | |
1970 | | - | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
1971 | 1975 | | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
1972 | 1979 | | |
1973 | 1980 | | |
1974 | 1981 | | |
| |||
0 commit comments