mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
ZJIT: Write the result of UnboxFixnum HIR as type spec so that we can make use of it later (e.g. fold_constants for ArrayAref)
This commit is contained in:
parent
065db7cf61
commit
256c806a1d
Notes:
git
2026-01-15 17:01:39 +00:00
@ -2251,7 +2251,13 @@ impl Function {
|
||||
Insn::IsBitNotEqual { .. } => types::CBool,
|
||||
Insn::BoxBool { .. } => types::BoolExact,
|
||||
Insn::BoxFixnum { .. } => types::Fixnum,
|
||||
Insn::UnboxFixnum { .. } => types::CInt64,
|
||||
Insn::UnboxFixnum { val } => {
|
||||
if let Some(fixnum) = self.type_of(*val).fixnum_value() {
|
||||
Type::from_cint(types::CInt64, fixnum)
|
||||
} else {
|
||||
types::CInt64
|
||||
}
|
||||
},
|
||||
Insn::FixnumAref { .. } => types::Fixnum,
|
||||
Insn::StringCopy { .. } => types::StringExact,
|
||||
Insn::StringIntern { .. } => types::Symbol,
|
||||
@ -4073,15 +4079,16 @@ impl Function {
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
Insn::ArrayAref { array, index } if self.type_of(array).ruby_object_known()
|
||||
&& self.type_of(index).ruby_object_known() => {
|
||||
Insn::ArrayAref { array, index }
|
||||
if self.type_of(array).ruby_object_known()
|
||||
&& self.type_of(index).is_subtype(types::CInt64) => {
|
||||
let array_obj = self.type_of(array).ruby_object().unwrap();
|
||||
if array_obj.is_frozen() {
|
||||
let index = self.type_of(index).cint64_value().unwrap();
|
||||
let val = unsafe { rb_yarv_ary_entry_internal(array_obj, index) };
|
||||
self.new_insn(Insn::Const { val: Const::Value(val) })
|
||||
} else {
|
||||
insn_id
|
||||
match (array_obj.is_frozen(), self.type_of(index).cint64_value()) {
|
||||
(true, Some(index)) => {
|
||||
let val = unsafe { rb_yarv_ary_entry_internal(array_obj, index) };
|
||||
self.new_insn(Insn::Const { val: Const::Value(val) })
|
||||
}
|
||||
_ => insn_id,
|
||||
}
|
||||
}
|
||||
Insn::Test { val } if self.type_of(val).is_known_falsy() => {
|
||||
|
||||
@ -1606,7 +1606,7 @@ mod hir_opt_tests {
|
||||
PatchPoint NoSingletonClass(Array@0x1000)
|
||||
PatchPoint MethodRedefined(Array@0x1000, []@0x1008, cme:0x1010)
|
||||
v25:ArrayExact = GuardType v9, ArrayExact
|
||||
v26:CInt64 = UnboxFixnum v14
|
||||
v26:CInt64[0] = UnboxFixnum v14
|
||||
v27:BasicObject = ArrayAref v25, v26
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
@ -4735,7 +4735,7 @@ mod hir_opt_tests {
|
||||
v13:Fixnum[0] = Const Value(0)
|
||||
PatchPoint NoSingletonClass(Array@0x1010)
|
||||
PatchPoint MethodRedefined(Array@0x1010, []@0x1018, cme:0x1020)
|
||||
v27:CInt64 = UnboxFixnum v13
|
||||
v27:CInt64[0] = UnboxFixnum v13
|
||||
v28:BasicObject = ArrayAref v23, v27
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
@ -4765,11 +4765,11 @@ mod hir_opt_tests {
|
||||
v13:Fixnum[1] = Const Value(1)
|
||||
PatchPoint NoSingletonClass(Array@0x1008)
|
||||
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
|
||||
v24:CInt64 = UnboxFixnum v13
|
||||
v25:BasicObject = ArrayAref v11, v24
|
||||
v24:CInt64[1] = UnboxFixnum v13
|
||||
v27:Fixnum[5] = Const Value(5)
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
Return v25
|
||||
Return v27
|
||||
");
|
||||
}
|
||||
|
||||
@ -4793,11 +4793,11 @@ mod hir_opt_tests {
|
||||
v13:Fixnum[-3] = Const Value(-3)
|
||||
PatchPoint NoSingletonClass(Array@0x1008)
|
||||
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
|
||||
v24:CInt64 = UnboxFixnum v13
|
||||
v25:BasicObject = ArrayAref v11, v24
|
||||
v24:CInt64[-3] = UnboxFixnum v13
|
||||
v27:Fixnum[4] = Const Value(4)
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
Return v25
|
||||
Return v27
|
||||
");
|
||||
}
|
||||
|
||||
@ -4821,11 +4821,11 @@ mod hir_opt_tests {
|
||||
v13:Fixnum[-10] = Const Value(-10)
|
||||
PatchPoint NoSingletonClass(Array@0x1008)
|
||||
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
|
||||
v24:CInt64 = UnboxFixnum v13
|
||||
v25:BasicObject = ArrayAref v11, v24
|
||||
v24:CInt64[-10] = UnboxFixnum v13
|
||||
v27:NilClass = Const Value(nil)
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
Return v25
|
||||
Return v27
|
||||
");
|
||||
}
|
||||
|
||||
@ -4849,11 +4849,11 @@ mod hir_opt_tests {
|
||||
v13:Fixnum[10] = Const Value(10)
|
||||
PatchPoint NoSingletonClass(Array@0x1008)
|
||||
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
|
||||
v24:CInt64 = UnboxFixnum v13
|
||||
v25:BasicObject = ArrayAref v11, v24
|
||||
v24:CInt64[10] = UnboxFixnum v13
|
||||
v27:NilClass = Const Value(nil)
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
Return v25
|
||||
Return v27
|
||||
");
|
||||
}
|
||||
|
||||
@ -6741,7 +6741,7 @@ mod hir_opt_tests {
|
||||
v19:Fixnum[0] = Const Value(0)
|
||||
PatchPoint NoSingletonClass(Array@0x1008)
|
||||
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
|
||||
v30:CInt64 = UnboxFixnum v19
|
||||
v30:CInt64[0] = UnboxFixnum v19
|
||||
v31:BasicObject = ArrayAref v14, v30
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
CheckInterrupts
|
||||
@ -7087,11 +7087,11 @@ mod hir_opt_tests {
|
||||
v31:ArrayExact = GuardType v9, ArrayExact
|
||||
v32:ArrayExact = GuardNotFrozen v31
|
||||
v33:ArrayExact = GuardNotShared v32
|
||||
v34:CInt64 = UnboxFixnum v16
|
||||
v34:CInt64[1] = UnboxFixnum v16
|
||||
v35:CInt64 = ArrayLength v33
|
||||
v36:CInt64 = GuardLess v34, v35
|
||||
v36:CInt64[1] = GuardLess v34, v35
|
||||
v37:CInt64[0] = Const CInt64(0)
|
||||
v38:CInt64 = GuardGreaterEq v36, v37
|
||||
v38:CInt64[1] = GuardGreaterEq v36, v37
|
||||
ArrayAset v33, v38, v18
|
||||
WriteBarrier v33, v18
|
||||
IncrCounter inline_cfunc_optimized_send_count
|
||||
|
||||
@ -3566,10 +3566,10 @@ pub mod hir_build_tests {
|
||||
v22:CInt64 = ArrayLength v21
|
||||
v23:CInt64[2] = GuardBitEquals v22, CInt64(2)
|
||||
v24:Fixnum[1] = Const Value(1)
|
||||
v25:CInt64 = UnboxFixnum v24
|
||||
v25:CInt64[1] = UnboxFixnum v24
|
||||
v26:BasicObject = ArrayAref v21, v25
|
||||
v27:Fixnum[0] = Const Value(0)
|
||||
v28:CInt64 = UnboxFixnum v27
|
||||
v28:CInt64[0] = UnboxFixnum v27
|
||||
v29:BasicObject = ArrayAref v21, v28
|
||||
PatchPoint NoEPEscape(test)
|
||||
CheckInterrupts
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user