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

Cherry-pick [SimplifyCFG] Add support for sinking instructions with multiple uses #636

Closed
wants to merge 2 commits into from

Conversation

akiramenai
Copy link
Collaborator

No description provided.

fhahn and others added 2 commits June 27, 2024 13:41
swifterror pointers can only be used as pointer operands of load & store
instructions (and as swifterror argument of a call). Sinking loads or
stores with swifterror pointer operands would require introducing a
select of of the pointer operands, which isn't allowed.

Check for this condition in canSinkInstructions.

Reviewed By: aschwaighofer

Differential Revision: https://reviews.llvm.org/D158083
… (#95521)

Sinking currently only supports instructions that have zero or one uses.
Extend this to handle instructions with any number of uses, as long as
all uses are consistent (i.e. the "same" for all sinking candidates).

After #94462 this is basically just a matter of looping over all uses
instead of checking the first one only.
@akiramenai akiramenai force-pushed the dborisenkov/cp-sink-mult-uses branch from 7d53411 to 092a44d Compare June 27, 2024 13:35
Copy link

Benchmark results:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                               -0.178 ║
║ Best                                7.407 ║
║ Worst                             -31.579 ║
║ Total                              -0.083 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                                0.201 ║
║ Best                               22.000 ║
║ Worst                              -4.275 ║
║ Total                               0.088 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                                0.029 ║
║ Best                               17.206 ║
║ Worst                              -2.495 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                               -0.135 ║
║ Best                                4.651 ║
║ Worst                             -21.053 ║
║ Total                              -0.080 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                                0.187 ║
║ Best                               12.766 ║
║ Worst                              -4.275 ║
║ Total                               0.078 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                                0.025 ║
║ Best                               11.368 ║
║ Worst                              -3.355 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.031 ║
║ Best                                0.155 ║
║ Worst                              -4.275 ║
║ Total                               0.013 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.001 ║
║ Best                                0.006 ║
║ Worst                              -0.845 ║
║ Total                               0.001 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                60.750 ║
║ MUL                                36.450 ║
║ SUB                                60.750 ║
║ DIV                                44.850 ║
║ SDIV                               59.250 ║
║ MOD                                43.650 ║
║ SMOD                               58.050 ║
║ ADDMOD                             34.156 ║
║ MULMOD                             34.156 ║
║ EXP                                 8.537 ║
║ SIGNEXTEND                         42.450 ║
║ LT                                 64.750 ║
║ GT                                 64.750 ║
║ SLT                                88.750 ║
║ SGT                                86.750 ║
║ EQ                                 64.750 ║
║ ISZERO                             56.417 ║
║ AND                                58.750 ║
║ OR                                 60.750 ║
║ XOR                                60.750 ║
║ NOT                                52.417 ║
║ BYTE                               66.750 ║
║ SHL                                64.750 ║
║ SHR                                62.750 ║
║ SAR                                90.750 ║
║ SGT                                86.750 ║
║ SHA3                               27.647 ║
║ ADDRESS                            80.906 ║
║ BALANCE                            73.585 ║
║ ORIGIN                           1372.594 ║
║ CALLER                             80.906 ║
║ CALLVALUE                          80.906 ║
║ CALLDATALOAD                       54.750 ║
║ CALLDATASIZE                       81.125 ║
║ CALLDATACOPY                       66.231 ║
║ CODESIZE                           81.625 ║
║ CODECOPY                          142.241 ║
║ GASPRICE                         1378.312 ║
║ EXTCODESIZE                         5.105 ║
║ EXTCODECOPY                         5.178 ║
║ RETURNDATASIZE                     76.500 ║
║ RETURNDATACOPY                     51.778 ║
║ EXTCODEHASH                         8.315 ║
║ BLOCKHASH                         243.119 ║
║ COINBASE                         1375.594 ║
║ TIMESTAMP                        1372.594 ║
║ NUMBER                           1372.594 ║
║ PREVRANDAO                       1372.594 ║
║ GASLIMIT                         1378.594 ║
║ CHAINID                          1372.594 ║
║ SELFBALANCE                       649.612 ║
║ BASEFEE                          1369.594 ║
║ POP                                65.625 ║
║ MLOAD                              71.931 ║
║ MSTORE                             75.696 ║
║ MSTORE8                            83.539 ║
║ SLOAD                              27.014 ║
║ SSTORE                              9.044 ║
║ JUMP                               32.444 ║
║ JUMPI                              30.455 ║
║ PC                                 81.406 ║
║ MSIZE                              87.906 ║
║ GAS                                81.406 ║
║ JUMPDEST                          113.812 ║
║ PUSH0                              75.406 ║
║ PUSH1                              62.021 ║
║ PUSH2                              65.438 ║
║ PUSH4                              68.271 ║
║ PUSH5                              69.688 ║
║ PUSH6                              71.104 ║
║ PUSH7                              72.521 ║
║ PUSH8                              73.938 ║
║ PUSH9                              75.354 ║
║ PUSH10                             76.771 ║
║ PUSH11                             78.188 ║
║ PUSH12                             79.604 ║
║ PUSH13                             81.021 ║
║ PUSH14                             82.438 ║
║ PUSH15                             83.854 ║
║ PUSH16                             85.271 ║
║ PUSH17                             86.688 ║
║ PUSH18                             88.104 ║
║ PUSH19                             89.521 ║
║ PUSH20                             90.938 ║
║ PUSH21                             92.354 ║
║ PUSH22                             93.771 ║
║ PUSH23                             95.188 ║
║ PUSH24                             96.604 ║
║ PUSH25                             98.021 ║
║ PUSH26                             99.438 ║
║ PUSH27                            100.854 ║
║ PUSH28                            102.271 ║
║ PUSH29                            103.688 ║
║ PUSH30                            105.104 ║
║ PUSH31                            106.521 ║
║ PUSH32                            105.938 ║
║ DUP1                               54.417 ║
║ DUP2                               58.417 ║
║ DUP3                               58.417 ║
║ DUP4                               58.417 ║
║ DUP5                               58.417 ║
║ DUP6                               58.417 ║
║ DUP7                               58.417 ║
║ DUP8                               58.417 ║
║ DUP9                               56.417 ║
║ DUP10                              58.417 ║
║ DUP11                              58.417 ║
║ DUP12                              58.417 ║
║ DUP13                              58.417 ║
║ DUP14                              58.417 ║
║ DUP15                              58.417 ║
║ DUP16                              58.417 ║
║ SWAP1                              59.083 ║
║ SWAP2                              59.083 ║
║ SWAP3                              59.083 ║
║ SWAP4                              59.083 ║
║ SWAP5                              59.083 ║
║ SWAP6                              59.083 ║
║ SWAP7                              59.083 ║
║ SWAP8                              59.083 ║
║ SWAP9                              59.083 ║
║ SWAP10                             59.083 ║
║ SWAP11                             59.083 ║
║ SWAP12                             59.083 ║
║ SWAP13                             59.083 ║
║ SWAP14                             59.083 ║
║ SWAP15                             59.083 ║
║ SWAP16                             57.083 ║
║ CALL                               62.275 ║
║ STATICCALL                         62.240 ║
║ DELEGATECALL                       61.285 ║
║ CREATE                              5.490 ║
║ CREATE2                             7.745 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
║ SAR                               -12.384 ║
║ ADDRESS                             0.116 ║
║ ORIGIN                              0.007 ║
║ CALLER                              0.116 ║
║ CALLVALUE                           0.116 ║
║ COINBASE                            0.007 ║
║ TIMESTAMP                           0.007 ║
║ NUMBER                              0.007 ║
║ PREVRANDAO                          0.007 ║
║ GASLIMIT                            0.007 ║
║ CHAINID                             0.007 ║
║ SELFBALANCE                         0.006 ║
║ BASEFEE                             0.007 ║
║ PC                                  0.115 ║
║ MSIZE                               0.107 ║
║ GAS                                 0.115 ║
║ JUMPDEST                            0.164 ║
║ PUSH0                               0.124 ║
║ PUSH1                               0.101 ║
║ PUSH2                               0.095 ║
║ PUSH4                               0.091 ║
║ PUSH5                               0.090 ║
║ PUSH6                               0.088 ║
║ PUSH7                               0.086 ║
║ PUSH8                               0.084 ║
║ PUSH9                               0.083 ║
║ PUSH10                              0.081 ║
║ PUSH11                              0.080 ║
║ PUSH12                              0.078 ║
║ PUSH13                              0.077 ║
║ PUSH14                              0.076 ║
║ PUSH15                              0.074 ║
║ PUSH16                              0.073 ║
║ PUSH17                              0.072 ║
║ PUSH18                              0.071 ║
║ PUSH19                              0.070 ║
║ PUSH20                              0.069 ║
║ PUSH21                              0.068 ║
║ PUSH22                              0.067 ║
║ PUSH23                              0.066 ║
║ PUSH24                              0.065 ║
║ PUSH25                              0.064 ║
║ PUSH26                              0.063 ║
║ PUSH27                              0.062 ║
║ PUSH28                              0.061 ║
║ PUSH29                              0.060 ║
║ PUSH30                              0.059 ║
║ PUSH31                              0.059 ║
║ PUSH32                              0.059 ║
║ CALL                                0.003 ║
║ STATICCALL                         -0.007 ║
║ DELEGATECALL                       -0.007 ║
║ CREATE                              0.003 ║
║ CREATE2                             0.002 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter MzB3 ╞═╣
║ Mean                                0.031 ║
║ Best                                0.155 ║
║ Worst                              -4.275 ║
║ Total                               0.013 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╣
║ Mean                                0.001 ║
║ Best                                0.006 ║
║ Worst                              -0.845 ║
║ Total                               0.001 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.208 ║
║ Best                                0.416 ║
║ Worst                               0.000 ║
║ Total                               0.003 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.026 ║
║ Best                                0.054 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.208 ║
║ Best                                0.416 ║
║ Worst                               0.000 ║
║ Total                               0.003 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.027 ║
║ Best                                0.054 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life M3B3 ╞═╗
║ Mean                                0.003 ║
║ Best                                1.717 ║
║ Worst                              -0.584 ║
║ Total                              -0.042 ║
╠═╡ Cycles (-%) ╞════════╡ Real life M3B3 ╞═╣
║ Mean                                0.114 ║
║ Best                                0.575 ║
║ Worst                              -0.377 ║
║ Total                               0.077 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Mean                                0.010 ║
║ Best                                0.091 ║
║ Worst                              -0.147 ║
║ Total                               0.015 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life MzB3 ╞═╗
║ Mean                               -0.010 ║
║ Best                                0.084 ║
║ Worst                              -0.229 ║
║ Total                              -0.032 ║
╠═╡ Cycles (-%) ╞════════╡ Real life MzB3 ╞═╣
║ Mean                                0.108 ║
║ Best                                0.515 ║
║ Worst                              -0.637 ║
║ Total                               0.061 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Mean                                0.011 ║
║ Best                                0.054 ║
║ Worst                              -0.040 ║
║ Total                               0.015 ║
╚═══════════════════════════════════════════╝

@akiramenai
Copy link
Collaborator Author

As we don't plan to address SAR regression now, closing the ticket. #644 is to address it when upgrading LLVM.

@akiramenai akiramenai closed this Jul 3, 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.

3 participants