Skip to content

ZJIT: Implement dead store elimination #956

@jacob-shops

Description

@jacob-shops

Right now, the following Ruby code generates the following HIR.

class C
  def initialize
    @a = 1
    @b = 2
    @c = 3
  end
end

C.new
fn initialize@<compiled>:4:
bb1():
  EntryPoint interpreter
  v1:BasicObject = LoadSelf
  Jump bb3(v1)
bb2():
  EntryPoint JIT(0)
  v4:BasicObject = LoadArg :self@0
  Jump bb3(v4)
bb3(v6:BasicObject):
  v10:Fixnum[1] = Const Value(1)
  PatchPoint SingleRactorMode
  v35:HeapBasicObject = GuardType v6, HeapBasicObject
  v36:CShape = LoadField v35, :_shape_id@0x1000
  v37:CShape[0x1001] = GuardBitEquals v36, CShape(0x1001)
  StoreField v35, :@a@0x1002, v10
  WriteBarrier v35, v10
  v40:CShape[0x1003] = Const CShape(0x1003)
  StoreField v35, :_shape_id@0x1000, v40
  v14:HeapBasicObject = RefineType v6, HeapBasicObject
  v17:Fixnum[2] = Const Value(2)
  PatchPoint SingleRactorMode
  StoreField v14, :@b@0x1004, v17
  WriteBarrier v14, v17
  v47:CShape[0x1005] = Const CShape(0x1005)
  StoreField v14, :_shape_id@0x1000, v47
  v21:HeapBasicObject = RefineType v14, HeapBasicObject
  v24:Fixnum[3] = Const Value(3)
  PatchPoint SingleRactorMode
  StoreField v21, :@c@0x1006, v24
  WriteBarrier v21, v24
  v54:CShape[0x1007] = Const CShape(0x1007)
  StoreField v21, :_shape_id@0x1000, v54
  CheckInterrupts
  Return v24

We would like it to look roughly like the following instead

fn initialize@<compiled>:4:
bb1():
  EntryPoint interpreter
  v1:BasicObject = LoadSelf
  Jump bb3(v1)
bb2():
  EntryPoint JIT(0)
  v4:BasicObject = LoadArg :self@0
  Jump bb3(v4)
bb3(v6:BasicObject):
  v10:Fixnum[1] = Const Value(1)
  PatchPoint SingleRactorMode
  v35:HeapBasicObject = GuardType v6, HeapBasicObject
  v36:CShape = LoadField v35, :_shape_id@0x1000
  v37:CShape[0x1001] = GuardBitEquals v36, CShape(0x1001)
  StoreField v35, :@a@0x1002, v10
  WriteBarrier v35, v10
  v40:CShape[0x1003] = Const CShape(0x1003)
- StoreField v35, :_shape_id@0x1000, v40
  v14:HeapBasicObject = RefineType v6, HeapBasicObject
  v17:Fixnum[2] = Const Value(2)
  PatchPoint SingleRactorMode
  StoreField v14, :@b@0x1004, v17
  WriteBarrier v14, v17
  v47:CShape[0x1005] = Const CShape(0x1005)
- StoreField v14, :_shape_id@0x1000, v47
  v21:HeapBasicObject = RefineType v14, HeapBasicObject
  v24:Fixnum[3] = Const Value(3)
  PatchPoint SingleRactorMode
  StoreField v21, :@c@0x1006, v24
  WriteBarrier v21, v24
  v54:CShape[0x1007] = Const CShape(0x1007)
  StoreField v21, :_shape_id@0x1000, v54
  CheckInterrupts
  Return v24

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions