From 44bbcd458fc18b06d3d736df86a871c3573ae34f Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 28 Sep 2024 22:19:16 -0400 Subject: [PATCH] handle effects --- vyper/venom/passes/load_elimination.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/vyper/venom/passes/load_elimination.py b/vyper/venom/passes/load_elimination.py index f97ef45a2d..6321c7eeb6 100644 --- a/vyper/venom/passes/load_elimination.py +++ b/vyper/venom/passes/load_elimination.py @@ -26,6 +26,13 @@ def _process_bb(self, bb): memory = () for inst in bb.instructions: + if "memory" in inst.get_write_effects(): + memory = () + if "storage" in inst.get_write_effects(): + storage = () + if "transient" in inst.get_write_effects(): + transient = () + if inst.opcode == "mstore": # mstore [val, ptr] memory = (inst.operands[1], inst.operands[0]) @@ -37,7 +44,9 @@ def _process_bb(self, bb): if inst.opcode == "mload": prev_memory = memory memory = (inst.operands[0], inst.output) - if not prev_memory or not self.equivalent(inst.operands[0], prev_memory[0]): + if not prev_memory: + continue + if not self.equivalent(inst.operands[0], prev_memory[0]): continue inst.opcode = "store" inst.operands = [prev_memory[1]] @@ -45,7 +54,9 @@ def _process_bb(self, bb): if inst.opcode == "sload": prev_storage = storage storage = (inst.operands[0], inst.output) - if not prev_storage or not self.equivalent(inst.operands[0], prev_storage[0]): + if not prev_storage: + continue + if not self.equivalent(inst.operands[0], prev_storage[0]): continue inst.opcode = "store" inst.operands = [prev_storage[1]] @@ -54,7 +65,9 @@ def _process_bb(self, bb): if inst.opcode == "tload": prev_transient = transient transient = (inst.operands[0], inst.output) - if not prev_transient or not self.equivalent(inst.operands[0], prev_transient[0]): + if not prev_transient: + continue + if not self.equivalent(inst.operands[0], prev_transient[0]): continue inst.opcode = "store" inst.operands = [prev_transient[1]]