Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[venom]: merge memory writes (vyperlang#4341)
Adapt the memory merging pass from the legacy pipeline into venom pipeline with additional improvements. It merges instructions that copy data or zero memory into a single copy instruction if possible (with the exception that if the copy is exactly 32 bytes, it uses a load/mstore pair to save 1 byte / 3 gas). It also handles sequences of interleaved and out-of-order copies, even though these are not currently generated by the frontend. Examples: input1: ``` %1 = mload 0 mstore 1000, %1 %2 = mload 32 mstore 1032, %2 ``` output1: ``` mcopy 1000, 0, 64 ``` input2: ``` mstore 100, 0 mstore 132, 0 ``` output2: ``` %1 = calldatasize calldatacopy 100, %1, 64 ``` It handles copies from memory (mload/mstore/mcopy) and calldata (calldataload/calldatacopy). For zeroing memory it uses `calldatacopy` from the `calldatasize` offset. --------- Co-authored-by: Charles Cooper <[email protected]>
- Loading branch information