Skip to content

SSA CFG: Add reducibility assert on input graph for liveness - #17092

Open
clonker wants to merge 4 commits into
developfrom
ssa-cfg-reducibility-check
Open

clonker wants to merge 4 commits into
developfrom
ssa-cfg-reducibility-check

Conversation

@clonker

@clonker clonker commented Oct 7, 2026

Copy link
Copy Markdown
Member

Also adds dominator tree implementation for that purpose with its own small property test

@clonker
clonker requested review from blishko, msooseth and r0qs October 7, 2026 07:12
@clonker
clonker marked this pull request as ready for review October 7, 2026 07:15
nikola-matic
nikola-matic previously approved these changes Oct 7, 2026
Comment thread libyul/backends/evm/ssa/analysis/DominatorTree.cpp Outdated
Comment thread libyul/backends/evm/ssa/traversal/ForwardTopologicalSort.h Outdated
@nikola-matic
nikola-matic dismissed their stale review October 7, 2026 08:11

Approved by accident

@r0qs

r0qs commented Oct 7, 2026

Copy link
Copy Markdown
Member

Can we maybe have a commit removing the old implementation and tests? It is not used anyway. Could also be a separate PR, but I think a separate commit should be fine as well:

class DominatorFinder

@blishko blishko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some initial comments. Will have to look at the whole thing properly later.

Comment thread libyul/backends/evm/ssa/traversal/ForwardTopologicalSort.h Outdated
Comment thread libyul/backends/evm/ssa/traversal/DominatorTree.h Outdated
Comment thread libyul/backends/evm/ssa/traversal/ReducibilityCheck.cpp Outdated
@clonker

clonker commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Can we maybe have a commit removing the old implementation and tests? It is not used anyway. Could also be a separate PR, but I think a separate commit should be fine as well:

class DominatorFinder

I would have done it separately

@clonker
clonker force-pushed the ssa-cfg-reducibility-check branch 2 times, most recently from c5e697f to f61197e Compare October 8, 2026 07:47

@blishko blishko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments.

The property test looks reasonable on first reading.
I will try to understand the dominator algorithm.

Comment thread libyul/backends/evm/ssa/analysis/DepthFirstSpanningTree.h Outdated
Comment thread libyul/backends/evm/ssa/analysis/DominatorTree.cpp Outdated
Comment thread test/fuzztest/libyul/DominatorTreePropertyTest.cpp Outdated
{
auto const numBlocks = static_cast<NodeID>(_exits.size());

SSACFG cfg(EVMDialect::strictAssemblyForEVM(langutil::EVMVersion::current()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but I am wondering if we could decouple the general graph structure representation from EVM specific properties.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It absolutely can be decoupled but then we have to drag around the dialect. I put it into the graph so it's part of its definition. But maybe that wasn't the best idea :)

Comment thread test/fuzztest/libyul/DominatorTreePropertyTest.cpp Outdated
Comment thread test/fuzztest/libyul/DominatorTreePropertyTest.cpp Outdated
Comment thread test/fuzztest/libyul/DominatorTreePropertyTest.cpp Outdated
Comment thread test/fuzztest/libyul/DominatorTreePropertyTest.cpp Outdated
Comment thread libyul/backends/evm/ssa/analysis/DominatorTree.cpp Outdated
@clonker
clonker force-pushed the ssa-cfg-reducibility-check branch from 1cb9307 to d0016c3 Compare October 9, 2026 05:27
Comment thread libyul/backends/evm/ssa/analysis/ReducibilityCheck.h Outdated
Comment thread libyul/backends/evm/ssa/LivenessAnalysis.cpp Outdated
Comment thread libyul/backends/evm/ssa/analysis/DominatorTree.cpp

@blishko blishko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't fully understand the dominator tree construction, but the property test seems reasonable to me.

I have one more question, but otherwise, I think we can merge.

// GTW06, Section 2.3 (b): compute immediate dominators
//
// For each node in preorder, walk from its DFS-tree parent up toward the root (via already-computed idoms) until
// reaching a node at or above its semidominator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// reaching a node at or above its semidominator
// reaching a node at or below its semidominator

no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant above in the tree sense, ie, closer to the root. in the sense of index comparison you're right of course. I have reworded it so that it's not the ambiguous "above" or "below" anymore:

For each node in preorder, walk from its DFS-tree parent up toward the root (via already-computed idoms) until reaching a node whose preorder index is at most that of its semidominator, i.e., the semidominator itself or a DFS tree ancestor of it

@clonker
clonker force-pushed the ssa-cfg-reducibility-check branch from 7a864fa to 7672790 Compare October 20, 2026 08:06
@clonker
clonker force-pushed the ssa-cfg-reducibility-check branch from 7672790 to 3c3d813 Compare October 20, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants