diff options
| author | Max Bernstein <ruby@bernsteinbear.com> | 2025-10-24 18:19:40 -0700 |
|---|---|---|
| committer | Max Bernstein <tekknolagi@gmail.com> | 2025-10-28 10:49:30 -0400 |
| commit | 3624031bb594d856c9449130cb162aad612435e7 (patch) | |
| tree | fa716e3a8f620799d3ba5b6c5a83ff6dce9628c9 | |
| parent | b0825d78f3e42565af47a53d93713c7e1dd7a04d (diff) | |
ZJIT: Inline Kernel#nil? and NilClass#nil?
We can fully remove the CCall now.
| -rw-r--r-- | zjit/src/cruby_methods.rs | 14 | ||||
| -rw-r--r-- | zjit/src/hir.rs | 36 |
2 files changed, 30 insertions, 20 deletions
diff --git a/zjit/src/cruby_methods.rs b/zjit/src/cruby_methods.rs index dd33bb206a..5530b555bd 100644 --- a/zjit/src/cruby_methods.rs +++ b/zjit/src/cruby_methods.rs @@ -210,8 +210,8 @@ pub fn init() -> Annotations { annotate!(rb_cHash, "[]", inline_hash_aref); annotate!(rb_cHash, "size", types::Fixnum, no_gc, leaf, elidable); annotate!(rb_cHash, "empty?", types::BoolExact, no_gc, leaf, elidable); - annotate!(rb_cNilClass, "nil?", types::TrueClass, no_gc, leaf, elidable); - annotate!(rb_mKernel, "nil?", types::FalseClass, no_gc, leaf, elidable); + annotate!(rb_cNilClass, "nil?", inline_nilclass_nil_p); + annotate!(rb_mKernel, "nil?", inline_kernel_nil_p); annotate!(rb_mKernel, "respond_to?", inline_kernel_respond_to_p); annotate!(rb_cBasicObject, "==", types::BoolExact, no_gc, leaf, elidable); annotate!(rb_cBasicObject, "!", types::BoolExact, no_gc, leaf, elidable); @@ -363,6 +363,16 @@ fn inline_basic_object_initialize(fun: &mut hir::Function, block: hir::BlockId, Some(result) } +fn inline_nilclass_nil_p(fun: &mut hir::Function, block: hir::BlockId, _recv: hir::InsnId, args: &[hir::InsnId], _state: hir::InsnId) -> Option<hir::InsnId> { + if !args.is_empty() { return None; } + Some(fun.push_insn(block, hir::Insn::Const { val: hir::Const::Value(Qtrue) })) +} + +fn inline_kernel_nil_p(fun: &mut hir::Function, block: hir::BlockId, _recv: hir::InsnId, args: &[hir::InsnId], _state: hir::InsnId) -> Option<hir::InsnId> { + if !args.is_empty() { return None; } + Some(fun.push_insn(block, hir::Insn::Const { val: hir::Const::Value(Qfalse) })) +} + fn inline_kernel_respond_to_p( fun: &mut hir::Function, block: hir::BlockId, diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index e0e682ccb2..0f415a4a21 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -12724,10 +12724,10 @@ mod opt_tests { bb2(v6:BasicObject): v10:NilClass = Const Value(nil) PatchPoint MethodRedefined(NilClass@0x1000, nil?@0x1008, cme:0x1010) + v22:TrueClass = Const Value(true) IncrCounter inline_cfunc_optimized_send_count - v23:TrueClass = CCall nil?@0x1038, v10 CheckInterrupts - Return v23 + Return v22 "); } @@ -12775,10 +12775,10 @@ mod opt_tests { bb2(v6:BasicObject): v10:Fixnum[1] = Const Value(1) PatchPoint MethodRedefined(Integer@0x1000, nil?@0x1008, cme:0x1010) + v22:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v23:FalseClass = CCall nil?@0x1038, v10 CheckInterrupts - Return v23 + Return v22 "); } @@ -12829,10 +12829,10 @@ mod opt_tests { bb2(v8:BasicObject, v9:BasicObject): PatchPoint MethodRedefined(NilClass@0x1000, nil?@0x1008, cme:0x1010) v24:NilClass = GuardType v9, NilClass + v25:TrueClass = Const Value(true) IncrCounter inline_cfunc_optimized_send_count - v26:TrueClass = CCall nil?@0x1038, v24 CheckInterrupts - Return v26 + Return v25 "); } @@ -12856,10 +12856,10 @@ mod opt_tests { bb2(v8:BasicObject, v9:BasicObject): PatchPoint MethodRedefined(FalseClass@0x1000, nil?@0x1008, cme:0x1010) v24:FalseClass = GuardType v9, FalseClass + v25:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v26:FalseClass = CCall nil?@0x1038, v24 CheckInterrupts - Return v26 + Return v25 "); } @@ -12883,10 +12883,10 @@ mod opt_tests { bb2(v8:BasicObject, v9:BasicObject): PatchPoint MethodRedefined(TrueClass@0x1000, nil?@0x1008, cme:0x1010) v24:TrueClass = GuardType v9, TrueClass + v25:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v26:FalseClass = CCall nil?@0x1038, v24 CheckInterrupts - Return v26 + Return v25 "); } @@ -12910,10 +12910,10 @@ mod opt_tests { bb2(v8:BasicObject, v9:BasicObject): PatchPoint MethodRedefined(Symbol@0x1000, nil?@0x1008, cme:0x1010) v24:StaticSymbol = GuardType v9, StaticSymbol + v25:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v26:FalseClass = CCall nil?@0x1038, v24 CheckInterrupts - Return v26 + Return v25 "); } @@ -12937,10 +12937,10 @@ mod opt_tests { bb2(v8:BasicObject, v9:BasicObject): PatchPoint MethodRedefined(Integer@0x1000, nil?@0x1008, cme:0x1010) v24:Fixnum = GuardType v9, Fixnum + v25:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v26:FalseClass = CCall nil?@0x1038, v24 CheckInterrupts - Return v26 + Return v25 "); } @@ -12964,10 +12964,10 @@ mod opt_tests { bb2(v8:BasicObject, v9:BasicObject): PatchPoint MethodRedefined(Float@0x1000, nil?@0x1008, cme:0x1010) v24:Flonum = GuardType v9, Flonum + v25:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v26:FalseClass = CCall nil?@0x1038, v24 CheckInterrupts - Return v26 + Return v25 "); } @@ -12992,10 +12992,10 @@ mod opt_tests { PatchPoint MethodRedefined(String@0x1000, nil?@0x1008, cme:0x1010) PatchPoint NoSingletonClass(String@0x1000) v25:StringExact = GuardType v9, StringExact + v26:FalseClass = Const Value(false) IncrCounter inline_cfunc_optimized_send_count - v27:FalseClass = CCall nil?@0x1038, v25 CheckInterrupts - Return v27 + Return v26 "); } |
