diff --git a/vyper/venom/__init__.py b/vyper/venom/__init__.py index 542bd70bad..772686d286 100644 --- a/vyper/venom/__init__.py +++ b/vyper/venom/__init__.py @@ -46,9 +46,8 @@ def _run_passes(fn: IRFunction, optimize: OptimizationLevel) -> None: FunctionInlinerPass(ac, fn).run_pass() - fn.remove_unreachable_blocks() - return - + RemoveUnusedVariablesPass(ac, fn).run_pass() + StoreElimination(ac, fn).run_pass() SimplifyCFGPass(ac, fn).run_pass() MakeSSA(ac, fn).run_pass() @@ -70,6 +69,6 @@ def generate_ir(ir: IRnode, optimize: OptimizationLevel) -> IRContext: for fn in ctx.functions.values(): _run_passes(fn, optimize) - #ctx.prune_unreachable_functions() + ctx.prune_unreachable_functions() return ctx diff --git a/vyper/venom/passes/function_inliner.py b/vyper/venom/passes/function_inliner.py index e97d4fbda5..996f86cae2 100644 --- a/vyper/venom/passes/function_inliner.py +++ b/vyper/venom/passes/function_inliner.py @@ -74,13 +74,9 @@ def _handle_invoke(self, invoke_inst, invoke_idx): inst.parent = new_bb new_bb.instructions.append(inst) - new_var = fn.get_next_variable() - var_map[inst.output] = new_var - - for j, op in enumerate(inst.operands): if isinstance(op, IRVariable): - inst.operands[j] = var_map[inst.operands[j]] + inst.operands[j] = var_map[op] if inst.opcode in CFG_ALTERING_INSTRUCTIONS and isinstance(op, IRLabel): inst.operands[j] = label_map[op] @@ -90,18 +86,16 @@ def _handle_invoke(self, invoke_inst, invoke_idx): inst.output = None if inst.opcode.startswith("palloca"): alloca_id = tuple(inst.operands) - var_map[inst.output] = self._alloca_map[alloca_id].output - print("ENTER0", var_map[inst.output], inst) - inst.opcode = "nop" - inst.operands = [] - inst.output = None + inst.opcode = "store" + inst.operands = [self._alloca_map[alloca_id].output] if inst.opcode == "param": - var_map[inst.output] = invoke_inst.operands[-i-1] - #print("ENTER", var_map[inst.output], inst) - inst.opcode = "nop" - inst.operands = [] - inst.output = None - #print("ENTER", inst) + inst.opcode = "store" + op = invoke_inst.operands[-i-1] + inst.operands = [invoke_inst.operands[-i-1]] + + new_var = fn.get_next_variable() + var_map[inst.output] = new_var + inst.output = new_var fn.append_basic_block(new_bb) self.worklist.append(new_bb) diff --git a/vyper/venom/passes/remove_unused_variables.py b/vyper/venom/passes/remove_unused_variables.py index be9c1ed535..e022b300cc 100644 --- a/vyper/venom/passes/remove_unused_variables.py +++ b/vyper/venom/passes/remove_unused_variables.py @@ -27,6 +27,7 @@ def run_pass(self): self._process_instruction(inst) self.analyses_cache.invalidate_analysis(LivenessAnalysis) + self.analyses_cache.invalidate_analysis(DFGAnalysis) def _process_instruction(self, inst): if inst.output is None: diff --git a/vyper/venom/passes/sccp/sccp.py b/vyper/venom/passes/sccp/sccp.py index 8596bc8405..d6604bb62b 100644 --- a/vyper/venom/passes/sccp/sccp.py +++ b/vyper/venom/passes/sccp/sccp.py @@ -145,7 +145,7 @@ def _handle_SSA_work_item(self, work_item: SSAWorkListItem): self._visit_expr(work_item.inst) def _lookup_from_lattice(self, op: IROperand) -> LatticeItem: - assert isinstance(op, IRVariable), "Can't get lattice for non-variable" + assert isinstance(op, IRVariable), op lat = self.lattice[op] assert lat is not None, f"Got undefined var {op}" return lat