Skip to content

fix[venom]: liveness assumption venom to assembly #4716

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

Closed
Show file tree
Hide file tree
Changes from all 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
19 changes: 18 additions & 1 deletion vyper/venom/passes/phi_elimination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from vyper.venom.analysis import DFGAnalysis, LivenessAnalysis
from vyper.venom.basicblock import IRInstruction, IRVariable
from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IROperand, IRVariable

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'IROperand' is not used.
from vyper.venom.passes.base_pass import InstUpdater, IRPass


Expand All @@ -11,6 +11,9 @@
self.updater = InstUpdater(self.dfg)
self._calculate_phi_origins()

for bb in self.function.get_basic_blocks():
self._deduplicate_phis(bb)

for _, inst in self.dfg.outputs.copy().items():
if inst.opcode != "phi":
continue
Expand All @@ -22,6 +25,20 @@

self.analyses_cache.invalidate_analysis(LivenessAnalysis)

def _deduplicate_phis(self, bb: IRBasicBlock):
phis: dict[tuple, IRVariable] = dict()

for inst in bb.instructions:
if inst.opcode != "phi":
continue
ops = tuple(inst.operands)
if ops in phis:
self.updater.mk_assign(inst, phis[ops])
continue

assert inst.output is not None
phis[ops] = inst.output

def _process_phi(self, inst: IRInstruction):
srcs = self.phi_to_origins[inst]

Expand Down
10 changes: 3 additions & 7 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,9 @@ def _generate_evm_for_instruction(
# example, for `%56 = %label1 %13 %label2 %14`, we will
# find an instance of %13 *or* %14 in the stack and replace it with %56.
to_be_replaced = stack.peek(depth)
if to_be_replaced in next_liveness:
# this branch seems unreachable (maybe due to make_ssa)
# %13/%14 is still live(!), so we make a copy of it
self.dup(assembly, stack, depth)
stack.poke(0, ret)
else:
stack.poke(depth, ret)
# precondition from SSA
assert to_be_replaced not in next_liveness
stack.poke(depth, ret)
return apply_line_numbers(inst, assembly)

if opcode == "offset":
Expand Down
Loading