Skip to content

Commit

Permalink
feat[venom]: merge memory writes (vyperlang#4341)
Browse files Browse the repository at this point in the history
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
HodanPlodky and charles-cooper authored Dec 18, 2024
1 parent 296a071 commit e20c363
Show file tree
Hide file tree
Showing 6 changed files with 1,434 additions and 14 deletions.
Loading

0 comments on commit e20c363

Please sign in to comment.