matter-labs / era-compiler-llvm

ZKsync fork of the LLVM framework.
Other
33 stars 16 forks source link

Cherry-pick nikic's APint fixes #693

Closed akiramenai closed 2 months ago

github-actions[bot] commented 2 months ago

:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.

github-actions[bot] commented 2 months ago

Benchmark results default:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.135 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                               -0.078 ║
║ Best                                0.011 ║
║ Worst                             -83821.271 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.135 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                               -0.077 ║
║ Best                                0.011 ║
║ Worst                             -81182.616 ║
║ Total                              -0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.135 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.011 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                42.750 ║
║ MUL                                25.650 ║
║ SUB                                42.750 ║
║ DIV                                30.450 ║
║ SDIV                               46.050 ║
║ MOD                                30.450 ║
║ SMOD                               43.650 ║
║ ADDMOD                             24.406 ║
║ MULMOD                             25.906 ║
║ EXP                                 7.438 ║
║ SIGNEXTEND                         28.050 ║
║ LT                                 46.750 ║
║ GT                                 46.750 ║
║ SLT                                70.750 ║
║ SGT                                68.750 ║
║ EQ                                 46.750 ║
║ ISZERO                             44.417 ║
║ AND                                42.750 ║
║ OR                                 42.750 ║
║ XOR                                42.750 ║
║ NOT                                38.417 ║
║ BYTE                               54.750 ║
║ SHL                                46.750 ║
║ SHR                                48.750 ║
║ SAR                                68.750 ║
║ SGT                                68.750 ║
║ SHA3                               28.243 ║
║ ADDRESS                            53.812 ║
║ BALANCE                            73.332 ║
║ ORIGIN                           1349.500 ║
║ CALLER                             53.812 ║
║ CALLVALUE                          53.812 ║
║ CALLDATALOAD                       40.750 ║
║ CALLDATASIZE                       54.125 ║
║ CALLDATACOPY                       73.123 ║
║ CODESIZE                           54.625 ║
║ CODECOPY                          133.379 ║
║ GASPRICE                         1352.312 ║
║ EXTCODESIZE                         5.128 ║
║ EXTCODECOPY                         5.180 ║
║ RETURNDATASIZE                     52.500 ║
║ RETURNDATACOPY                     45.222 ║
║ EXTCODEHASH                         6.206 ║
║ BLOCKHASH                         241.019 ║
║ COINBASE                         1352.500 ║
║ TIMESTAMP                        1349.500 ║
║ NUMBER                           1349.500 ║
║ PREVRANDAO                       1349.500 ║
║ GASLIMIT                         1355.500 ║
║ CHAINID                          1349.500 ║
║ SELFBALANCE                       642.125 ║
║ BASEFEE                          1349.500 ║
║ POP                                44.625 ║
║ MLOAD                              64.390 ║
║ MSTORE                             62.562 ║
║ MSTORE8                            74.127 ║
║ SLOAD                              26.837 ║
║ SSTORE                              9.059 ║
║ JUMP                               23.111 ║
║ JUMPI                              21.727 ║
║ PC                                 54.312 ║
║ MSIZE                              60.812 ║
║ GAS                                51.312 ║
║ JUMPDEST                           77.625 ║
║ PUSH0                              51.312 ║
║ PUSH1                              45.958 ║
║ PUSH2                              49.375 ║
║ PUSH4                              52.208 ║
║ PUSH5                              53.625 ║
║ PUSH6                              55.042 ║
║ PUSH7                              56.458 ║
║ PUSH8                              57.875 ║
║ PUSH9                              59.292 ║
║ PUSH10                             60.708 ║
║ PUSH11                             62.125 ║
║ PUSH12                             63.542 ║
║ PUSH13                             64.958 ║
║ PUSH14                             66.375 ║
║ PUSH15                             67.792 ║
║ PUSH16                             69.208 ║
║ PUSH17                             70.625 ║
║ PUSH18                             72.042 ║
║ PUSH19                             73.458 ║
║ PUSH20                             74.875 ║
║ PUSH21                             76.292 ║
║ PUSH22                             77.708 ║
║ PUSH23                             79.125 ║
║ PUSH24                             80.542 ║
║ PUSH25                             81.958 ║
║ PUSH26                             83.375 ║
║ PUSH27                             84.792 ║
║ PUSH28                             86.208 ║
║ PUSH29                             87.625 ║
║ PUSH30                             89.042 ║
║ PUSH31                             90.458 ║
║ PUSH32                             89.875 ║
║ DUP1                               36.417 ║
║ DUP2                               44.417 ║
║ DUP3                               42.417 ║
║ DUP4                               44.417 ║
║ DUP5                               44.417 ║
║ DUP6                               44.417 ║
║ DUP7                               44.417 ║
║ DUP8                               44.417 ║
║ DUP9                               44.417 ║
║ DUP10                              44.417 ║
║ DUP11                              44.417 ║
║ DUP12                              44.417 ║
║ DUP13                              44.417 ║
║ DUP14                              44.417 ║
║ DUP15                              44.417 ║
║ DUP16                              44.417 ║
║ SWAP1                              47.083 ║
║ SWAP2                              47.083 ║
║ SWAP3                              47.083 ║
║ SWAP4                              47.083 ║
║ SWAP5                              45.083 ║
║ SWAP6                              47.083 ║
║ SWAP7                              47.083 ║
║ SWAP8                              47.083 ║
║ SWAP9                              47.083 ║
║ SWAP10                             47.083 ║
║ SWAP11                             47.083 ║
║ SWAP12                             47.083 ║
║ SWAP13                             47.083 ║
║ SWAP14                             47.083 ║
║ SWAP15                             47.083 ║
║ SWAP16                             47.083 ║
║ CALL                               56.178 ║
║ STATICCALL                         56.168 ║
║ DELEGATECALL                       55.204 ║
║ CREATE                              5.033 ║
║ CREATE2                             7.054 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
║ EXTCODECOPY                         0.089 ║
║ CALL                                0.005 ║
║ STATICCALL                          0.005 ║
║ DELEGATECALL                        0.005 ║
║ CREATE                              0.002 ║
║ CREATE2                             0.003 ║
╚═══════════════════════════════════════════╝

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

╔═╡ Size (-%) ╞════════╡ Precompiles M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ 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.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

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

╔═╡ Size (-%) ╞══════════╡ Real life MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝
PavelKopyl commented 2 months ago

I wonder, why do we need to revert the assertions in APInt constructor - "Revert "Assert correct values in APInt constructor""? Are that assertions triggered on our codebase?

akiramenai commented 2 months ago

@PavelKopyl we've already merged pieces of nikic's patches when they were under development, so basically I reverted the old version, then cherry-picked accepted patches, then reapplied the current nikic's WIP.

akiramenai commented 2 months ago

@vladimirradosavljevic I didn't dig deep into the transformation itself, but you listed https://github.com/llvm/llvm-project/commit/3512bcc2e9ab06b0ae2cab78744550b515e54184 in the ticket. The rest are to apply this patch cleanly, aside from introducing new functionality it reimplements the old one and then we apply the patch. So I don't that confident that there wasn't a bug in LLVM 17 and prefer to cherry-pick.