Skip to content

--llzk-duplicate-op-elim reuses stateful reads across writes/stores #568

Description

@1sgtpepper

Summary

--llzk-duplicate-op-elim can reuse a global.read or ram.load across an intervening write/store to the same state.

Reproduction

Reproducer run:
https://github.com/Kuhai9801/llzk-lib/actions/runs/28180228869

Global read/write:

global.def @g : !felt.type = 1

function.def @compute() -> !struct.type<@GlobalState> {
  %self = struct.new : !struct.type<@GlobalState>
  %two = felt.const 2
  %before = global.read @g : !felt.type
  global.write @g = %two : !felt.type
  %after = global.read @g : !felt.type
  struct.writem %self[@out] = %after : !struct.type<@GlobalState>, !felt.type
  function.return %self : !struct.type<@GlobalState>
}

Run: llzk-opt --llzk-duplicate-op-elim repro.llzk

Actual: later uses are rewritten to the first global.read / ram.load.

Expected

The second global.read @g and second ram.load %addr remain after the intervening write/store.

Actual

The later read/load is removed and its uses are rewritten to the earlier read/load result.

Notes

The relevant pass is in lib/Transforms/LLZKRedundantOperationEliminationPass.cpp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions