Skip to content

Commit

Permalink
fix[venom]: error when the store is not constant
Browse files Browse the repository at this point in the history
  • Loading branch information
HodanPlodky committed Aug 13, 2024
1 parent 715b128 commit 8edce11
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions vyper/venom/passes/loop_invariant_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from vyper.venom.analysis.dfg import DFGAnalysis
from vyper.venom.analysis.liveness import LivenessAnalysis
from vyper.venom.analysis.loop_detection import NaturalLoopDetectionAnalysis
from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRLabel, IRVariable
from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRLabel, IRVariable, IRLiteral
from vyper.venom.function import IRFunction
from vyper.venom.passes.base_pass import IRPass

Expand All @@ -19,8 +19,11 @@ def _ignore_instruction(inst: IRInstruction) -> bool:
)


def _is_store(inst: IRInstruction) -> bool:
return inst.opcode == "store"
# must check if it has as operand as literal because
# there are cases when the store just moves value
# from one variable to another
def _is_correct_store(inst: IRInstruction) -> bool:
return inst.opcode == "store" and isinstance(inst.operands[0], IRLiteral)


class LoopInvariantHoisting(IRPass):
Expand Down Expand Up @@ -86,7 +89,7 @@ def _store_dependencies(
for var in inst.get_input_variables():
source_inst = self.dfg.get_producing_instruction(var)
assert isinstance(source_inst, IRInstruction)
if not _is_store(source_inst):
if not _is_correct_store(source_inst):
continue
for bb in self.loops[loop_idx]:
if source_inst.parent == bb:
Expand All @@ -113,7 +116,7 @@ def _dependent_in_bb(self, inst: IRInstruction, bb: IRBasicBlock):

# ignores stores since all stores are independant
# and can be always hoisted
if _is_store(source_ins):
if _is_correct_store(source_ins):
continue

if source_ins.parent == bb:
Expand Down

0 comments on commit 8edce11

Please sign in to comment.