Implement optimization pipeline: peephole, constant folding, strength reduction, DCE, tail calls

IR optimizer with 6 composable passes:
- Peephole: PushI32+Drop, Dup+Drop, Swap+Swap, Swap+Drop→Nip, identity ops
- Constant folding: binary (Add/Sub/Mul/And/Or/Xor/shifts/comparisons) + unary (Negate/Abs/Invert/ZeroEq/ZeroLt)
- Strength reduction: power-of-2 multiply→shift, PushI32(0)+Eq→ZeroEq
- Dead code elimination: truncate after Exit, constant-conditional If
- Tail call detection: last Call→TailCall when return stack balanced
- Compound ops: Over+Over→TwoDup, Drop+Drop→TwoDrop with optimized codegen

Dictionary hash index for O(1) word lookup during compilation.
wasmtime config: disable NaN canonicalization, enable module caching.
319 unit tests + 11 compliance, all passing.
This commit is contained in:
2026-04-01 21:50:08 +02:00
parent 2c1f7fb3af
commit 282f884a3d
5 changed files with 718 additions and 11 deletions
+4
View File
@@ -24,6 +24,10 @@ pub enum IrOp {
Rot,
Nip,
Tuck,
/// Two-item duplication: ( a b -- a b a b )
TwoDup,
/// Two-item drop: ( a b -- )
TwoDrop,
// -- Arithmetic --
Add,