Skip to content

venom: dominated condition elimination optimization #4812

@charles-cooper

Description

@charles-cooper

Summary

The Venom optimizer could eliminate redundant condition checks when control flow guarantees the condition is true.

Example

In selector dispatch (dense jumptable), we have:

entry:
  if calldatasize < 4: jump fallback
  ... dispatch logic ...

bucket_N:
  if calldatasize > 3 AND selector_match: jump handler

The calldatasize > 3 check in bucket_N is redundant - if we reached that block, we already passed the calldatasize >= 4 check at entry.

Potential Approaches

  1. Range/interval analysis - track value ranges through control flow
  2. Dominated conditions tracking - if block B is dominated by a branch on condition C, C is known true/false in B
  3. Path-sensitive value numbering - extend SCCP with path conditions

Notes

  • SCCP can't handle this (it's about path conditions, not constant values)
  • This is a general optimization that would benefit any code with guarded branches
  • Low priority but would improve bytecode size/gas for contracts with many external functions

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions