-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ZJIT: NewRangeFixnum instruction #14409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZJIT: NewRangeFixnum instruction #14409
Conversation
Could you take a look at this draft PR? Want to make sure this is the right direction. |
I'm on vacation for the next two weeks but someone else on the team can give it a look! |
cc @ruby/jit |
zjit/src/hir.rs
Outdated
@@ -2082,6 +2135,11 @@ impl Function { | |||
worklist.push_back(high); | |||
worklist.push_back(state); | |||
} | |||
&Insn::NewRangeFixnum { low, high, state, .. } => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be stacked with NewRange
like
&Insn::NewRangeFixnum { low, high, state, .. } |
&Insn::NewRange { low, high, state, .. } => {
worklist.push_back(low);
worklist.push_back(high);
worklist.push_back(state);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
zjit/src/hir.rs
Outdated
@@ -6548,6 +6608,116 @@ mod opt_tests { | |||
"); | |||
} | |||
|
|||
#[test] | |||
fn test_optimize_range_fixnum_inclusive_literals() { | |||
eval(r#" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think none of the new tests new r#
as there's no character needs escaping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
def test(a) | ||
(a...10) | ||
end | ||
test(2); test(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add these cases to test/ruby/test_zjit.rb
too as integration tests? Remember to add call_threshold: 2
option so we actually run the optimzied HIR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added
Context
Closes Shopify#710
Changes
HIR
NewRangeFixnum
that mirrorsNewRange
but is specialized for Fixnum endpoints.NewRange
, which may call<=>
).Codegen
gen_new_range_fixnum
, wired to the new instruction.gen_prepare_call_with_gc(asm, state)
since range allocation may trigger GC, but does not call Ruby methods.rb_range_new
.Optimization
optimize_ranges
pass: conservatively rewritesNewRange
intoNewRangeFixnum
when one or both ends are statically Fixnum literals (with guards added for the dynamic side if needed).At this point I haven’t added rewrites for parameter–parameter ranges.
From looking at how
opt_plus
works, it seems to rely on profiling info, but I don’t fully understand whether that same info is available fornewrange
.Since I’m still new to this codebase (and to low-level Rust in general), I decided to keep the optimization conservative for now and get maintainer feedback before broadening it.