Skip to content

Commit 491be57

Browse files
committed
ZJIT: Move special Fixnum BOP_OR into cruby_methods
1 parent 22d2bb0 commit 491be57

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

zjit/src/cruby_methods.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub fn init() -> Annotations {
233233
annotate!(rb_cInteger, "/", inline_integer_div);
234234
annotate!(rb_cInteger, "%", inline_integer_mod);
235235
annotate!(rb_cInteger, "&", inline_integer_and);
236+
annotate!(rb_cInteger, "|", inline_integer_or);
236237
annotate!(rb_cInteger, ">", inline_integer_gt);
237238
annotate!(rb_cInteger, ">=", inline_integer_ge);
238239
annotate!(rb_cInteger, "<", inline_integer_lt);
@@ -484,6 +485,11 @@ fn inline_integer_and(fun: &mut hir::Function, block: hir::BlockId, recv: hir::I
484485
try_inline_fixnum_op(fun, block, &|left, right| hir::Insn::FixnumAnd { left, right, }, BOP_AND, recv, other, state)
485486
}
486487

488+
fn inline_integer_or(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
489+
let &[other] = args else { return None; };
490+
try_inline_fixnum_op(fun, block, &|left, right| hir::Insn::FixnumOr { left, right, }, BOP_OR, recv, other, state)
491+
}
492+
487493
fn inline_integer_gt(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
488494
let &[other] = args else { return None; };
489495
try_inline_fixnum_op(fun, block, &|left, right| hir::Insn::FixnumGt { left, right }, BOP_GT, recv, other, state)

zjit/src/hir.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,8 +2319,6 @@ impl Function {
23192319
assert!(self.blocks[block.0].insns.is_empty());
23202320
for insn_id in old_insns {
23212321
match self.find(insn_id) {
2322-
Insn::SendWithoutBlock { recv, args, state, cd, .. } if ruby_call_method_id(cd) == ID!(or) && args.len() == 1 =>
2323-
self.try_rewrite_fixnum_op(block, insn_id, &|left, right| Insn::FixnumOr { left, right }, BOP_OR, recv, args[0], state),
23242322
Insn::SendWithoutBlock { recv, args, state, cd, .. } if ruby_call_method_id(cd) == ID!(freeze) && args.is_empty() =>
23252323
self.try_rewrite_freeze(block, insn_id, recv, state),
23262324
Insn::SendWithoutBlock { recv, args, state, cd, .. } if ruby_call_method_id(cd) == ID!(minusat) && args.is_empty() =>
@@ -5884,13 +5882,15 @@ mod graphviz_tests {
58845882
<TR><TD ALIGN="LEFT" PORT="params" BGCOLOR="gray">bb2(v10:BasicObject, v11:BasicObject, v12:BasicObject)&nbsp;</TD></TR>
58855883
<TR><TD ALIGN="left" PORT="v15">PatchPoint NoTracePoint&nbsp;</TD></TR>
58865884
<TR><TD ALIGN="left" PORT="v18">PatchPoint NoTracePoint&nbsp;</TD></TR>
5887-
<TR><TD ALIGN="left" PORT="v24">PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, 29)&nbsp;</TD></TR>
5888-
<TR><TD ALIGN="left" PORT="v25">v25:Fixnum = GuardType v11, Fixnum&nbsp;</TD></TR>
5889-
<TR><TD ALIGN="left" PORT="v26">v26:Fixnum = GuardType v12, Fixnum&nbsp;</TD></TR>
5890-
<TR><TD ALIGN="left" PORT="v27">v27:Fixnum = FixnumOr v25, v26&nbsp;</TD></TR>
5885+
<TR><TD ALIGN="left" PORT="v24">PatchPoint NoTracePoint&nbsp;</TD></TR>
5886+
<TR><TD ALIGN="left" PORT="v25">PatchPoint MethodRedefined(Integer@0x1000, |@0x1008, cme:0x1010)&nbsp;</TD></TR>
5887+
<TR><TD ALIGN="left" PORT="v26">v26:Fixnum = GuardType v11, Fixnum&nbsp;</TD></TR>
5888+
<TR><TD ALIGN="left" PORT="v27">v27:Fixnum = GuardType v12, Fixnum&nbsp;</TD></TR>
5889+
<TR><TD ALIGN="left" PORT="v28">v28:Fixnum = FixnumOr v26, v27&nbsp;</TD></TR>
5890+
<TR><TD ALIGN="left" PORT="v29">IncrCounter inline_cfunc_optimized_send_count&nbsp;</TD></TR>
58915891
<TR><TD ALIGN="left" PORT="v21">PatchPoint NoTracePoint&nbsp;</TD></TR>
58925892
<TR><TD ALIGN="left" PORT="v22">CheckInterrupts&nbsp;</TD></TR>
5893-
<TR><TD ALIGN="left" PORT="v23">Return v27&nbsp;</TD></TR>
5893+
<TR><TD ALIGN="left" PORT="v23">Return v28&nbsp;</TD></TR>
58945894
</TABLE>>];
58955895
}
58965896
"#);

zjit/src/hir/opt_tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4635,12 +4635,13 @@ mod hir_opt_tests {
46354635
EntryPoint JIT(0)
46364636
Jump bb2(v6, v7, v8)
46374637
bb2(v10:BasicObject, v11:BasicObject, v12:BasicObject):
4638-
PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, 29)
4639-
v25:Fixnum = GuardType v11, Fixnum
4640-
v26:Fixnum = GuardType v12, Fixnum
4641-
v27:Fixnum = FixnumOr v25, v26
4638+
PatchPoint MethodRedefined(Integer@0x1000, |@0x1008, cme:0x1010)
4639+
v26:Fixnum = GuardType v11, Fixnum
4640+
v27:Fixnum = GuardType v12, Fixnum
4641+
v28:Fixnum = FixnumOr v26, v27
4642+
IncrCounter inline_cfunc_optimized_send_count
46424643
CheckInterrupts
4643-
Return v27
4644+
Return v28
46444645
");
46454646
}
46464647

0 commit comments

Comments
 (0)