Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EVM] Move non-trivial rematerialization from EVMSingleUseExpression to stackification algorithm #737

Open
vladimirradosavljevic opened this issue Nov 15, 2024 · 1 comment

Comments

@vladimirradosavljevic
Copy link
Contributor

In some cases, EVMSingleUseExpression pass is doing rematerialization of 2 instructions (CALLDATA + PUSH) to reduce stack pressure. This is not always profitable, since we could generate 1 stack manipulation instruction instead, like in the tests/solidity/simple/yul_instructions/keccak256.sol test:

Loop with rematerialization:
.BB0_8:                                 ; %for_body
                                        ; =>This Inner Loop Header: Depth=1
	JUMPDEST
	PUSH1 68
	CALLDATALOAD
	PUSH1 4
	CALLDATALOAD
	DUP3
	ADD
	MSTORE8
	ADD
	PUSH1 36
	CALLDATALOAD
	DUP2
	LT
	PUSH4 @.BB0_17
	JUMPI
Loop without rematerialization:
.BB0_8:                                 ; %for_body
                                        ; =>This Inner Loop Header: Depth=1
	JUMPDEST
	DUP3              <- No remat
	DUP6              <- No remat
	DUP3
	ADD
	MSTORE8
	ADD
	DUP3              <- No remat
	DUP2
	LT
	PUSH4 @.BB0_17
	JUMPI

Move 2 instruction rematerialization to stackification algorithm, since it should be possible to determine whether to do rematerialization or to reuse value from the stack.

@akiramenai
Copy link
Collaborator

Doesn't it duplicate #718 ?
Should we leave a comment there and close this one as a duplicate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants