Skip to content

bugc: rename phi incoming blocks when block merging folds a block - #320

Merged
gnidan merged 1 commit into
mainfrom
bugc-o3-call-revert
Oct 4, 2026
Merged

gnidan merged 1 commit into
mainfrom
bugc-o3-call-revert

Conversation

@gnidan

@gnidan gnidan commented Oct 4, 2026

Copy link
Copy Markdown
Member

At -O3, a for loop that carries a local across iterations compiled to bytecode that reverted. Levels 0–2 were correct. A loop that calls an internal function to update an accumulator is one common way to hit it, but the call is incidental: level 2 inlines it, and a plain acc = acc + i loop fails the same way.

The cause is in the block-merging step, which only runs at level 3. It folds the loop's update block into the body block and rewrites predecessor sets and jump targets, but it left the loop header's phi operands keyed by the deleted block. The header's phis then had no operand for the back edge, and the generated bytecode reverted.

The step now renames the key in every phi's sources (and sourcesDebug) from the merged block to the block it merged into.

Behavioral tests in evmgen/behavioral.test.ts run a loop-carried local and an internal call in a loop at every optimization level and check the stored result.

@gnidan
gnidan force-pushed the bugc-o3-call-revert branch from 903131a to 84745b7 Compare October 4, 2026 17:44
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-04 17:55 UTC

@gnidan
gnidan merged commit fd99bd4 into main Oct 4, 2026
7 checks passed
@gnidan
gnidan deleted the bugc-o3-call-revert branch October 4, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant