Skip to content

Commit 875d600

Browse files
committed
Get load_store optimization working
1 parent fe2fac4 commit 875d600

2 files changed

Lines changed: 9 additions & 24 deletions

File tree

zjit/src/hir.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ impl Insn {
11721172
Insn::LoadSelf { .. } => Effect::read_write(abstract_heaps::Frame, abstract_heaps::Empty),
11731173
Insn::LoadField { .. } => Effect::read_write(abstract_heaps::Memory, abstract_heaps::Empty),
11741174
Insn::StoreField { .. } => effects::Any,
1175-
Insn::WriteBarrier { .. } => effects::Any,
1175+
Insn::WriteBarrier { .. } => effects::Allocator,
11761176
Insn::GetLocal { .. } => Effect::read_write(abstract_heaps::Locals, abstract_heaps::Empty),
11771177
Insn::SetLocal { .. } => effects::Any,
11781178
Insn::GetSpecialSymbol { .. } => effects::Any,
@@ -1262,6 +1262,9 @@ impl Insn {
12621262
/// Note: These are restrictions on the `write` `EffectSet` only. Even instructions with
12631263
/// `read: effects::Any` could potentially be omitted.
12641264
fn is_elidable(&self) -> bool {
1265+
if let Insn::WriteBarrier { .. } = self {
1266+
return false
1267+
}
12651268
abstract_heaps::Allocator.includes(self.effects_of().write_bits())
12661269
}
12671270
}
@@ -4486,41 +4489,35 @@ impl Function {
44864489
// The key for the hashmap should be type and offset, with a value of value
44874490
// This lets us to index in with both load and store fields since insn_ids are probably always going to be different and we can't easily match on that
44884491
// So... how do we match against and store the enum label without all the data?? not sure yet :/
4489-
eprintln!("{}", FunctionPrinter::with_snapshot(self));
44904492
let mut compile_time_heap: HashMap<(InsnId, i32), InsnId> = HashMap::new();
44914493
for block in self.rpo() {
44924494
let old_insns = std::mem::take(&mut self.blocks[block.0].insns);
44934495
let mut new_insns = vec![];
44944496
for insn_id in old_insns {
44954497
let replacement_insn: InsnId = match self.find(insn_id) {
44964498
Insn::StoreField { recv, offset, val, .. } => {
4497-
let key = (recv, offset);
4498-
eprintln!("hi jane");
4499+
let key = (self.chase_insn(recv), offset);
44994500
let heap_entry = compile_time_heap.get(&key).copied();
4500-
eprintln!("{heap_entry:?}");
45014501
// TODO(Jacob): Switch from actual to partial equality
45024502
if Some(val) == heap_entry {
4503-
eprintln!("Matched value {val}, {heap_entry:?}");
45044503
// TODO(Jacob): Add TBAA to avoid removing so many entries
4505-
eprintln!("Erasing aliasing offsets {offset}");
45064504
compile_time_heap.retain(|(_, off), _| *off != offset);
45074505
// If the value is already stored, short circuit and don't add an instruction to the block
45084506
continue
45094507
}
45104508
// TODO(Jacob): Add TBAA to avoid removing so many entries
4511-
eprintln!("Erasing aliasing offsets {offset}");
45124509
compile_time_heap.retain(|(_, off), _| *off != offset);
45134510
compile_time_heap.insert(key, val);
4514-
eprintln!("Inserted into heap {key:?}, {val}");
45154511
insn_id
45164512
},
45174513
Insn::LoadField { recv, offset, .. } => {
4518-
let key = (recv, offset);
4514+
let key = (self.chase_insn(recv), offset);
45194515
match compile_time_heap.entry(key) {
45204516
std::collections::hash_map::Entry::Occupied(entry) => {
45214517
// If the value is already saved, we can't short circuit like we can with a store.
45224518
// However, we can avoid the load with a reference to the representative to the union from SSA.
45234519
self.make_equal_to(insn_id, *entry.get());
4520+
continue
45244521
}
45254522
std::collections::hash_map::Entry::Vacant(_) => {
45264523
// TODO(Jacob): Make sure this is correct, could be wrong?
@@ -4532,7 +4529,6 @@ impl Function {
45324529
insn => {
45334530
// If an instruction affects memory and we haven't modeled it, the compile_time_heap is invalidated
45344531
if insn.effects_of().includes(Effect::write(abstract_heaps::Memory)) {
4535-
eprintln!("Clearing... {insn:?}");
45364532
compile_time_heap.clear();
45374533
}
45384534
insn_id

zjit/src/hir/opt_tests.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5007,8 +5007,6 @@ mod hir_opt_tests {
50075007
v14:HeapBasicObject = RefineType v6, HeapBasicObject
50085008
v17:Fixnum[2] = Const Value(2)
50095009
PatchPoint SingleRactorMode
5010-
v36:CShape = LoadField v14, :_shape_id@0x1000
5011-
v37:CShape[0x1003] = GuardBitEquals v36, CShape(0x1003)
50125010
StoreField v14, :@bar@0x1004, v17
50135011
WriteBarrier v14, v17
50145012
v40:CShape[0x1005] = Const CShape(0x1005)
@@ -8390,8 +8388,7 @@ mod hir_opt_tests {
83908388
v32:ArrayExact = GuardType v9, ArrayExact
83918389
v33:CUInt64 = LoadField v32, :_rbasic_flags@0x1038
83928390
v34:CUInt64 = GuardNoBitsSet v33, RUBY_FL_FREEZE=CUInt64(2048)
8393-
v35:CUInt64 = LoadField v32, :_rbasic_flags@0x1038
8394-
v36:CUInt64 = GuardNoBitsSet v35, RUBY_ELTS_SHARED=CUInt64(4096)
8391+
v36:CUInt64 = GuardNoBitsSet v33, RUBY_ELTS_SHARED=CUInt64(4096)
83958392
v37:CInt64[1] = UnboxFixnum v16
83968393
v38:CInt64 = ArrayLength v32
83978394
v39:CInt64[1] = GuardLess v37, v38
@@ -8436,8 +8433,7 @@ mod hir_opt_tests {
84368433
v37:Fixnum = GuardType v14, Fixnum
84378434
v38:CUInt64 = LoadField v36, :_rbasic_flags@0x1038
84388435
v39:CUInt64 = GuardNoBitsSet v38, RUBY_FL_FREEZE=CUInt64(2048)
8439-
v40:CUInt64 = LoadField v36, :_rbasic_flags@0x1038
8440-
v41:CUInt64 = GuardNoBitsSet v40, RUBY_ELTS_SHARED=CUInt64(4096)
8436+
v41:CUInt64 = GuardNoBitsSet v38, RUBY_ELTS_SHARED=CUInt64(4096)
84418437
v42:CInt64 = UnboxFixnum v37
84428438
v43:CInt64 = ArrayLength v36
84438439
v44:CInt64 = GuardLess v42, v43
@@ -13032,17 +13028,13 @@ mod hir_opt_tests {
1303213028
v14:HeapBasicObject = RefineType v6, HeapBasicObject
1303313029
v17:Fixnum[2] = Const Value(2)
1303413030
PatchPoint SingleRactorMode
13035-
v50:CShape = LoadField v14, :_shape_id@0x1000
13036-
v51:CShape[0x1003] = GuardBitEquals v50, CShape(0x1003)
1303713031
StoreField v14, :@b@0x1004, v17
1303813032
WriteBarrier v14, v17
1303913033
v54:CShape[0x1005] = Const CShape(0x1005)
1304013034
StoreField v14, :_shape_id@0x1000, v54
1304113035
v21:HeapBasicObject = RefineType v14, HeapBasicObject
1304213036
v24:Fixnum[3] = Const Value(3)
1304313037
PatchPoint SingleRactorMode
13044-
v57:CShape = LoadField v21, :_shape_id@0x1000
13045-
v58:CShape[0x1005] = GuardBitEquals v57, CShape(0x1005)
1304613038
StoreField v21, :@c@0x1006, v24
1304713039
WriteBarrier v21, v24
1304813040
v61:CShape[0x1007] = Const CShape(0x1007)
@@ -13247,9 +13239,6 @@ mod hir_opt_tests {
1324713239
v20:HeapBasicObject = RefineType v8, HeapBasicObject
1324813240
PatchPoint NoEPEscape(initialize)
1324913241
PatchPoint SingleRactorMode
13250-
v43:CShape = LoadField v20, :_shape_id@0x1000
13251-
v44:CShape[0x1003] = GuardBitEquals v43, CShape(0x1003)
13252-
StoreField v20, :@a@0x1002, v13
1325313242
WriteBarrier v20, v13
1325413243
CheckInterrupts
1325513244
Return v13

0 commit comments

Comments
 (0)