Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dflupu
Copy link
Contributor

@dflupu dflupu commented May 1, 2022

This fixes #10688

I'm not sure about the placement of these rules, it just seemed like they should be somewhere above the following rule: Replace MOD X, <power-of-two> with AND X, <power-of-two> - 1

@hrkrshnn hrkrshnn self-requested a review May 2, 2022 12:28
@hrkrshnn
Copy link
Contributor

hrkrshnn commented May 9, 2022

Let me rebase this to see if the tests pass.

@wechman
Copy link
Contributor

wechman commented Jun 7, 2022

I have rebased changes to make clear what still needs to be fixed.

@ekpyron
Copy link
Collaborator

ekpyron commented Jun 8, 2022

The assertion hit by the tests is libevmasm/CommonSubexpressionEliminator.cpp:L386 - I'd actually say that it's not worth the effort to actually implement that part for legacy code generation - so the easiest solution to this would be to only add these simplification rules for via-IR code generation (which would require passing that down as a flag to the rule list generation).

@dflupu
Copy link
Contributor Author

dflupu commented Jun 9, 2022

The assertion hit by the tests is libevmasm/CommonSubexpressionEliminator.cpp:L386 - I'd actually say that it's not worth the effort to actually implement that part for legacy code generation - so the easiest solution to this would be to only add these simplification rules for via-IR code generation (which would require passing that down as a flag to the rule list generation).

Thanks for clarifying! The output wasn't really telling me much.

I could make that change. Do you have a name in mind for the flag? And do you recommend passing that flag down to each simplificationRuleListPart or just adding another "Part" that is wrapped in an if statement?

I notice that there's a few rules, evmRuleList to be specific, that are added if the _evmVersion is set (it is only set from libyul). I figure that there is the option of making use of that. The only issue is that those rules are added at the end.

@ekpyron
Copy link
Collaborator

ekpyron commented Jun 10, 2022

Thanks for clarifying! The output wasn't really telling me much.

I could make that change. Do you have a name in mind for the flag? And do you recommend passing that flag down to each simplificationRuleListPart or just adding another "Part" that is wrapped in an if statement?

I notice that there's a few rules, evmRuleList to be specific, that are added if the _evmVersion is set (it is only set from libyul). I figure that there is the option of making use of that. The only issue is that those rules are added at the end.

Ah, right! I didn't realize myself that we don't set the evm version for legacy code generation. In that case, it makes sense to just reuse that. You can add a flag only to the rule list Part in which you add the new rules only and set it based on _evmVersion.has_value(). As for a name, maybe something like _forYulOptimizer.

I'd also add a comment before conditionally adding the new rules stating something like:

// The libevmasm optimizer does not support rules resulting in opcodes with more than two arguments.

@dflupu
Copy link
Contributor Author

dflupu commented Jun 11, 2022

@ekpyron Looks like that solved it! Tests are passing now 🙌

@ekpyron
Copy link
Collaborator

ekpyron commented Jun 13, 2022

We'll still need a changelog entry for this - apart from that I think we can merge.

@dflupu dflupu dismissed a stale review via 4857340 June 15, 2022 20:27
@dflupu
Copy link
Contributor Author

dflupu commented Jun 15, 2022

I've added changelog entries as well. Feel free to edit if necessary.

ekpyron
ekpyron previously approved these changes Jun 15, 2022
@wechman wechman dismissed stale reviews from ghost and ekpyron via bd61507 June 22, 2022 07:21
@wechman wechman merged commit 02fdcb3 into argotorg:develop Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert certain mod(mul(X, Y), A) into mulmod(X, Y, A)

5 participants