@@ -13196,7 +13196,7 @@ mod hir_opt_tests {
1319613196 }
1319713197
1319813198 #[ test]
13199- fn test_double_store_removal ( ) {
13199+ fn test_double_store_with_removal ( ) {
1320013200 eval ( "
1320113201 class C
1320213202 def initialize
@@ -13238,4 +13238,156 @@ mod hir_opt_tests {
1323813238 Return v13
1323913239 " ) ;
1324013240 }
13241+
13242+ #[ test]
13243+ fn test_double_store_no_removal_with_alias_between ( ) {
13244+ eval ( "
13245+ class C
13246+ def initialize
13247+ a = 1
13248+ @a = a
13249+ @b = a
13250+ @a = a
13251+ end
13252+ end
13253+
13254+ C.new
13255+ " ) ;
13256+ assert_snapshot ! ( hir_string_proc( "C.instance_method(:initialize)" ) , @r"
13257+ fn initialize@<compiled>:4:
13258+ bb1():
13259+ EntryPoint interpreter
13260+ v1:BasicObject = LoadSelf
13261+ v2:NilClass = Const Value(nil)
13262+ Jump bb3(v1, v2)
13263+ bb2():
13264+ EntryPoint JIT(0)
13265+ v5:BasicObject = LoadArg :self@0
13266+ v6:NilClass = Const Value(nil)
13267+ Jump bb3(v5, v6)
13268+ bb3(v8:BasicObject, v9:NilClass):
13269+ v13:Fixnum[1] = Const Value(1)
13270+ PatchPoint SingleRactorMode
13271+ v43:HeapBasicObject = GuardType v8, HeapBasicObject
13272+ v44:CShape = LoadField v43, :_shape_id@0x1000
13273+ v45:CShape[0x1001] = GuardBitEquals v44, CShape(0x1001)
13274+ StoreField v43, :@a@0x1002, v13
13275+ WriteBarrier v43, v13
13276+ v48:CShape[0x1003] = Const CShape(0x1003)
13277+ StoreField v43, :_shape_id@0x1000, v48
13278+ v20:HeapBasicObject = RefineType v8, HeapBasicObject
13279+ PatchPoint NoEPEscape(initialize)
13280+ PatchPoint SingleRactorMode
13281+ StoreField v20, :@b@0x1004, v13
13282+ WriteBarrier v20, v13
13283+ v55:CShape[0x1005] = Const CShape(0x1005)
13284+ StoreField v20, :_shape_id@0x1000, v55
13285+ v28:HeapBasicObject = RefineType v20, HeapBasicObject
13286+ PatchPoint NoEPEscape(initialize)
13287+ PatchPoint SingleRactorMode
13288+ WriteBarrier v28, v13
13289+ CheckInterrupts
13290+ Return v13
13291+ " ) ;
13292+ }
13293+
13294+ #[ test]
13295+ fn test_double_store_with_removal_and_insns_between ( ) {
13296+ eval ( "
13297+ class C
13298+ def initialize
13299+ a = 1
13300+ @a = a
13301+ b = 5
13302+ b += a
13303+ @a = a
13304+ end
13305+ end
13306+
13307+ C.new
13308+ " ) ;
13309+ assert_snapshot ! ( hir_string_proc( "C.instance_method(:initialize)" ) , @r"
13310+ fn initialize@<compiled>:4:
13311+ bb1():
13312+ EntryPoint interpreter
13313+ v1:BasicObject = LoadSelf
13314+ v2:NilClass = Const Value(nil)
13315+ v3:NilClass = Const Value(nil)
13316+ Jump bb3(v1, v2, v3)
13317+ bb2():
13318+ EntryPoint JIT(0)
13319+ v6:BasicObject = LoadArg :self@0
13320+ v7:NilClass = Const Value(nil)
13321+ v8:NilClass = Const Value(nil)
13322+ Jump bb3(v6, v7, v8)
13323+ bb3(v10:BasicObject, v11:NilClass, v12:NilClass):
13324+ v16:Fixnum[1] = Const Value(1)
13325+ PatchPoint SingleRactorMode
13326+ v49:HeapBasicObject = GuardType v10, HeapBasicObject
13327+ v50:CShape = LoadField v49, :_shape_id@0x1000
13328+ v51:CShape[0x1001] = GuardBitEquals v50, CShape(0x1001)
13329+ StoreField v49, :@a@0x1002, v16
13330+ WriteBarrier v49, v16
13331+ v54:CShape[0x1003] = Const CShape(0x1003)
13332+ StoreField v49, :_shape_id@0x1000, v54
13333+ v23:HeapBasicObject = RefineType v10, HeapBasicObject
13334+ v26:Fixnum[5] = Const Value(5)
13335+ PatchPoint NoEPEscape(initialize)
13336+ PatchPoint MethodRedefined(Integer@0x1008, +@0x1010, cme:0x1018)
13337+ v65:Fixnum[6] = Const Value(6)
13338+ IncrCounter inline_cfunc_optimized_send_count
13339+ PatchPoint SingleRactorMode
13340+ WriteBarrier v23, v16
13341+ CheckInterrupts
13342+ Return v16
13343+ " ) ;
13344+ }
13345+
13346+ #[ test]
13347+ fn test_triple_store_with_removal ( ) {
13348+ eval ( "
13349+ class C
13350+ def initialize
13351+ a = 1
13352+ @a = a
13353+ @a = a
13354+ @a = a
13355+ end
13356+ end
13357+
13358+ C.new
13359+ " ) ;
13360+ assert_snapshot ! ( hir_string_proc( "C.instance_method(:initialize)" ) , @r"
13361+ fn initialize@<compiled>:4:
13362+ bb1():
13363+ EntryPoint interpreter
13364+ v1:BasicObject = LoadSelf
13365+ v2:NilClass = Const Value(nil)
13366+ Jump bb3(v1, v2)
13367+ bb2():
13368+ EntryPoint JIT(0)
13369+ v5:BasicObject = LoadArg :self@0
13370+ v6:NilClass = Const Value(nil)
13371+ Jump bb3(v5, v6)
13372+ bb3(v8:BasicObject, v9:NilClass):
13373+ v13:Fixnum[1] = Const Value(1)
13374+ PatchPoint SingleRactorMode
13375+ v43:HeapBasicObject = GuardType v8, HeapBasicObject
13376+ v44:CShape = LoadField v43, :_shape_id@0x1000
13377+ v45:CShape[0x1001] = GuardBitEquals v44, CShape(0x1001)
13378+ StoreField v43, :@a@0x1002, v13
13379+ WriteBarrier v43, v13
13380+ v48:CShape[0x1003] = Const CShape(0x1003)
13381+ StoreField v43, :_shape_id@0x1000, v48
13382+ v20:HeapBasicObject = RefineType v8, HeapBasicObject
13383+ PatchPoint NoEPEscape(initialize)
13384+ PatchPoint SingleRactorMode
13385+ WriteBarrier v20, v13
13386+ v28:HeapBasicObject = RefineType v20, HeapBasicObject
13387+ StoreField v28, :@a@0x1002, v13
13388+ WriteBarrier v28, v13
13389+ CheckInterrupts
13390+ Return v13
13391+ " ) ;
13392+ }
1324113393}
0 commit comments