Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[venom]: common subexpression elimination pass #4241

Open
wants to merge 113 commits into
base: master
Choose a base branch
from

Conversation

HodanPlodky
Copy link
Collaborator

What I did

Created common subexpression elimination pass

How I did it

Created available expression analysis and common subexpressions elimination pass. The available expression analysis is done with consideration to effects which heavy inspired by multidimensional fencing.

How to verify it

Created tests

Commit message

feat[venom]: common subexpression elimination

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

class _Expression:
first_inst : IRInstruction
opcode: str
operands : list[IROperand]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this can be IROperand | _Expression

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 94.91525% with 15 lines in your changes missing coverage. Please review.

Project coverage is 92.14%. Comparing base (1b0fa5b) to head (6a79288).

Files with missing lines Patch % Lines
vyper/venom/analysis/available_expression.py 93.77% 14 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4241      +/-   ##
==========================================
+ Coverage   92.09%   92.14%   +0.04%     
==========================================
  Files         119      121       +2     
  Lines       16931    17225     +294     
  Branches     2865     2935      +70     
==========================================
+ Hits        15593    15872     +279     
- Misses        919      933      +14     
- Partials      419      420       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

from vyper.venom.passes.common_subexpression_elimination import CSE


def _check_pre_post(pre: str, post: str):
Copy link
Member

@charles-cooper charles-cooper Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style thing: maybe instead of both _check_pre_post() and _check_pre_post_fn(), just have check_pre_post(pre, post, scope="basicblock"), and have a decision for which parsing function to use:

if scope == "basicblock":
    parse = parse_from_basic_block
else:
    assert scope == "function"
    parse = parse_venom

_check_pre_post(pre, post)


def test_common_subexpression_elimination_logs_no_indepontent():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idempotent

_check_no_change(pre)


def test_common_subexpression_elimination_effects_3():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slightly shorter names will be helpful when selecting tests manually, e.g. pytest -k test_cse_elim_effects3

@@ -86,6 +87,10 @@ def _run_passes(fn: IRFunction, optimize: OptimizationLevel) -> None:
AlgebraicOptimizationPass(ac, fn).run_pass()
RemoveUnusedVariablesPass(ac, fn).run_pass()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this extra RemoveUnusedVariablesPass is now unnecessary

%sum1 = add %1, 10
%mul1 = mul %sum1, 10
%sum2 = add 10, %1
%mul2 = mul 10, %sum2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use variables here, since algebraic optimization pass moves literals to the same position

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants