summaryrefslogtreecommitdiff
path: root/zjit/src/hir/tests.rs
AgeCommit message (Collapse)Author
31 hoursZJIT: Remove redundant unboxingnozomemein
31 hoursZJIT: Write the result of UnboxFixnum HIR as type spec so that we can make ↵nozomemein
use of it later (e.g. fold_constants for ArrayAref)
31 hoursZJIT: Rename ArrayArefFixnum -> ArrayArefnozomemein
2 daysZJIT: Add assume_no_singleton_classes to avoid invalidation loops (#15871)Max Bernstein
Make sure we check if we have seen a singleton for this class before assuming we have not. Port the API from YJIT.
4 daysZJIT: Check arg limit before pushing SendWithoutBLockDirect insn (#15854)Randy Stauner
This reduces some processing and makes the HIR more accurate.
4 daysZJIT: Snapshot FrameState with reordered args before direct sendRandy Stauner
You can see the reordered args in the new Snapshot right before the DirectSend insn: v14:Any = Snapshot FrameState { pc: 0x00, stack: [v6, v11, v13], locals: [] } PatchPoint MethodRedefined(Object@0x00, a@0x00, cme:0x00) PatchPoint NoSingletonClass(Object@0x00) v22:HeapObject[class_exact*:Object@VALUE(0x00)] = GuardType v6, HeapObject[class_exact*:Object@VALUE(0x00)] - v23:BasicObject = SendWithoutBlockDirect v22, :a (0x00), v13, v11 - v16:Any = Snapshot FrameState { pc: 0x00, stack: [v23], locals: [] } + v23:Any = Snapshot FrameState { pc: 0x00, stack: [v6, v13, v11], locals: [] } + v24:BasicObject = SendWithoutBlockDirect v22, :a (0x00), v13, v11 + v16:Any = Snapshot FrameState { pc: 0x00, stack: [v24], locals: [] }
4 daysZJIT: Add snapshot tests for direct sendRandy Stauner
2025-12-24ZJIT: Don't mark control-flow opcodes as invalidating locals (#15694)Max Bernstein
jump, branchif, etc don't invalidate locals in the JIT; they might in the interpreter because they can execute arbitrary code, but the JIT side exits before that happens.
2025-12-15ZJIT: Fix test failures from line number of `Primitive` shiftingAlan Wu
This can happen with documentation updates and we don't want those to trip on ZJIT tests. Redact the whole name since names like "_bi342" aren't that helpful anyways.
2025-12-09ZJIT: Show send fallback reason in HIR dump (#15454)Randy Stauner
This adds comments to the hir dump output like this: v13:BasicObject = SendWithoutBlock v6, :test, v11 # SendFallbackReason: Complex argument passing
2025-12-09ZJIT: Put keyword bits in callee frame rather than c_argsRandy Stauner
2025-12-09ZJIT: Support opt_newarray_send with PACK_BUFFERMax Bernstein
2025-12-05ZJIT: Include local variable names in `Get|SetLocal` insn's print value (#15423)Stan Lo
ZJIT: Print local variable names GetLocal and SetLocal instructions
2025-12-01ZJIT: Add HIR test for VM_OPT_NEWARRAY_SEND_PACK_BUFFERMax Bernstein
2025-12-01ZJIT: Standardize method dispatch insns' `recv` field (#15334)Stan Lo
ZJIT: Standardize C call related insn fields - Add `recv` field to `CCall` and `CCallWithFrame` so now all method dispatch related instructions have `recv` field, separate from `args` field. This ensures consistent pointer arithmetic when generating code for these instructions. - Standardize `recv` field's display position in send related instructions.
2025-11-24ZJIT: For JIT-to-JIT send, avoid loading uninitialized local through EPAlan Wu
JIT-to-JIT sends don't blit locals to nil in the callee's EP memory region because HIR is aware of this initial state and memory ops are only done when necessary. Previously, we read from this initialized memory by emitting `GetLocal` in e.g. BBs that are immediate successor to an entrypoint. The entry points sets up the frame state properly and we also reload locals if necessary after an operation that potentially makes the environment escape. So, listen to the frame state when it's supposed to be up-to-date (`!local_inval`).
2025-11-20ZJIT: Add tests for `opt_newarray_send` with target methods redefinedKevin Menard
2025-11-20ZJIT: Handle display formatting for all defined bopsKevin Menard
2025-11-20ZJIT: Compile the VM_OPT_NEWARRAY_SEND_HASH variant of opt_newarray_sendKevin Menard
2025-11-20ZJIT: Deduplicate successor and predecessor sets (#15263)Aiden Fox Ivey
Fixes https://github.com/Shopify/ruby/issues/877 I didn't consider the ability to have the successor or predecessor sets having duplicates when originally crafting the Iongraph support PR, but have added this to prevent that happening in the future. I don't think it interferes with the underlying Iongraph implementation, but it doesn't really make sense. I think this kind of behaviour happens when there are multiple jump instructions that go to the same basic block within a given block.
2025-11-20ZJIT: Put optional interpreter cache on both GetIvar and SetIvarMax Bernstein
2025-11-19ZJIT: Add Iongraph compatibility (#14999)Aiden Fox Ivey
## Components This PR adds functionality to visualize HIR using the [Iongraph](https://spidermonkey.dev/blog/2025/10/28/iongraph-web.html) tool first created for use with Spidermonkey. ## Justification Iongraph's viewer is (as mentioned in the article above) a few notches above graphviz for viewing large CFGs. It also allows easily inspecting different compiler optimization passes and multiple functions in the same browser window. Since Spidermonkey is using this format, it may be beneficial to use it for our own JIT development. The requirement for JSON is downstream from that of the Iongraph format. As for writing the implementation myself, ZJIT leans towards having fewer dependencies, so this is the preferred approach. ## How does it look? <img width="902" height="957" alt="image" src="https://github.com/user-attachments/assets/e4e0991b-572a-41fd-9fed-1215bd1926c3" /> <img width="770" height="624" alt="image" src="https://github.com/user-attachments/assets/01398373-1f75-46b8-b1aa-7f5d4cbca6b8" /> Right now, it's aesthetically minimal, but is fairly robust. ## Functionality Using `--zjit-dump-hir-iongraph` will dump all compiled functions into a directory named `/tmp/zjit-iongraph-{PROCESS_PID}`. Each file will be named `func_{ZJIT_FUNC_NAME}.json`. In order to use them in the Iongraph viewer, you'll need to use `jq` to collate them to a single file. An example invocation of `jq` is shown below for reference. The name of the file created does not matter to my understanding. `jq --slurp --null-input '.functions=inputs | .version=2' /tmp/zjit-iongraph-{PROCESS_PID}/func*.json > ~/Downloads/foo.json` From there, you can use https://mozilla-spidermonkey.github.io/iongraph/ to view your trace. ### Caveats - The upstream Iongraph viewer doesn't allow you to click arguments to an instruction to find the instruction that they originate from when using the format that this PR generates. (I have made a small fork at https://github.com/aidenfoxivey/iongraph that fixes that functionality via https://github.com/aidenfoxivey/iongraph/commit/9e9c29b41c4dbb35cf66cb6161e5b19c8b796379.patch) - The upstream Iongraph viewer can sometimes show "exiting edges" in the CFG as being not attached to the box representing its basic block. <img width="1814" height="762" alt="image" src="https://github.com/user-attachments/assets/afbbaa16-332f-498f-849e-11c69a8cb0cc" /> (Image courtesy of @tekknolagi) This is because the original tool was (to our understanding) written for an SSA format that does not use extended basic blocks. (Extended basic blocks let you put a jump instruction, conditional or otherwise, anywhere in the basic block.) This means that our format may generate more outgoing edges than the viewer is written to handle.
2025-11-14ZJIT: Support JIT-to-JIT calls to callees with optional parametersAlan Wu
* Correct JIT entry points for optionals so each optional start with nil before their initialization routine runs. Establish `jit_entry_points[filled_opts_num]` gives the appropriate entry point * Correct number of HIR block parameters for each JIT entry point * Entry points that share the same ISEQ PC get separate entries since they start with different state. No more deduplication. * Reject post parameters. Was hidden behind check for optionals. * Make sure to visit every BB in iseq_to_hir(). Some wasn't visited when the initialization routine for an optional terminates the block in a `SideExit`. Remove the now impossible `FailedOptionalArguments`.
2025-11-10ZJIT: Split unhandled_hir_insn and unknown_newarray_send stats (#15127)Takashi Kokubun
2025-11-10ZJIT: Snapshot once per YARV insn (#15082)Max Bernstein
This is roughly net-neutral for the number of instructions created but at least cenetralizes where the Snapshot is made. Previously, we might have multiple Snapshot per YARV instruction depending on if it had event flags, if the body of the instruction also needed a Snapshot, etc.
2025-11-07ZJIT: Add compilation for checkkeyword (#14764)Jacob
<details> <summary>Before</summary> <br> ``` **ZJIT: Printing ZJIT statistics on exit*** Top-20 not inlined C methods (64.0% of total 3,683,424): Kernel#is_a?: 427,127 (11.6%) Hash#[]=: 426,276 (11.6%) String#start_with?: 336,245 ( 9.1%) ObjectSpace::WeakKeyMap#[]: 139,406 ( 3.8%) Hash#fetch: 127,291 ( 3.5%) String#hash: 79,259 ( 2.2%) Process.clock_gettime: 74,658 ( 2.0%) Array#any?: 74,441 ( 2.0%) Integer#==: 71,067 ( 1.9%) Kernel#dup: 68,058 ( 1.8%) Hash#key?: 62,306 ( 1.7%) Regexp#match?: 62,247 ( 1.7%) SQLite3::Statement#step: 61,172 ( 1.7%) SQLite3::Statement#done?: 61,172 ( 1.7%) Kernel#Array: 55,015 ( 1.5%) Integer#<=>: 49,127 ( 1.3%) String.new: 48,363 ( 1.3%) IO#read: 47,753 ( 1.3%) Array#include?: 43,307 ( 1.2%) Struct#initialize: 42,650 ( 1.2%) Top-3 not optimized method types for send (100.0% of total 1,022,743): iseq: 736,483 (72.0%) cfunc: 286,174 (28.0%) null: 86 ( 0.0%) Top-6 not optimized method types for send_without_block (100.0% of total 189,556): optimized_call: 115,966 (61.2%) optimized_send: 36,767 (19.4%) optimized_struct_aset: 33,788 (17.8%) null: 2,521 ( 1.3%) optimized_block_call: 510 ( 0.3%) cfunc: 4 ( 0.0%) Top-13 not optimized instructions (100.0% of total 1,648,882): invokesuper: 697,471 (42.3%) invokeblock: 496,687 (30.1%) sendforward: 221,094 (13.4%) opt_eq: 147,620 ( 9.0%) opt_minus: 40,865 ( 2.5%) opt_plus: 22,912 ( 1.4%) opt_send_without_block: 18,932 ( 1.1%) opt_gt: 867 ( 0.1%) opt_mult: 768 ( 0.0%) opt_neq: 654 ( 0.0%) opt_or: 508 ( 0.0%) opt_lt: 359 ( 0.0%) opt_ge: 145 ( 0.0%) Top-13 send fallback reasons (100.0% of total 8,308,826): send_without_block_polymorphic: 3,174,975 (38.2%) not_optimized_instruction: 1,648,882 (19.8%) fancy_call_feature: 1,072,807 (12.9%) send_not_optimized_method_type: 1,022,743 (12.3%) send_no_profiles: 599,715 ( 7.2%) send_without_block_no_profiles: 486,108 ( 5.9%) send_without_block_not_optimized_optimized_method_type: 187,031 ( 2.3%) send_polymorphic: 101,834 ( 1.2%) obj_to_string_not_string: 7,610 ( 0.1%) send_without_block_not_optimized_method_type: 2,525 ( 0.0%) send_without_block_direct_too_many_args: 2,369 ( 0.0%) send_without_block_cfunc_array_variadic: 2,190 ( 0.0%) ccall_with_frame_too_many_args: 37 ( 0.0%) Top-8 popular unsupported argument-parameter features (100.0% of total 1,209,121): param_opt: 583,595 (48.3%) param_forwardable: 178,162 (14.7%) param_block: 162,689 (13.5%) param_kw: 150,575 (12.5%) param_rest: 90,091 ( 7.5%) param_kwrest: 33,791 ( 2.8%) caller_splat: 10,214 ( 0.8%) caller_kw_splat: 4 ( 0.0%) Top-7 unhandled YARV insns (100.0% of total 128,032): checkkeyword: 88,698 (69.3%) invokesuperforward: 22,296 (17.4%) getblockparam: 16,292 (12.7%) getconstant: 336 ( 0.3%) checkmatch: 290 ( 0.2%) setblockparam: 101 ( 0.1%) once: 19 ( 0.0%) Top-1 compile error reasons (100.0% of total 21,283): exception_handler: 21,283 (100.0%) Top-18 side exit reasons (100.0% of total 2,335,562): guard_type_failure: 677,930 (29.0%) guard_shape_failure: 410,183 (17.6%) unhandled_kwarg: 235,100 (10.1%) patchpoint_stable_constant_names: 206,172 ( 8.8%) block_param_proxy_not_iseq_or_ifunc: 199,931 ( 8.6%) patchpoint_no_singleton_class: 188,359 ( 8.1%) unhandled_yarv_insn: 128,032 ( 5.5%) unknown_newarray_send: 124,805 ( 5.3%) patchpoint_method_redefined: 73,062 ( 3.1%) unhandled_hir_insn: 56,688 ( 2.4%) compile_error: 21,283 ( 0.9%) block_param_proxy_modified: 11,647 ( 0.5%) fixnum_mult_overflow: 954 ( 0.0%) patchpoint_no_ep_escape: 813 ( 0.0%) guard_bit_equals_failure: 316 ( 0.0%) obj_to_string_fallback: 230 ( 0.0%) interrupt: 35 ( 0.0%) guard_type_not_failure: 22 ( 0.0%) send_count: 26,775,579 dynamic_send_count: 8,308,826 (31.0%) optimized_send_count: 18,466,753 (69.0%) iseq_optimized_send_count: 7,611,729 (28.4%) inline_cfunc_optimized_send_count: 5,935,290 (22.2%) inline_iseq_optimized_send_count: 657,555 ( 2.5%) non_variadic_cfunc_optimized_send_count: 3,169,054 (11.8%) variadic_cfunc_optimized_send_count: 1,093,125 ( 4.1%) dynamic_getivar_count: 2,793,635 dynamic_setivar_count: 3,040,844 compiled_iseq_count: 4,496 failed_iseq_count: 0 compile_time: 915ms profile_time: 6ms gc_time: 6ms invalidation_time: 20ms vm_write_pc_count: 26,857,114 vm_write_sp_count: 25,770,558 vm_write_locals_count: 25,770,558 vm_write_stack_count: 25,770,558 vm_write_to_parent_iseq_local_count: 106,036 vm_read_from_parent_iseq_local_count: 3,213,992 guard_type_count: 27,683,170 guard_type_exit_ratio: 2.4% code_region_bytes: 32,178,176 side_exit_count: 2,335,562 total_insn_count: 170,714,077 vm_insn_count: 28,999,194 zjit_insn_count: 141,714,883 ratio_in_zjit: 83.0% ``` </details> <details> <summary>After</summary> <br> ``` **ZJIT: Printing ZJIT statistics on exit*** Top-20 not inlined C methods (63.9% of total 3,686,703): Kernel#is_a?: 427,123 (11.6%) Hash#[]=: 426,276 (11.6%) String#start_with?: 336,245 ( 9.1%) ObjectSpace::WeakKeyMap#[]: 139,406 ( 3.8%) Hash#fetch: 127,291 ( 3.5%) String#hash: 79,259 ( 2.1%) Process.clock_gettime: 74,658 ( 2.0%) Array#any?: 74,441 ( 2.0%) Integer#==: 71,067 ( 1.9%) Kernel#dup: 68,058 ( 1.8%) Regexp#match?: 62,336 ( 1.7%) Hash#key?: 62,306 ( 1.7%) SQLite3::Statement#step: 61,172 ( 1.7%) SQLite3::Statement#done?: 61,172 ( 1.7%) Kernel#Array: 55,048 ( 1.5%) Integer#<=>: 49,127 ( 1.3%) String.new: 48,363 ( 1.3%) IO#read: 47,753 ( 1.3%) Array#include?: 43,309 ( 1.2%) Struct#initialize: 42,650 ( 1.2%) Top-3 not optimized method types for send (100.0% of total 1,026,413): iseq: 737,496 (71.9%) cfunc: 288,831 (28.1%) null: 86 ( 0.0%) Top-6 not optimized method types for send_without_block (100.0% of total 189,556): optimized_call: 115,966 (61.2%) optimized_send: 36,767 (19.4%) optimized_struct_aset: 33,788 (17.8%) null: 2,521 ( 1.3%) optimized_block_call: 510 ( 0.3%) cfunc: 4 ( 0.0%) Top-13 not optimized instructions (100.0% of total 1,648,949): invokesuper: 697,452 (42.3%) invokeblock: 496,687 (30.1%) sendforward: 221,094 (13.4%) opt_eq: 147,620 ( 9.0%) opt_minus: 40,863 ( 2.5%) opt_plus: 22,912 ( 1.4%) opt_send_without_block: 19,020 ( 1.2%) opt_gt: 867 ( 0.1%) opt_mult: 768 ( 0.0%) opt_neq: 654 ( 0.0%) opt_or: 508 ( 0.0%) opt_lt: 359 ( 0.0%) opt_ge: 145 ( 0.0%) Top-13 send fallback reasons (100.0% of total 8,318,975): send_without_block_polymorphic: 3,177,471 (38.2%) not_optimized_instruction: 1,648,949 (19.8%) fancy_call_feature: 1,075,143 (12.9%) send_not_optimized_method_type: 1,026,413 (12.3%) send_no_profiles: 599,748 ( 7.2%) send_without_block_no_profiles: 486,190 ( 5.8%) send_without_block_not_optimized_optimized_method_type: 187,031 ( 2.2%) send_polymorphic: 102,497 ( 1.2%) obj_to_string_not_string: 8,412 ( 0.1%) send_without_block_not_optimized_method_type: 2,525 ( 0.0%) send_without_block_direct_too_many_args: 2,369 ( 0.0%) send_without_block_cfunc_array_variadic: 2,190 ( 0.0%) ccall_with_frame_too_many_args: 37 ( 0.0%) Top-8 popular unsupported argument-parameter features (100.0% of total 1,211,457): param_opt: 584,073 (48.2%) param_forwardable: 178,907 (14.8%) param_block: 162,689 (13.4%) param_kw: 151,688 (12.5%) param_rest: 90,091 ( 7.4%) param_kwrest: 33,791 ( 2.8%) caller_splat: 10,214 ( 0.8%) caller_kw_splat: 4 ( 0.0%) Top-6 unhandled YARV insns (100.0% of total 39,334): invokesuperforward: 22,296 (56.7%) getblockparam: 16,292 (41.4%) getconstant: 336 ( 0.9%) checkmatch: 290 ( 0.7%) setblockparam: 101 ( 0.3%) once: 19 ( 0.0%) Top-1 compile error reasons (100.0% of total 21,283): exception_handler: 21,283 (100.0%) Top-18 side exit reasons (100.0% of total 2,253,541): guard_type_failure: 682,695 (30.3%) guard_shape_failure: 410,183 (18.2%) unhandled_kwarg: 236,780 (10.5%) patchpoint_stable_constant_names: 206,310 ( 9.2%) block_param_proxy_not_iseq_or_ifunc: 199,931 ( 8.9%) patchpoint_no_singleton_class: 188,438 ( 8.4%) unknown_newarray_send: 124,805 ( 5.5%) patchpoint_method_redefined: 73,056 ( 3.2%) unhandled_hir_insn: 56,686 ( 2.5%) unhandled_yarv_insn: 39,334 ( 1.7%) compile_error: 21,283 ( 0.9%) block_param_proxy_modified: 11,647 ( 0.5%) fixnum_mult_overflow: 954 ( 0.0%) patchpoint_no_ep_escape: 813 ( 0.0%) guard_bit_equals_failure: 316 ( 0.0%) obj_to_string_fallback: 230 ( 0.0%) interrupt: 58 ( 0.0%) guard_type_not_failure: 22 ( 0.0%) send_count: 27,032,751 dynamic_send_count: 8,318,975 (30.8%) optimized_send_count: 18,713,776 (69.2%) iseq_optimized_send_count: 7,809,698 (28.9%) inline_cfunc_optimized_send_count: 5,980,083 (22.1%) inline_iseq_optimized_send_count: 657,677 ( 2.4%) non_variadic_cfunc_optimized_send_count: 3,170,381 (11.7%) variadic_cfunc_optimized_send_count: 1,095,937 ( 4.1%) dynamic_getivar_count: 2,793,987 dynamic_setivar_count: 3,350,905 compiled_iseq_count: 4,498 failed_iseq_count: 0 compile_time: 884ms profile_time: 6ms gc_time: 6ms invalidation_time: 19ms vm_write_pc_count: 27,417,915 vm_write_sp_count: 26,327,928 vm_write_locals_count: 26,327,928 vm_write_stack_count: 26,327,928 vm_write_to_parent_iseq_local_count: 106,036 vm_read_from_parent_iseq_local_count: 3,213,992 guard_type_count: 27,937,831 guard_type_exit_ratio: 2.4% code_region_bytes: 32,571,392 side_exit_count: 2,253,541 total_insn_count: 170,630,429 vm_insn_count: 26,617,244 zjit_insn_count: 144,013,185 ratio_in_zjit: 84.4% ``` </details>
2025-11-06ZJIT: Use interpreter inline cache in setinstancevariable (#14925)Max Bernstein
We have both `SetIvar` and `SetInstanceVariable`. The former is a purely dynamic fallback that we can inline `attr_accessor`/`attr_writer` into, whereas the latter comes straight from the interpreter's `setinstancevariable` opcode.
2025-11-05ZJIT: Don't side-exit on VM_CALL_KWARG just SendWithoutBlock (#15065)Randy Stauner
2025-11-03ZJIT: Implement include_p for opt_(new|dup)array_send YARV insns (#14885)Randy Stauner
These just call to the C functions that do the optimized test but this avoids the side exit. See https://github.com/ruby/ruby/pull/12123 for the original CRuby/YJIT implementation.
2025-10-30ZJIT: Prevent specialization of splats instead of side-exiting (#15005)Aiden Fox Ivey
2025-10-30ZJIT: Fix incorrect self.class.respond_to? folding (#15001)Max Bernstein
Right now we have a subtle type system bug around `types::Class`. Until that is resolved, stop marking `Kernel#class` as returning `types::Class`, which fixes Rubocop. Re: https://github.com/Shopify/ruby/issues/850
2025-10-28ZJIT: Split HIR tests (#14967)Aiden Fox Ivey
`hir.rs` was getting rather large, so I've opted to move the inline tests into their own files. This should also help when looking for where to put your tests, as the optimization tests have a dedicated file. Future follow up work could make the layout of test modules more idiomatic to Rust.