Skip to content

Conversation

@HodanPlodky
Copy link
Collaborator

@HodanPlodky HodanPlodky commented Jul 25, 2024

What I did

Created offset handling for statically resolvable values

How I did it

I introduced offset instruction that is emited in algebraic pass when the add instruction calculates offset with literal values

How to verify it

Created new test in algebraic pass tests

Commit message

this commit introduces an `offset` instruction that is emitted in the
algebraic pass when the add instruction calculates an offset from a
code label, which is used for immutables. this allows compilation
directly to the magic `OFST` assembly instruction, which does
additional constant folding after symbol resolution.

while i < len(bb.instructions):
inst = bb.instructions[i]
if inst.opcode == "store":
if inst.opcode in ["store", "offset"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if inst.opcode in ["store", "offset"]:
if inst.opcode in ("store", "offset"):

for inst in bb.instructions:
if (
inst.opcode == "add"
and isinstance(inst.operands[0], IRLiteral)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this works so long as this pass runs after the store elimination pass

@charles-cooper
Copy link
Member

i'm seeing about a 1% reduction in bytecode size for some contracts which use immutables :)

@charles-cooper charles-cooper changed the title feat[venom]:offset instruction feat[venom]: offset instruction Jul 26, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) July 26, 2024 01:35
@charles-cooper charles-cooper merged commit fc19284 into vyperlang:master Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants