Skip to content

Truly independent web browser

LibJS/JIT: Number values before check elimination

Andreas Klingaef9804874d7
diff --git a/Libraries/LibJS/JIT/ARCHITECTURE.md b/Libraries/LibJS/JIT/ARCHITECTURE.md
index 3746508375d..21543eff735 100644
--- a/Libraries/LibJS/JIT/ARCHITECTURE.md
+++ b/Libraries/LibJS/JIT/ARCHITECTURE.md
@@ -313,9 +313,10 @@ unreachable. Each one keeps the graph valid (`passes/verify.rs`), and IR tests i
| Simplification | Constant folding and strength reduction; branches on constants become jumps; unboxing a box is the boxed value, and so is an int32 check of the boxed double of an int32; int32 operations that leave their left-hand side as it is, like `x \| 0`, become it. |
| Representation selection | Phis of int32, bool or float64 values become unboxed phis, and int32 inputs of float64 phis are converted. Tagged inputs of an int32 phi that the code checks somewhere (or of the phis connected to it) are checked where they enter, exiting to the start of the phi's block, unless such a check exited there before. |
| Simplification | Again, for what unboxing made foldable. |
+| Global value numbering | A CSE-able node computing what a dominating node computed is replaced by it, so that check elimination sees one value where the builder computed it twice (like the index of `k[Math.abs(j)]` in two expressions). Memory reads are left to check elimination. |
| Check elimination | A forward dataflow of facts removes checks that passed already and reuses loads whose value is known; may turn shape checks into `AssumeValid` plus a stable shape dependency. |
| Simplification | Again, for what the branches that check elimination decided left foldable (like the double path of `Math.abs` of an int32). |
-| Global value numbering | A CSE-able node computing what a dominating node computed is replaced by it. Memory reads are left to check elimination. |
+| Global value numbering | Again, for the nodes that check elimination and simplification made the same. |
| Loop invariant code motion | Gives loops entered from several blocks a merged preheader, then moves effect-free nodes with inputs from outside the loop to it; nodes that may exit only from blocks every iteration runs, exiting to the loop header, and not where that kind of exit was taken there before. |
| Bounds check elimination | Bounds checks against constant counts go away where the index is known to be in range: induction variables of loops whose back edge compares the grown counter with a constant bound, merges of values from outside a loop, and int32 arithmetic on them that cannot overflow. The counter an on-stack replacement entry brings is checked against the bound once where it enters, unless such a check exited there before. With the same ranges, `((x << k) + c) >> k` becomes `x + (c >> k)` where nothing overflows and `c` is a multiple of 2^k. Int32 additions, subtractions and multiplications become `Int32WrappingBinary` where the ranges of their operands keep the result an int32 (and not -0), with operands also bounded by the masks and shifts of any int32, and by the dominating bounds checks and in-bounds branches of indices. |
| Exit unboxing | Frame states take the unboxed value of an int32, float64 or bool boxing that only frame states use, so that exits box it instead of the fast path. |
diff --git a/Libraries/LibJS/JIT/Rust/src/passes/mod.rs b/Libraries/LibJS/JIT/Rust/src/passes/mod.rs
index 2c8aac0ad4c..3dc4c839b82 100644
--- a/Libraries/LibJS/JIT/Rust/src/passes/mod.rs
+++ b/Libraries/LibJS/JIT/Rust/src/passes/mod.rs
@@ -64,6 +64,10 @@ const PASSES: &[Pass] = &[
name: "simplification",
run: simplify::run,
},
+ Pass {
+ name: "global value numbering",
+ run: gvn::run,
+ },
Pass {
name: "check elimination",
run: check_elimination::run,
diff --git a/Tests/LibJS/JIT/ir/gvn-redundant-loads.js b/Tests/LibJS/JIT/ir/gvn-redundant-loads.js
index 929799d540c..9507b996c73 100644
--- a/Tests/LibJS/JIT/ir/gvn-redundant-loads.js
+++ b/Tests/LibJS/JIT/ir/gvn-redundant-loads.js
@@ -11,7 +11,7 @@ jit.compile(sum);
// CHECK-PASS: graph building
// CHECK-COUNT-2: CheckShape
// CHECK-COUNT-2: LoadNamed +0
-// CHECK-PASS: global value numbering
+// CHECK-PASS: global value numbering#2
// CHECK-COUNT-1: CheckShape
// CHECK-COUNT-1: LoadNamed
// CHECK: [[VALUE:v[0-9]+]] = LoadNamed +0