Truly independent web browser
LibJS: Keep JIT int32 checks of doubles that any node still uses
Tim Ledbetter079f25aacbdc
diff --git a/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs b/Libraries/LibJS/JIT/Rust/src/passes/simplify.rsindex 38f6da5dee0..5a215aa6820 100644--- a/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs+++ b/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs@@ -619,19 +619,29 @@ fn simplify(graph: &mut Graph, dissolve_checks: bool) {replacements.apply(graph);edit::remove_nodes(graph, &removed);// NB: Folds can give a check users that need the int32, like the- // unboxing of a boxing of it, which keep the check. The other users- // of the checks that go took the doubles above, and frame states- // take them now.+ // unboxing of a boxing of it, and the loop never visits the nodes+ // that folds add before the node they replace. A check that any node+ // still uses stays, and frame states take the doubles of the others.if dissolvable.is_empty() {if changed_control_flow {edit::clean_up_control_flow(graph);}return;}- let still_dissolvable = dissolvable_checks(graph);+ let mut dissolvable = dissolvable;+ dissolvable.subtract(&removed);+ for block in &graph.blocks {+ for node in block.nodes() {+ for input in &graph.node(node).inputs {+ if input.index() < dissolvable.capacity() {+ dissolvable.remove(input.index());+ }+ }+ }+ }let mut replacements = Replacements::new(graph);let mut removed = BitSet::new(graph.nodes.len());- for check in dissolvable.iter().filter(|check| still_dissolvable.contains(*check)) {+ for check in dissolvable.iter() {let check = NodeId::from_index(check);let double = checked_double(graph, check).expect("dissolvable checks check doubles");replacements.replace(check, double);diff --git a/Tests/LibJS/Runtime/jit/checked-doubles.js b/Tests/LibJS/Runtime/jit/checked-doubles.jsindex 41a957c3b02..ebff1d86770 100644--- a/Tests/LibJS/Runtime/jit/checked-doubles.js+++ b/Tests/LibJS/Runtime/jit/checked-doubles.js@@ -125,3 +125,42 @@ test("folds that give doubles checked to be int32 values int32 users keep the chexpect(sum(1.25, 2, 2, 1)).toBe(6);expect(sum(1.25, 2, 2, "b")).toBe("b2.52.5");});++test("number conversions of boxed doubles checked to be int32 values keep the checks", () => {+ const keys = new Float64Array([1, 2, 3, 4]);+ const add = new Function("x", "j", "const y = +x; return j + (y | 0);");+ // NB: Math.min() needs the key as an int32, so compiled code checks that it is one.+ // The inlined `+x` then converts that int32 back, through the loop's copy of the key.+ const addKey = new Function(+ "add",+ "keys",+ "i",+ "n",+ `const key = +keys[i];+ Math.min(key, key);+ let index = key;+ let sum = 0;+ for (let j = 0; j < n; ++j) {+ sum = add(index, j);+ const same = index;+ index = same;+ }+ return sum;`+ );+ jit.prepare(add);+ jit.prepare(addKey);+ for (let k = 0; k < 10; ++k) {+ add(1, k);+ add("5", k);+ add(1.5, k);+ }+ for (let k = 0; k < 10; ++k) addKey(add, keys, k & 3, 2);+ expect(jit.compile(addKey)).toBe(jit.enabled);+ expect(addKey(add, keys, 1, 2)).toBe(3);+ expect(addKey(add, keys, 2, 3)).toBe(5);+ keys.set([0.5, 2.75, -1.5, 2 ** 40]);+ expect(addKey(add, keys, 0, 2)).toBe(1);+ expect(addKey(add, keys, 1, 2)).toBe(3);+ expect(addKey(add, keys, 2, 2)).toBe(0);+ expect(addKey(add, keys, 3, 2)).toBe(1);+});