Skip to content

feat(mlir): canonicalize the Yul module before its lowering - #850

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

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

Conversation

@abinavpp

@abinavpp abinavpp commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Companion: NomicFoundation/solx-llvm#202

Runs the canonicalizer on every yul.func after the Sol lowering. Each object's entry code is now its own function, so this covers the whole module and folds the constant, arithmetic and EVM builtin ops. Adds semantic tests for the builtin folding corner cases (each run once from calldata and once from literals that fold), an out-of-range enum constant, and an external call with a short static return.

Copilot AI 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.

🔵 Needs a closer look

Compatibility with the dependent LLVM change remains unverified, and modular-overflow regression coverage needs correction.

1 open issue
What changed in this PR

Moves canonicalization into the Yul stage of the compiler pipeline, depending on solx-llvm PR #202.

  • Canonicalizes Yul functions before lowering.
  • Adds comparison-shape and semantic regression tests.
File Description
tests/​solidity/​simple/​yul_instructions/​fold_corner_cases.sol Compares literal and runtime arithmetic edge cases.
tests/​solidity/​simple/​mlir/​ext_call_short_return.sol Tests external-call return-data boundaries.
tests/​solidity/​simple/​mlir/​enum_constant_out_of_range.sol Tests constant-to-enum range checks.
solx-mlir/​tests/​lit/​yul_canonicalize.sol Checks comparison simplification.
solx-mlir/​src/​context/​mod.rs Moves canonicalization before Yul lowering.

Review effort: Balanced

Copilot AI 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.

🔵 Needs a closer look

The compiler-wide pass reordering requires integrated LIT and REVM validation with solx-llvm#202 before approval.

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 requested a review from hedgar2017 October 27, 2026 10:15

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

Thanks!

Worth adding to the PR description what the PR improves exactly.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Coverage Summary

Crate Line Coverage Function Coverage
solx 🟢 83.8% 🔴 20.0%
solx-benchmark-converter 🔴 0.0% 🔴 0.0%
solx-codegen-evm 🟡 56.6% 🟡 51.5%
solx-compiler-downloader 🔴 0.0% 🔴 0.0%
solx-core 🔴 47.2% 🟡 58.8%
solx-dev 🔴 2.2% 🔴 2.1%
solx-mlir 🟡 50.2% 🔴 48.2%
solx-slang 🔴 30.4% 🔴 34.7%
solx-solc-test-adapter 🔴 1.7% 🔴 2.1%
solx-standard-json 🔴 38.8% 🔴 42.5%
solx-tester 🔴 36.6% 🔴 34.6%
solx-utils 🔴 44.7% 🔴 45.2%
Total 🔴 13.3% 🔴 16.5%

Codecov Report | HTML Report | Workflow Run

@abinavpp abinavpp added ci:integration Trigger integration tests workflow on PR ci:sourcify-sweep Run Sourcify corpus on this PR labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Compile-time benchmark (--standard-json)

pr: slang v0.2.0, LLVM-based Solidity compiler for the EVM, Front end: Slang, LLVM build: 5b4b4b833db8d3f5beeedeee14e5de629201b69e
main: slang v0.2.0, LLVM-based Solidity compiler for the EVM, Front end: Slang, LLVM build: 9f9fa88b7d317949d42a7cc70f287cb271cace6d
prerelease: slang v0.2.0, LLVM-based Solidity compiler for the EVM, Front end: Slang, LLVM build: 716613b727e0de5b086556ca69b475aa3e496c06
runner: solx-bench-ams-1
commits: pr 15353ffb merged into app-halt-terminators, main c2fb68a0

ens-verifiable-factory-solx--solx-legacy-dwarf

binary median mean ± σ min … max vs baseline
pr 0.282 s 0.282 s ± 0.004 s 0.276 s … 0.289 s 0.962×
main 0.293 s 0.294 s ± 0.005 s 0.285 s … 0.302 s 1.000×
prerelease 0.495 s 0.495 s ± 0.005 s 0.487 s … 0.504 s 1.688×

openzeppelin-contracts-0.34--solx-legacy-dwarf

binary median mean ± σ min … max vs baseline
pr 2.164 s 2.164 s ± 0.007 s 2.153 s … 2.178 s 0.983×
main 2.201 s 2.200 s ± 0.005 s 2.191 s … 2.209 s 1.000×
prerelease 3.205 s 3.198 s ± 0.030 s 3.137 s … 3.231 s 1.457×

uniswap-v4-core-solx--solx-legacy-dwarf

binary median mean ± σ min … max vs baseline
pr 0.902 s 0.901 s ± 0.014 s 0.880 s … 0.923 s 0.939×
main 0.961 s 0.963 s ± 0.009 s 0.953 s … 0.976 s 1.000×
prerelease 2.118 s 2.122 s ± 0.028 s 2.078 s … 2.160 s 2.204×

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Sourcify sweep

  • candidate: slang (slang v0.2.0, LLVM-based Solidity compiler for the EVM, Front end: Slang, LLVM build: 5b4b4b833db8d3f5beeedeee14e5de629201b69e)
  • reference: solx-latest (solx v0.1.8, LLVM-based Solidity compiler for the EVM, Front end: solc, LLVM build: 7d0702e169889fe4f1a2241c57bef7d2c1c68737)
  • contracts: 119117
outcome count share meaning
ok 118924 99.84% compiles: no errors and bytecode for the target source
candidate-fail 42 0.04% candidate fails, reference compiles
both-fail 151 0.13% candidate and reference both fail

Candidate-only failures (42)

kinds: error 42

