Skip to content

Commit 1197566

Browse files
committed
.
1 parent f0e49a1 commit 1197566

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

zjit/mini_zjit.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,32 @@ def test_store_to_disjoint_receiver_does_not_kill_load
24882488
Return v6
24892489
HIR
24902490
end
2491+
2492+
def test_store_to_same_slot_kills_prior_load
2493+
fun = Function.new("test")
2494+
bb0 = fun.new_block
2495+
obj = fun.push_insn(bb0, Param.new(0, Types::BasicObject))
2496+
val = fun.push_insn(bb0, Const.new(5, Types::Fixnum.with_const(5)))
2497+
load1 = fun.push_insn(bb0, LoadField.new(obj, :x))
2498+
fun.push_insn(bb0, StoreField.new(obj, :x, val))
2499+
load2 = fun.push_insn(bb0, LoadField.new(obj, :x))
2500+
add = fun.push_insn(bb0, FixnumAdd.new(load1, load2, nil))
2501+
fun.push_insn(bb0, Return.new(add))
2502+
2503+
fun.optimize_load_store_tbaa
2504+
fun.eliminate_dead_code
2505+
2506+
assert_hir_text fun.to_s, <<~HIR
2507+
fn test:
2508+
bb0(v0:BasicObject):
2509+
v1:Fixnum[5] = Const 5
2510+
v2:BasicObject = LoadField v0, :x
2511+
StoreField v0, :x, v1
2512+
v4:BasicObject = LoadField v0, :x
2513+
v5:Fixnum = FixnumAdd v2, v4
2514+
Return v5
2515+
HIR
2516+
end
24912517
end
24922518

24932519
# ── clean_cfg tests ─────────────────────────────────────────────

0 commit comments

Comments
 (0)