Skip to content

Add SSA-CFG invariant checks - #16983

Open
msooseth wants to merge 31 commits into
developfrom
mate-ssa-invariants-only
Open

msooseth wants to merge 31 commits into
developfrom
mate-ssa-invariants-only

Conversation

@msooseth

@msooseth msooseth commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Adds invariant checks to SSA-CFG. Currently, the SSA-CFG fails the phis at the beginning, sol it's disabled. MainExit count is also often 0, even though I think it should be 1? Also disabled. Both are disabled with #if 0 so it's ugly as hell and should be quite visible. All is gated with SLOW_DEBUG, but this is ugly and will need to go. Look past it please.

Checks added are listed below.

InstructionStore:

  • Per-opcode checks (e.g. Const has no inputs)
  • Every referenced operand exists
  • Literal dedup table is actually dedup-ed
  • Value-dependency graph acyclic

SSACFG:

  • Projections: no other instructions in between, returns match projection number
  • Edge consistency between blocks
  • Phi/Upsilon symmetries/relationships
  • Every instruction is first defined, then used
  • Every instruction scheduled

Things I need help with

  • We need to figure out what to do with SLOW_DEBUG. Some of these should run always, and some only in a debug build. We should decide which ones.
  • What should we do with _ctx? It's built, always, but only used when emitting an error, which could be expensive. Perhaps only pass non-empty _ctx in debug build only?
  • The #if 0-s in SSACFG.cpp are things we want, but are not currently true. Should they stay?
  • The SSACFG.h has a public&private block in SLOW_DEBUG, which makes it a bit messy. But also not sure how to structure it otherwise. Maybe a friend class? Perhaps would make more sense?

Checklist

AI Disclosure

  • No AI tools were used
  • Claude was used
  • I did, actually, review, line by line, and character by character, the whole thing

Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/InstructionStore.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/InstructionStore.cpp Outdated
Comment thread libyul/backends/evm/ssa/InstructionStore.h Outdated
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

There was an error when running Code Style Check for commit 6f3a086b8c96e1a49eec9e168968a5af225d6e84:

Coding style error:
[Use angle brackets for includes] libyul/backends/evm/ssa/SSACFG.cpp:19:#include "libyul/Exceptions.h"
[Missing space after keyword] libyul/backends/evm/ssa/InstructionStore.cpp:62:	if(i.isTombstone())
[Missing space after keyword] libyul/backends/evm/ssa/SSACFG.cpp:247:			for(i2 = (ssize_t)i-1; i2 >= 0; i2--) {
[Opening brace on same line as if] libyul/backends/evm/ssa/SSACFG.cpp:250:				if (!inst.isProjection()) {
[const should be on the right side of the type] libyul/backends/evm/ssa/SSACFG.cpp:224:		parentBlock.forEachExit([&](const BlockId succBlockId){
[const should be on the right side of the type] libyul/backends/evm/ssa/SSACFG.cpp:223:		const auto& parentBlock = block(parentBlockId);
[Use tabs for indentation] libyul/backends/evm/ssa/InstructionStore.cpp:63:	  return;
[Use tabs for indentation] libyul/backends/evm/ssa/InstructionStore.h:106:		    return opcode == InstOpcode::Call || opcode == InstOpcode::BuiltinCall;

Please check that your changes are working as intended.

Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/InstructionStore.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/SSACFG.cpp Outdated
Comment thread libyul/backends/evm/ssa/InstructionStore.cpp Outdated
Comment thread libyul/backends/evm/ssa/InstructionStore.h Outdated
@argotorg argotorg deleted a comment from github-actions Bot Sep 8, 2026
@msooseth
msooseth marked this pull request as ready for review September 8, 2026 16:23
@msooseth
msooseth force-pushed the mate-ssa-invariants-only branch from 2dfd7ed to 1a5b95c Compare September 16, 2026 14:24
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