summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zjit/src/cruby_methods.rs6
-rw-r--r--zjit/src/hir.rs2
-rw-r--r--zjit/src/hir/opt_tests.rs26
3 files changed, 21 insertions, 13 deletions
diff --git a/zjit/src/cruby_methods.rs b/zjit/src/cruby_methods.rs
index 039a016504..5de7059167 100644
--- a/zjit/src/cruby_methods.rs
+++ b/zjit/src/cruby_methods.rs
@@ -228,6 +228,7 @@ pub fn init() -> Annotations {
annotate!(rb_cInteger, "^", inline_integer_xor);
annotate!(rb_cInteger, "==", inline_integer_eq);
annotate!(rb_cInteger, "+", inline_integer_plus);
+ annotate!(rb_cInteger, "-", inline_integer_minus);
annotate!(rb_cString, "to_s", inline_string_to_s, types::StringExact);
let thread_singleton = unsafe { rb_singleton_class(rb_cThread) };
annotate!(thread_singleton, "current", types::BasicObject, no_gc, leaf);
@@ -450,6 +451,11 @@ fn inline_integer_plus(fun: &mut hir::Function, block: hir::BlockId, recv: hir::
try_inline_fixnum_op(fun, block, &|left, right| hir::Insn::FixnumAdd { left, right, state }, BOP_PLUS, recv, other, state)
}
+fn inline_integer_minus(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
+ let &[other] = args else { return None; };
+ try_inline_fixnum_op(fun, block, &|left, right| hir::Insn::FixnumSub { left, right, state }, BOP_MINUS, recv, other, state)
+}
+
fn inline_basic_object_eq(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], _state: hir::InsnId) -> Option<hir::InsnId> {
let &[other] = args else { return None; };
let c_result = fun.push_insn(block, hir::Insn::IsBitEqual { left: recv, right: other });
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs
index 8531e50524..23beacf84f 100644
--- a/zjit/src/hir.rs
+++ b/zjit/src/hir.rs
@@ -2319,8 +2319,6 @@ impl Function {
assert!(self.blocks[block.0].insns.is_empty());
for insn_id in old_insns {
match self.find(insn_id) {
- Insn::SendWithoutBlock { recv, args, state, cd, .. } if ruby_call_method_id(cd) == ID!(minus) && args.len() == 1 =>
- self.try_rewrite_fixnum_op(block, insn_id, &|left, right| Insn::FixnumSub { left, right, state }, BOP_MINUS, recv, args[0], state),
Insn::SendWithoutBlock { recv, args, state, cd, .. } if ruby_call_method_id(cd) == ID!(mult) && args.len() == 1 =>
self.try_rewrite_fixnum_op(block, insn_id, &|left, right| Insn::FixnumMult { left, right, state }, BOP_MULT, recv, args[0], state),
Insn::SendWithoutBlock { recv, args, state, cd, .. } if ruby_call_method_id(cd) == ID!(div) && args.len() == 1 =>
diff --git a/zjit/src/hir/opt_tests.rs b/zjit/src/hir/opt_tests.rs
index 452ebddf92..e716640d8a 100644
--- a/zjit/src/hir/opt_tests.rs
+++ b/zjit/src/hir/opt_tests.rs
@@ -140,13 +140,15 @@ mod hir_opt_tests {
bb2(v6:BasicObject):
v10:Fixnum[5] = Const Value(5)
v12:Fixnum[3] = Const Value(3)
- PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MINUS)
- v29:Fixnum[2] = Const Value(2)
+ PatchPoint MethodRedefined(Integer@0x1000, -@0x1008, cme:0x1010)
+ v33:Fixnum[2] = Const Value(2)
+ IncrCounter inline_cfunc_optimized_send_count
v17:Fixnum[1] = Const Value(1)
- PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MINUS)
- v30:Fixnum[1] = Const Value(1)
+ PatchPoint MethodRedefined(Integer@0x1000, -@0x1008, cme:0x1010)
+ v34:Fixnum[1] = Const Value(1)
+ IncrCounter inline_cfunc_optimized_send_count
CheckInterrupts
- Return v30
+ Return v34
");
}
@@ -169,10 +171,11 @@ mod hir_opt_tests {
bb2(v6:BasicObject):
v10:Fixnum[0] = Const Value(0)
v12:Fixnum[1073741825] = Const Value(1073741825)
- PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MINUS)
- v22:Fixnum[-1073741825] = Const Value(-1073741825)
+ PatchPoint MethodRedefined(Integer@0x1000, -@0x1008, cme:0x1010)
+ v24:Fixnum[-1073741825] = Const Value(-1073741825)
+ IncrCounter inline_cfunc_optimized_send_count
CheckInterrupts
- Return v22
+ Return v24
");
}
@@ -1717,9 +1720,10 @@ mod hir_opt_tests {
EntryPoint JIT(0)
Jump bb2(v6, v7, v8)
bb2(v10:BasicObject, v11:BasicObject, v12:BasicObject):
- PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MINUS)
- v29:Fixnum = GuardType v11, Fixnum
- v30:Fixnum = GuardType v12, Fixnum
+ PatchPoint MethodRedefined(Integer@0x1000, -@0x1008, cme:0x1010)
+ v30:Fixnum = GuardType v11, Fixnum
+ v31:Fixnum = GuardType v12, Fixnum
+ IncrCounter inline_cfunc_optimized_send_count
v23:Fixnum[5] = Const Value(5)
CheckInterrupts
Return v23