Skip to content

bugc: CSE leaves a removed temp in ssaVariables, so the local loses its location #392

Open

Description

@gnidan

Common subexpression elimination (packages/bugc/src/optimizer/steps/common-subexpression-elimination.ts) replaces a duplicate computation's temp with the earlier one, but it does not update func.ssaVariables. A local whose temp it removes keeps pointing at a temp that no longer exists, so evmgen gives it no location.

name CseLocal;
storage { [0] s: address; [1] t: address; [2] n: uint256; }
create {}
code {
  let a = msg.sender;
  n = 1;
  let b = msg.sender;
  s = b;
  t = a;
}

At -O0 and -O1, b has stack pointers in the runtime program's variables contexts. At -O2 and -O3, the IR is

%t0 = env msg_sender
storage[0x02*] = 0x01
storage[slot: 0x00, length: 0x14] = %t0
storage[slot: 0x01, length: 0x14] = %t0

b's SSA entry still names t3, and b appears only as {"identifier":"b"}, with no pointer anywhere, although its value is in t0 (a's home) the whole time.

CSE could record the replacement in ssaVariables (the entry's temp field), the way other passes keep a local's location when they rename its temp.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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