Skip to content

Commit ed10313

Browse files
committed
Clean up for PR review
1 parent d822390 commit ed10313

2 files changed

Lines changed: 155 additions & 15 deletions

File tree

zjit/src/hir.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,18 +4607,7 @@ impl Function {
46074607
self.infer_types();
46084608
}
46094609

4610-
// struct Heap {
4611-
// fn load(obj, offset)
4612-
// fn kill(obj, offset)
4613-
// fn store(obj, offset, val)
4614-
// }
4615-
46164610
fn optimize_load_store(&mut self) {
4617-
// TODO: Add specific tests for load_store
4618-
// TODO: Add dead store elimination
4619-
// The key for the hashmap should be type and offset, with a value of value
4620-
// 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
4621-
// So... how do we match against and store the enum label without all the data?? not sure yet :/
46224611
let mut compile_time_heap: HashMap<(InsnId, i32), InsnId> = HashMap::new();
46234612
for block in self.rpo() {
46244613
let old_insns = std::mem::take(&mut self.blocks[block.0].insns);
@@ -4644,13 +4633,12 @@ impl Function {
46444633
let key = (self.chase_insn(recv), offset);
46454634
match compile_time_heap.entry(key) {
46464635
std::collections::hash_map::Entry::Occupied(entry) => {
4647-
// If the value is already saved, we can't short circuit like we can with a store.
4648-
// However, we can avoid the load with a reference to the representative to the union from SSA.
4636+
// If the value is stored already, we should short circuit.
4637+
// However, we need to replace insn_id with its representative in the SSA union.
46494638
self.make_equal_to(insn_id, *entry.get());
46504639
continue
46514640
}
46524641
std::collections::hash_map::Entry::Vacant(_) => {
4653-
// TODO(Jacob): Make sure this is correct, could be wrong?
46544642
compile_time_heap.insert(key, insn_id);
46554643
}
46564644
}

zjit/src/hir/opt_tests.rs

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13690,7 +13690,7 @@ mod hir_opt_tests {
1369013690
}
1369113691

1369213692
#[test]
13693-
fn test_double_store_removal() {
13693+
fn test_double_store_with_removal() {
1369413694
eval("
1369513695
class C
1369613696
def initialize
@@ -13732,4 +13732,156 @@ mod hir_opt_tests {
1373213732
Return v13
1373313733
");
1373413734
}
13735+
13736+
#[test]
13737+
fn test_double_store_no_removal_with_alias_between() {
13738+
eval("
13739+
class C
13740+
def initialize
13741+
a = 1
13742+
@a = a
13743+
@b = a
13744+
@a = a
13745+
end
13746+
end
13747+
13748+
C.new
13749+
");
13750+
assert_snapshot!(hir_string_proc("C.instance_method(:initialize)"), @r"
13751+
fn initialize@<compiled>:4:
13752+
bb1():
13753+
EntryPoint interpreter
13754+
v1:BasicObject = LoadSelf
13755+
v2:NilClass = Const Value(nil)
13756+
Jump bb3(v1, v2)
13757+
bb2():
13758+
EntryPoint JIT(0)
13759+
v5:BasicObject = LoadArg :self@0
13760+
v6:NilClass = Const Value(nil)
13761+
Jump bb3(v5, v6)
13762+
bb3(v8:BasicObject, v9:NilClass):
13763+
v13:Fixnum[1] = Const Value(1)
13764+
PatchPoint SingleRactorMode
13765+
v43:HeapBasicObject = GuardType v8, HeapBasicObject
13766+
v44:CShape = LoadField v43, :_shape_id@0x1000
13767+
v45:CShape[0x1001] = GuardBitEquals v44, CShape(0x1001)
13768+
StoreField v43, :@a@0x1002, v13
13769+
WriteBarrier v43, v13
13770+
v48:CShape[0x1003] = Const CShape(0x1003)
13771+
StoreField v43, :_shape_id@0x1000, v48
13772+
v20:HeapBasicObject = RefineType v8, HeapBasicObject
13773+
PatchPoint NoEPEscape(initialize)
13774+
PatchPoint SingleRactorMode
13775+
StoreField v20, :@b@0x1004, v13
13776+
WriteBarrier v20, v13
13777+
v55:CShape[0x1005] = Const CShape(0x1005)
13778+
StoreField v20, :_shape_id@0x1000, v55
13779+
v28:HeapBasicObject = RefineType v20, HeapBasicObject
13780+
PatchPoint NoEPEscape(initialize)
13781+
PatchPoint SingleRactorMode
13782+
WriteBarrier v28, v13
13783+
CheckInterrupts
13784+
Return v13
13785+
");
13786+
}
13787+
13788+
#[test]
13789+
fn test_double_store_with_removal_and_insns_between() {
13790+
eval("
13791+
class C
13792+
def initialize
13793+
a = 1
13794+
@a = a
13795+
b = 5
13796+
b += a
13797+
@a = a
13798+
end
13799+
end
13800+
13801+
C.new
13802+
");
13803+
assert_snapshot!(hir_string_proc("C.instance_method(:initialize)"), @r"
13804+
fn initialize@<compiled>:4:
13805+
bb1():
13806+
EntryPoint interpreter
13807+
v1:BasicObject = LoadSelf
13808+
v2:NilClass = Const Value(nil)
13809+
v3:NilClass = Const Value(nil)
13810+
Jump bb3(v1, v2, v3)
13811+
bb2():
13812+
EntryPoint JIT(0)
13813+
v6:BasicObject = LoadArg :self@0
13814+
v7:NilClass = Const Value(nil)
13815+
v8:NilClass = Const Value(nil)
13816+
Jump bb3(v6, v7, v8)
13817+
bb3(v10:BasicObject, v11:NilClass, v12:NilClass):
13818+
v16:Fixnum[1] = Const Value(1)
13819+
PatchPoint SingleRactorMode
13820+
v49:HeapBasicObject = GuardType v10, HeapBasicObject
13821+
v50:CShape = LoadField v49, :_shape_id@0x1000
13822+
v51:CShape[0x1001] = GuardBitEquals v50, CShape(0x1001)
13823+
StoreField v49, :@a@0x1002, v16
13824+
WriteBarrier v49, v16
13825+
v54:CShape[0x1003] = Const CShape(0x1003)
13826+
StoreField v49, :_shape_id@0x1000, v54
13827+
v23:HeapBasicObject = RefineType v10, HeapBasicObject
13828+
v26:Fixnum[5] = Const Value(5)
13829+
PatchPoint NoEPEscape(initialize)
13830+
PatchPoint MethodRedefined(Integer@0x1008, +@0x1010, cme:0x1018)
13831+
v65:Fixnum[6] = Const Value(6)
13832+
IncrCounter inline_cfunc_optimized_send_count
13833+
PatchPoint SingleRactorMode
13834+
WriteBarrier v23, v16
13835+
CheckInterrupts
13836+
Return v16
13837+
");
13838+
}
13839+
13840+
#[test]
13841+
fn test_triple_store_with_removal() {
13842+
eval("
13843+
class C
13844+
def initialize
13845+
a = 1
13846+
@a = a
13847+
@a = a
13848+
@a = a
13849+
end
13850+
end
13851+
13852+
C.new
13853+
");
13854+
assert_snapshot!(hir_string_proc("C.instance_method(:initialize)"), @r"
13855+
fn initialize@<compiled>:4:
13856+
bb1():
13857+
EntryPoint interpreter
13858+
v1:BasicObject = LoadSelf
13859+
v2:NilClass = Const Value(nil)
13860+
Jump bb3(v1, v2)
13861+
bb2():
13862+
EntryPoint JIT(0)
13863+
v5:BasicObject = LoadArg :self@0
13864+
v6:NilClass = Const Value(nil)
13865+
Jump bb3(v5, v6)
13866+
bb3(v8:BasicObject, v9:NilClass):
13867+
v13:Fixnum[1] = Const Value(1)
13868+
PatchPoint SingleRactorMode
13869+
v43:HeapBasicObject = GuardType v8, HeapBasicObject
13870+
v44:CShape = LoadField v43, :_shape_id@0x1000
13871+
v45:CShape[0x1001] = GuardBitEquals v44, CShape(0x1001)
13872+
StoreField v43, :@a@0x1002, v13
13873+
WriteBarrier v43, v13
13874+
v48:CShape[0x1003] = Const CShape(0x1003)
13875+
StoreField v43, :_shape_id@0x1000, v48
13876+
v20:HeapBasicObject = RefineType v8, HeapBasicObject
13877+
PatchPoint NoEPEscape(initialize)
13878+
PatchPoint SingleRactorMode
13879+
WriteBarrier v20, v13
13880+
v28:HeapBasicObject = RefineType v20, HeapBasicObject
13881+
StoreField v28, :@a@0x1002, v13
13882+
WriteBarrier v28, v13
13883+
CheckInterrupts
13884+
Return v13
13885+
");
13886+
}
1373513887
}

0 commit comments

Comments
 (0)