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

[TailDuplication] Add option to enable tail duplication of fallthrough BBs #727

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

vladimirradosavljevic
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Oct 29, 2024

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                28.083 ║
║ MUL                                16.850 ║
║ SUB                                28.083 ║
║ DIV                                19.250 ║
║ SDIV                               36.050 ║
║ MOD                                19.250 ║
║ SMOD                               33.650 ║
║ ADDMOD                             18.156 ║
║ MULMOD                             16.656 ║
║ EXP                                 6.904 ║
║ SIGNEXTEND                         19.250 ║
║ LT                                 32.083 ║
║ GT                                 32.083 ║
║ SLT                                54.083 ║
║ SGT                                54.083 ║
║ EQ                                 32.083 ║
║ ISZERO                             27.750 ║
║ AND                                28.083 ║
║ OR                                 28.083 ║
║ XOR                                28.083 ║
║ NOT                                23.750 ║
║ BYTE                               38.083 ║
║ SHL                                34.083 ║
║ SHR                                34.083 ║
║ SAR                                52.083 ║
║ SGT                                54.083 ║
║ SHA3                               25.073 ║
║ ADDRESS                            41.812 ║
║ BALANCE                            20.924 ║
║ ORIGIN                           1351.625 ║
║ CALLER                             41.812 ║
║ CALLVALUE                          41.812 ║
║ CALLDATALOAD                       26.083 ║
║ CALLDATASIZE                       42.125 ║
║ CALLDATACOPY                       49.492 ║
║ CODESIZE                           45.625 ║
║ CODECOPY                           62.456 ║
║ GASPRICE                         1348.438 ║
║ EXTCODESIZE                         3.635 ║
║ EXTCODECOPY                         3.723 ║
║ RETURNDATASIZE                     43.500 ║
║ RETURNDATACOPY                     44.556 ║
║ EXTCODEHASH                         4.651 ║
║ BLOCKHASH                         238.819 ║
║ COINBASE                         1348.625 ║
║ TIMESTAMP                        1342.625 ║
║ NUMBER                           1342.625 ║
║ PREVRANDAO                       1342.625 ║
║ GASLIMIT                         1348.625 ║
║ CHAINID                          1336.625 ║
║ SELFBALANCE                       639.250 ║
║ BASEFEE                          1342.625 ║
║ POP                                39.125 ║
║ MLOAD                              43.667 ║
║ MSTORE                             55.248 ║
║ MSTORE8                            64.716 ║
║ SLOAD                              19.044 ║
║ SSTORE                              4.467 ║
║ JUMP                               15.667 ║
║ JUMPI                              15.636 ║
║ PC                                 42.312 ║
║ MSIZE                              48.812 ║
║ GAS                                42.312 ║
║ JUMPDEST                           59.625 ║
║ PUSH0                              42.312 ║
║ PUSH1                              37.958 ║
║ PUSH2                              43.375 ║
║ PUSH4                              46.208 ║
║ PUSH5                              47.625 ║
║ PUSH6                              49.042 ║
║ PUSH7                              50.458 ║
║ PUSH8                              51.875 ║
║ PUSH9                              53.292 ║
║ PUSH10                             54.708 ║
║ PUSH11                             56.125 ║
║ PUSH12                             57.542 ║
║ PUSH13                             58.958 ║
║ PUSH14                             60.375 ║
║ PUSH15                             61.792 ║
║ PUSH16                             63.208 ║
║ PUSH17                             64.625 ║
║ PUSH18                             66.042 ║
║ PUSH19                             67.458 ║
║ PUSH20                             68.875 ║
║ PUSH21                             70.292 ║
║ PUSH22                             71.708 ║
║ PUSH23                             73.125 ║
║ PUSH24                             74.542 ║
║ PUSH25                             75.958 ║
║ PUSH26                             77.375 ║
║ PUSH27                             78.792 ║
║ PUSH28                             80.208 ║
║ PUSH29                             81.625 ║
║ PUSH30                             83.042 ║
║ PUSH31                             84.458 ║
║ PUSH32                             85.875 ║
║ DUP1                               26.083 ║
║ DUP2                               32.417 ║
║ DUP3                               32.417 ║
║ DUP4                               32.417 ║
║ DUP5                               32.417 ║
║ DUP6                               32.417 ║
║ DUP7                               32.417 ║
║ DUP8                               32.417 ║
║ DUP9                               32.417 ║
║ DUP10                              32.417 ║
║ DUP11                              32.417 ║
║ DUP12                              32.417 ║
║ DUP13                              32.417 ║
║ DUP14                              32.417 ║
║ DUP15                              32.417 ║
║ DUP16                              32.417 ║
║ SWAP1                              32.417 ║
║ SWAP2                              32.417 ║
║ SWAP3                              32.417 ║
║ SWAP4                              32.417 ║
║ SWAP5                              32.417 ║
║ SWAP6                              32.417 ║
║ SWAP7                              32.417 ║
║ SWAP8                              32.417 ║
║ SWAP9                              32.417 ║
║ SWAP10                             32.417 ║
║ SWAP11                             32.417 ║
║ SWAP12                             32.417 ║
║ SWAP13                             32.417 ║
║ SWAP14                             32.417 ║
║ SWAP15                             32.417 ║
║ SWAP16                             32.417 ║
║ CALL                               34.125 ║
║ STATICCALL                         34.095 ║
║ DELEGATECALL                       33.175 ║
║ CREATE                              3.713 ║
║ CREATE2                             5.009 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life M3B3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life MzB3 ╞═╗
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠══╡ Gas (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╚═══════════════════════════════════════════╝

…uplication of fallthrough BBs

Signed-off-by: Vladimir Radosavljevic <[email protected]>
@vladimirradosavljevic vladimirradosavljevic changed the title [DO NOT MERGE] [TailDuplication] Enable tail duplication of fallthrough BBs [TailDuplication] Add option to enable tail duplication of fallthrough BBs Oct 29, 2024
vladimirradosavljevic added a commit that referenced this pull request Oct 29, 2024
…h BBs

During TailDuplication pass, fallthrough BBs are not duplicated.
This is fine for most cases, but there are cases where we want
to duplicate fallthrough BBs as well (e.g. EvmEmulator). This
patch adds the `tail-dup-fallthrough-bbs` option to enable
tail duplication of fallthrough BBs.

PR: #727.

Signed-off-by: Vladimir Radosavljevic <[email protected]>
@vladimirradosavljevic vladimirradosavljevic force-pushed the tail_duplicate_fallthrough_bbs branch from 481bb85 to 53efc24 Compare October 29, 2024 15:29
Copy link
Collaborator

@akiramenai akiramenai left a comment

Choose a reason for hiding this comment

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

I assume it improved numbers on EvmEmulator. Could we provide clearer guidance on when this option is beneficial?

There are cases where we want to duplicate fallthrough BBs as well (e.g. EvmEmulator)

This explanation is vague. Additionally, the test case removes an empty BB (which ideally shouldn’t appear post-optimization), it doesn’t provide guidance - though it works fine as a test.
Could this be upstreamed?

…h BBs

During the TailDuplication pass, fallthrough BBs are
not duplicated. This is generally acceptable, but in
scenarios where a loop contains a large switch case
and the latch BB is a fallthrough, duplicating the
latch BB can eliminate jump instructions in its
predecessors. This patch introduces the
`tail-dup-fallthrough-bbs` option to enable the
duplication of fallthrough BBs.

PR: #727.

Signed-off-by: Vladimir Radosavljevic <[email protected]>
@vladimirradosavljevic vladimirradosavljevic force-pushed the tail_duplicate_fallthrough_bbs branch from 53efc24 to 2b28888 Compare October 30, 2024 10:46
@vladimirradosavljevic
Copy link
Contributor Author

I assume it improved numbers on EvmEmulator.

Yes, you can see the numbers here (please use edit button to check the numbers before this).

This explanation is vague.

I have changed the explanation, so PTAL.

Additionally, the test case removes an empty BB (which ideally shouldn’t appear post-optimization), it doesn’t provide guidance - though it works fine as a test.

To provide guidance through the test case, we would need to create a test which contains a loop with a switch case and a latch BB that is a fallthrough, and I don't think it is worth it, since current test is testing the option we introduced.

Could this be upstreamed?

I tried to enable this by default, but the numbers are not clear win. This option is to cover an edge case that is not common, so we wouldn't have anything to convince the community that this should be merged.

Copy link
Collaborator

@akiramenai akiramenai left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@akiramenai akiramenai merged commit 2a03cc8 into main Oct 30, 2024
13 checks passed
@akiramenai akiramenai deleted the tail_duplicate_fallthrough_bbs branch October 30, 2024 15:51
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