Skip to content

Commit b78a0fa

Browse files
committed
ZJIT: Keep array flags cached across ArrayAset
An element store never changes the array's flags, so we can keep cached RBASIC_FLAGS loads in the load/store optimization pass instead of clearing all cached loads.
1 parent b6fd1ed commit b78a0fa

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎zjit/src/hir.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,6 +6794,15 @@ impl Function {
67946794
}
67956795
insn_id
67966796
}
6797+
&Insn::ArrayAset { .. } => {
6798+
// TODO: Model this better using separate effects. Aset doesn't change the
6799+
// array's flags, but the current effects system lumps flags in with other
6800+
// memory writes, so we manually exclude the flags from invalidation for
6801+
// now.
6802+
let offset = RUBY_OFFSET_RBASIC_FLAGS;
6803+
compile_time_heap.retain(|(_, off), _| *off == offset);
6804+
insn_id
6805+
}
67976806
&Insn::WriteBarrier { .. } | &Insn::StringCoderange { .. } => {
67986807
// Both operations may update object flags. We must invalidate cached flag
67996808
// bits loads until the effect system can model individual fields.

‎zjit/src/hir/opt_tests.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27568,9 +27568,8 @@ mod hir_opt_tests {
2756827568
v31:Fixnum[2] = Const Value(2)
2756927569
PatchPoint NoSingletonClass(Array@0x1008)
2757027570
PatchPoint MethodRedefined(Array@0x1008, []=@0x1010, cme:0x1018)
27571-
v63:CUInt64 = LoadField v47, :RBASIC_FLAGS@0x1040
27572-
v64:CUInt64 = GuardNoBitsSet v63, RUBY_FL_FREEZE=CUInt64(2048)
27573-
v66:CUInt64 = GuardNoBitsSet v64, RUBY_ELTS_SHARED=CUInt64(4096)
27571+
v64:CUInt64 = GuardNoBitsSet v49, RUBY_FL_FREEZE=CUInt64(2048)
27572+
v66:CUInt64 = GuardNoBitsSet v49, RUBY_ELTS_SHARED=CUInt64(4096)
2757427573
v75:CInt64[1] = Const CInt64(1)
2757527574
v68:CInt64 = ArrayLength v47
2757627575
v69:CInt64[1] = GuardLess v75, v68
@@ -27646,9 +27645,8 @@ mod hir_opt_tests {
2764627645
v106:Fixnum = GuardType v103, Fixnum recompile
2764727646
v107:Fixnum = FixnumAdd v106, v50
2764827647
PatchPoint MethodRedefined(Array@0x1008, []=@0x1078, cme:0x1080)
27649-
v113:CUInt64 = LoadField v69, :RBASIC_FLAGS@0x10a8
27650-
v114:CUInt64 = GuardNoBitsSet v113, RUBY_FL_FREEZE=CUInt64(2048)
27651-
v116:CUInt64 = GuardNoBitsSet v114, RUBY_ELTS_SHARED=CUInt64(4096)
27648+
v114:CUInt64 = GuardNoBitsSet v85, RUBY_FL_FREEZE=CUInt64(2048)
27649+
v116:CUInt64 = GuardNoBitsSet v85, RUBY_ELTS_SHARED=CUInt64(4096)
2765227650
v117:CInt64 = UnboxFixnum v99
2765327651
v118:CInt64 = ArrayLength v69
2765427652
v119:CInt64 = GuardLess v117, v118

0 commit comments

Comments
 (0)