Repository navigation
feat(mlir): canonicalize the Yul module before its lowering - #850
Conversation
There was a problem hiding this comment.
🔵 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
feadb00 to
622fefc
Compare
622fefc to
18e15dc
Compare
hedgar2017
left a comment
There was a problem hiding this comment.
Thanks!
Worth adding to the PR description what the PR improves exactly.
18e15dc to
37a5dd9
Compare
37a5dd9 to
297e13c
Compare
Coverage Summary
|
297e13c to
6172268
Compare
Compile-time benchmark (
|
| 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× |
Sourcify sweep
Candidate-only failures (42)kinds:
Failures shared with the reference (reference diagnostics) (151)kinds:
|
🧪 Integration tests — standard · PR vs
|
| Suite | New failures | Size Δ | Gas Δ | Report |
|---|---|---|---|---|
| solx-tester | ✅ 0 | solx-tester-report.xlsx ↓ | ||
| Foundry · 26 proj | ✅ 0 (410 pre-existing) | ⚪ 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%
738cf90 to
c21ebce
Compare
c21ebce to
a87b706
Compare
a87b706 to
d72d969
Compare
d72d969 to
8e42af8
Compare
8e42af8 to
2678c84
Compare
2678c84 to
15353ff
Compare

Companion: NomicFoundation/solx-llvm#202
Runs the canonicalizer on every
yul.funcafter 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.