Skip to content

better heuristics for choosing variables to move to memory #14067

Open
@sifislag

Description

@sifislag

Description

I've been looking at bytecodes produced using the --via-ir pipeline and I noticed that in most cases, popular constants (0, 4, etc.) are pushed to the stack on the function selector code and shared between public functions. I stumbled upon a contract where the memory mover kicks in to resolve stack too deep errors. This behavior can be seen in the produced yul code, with 0 being stored at memory offset 0xa0. After this point the constant is loaded 271 times (can be observed by searching "60a051" in the deployed bytecode).

So in this case the sequence 60a051 is used instead of 6000, adding 271 extra bytes to the deployed bytecode. Thought to report it as it will probably be common in large programs.

Environment

  • Compiler version: 0.8.17 (also on 0.8.19)
  • Target EVM version (as per compiler settings): london
  • Operating system: ubuntu 20.04

Steps to Reproduce

I got the contract's code concatenated to a single file from here and compiled using 0.8.19 (after removing imports, etc). The same behavior is present. I'm not posting it here because its too large.

Metadata

Metadata

Assignees

No one assigned

    Labels

    high impactChanges are very prominent and affect users or the project in a major way.medium effortDefault level of effortselected for developmentIt's on our short-term developmentviair

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions