Skip to content

bugc: the optimizer's fixpoint loop compares JSON that leaves out every block #386

Open

Description

@gnidan

optimizeIr (packages/bugc/src/optimizer/simple-optimizer.ts) repeats the pipeline at -O2 and up "until fixpoint", and it compares rounds by JSON.stringify(current). But a function's blocks are a Map, and so is module.functions, and JSON.stringify writes a Map as {}. The comparison does not see the code at all.

Counting the rounds (a counter in the loop), every program I tried at -O3 runs exactly two: the first round changes something outside the Maps, the second does not, and the loop stops. Whether the second round changed the code, and whether a third would, makes no difference.

So the passes run twice, not to a fixpoint. An optimization that needs a third round (one pass's result enabling another's, two rounds down) does not happen. And tests that count on the fixpoint may test less than they say.

A fix is to compare something that includes the blocks: for example, a serialization that writes Maps as entries, or a "changed" flag from each pass.

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