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

fix[venom]: add make_ssa pass after algebraic optimizations #4292

Merged
merged 15 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/unit/compiler/venom/test_algebraic_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import vyper
from vyper.venom.analysis.analysis import IRAnalysesCache
from vyper.venom.basicblock import IRBasicBlock, IRLabel
from vyper.venom.context import IRContext
Expand Down Expand Up @@ -178,3 +179,29 @@ def test_offsets():
offset_count += 1

assert offset_count == 3


# Test the case of https://github.com/vyperlang/vyper/issues/4288
def test_ssa_after_algebraic_optimization():
code = """
@internal
def _do_math(x: uint256) -> uint256:
value: uint256 = x
result: uint256 = 0

if (x >> 128 != 0):
x >>= 128
if (x >> 64 != 0):
x >>= 64

if 1 < value:
result = 1

return result

@external
def run() -> uint256:
return self._do_math(10)
"""

vyper.compile_code(code, output_formats=["bytecode"])
1 change: 1 addition & 0 deletions vyper/venom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _run_passes(fn: IRFunction, optimize: OptimizationLevel) -> None:
StoreElimination(ac, fn).run_pass()
SimplifyCFGPass(ac, fn).run_pass()
AlgebraicOptimizationPass(ac, fn).run_pass()
MakeSSA(ac, fn).run_pass()
harkal marked this conversation as resolved.
Show resolved Hide resolved
BranchOptimizationPass(ac, fn).run_pass()
RemoveUnusedVariablesPass(ac, fn).run_pass()

Expand Down
Loading