Skip to content

Truly independent web browser

LibJS: Let JIT frame initialization follow stores of arguments

Andreas Klingfc63877d8c9a
diff --git a/Libraries/LibJS/JIT/Rust/src/passes/verify.rs b/Libraries/LibJS/JIT/Rust/src/passes/verify.rs
index ab3841b00be..247e5df360a 100644
--- a/Libraries/LibJS/JIT/Rust/src/passes/verify.rs
+++ b/Libraries/LibJS/JIT/Rust/src/passes/verify.rs
@@ -76,11 +76,17 @@ pub fn verify_frame_writes(graph: &Graph, layout: &FrameLayout) -> Result<(), St
if operand < RESERVED_REGISTER_COUNT || is_constant {
continue;
}
- // NB: Conversions of the reader's inputs may come in between.
+ // NB: Conversions of the reader's inputs may come in between, and
+ // so may the frame's initialization for stores of arguments,
+ // which it leaves as they are (see `frame_initialization`).
+ let is_argument = operand >= layout.arguments_base();
let reader = nodes[position + 1..].iter().find(|next| {
let op = &graph.node(**next).op;
let properties = op.properties();
+ let initializes_frame =
+ matches!(op, Op::InitializeFrame | Op::EnsureFrameInitialized | Op::PublishFrame);
!matches!(op, Op::StoreSlot { .. })
+ && !(is_argument && initializes_frame)
&& (properties.is_call
|| properties.reads != Locations::NONE
|| properties.writes != Locations::NONE)
diff --git a/Tests/LibJS/JIT/ir/default-and-rest-parameters.js b/Tests/LibJS/JIT/ir/default-and-rest-parameters.js
new file mode 100644
index 00000000000..a74e61eed63
--- /dev/null
+++ b/Tests/LibJS/JIT/ir/default-and-rest-parameters.js
@@ -0,0 +1,15 @@
+// A default parameter value is stored to its argument slot for the rest parameter's slow path, which reads the
+// frame. The frame is initialized right before that slow path, after the store: it leaves the arguments as they are.
+
+function withDefault(a, b = a + 1, ...rest) {
+ return a + b + rest.length;
+}
+jit.prepare(withDefault);
+for (let k = 0; k < 10; ++k) withDefault(k);
+jit.compile(withDefault);
+
+// CHECK-FUNCTION: withDefault
+// CHECK-PASS: frame initialization
+// CHECK: StoreSlot a1
+// CHECK-NEXT: InitializeFrame
+// CHECK-NEXT: Generic CreateRestParams