count kind signature examples
42 error This contract cannot be compiled due to a combination of a memory-unsafe assembly block and a stack-too-deep error. The compiler can automatically fix the stack 10_0x33442fc10a20aad0ddd73f6ae24500f5b370dc51, 10_0x3e7b6997399ec402491c4a049e4cd727d3aa1738, 10_0x467837f44a71e3eab90aecfc995c84dc6b3cfcf7 (+39 more)

Failures shared with the reference (reference diagnostics) (151)

kinds: error 151

count kind signature examples
150 error runtime code LLVM IR generator: This contract cannot be compiled due to a combination of a memory-unsafe assembly block and a stack-too-deep error. 100_0x239d413a6ac5322d3ccaaaf43e34045bdacd7e74, 100_0x27ebdb6cefd590feaf79b20f6e77bf79dc3c04fe, 100_0x325afb837204d46a3d4158ded26a8be2681761b5 (+147 more)
1 error Member "UnexpectedInitSelector" not found or not visible after argument-dependent lookup in type(contract ParkERC1967Proxy). 56_0x69d890f783a6662e8554c8f71d1daeda1baddda2

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🧪 Integration tests — standard · PR vs main

⚠️ Output changed — 1,369 of 28,466 size comparisons differ (-50,027 B total); 810 of 36,675 solx-tester gas comparisons differ. If this PR is meant to be output-preserving, investigate before merging.
✅ No new failures — Foundry's 410 failures already present on main.
⚠️ No baseline — solx-tester: 132 runs (0 failures) have no main counterpart; their failures are not compared.

Suite New failures Size Δ Gas Δ Report
solx-tester ✅ 0 ⚠️ 974 of 26,602 (-25,604 B) ⚠️ 810 of 36,675 solx-tester-report.xlsx ↓
Foundry · 26 proj ✅ 0 (410 pre-existing) ⚠️ 395 of 1,864 (-24,423 B) ⚪ jitter 707 of 3,249, median 0.1% (not gated) foundry-report.xlsx ↓
Hardhat · 3 proj ✅ 0 ⚪ not collected ⚪ not collected hardhat-report.xlsx ↓

solx-tester — largest size changes:

  • solidity/test/libsolidity/semanticTests/array/copying/nested_array_element_storage_to_memory.sol [EVMLA M3B3 0.8.37, deploy] 9,319 → 7,537 B (-19.1%)
  • solidity/test/libsolidity/semanticTests/array/copying/nested_array_element_storage_to_storage.sol [EVMLA M3B3 0.8.37, deploy] 9,625 → 8,048 B (-16.4%)
  • solidity/test/libsolidity/semanticTests/externalContracts/snark.sol [EVMLA M3B3 0.8.37, deploy] 9,453 → 8,444 B (-10.7%)
  • solidity/test/libsolidity/semanticTests/externalContracts/snark.sol [EVMLA M3B3 0.8.37, runtime] 9,426 → 8,417 B (-10.7%)
  • tests/solidity/complex/defi/Mooniswap/MooniswapPool/test.json::first [EVMLA M3B3 0.8.37, deploy] 12,896 → 12,249 B (-5.0%)
  • +969 more — see solx-tester-report.xlsx

solx-tester — largest gas changes:

  • solidity/test/libsolidity/semanticTests/externalContracts/strings.sol[benchmark:5] [EVMLA M3B3 0.8.37] 1,189,078 → 1,270,166 (+6.8%)
  • solidity/test/libsolidity/semanticTests/storage/storage_boundary_delete_overflow_bug.sol[fillArray:2] [EVMLA MzB3 0.8.37] 5,747,837 → 5,704,224 (-0.8%)
  • solidity/test/libsolidity/semanticTests/externalContracts/strings.sol[benchmark:5] [EVMLA MzB3 0.8.37] 1,195,774 → 1,236,871 (+3.4%)
  • tests/solidity/simple/recursion/fibonacci.sol::sixteenth[fib:1] [EVMLA M3B3 0.8.37] 253,991 → 234,833 (-7.5%)
  • tests/solidity/simple/recursion/fibonacci.sol::sixteenth[fib:1] [EVMLA MzB3 0.8.37] 253,991 → 234,833 (-7.5%)
  • +805 more — see solx-tester-report.xlsx

Foundry — largest size changes:

  • Feed [legacy, deploy] 28,142 → 30,303 B (+7.7%)
  • Feed [legacy, runtime] 27,911 → 30,072 B (+7.7%)
  • Graph [legacy, deploy] 20,166 → 21,704 B (+7.6%)
  • Graph [legacy, runtime] 19,942 → 21,480 B (+7.7%)
  • AaveV3HelpersBatchTwo [legacy, deploy] 30,415 → 31,538 B (+3.7%)
  • +390 more — see foundry-report.xlsx

Compile time — wall-clock tripwire, positive = PR slower (authoritative Δ in the compile-time benchmark comment)

Suite legacy (agg / median)
Foundry · 26 proj -3.3% / -2.1%
Hardhat · 3 proj +1.6% / +3.6%

Project outliers (≥15%): solady legacy -18.6%

@abinavpp
abinavpp force-pushed the app-yul-canon branch 3 times, most recently from 738cf90 to c21ebce Compare November 3, 2026 11:11
@abinavpp
abinavpp removed this pull request from stack #908 November 3, 2026 11:54
@abinavpp
abinavpp changed the base branch from main to app-halt-terminators November 3, 2026 11:54
@abinavpp
abinavpp added this pull request to stack #925 November 3, 2026 11:55
@abinavpp
abinavpp added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 022cf70 Nov 4, 2026
72 checks passed
@abinavpp
abinavpp deleted the app-yul-canon branch November 4, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:integration Trigger integration tests workflow on PR ci:sourcify-sweep Run Sourcify corpus on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants