Truly independent web browser
LibJS/JIT: Read constant indices of strings without a slow path call
Andreas Kling25672ccfc2b7
diff --git a/Libraries/LibJS/JIT/Rust/src/builder/keyed.rs b/Libraries/LibJS/JIT/Rust/src/builder/keyed.rsindex 36684b0e528..5ee5f19be08 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/keyed.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/keyed.rs@@ -105,6 +105,10 @@ impl GraphBuilder<'_> {return indexed.then_some(paths);}let key = self.tagged(key);+ if let Some(index) = self.graph.constant_value(key).and_then(value::as_int32) {+ paths.indexed = Some((self.block, self.int32_constant(index)));+ return indexed.then_some(paths);+ }if self.graph.constant_value(key).is_some() {paths.named = Some((self.block, key));return named.then_some(paths);diff --git a/Libraries/LibJS/JIT/Rust/src/builder/tests.rs b/Libraries/LibJS/JIT/Rust/src/builder/tests.rsindex 84eb4e95a86..62bd9491dc2 100644--- a/Libraries/LibJS/JIT/Rust/src/builder/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/builder/tests.rs@@ -1220,6 +1220,24 @@ pub(crate) mod property_access {dump(&optimized_graph(&snapshot), &test_layout())}+ #[test]+ fn constant_indices_of_strings_read_characters_inline() {+ use crate::snapshot::keyed_feedback_bits::{OTHER_ELEMENTS, OTHER_KEY};++ // `return a0[10]` where the feedback saw indices of strings.+ let program = assemble(|_| vec![get_by_value(r(5), a(0), c(1)), Instruction::Return { value: r(5) }]);+ let mut snapshot = snapshot_for(&program, test_layout());+ snapshot.executables[0].feedback.keyed = vec![crate::snapshot::KeyedFeedbackSnapshot {+ bits: OTHER_KEY | OTHER_ELEMENTS,+ }];+ snapshot.runtime.layout.single_ascii_character_strings = 0x1000;+ let text = dump(&optimized_graph(&snapshot), &test_layout());+ assert!(+ text.contains("LoadStringCodeUnit") && text.contains("SingleCharacterString"),+ "{text}"+ );+ }+#[test]fn keyed_feedback_of_one_elements_kind_loads_elements_directly() {// Int32 indices into Uint16Arrays: the kind, the length and the@@ -1412,7 +1430,7 @@ pub(crate) mod property_access {_ => assert!(text.contains("Float64ToInt32"), "{text}"),}assert!(!text.contains("CallSlowPath"), "{text}");- snapshot.executables[0].exit_sites = vec![(0, ExitKind::BadType)];+ snapshot.executables[0].exit_sites = vec![(0, ExitKind::BadType), (0, ExitKind::OutOfBounds)];let text = dump(&optimized_graph(&snapshot), &test_layout());assert!(!text.contains("CheckNumber"), "{text}");assert!(text.contains("CallSlowPath PutByValue"), "{text}");