Skip to content

Truly independent web browser

LibJS: Dissolve only JIT int32 checks whose users still take doubles

Andreas Kling00761396d30b
diff --git a/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs b/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs
index 7d85d54e548..3d9813e80be 100644
--- a/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs
+++ b/Libraries/LibJS/JIT/Rust/src/passes/simplify.rs
@@ -591,8 +591,16 @@ pub fn run(graph: &mut Graph) {
changed_control_flow = true;
}
}
- // NB: Frame states take the doubles of the checks that go.
- for check in dissolvable.iter() {
+ 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.
+ let still_dissolvable = dissolvable_checks(graph);
+ 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)) {
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.js
index 234b77768b5..41a957c3b02 100644
--- a/Tests/LibJS/Runtime/jit/checked-doubles.js
+++ b/Tests/LibJS/Runtime/jit/checked-doubles.js
@@ -97,3 +97,31 @@ test("compiled identities of doubles that held int32 values convert them", () =>
values[0] = -(2 ** 31) - 1.5;
expect(shifted(values)).toBe(3 * (2 ** 31 - 1));
});
+
+test("folds that give doubles checked to be int32 values int32 users keep the checks", () => {
+ const sum = new Function(
+ "a",
+ "b",
+ "count",
+ "start",
+ `let y = +(a * b);
+ let s = start;
+ for (let i = 0; i < count; i++) {
+ let t = y;
+ if (i > 1000) t = y;
+ y = t;
+ s = s + y;
+ }
+ return s;`
+ );
+ jit.prepare(sum);
+ for (let k = 0; k < 10; ++k) {
+ sum(1.5, 2, 3, 0);
+ sum(1.5, 2, 2, "a");
+ }
+ expect(jit.compile(sum)).toBe(jit.enabled);
+ expect(sum(1.5, 2, 3, 0)).toBe(9);
+ expect(sum(1.5, 2, 2, "a")).toBe("a33");
+ expect(sum(1.25, 2, 2, 1)).toBe(6);
+ expect(sum(1.25, 2, 2, "b")).toBe("b2.52.5");
+});