Skip to content

[mlir][Sol][Yul] Canonicalize the Yul module before its lowering - #202

Merged
abinavpp merged 4 commits into
app-halt-terminatorsfrom
app-yul-canon
Nov 4, 2026
Merged

abinavpp merged 4 commits into
app-halt-terminatorsfrom
app-yul-canon

Conversation

@abinavpp

@abinavpp abinavpp commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
  • Emit an object's entry code as its entry function
  • Skip the cleanup of a constant in its type's range
  • Fold and canonicalize the constant, arithmetic and builtin ops
  • Check an external call's static return size once

Companion: NomicFoundation/solx#850

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Entry-function fallthrough still uses caller-dependent return semantics instead of halting safely.

1 open issue
What changed in this PR

Prepares Sol and Yul intermediate representations for optimization before lowering, with explicit object entry functions and expanded regression coverage.

Changes:

  • Adds arithmetic folding, comparison canonicalization, and redundant-check elimination.
  • Moves object code into __entry functions and removes unreachable code after halting operations.
  • Updates conversion tests and adds folding and control-flow regressions.
File Description
mlir/​test/​Dialect/​Yul/​ops-invalid.mlir Tests object structure validation.
mlir/​test/​Dialect/​Yul/​object.mlir Updates object round-trip tests.
mlir/​test/​Dialect/​Yul/​fold.mlir Adds arithmetic and builtin folding tests.
mlir/​test/​Dialect/​Yul/​canonicalize.mlir Tests comparison inversion.
mlir/​test/​Dialect/​Sol/​canonicalize.mlir Tests checked and unchecked arithmetic folding.
mlir/​test/​Conversion/​YulToStandard/​unreachable-location.mlir Removes obsolete wrapper-location test.
mlir/​test/​Conversion/​YulToStandard/​switch.mlir Updates entry and halting-branch expectations.
mlir/​test/​Conversion/​YulToStandard/​stop.mlir Tests direct unreachable termination.
mlir/​test/​Conversion/​YulToStandard/​selfdestruct.mlir Updates termination expectation.
mlir/​test/​Conversion/​YulToStandard/​revert.mlir Updates entry and revert lowering tests.
mlir/​test/​Conversion/​YulToStandard/​returndata.mlir Wraps object code in entry functions.
mlir/​test/​Conversion/​YulToStandard/​pop.mlir Updates entry fallthrough expectation.
mlir/​test/​Conversion/​YulToStandard/​obj.mlir Tests explicit object entry functions.
mlir/​test/​Conversion/​YulToStandard/​noreturn.mlir Adds halting and continuation-removal tests.
mlir/​test/​Conversion/​YulToStandard/​memory.mlir Updates entry and byte-operation inputs.
mlir/​test/​Conversion/​YulToStandard/​log.mlir Wraps logging code in entry functions.
mlir/​test/​Conversion/​YulToStandard/​llvm-global.mlir Separates globals from entry code.
mlir/​test/​Conversion/​YulToStandard/​invalid.mlir Updates invalid-op termination tests.
mlir/​test/​Conversion/​YulToStandard/​if.mlir Moves conditional code into entry functions.
mlir/​test/​Conversion/​YulToStandard/​function.mlir Separates entry code from helper functions.
mlir/​test/​Conversion/​YulToStandard/​entry-function.mlir Checks entry and helper attributes.
mlir/​test/​Conversion/​YulToStandard/​empty-block.mlir Updates empty-entry expectation.
mlir/​test/​Conversion/​YulToStandard/​dead-loop-regions.mlir Tests removal of unreachable loop regions.
mlir/​test/​Conversion/​YulToStandard/​data.mlir Updates data-copy entry structure.
mlir/​test/​Conversion/​YulToStandard/​data-in-code.mlir Updates embedded-data object structure.
mlir/​test/​Conversion/​YulToStandard/​calldata.mlir Wraps calldata code in entry functions.
mlir/​test/​Conversion/​SolToYul/​unsafe-asm-effects.mlir Updates memory-guard checks for entry functions.
mlir/​test/​Conversion/​SolToYul/​malloc.mlir Expects constant cleanup elimination.
mlir/​test/​Conversion/​SolToYul/​immutable.mlir Updates constant immutable-store expectations.
mlir/​test/​Conversion/​SolToYul/​ext-call.mlir Checks simplified return-data size validation.
mlir/​test/​Conversion/​SolToYul/​empty-contract.mlir Checks generated entry-function structure.
mlir/​test/​Conversion/​SolToYul/​dispatch-locations.mlir Tests artificial entry debug information.
mlir/​test/​Conversion/​SolToYul/​ctor-diamond-args.mlir Updates tuple-size calculation expectations.
mlir/​test/​Conversion/​SolToYul/​constant-divisor.mlir Tests omitted constant-divisor checks.
mlir/​test/​Conversion/​SolToYul/​constant-cleanup.mlir Tests constant range handling.
mlir/​test/​Conversion/​SolToYul/​cmp.mlir Updates boolean constant cleanup expectations.
mlir/​test/​Conversion/​SolToYul/​abi-decode-storage.mlir Checks direct tuple-size reuse.
mlir/​lib/​Dialect/​Yul/​YulOps.cpp Implements folding, canonicalization, and object validation.
mlir/​lib/​Dialect/​Sol/​SolOps.cpp Implements arithmetic folding and division simplification.
mlir/​lib/​Conversion/​YulToStandard/​YulToStandard.cpp Lowers explicit entries and removes unreachable code.
mlir/​lib/​Conversion/​SolToYul/​SolToYul.cpp Generates entry functions and simplifies checks.
mlir/​lib/​Conversion/​SolToYul/​EVMUtil.cpp Skips redundant cleanup and runtime checks.
mlir/​include/​mlir/​Dialect/​Yul/​YulOps.td Declares folding hooks and entry conventions.
mlir/​include/​mlir/​Dialect/​Yul/​YulBase.td Declares the halting-operation trait.
mlir/​include/​mlir/​Dialect/​Yul/​Yul.h Defines the halting-operation trait.
mlir/​include/​mlir/​Dialect/​Yul/​Folders.h Adds shared integer-folding helpers.
mlir/​include/​mlir/​Dialect/​Sol/​SolOps.td Enables arithmetic folding and canonicalization.
mlir/​include/​mlir/​Conversion/​SolToYul/​EVMUtil.h Declares constant-aware division checking.

