perf(compiler): add EVM peepholes and branch shaping#435
Open
abmcar wants to merge 5 commits intoDTVMStack:mainfrom
Open
perf(compiler): add EVM peepholes and branch shaping#435abmcar wants to merge 5 commits intoDTVMStack:mainfrom
abmcar wants to merge 5 commits intoDTVMStack:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a set of EVM frontend and x86 backend peephole optimizations aimed at reducing redundant MIR materialization (notably around ISZERO/NOT) and producing tighter x86 compare/branch sequences and short-diamond branch layouts.
Changes:
- Add EVM MIR builder constant-identity folds (e.g.,
+0,*0/*1,&0,&~0,|0,^0) and introduce deferred operand kinds for bitwise-NOT and zero-test to enable collapsingISZEROchains. - Materialize deferred values only when needed by teaching
extractU256Operand()/ argument conversion paths to realize deferred operands and by extendinghandleCompareEQZ()with a negation mode. - Improve x86 output by (a) folding
cmp/test -> setcc -> [movzx] -> test -> jneinto a directjcc, and (b) shaping “short diamond” branches to prefer fallthrough to the true block.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/compiler/target/x86/x86lowering.cpp | Adds short-diamond detection and inverts branch emission to make the true block fall through when safe. |
| src/compiler/target/x86/x86_cg_peephole.cpp | Extends compare-chain peephole to handle optional movzx and shortens compare+branch sequences. |
| src/compiler/evm_frontend/evm_mir_compiler.h | Introduces deferred operand kinds and constant helper predicates; adds identity folds in arithmetic/bitwise handlers; updates handleCompareEQZ() signature. |
| src/compiler/evm_frontend/evm_mir_compiler.cpp | Implements MUL identity folds, deferred NOT/ISZERO materialization, and realizes deferred operands in extraction and arg-lowering paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
⚡ Performance Regression Check Results✅ Performance Check Passed (interpreter)Performance Benchmark Results (threshold: 25%)
Summary: 194 benchmarks, 0 regressions ✅ Performance Check Passed (multipass)Performance Benchmark Results (threshold: 25%)
Summary: 194 benchmarks, 0 regressions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ADD,SUB,MUL,AND,OR, andXORNOTand zero-test materialization soISZEROchains can collapse without building redundant 256-bit MIR valuesmovzx/testsequencesImplementation
src/compiler/evm_frontend/evm_mir_compiler.hOperandsrc/compiler/evm_frontend/evm_mir_compiler.cppMULzero/one fast pathshandleCompareEQZ()to emit eithereqornefor deferred zero testsU256Instis actually neededsrc/compiler/target/x86/x86_cg_peephole.cppcmp/test -> setcc -> [movzx] -> test -> jneinto a shorter compare/branch formsrc/compiler/target/x86/x86lowering.cppValidation
tools/format.sh check./build/evmStateTests1798/1798Benchmark
Compared with the same-session
fix2baseline onevmone-benchexternal totals:11.4%3.8%Representative wins:
external/total/main/jump_around/empty: about48%fasterexternal/total/main/memory_grow_mload/by32: improvedexternal/total/main/memory_grow_mstore/by16: improvedKnown remaining hot spots:
JUMPDEST_n0loop_with_many_jumpdests