refactor(compiler): inline EVM CLZ lowering (drop runtime-fallback path) - #21
Closed
abmcar wants to merge 2 commits into
Closed
refactor(compiler): inline EVM CLZ lowering (drop runtime-fallback path)#21abmcar wants to merge 2 commits into
abmcar wants to merge 2 commits into
Conversation
|
✅ 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 |
⚡ 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 |
Replace pure runtime fallback (callRuntimeFor -> intx::clz) with inline chain-select pattern modeled on handleExp's computeExpByteSize lambda (evm_mir_compiler.cpp:2511-2562). Saves HostArgScratch + Uint256ReturnBuffer roundtrip per CLZ. Tag result with ValueRange::U64 so downstream narrow consumers (PR DTVMStack#493 EVMRangeAnalyzer) can fire across basic blocks. clz(0) handled via outer Select(IsZero, 256, ...) for spec fidelity per EIP-7939, plus a defense-in-depth Limb|1 guard mirroring handleExp. Test: multipass unittests 223/223 (all 4 evm.clz_* incl. clz_osaka with 9 vectors), multipass statetest fork_Cancun 2723/2723.
handleClz now inlines a 4-limb chain-select pattern in the multipass frontend (previous commit), so the GetClz runtime helper has no remaining callers. Drop the typedef field, declaration, dispatch table registration, and implementation.
abmcar
force-pushed
the
perf/u256-clz-inline
branch
from
May 24, 2026 05:25
43916f8 to
ca3ca45
Compare
Owner
Author
|
Superseded by upstream DTVMStack#516 (now includes dead-code cleanup as a second commit). |
|
✅ 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
Replace
handleClzruntime-fallback path with an inline 4-limb expansion:when the EVM
CLZopcode (EIP-7939) is executed, the JIT now emits achain of compares +
OP_clz(64-bit) + selects, then an outer guardSelect(IsZero(value), 256, partial)for the all-zero input case. Theinner limb is also OR-masked with
1so the 64-bitOP_clzoperandis never zero on any select arm.
Output
Operandis taggedValueRange::U64(CLZ result is always ≤ 256,trivially U64). This is consistent with
EVMRangeAnalyzer, which alreadyclassifies
OP_CLZas U64 in its dataflow transfer table — the MIR taghelps same-block consumers; cross-BB consumers continue to be served by
the analyzer.
What this does NOT do
RuntimeFunctions.GetClzandevmGetClz(src/compiler/evm_frontend/evm_imported.{h,cpp}) areno longer called from the JIT path but remain in the table as dead
surface. Cleanup deferred to a follow-up to keep this diff focused.
CLZ-density signal; this PR is correctness-and-cleanup, not perf.
Test plan
tools/format.sh check— passcmake --build build --target dtvmapi— pass, no new warningsevmone-unittestscurated 223/223 — includingevm.clz_gas,evm.clz_osaka,evm.clz_pre_osaka,evm.clz_stack_underflowevmone-statetest -k fork_Cancun2723/2723 (fork_Cancunfilter excludes osaka/ tests, so statetest does not exercise EIP-7939
directly — coverage comes from unittests)
DRAFT — personal fork integration test
Drafting on
abmcar/DTVM(personal fork) for review/integration testing.Not for
DTVMStack/DTVMupstream submission yet.