Review effort: Balanced

@abinavpp
abinavpp changed the base branch from main to app-halt-terminators October 26, 2026 22:38
@abinavpp
abinavpp requested a balanced review from Copilot October 26, 2026 22:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cross-dialect folding and entry-function changes warrant human review alongside the linked end-to-end semantic tests.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@abinavpp
abinavpp marked this pull request as ready for review October 27, 2026 10:15
@abinavpp
abinavpp added this pull request to stack #222 October 30, 2026 09:44
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@vladimirradosavljevic vladimirradosavljevic 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.

LGTM, with comments addressed.

Comment thread mlir/include/mlir/Dialect/Yul/YulOps.td Resolved
Comment thread mlir/lib/Dialect/Sol/SolOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
@abinavpp
abinavpp force-pushed the app-yul-canon branch 5 times, most recently from bc68dcd to 6f0aa17 Compare November 3, 2026 12:10

@PavelKopyl PavelKopyl 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.

LGTM, thanks!

Comment thread mlir/lib/Dialect/Yul/YulOps.cpp Resolved
Every op in an object then sits in a yul.func, so a pass anchored on
functions covers the entry code too.
@abinavpp
abinavpp merged commit 660af7d into main Nov 4, 2026
10 checks passed
@abinavpp
abinavpp deleted the app-yul-canon branch November 4, 2026 09:27
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.

4 participants