mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
added optimization. shl comes out from being distributed over and
This commit is contained in:
parent
c72645327e
commit
efbd3666a7
@ -440,7 +440,8 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
|
||||
Pattern B,
|
||||
Pattern,
|
||||
Pattern X,
|
||||
Pattern Y
|
||||
Pattern Y,
|
||||
Pattern Z
|
||||
)
|
||||
{
|
||||
using Word = typename Pattern::Word;
|
||||
@ -629,6 +630,12 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
|
||||
feasibilityFunction
|
||||
});
|
||||
|
||||
rules.push_back({
|
||||
// AND(SHL(Z, X), SHL(Z, Y)) -> SHL(Z, AND(X, Y))
|
||||
Builtins::AND(Builtins::SHL(Z, X), Builtins::SHL(Z, Y)),
|
||||
[=]() -> Pattern { return Builtins::SHL(Z, Builtins::AND(X, Y)); }
|
||||
});
|
||||
|
||||
rules.push_back({
|
||||
Builtins::BYTE(A, Builtins::SHL(B, X)),
|
||||
[=]() -> Pattern { return Builtins::BYTE(A.d() + B.d() / 8, X); },
|
||||
@ -823,7 +830,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
|
||||
rules += simplificationRuleListPart4_5(A, B, C, W, X);
|
||||
rules += simplificationRuleListPart5(_evmVersion.has_value(), A, B, C, W, X);
|
||||
rules += simplificationRuleListPart6(A, B, C, W, X);
|
||||
rules += simplificationRuleListPart7(A, B, C, W, X);
|
||||
rules += simplificationRuleListPart7(A, B, C, W, X, Y);
|
||||
rules += simplificationRuleListPart8(A, B, C, W, X);
|
||||
|
||||
if (_evmVersion.has_value())
|
||||
|
25
test/formal/and_distributed_over_shl.py
Normal file
25
test/formal/and_distributed_over_shl.py
Normal file
@ -0,0 +1,25 @@
|
||||
from opcodes import AND, SHL
|
||||
from rule import Rule
|
||||
from z3 import BitVec
|
||||
|
||||
"""
|
||||
Rule:
|
||||
AND(SHL(Z,X), SHL(Z,Y)) -> SHL(Z, AND(X,Y))
|
||||
"""
|
||||
|
||||
rule = Rule()
|
||||
|
||||
n_bits = 128
|
||||
|
||||
# Input vars
|
||||
X = BitVec('X', n_bits)
|
||||
Y = BitVec('Y', n_bits)
|
||||
Z = BitVec('Z', n_bits)
|
||||
|
||||
# Non optimized result
|
||||
nonopt = AND(SHL(Z,X), SHL(Z,Y))
|
||||
|
||||
# Optimized result
|
||||
opt = SHL(Z, AND(X,Y))
|
||||
|
||||
rule.check(nonopt, opt)
|
@ -24,6 +24,6 @@ contract C {
|
||||
// ----
|
||||
// library: L
|
||||
// f() -> 8, 7, 1, 2, 7, 12
|
||||
// gas irOptimized: 166525
|
||||
// gas irOptimized: 166513
|
||||
// gas legacy: 169347
|
||||
// gas legacyOptimized: 167269
|
||||
|
@ -12,7 +12,7 @@ contract Test {
|
||||
}
|
||||
// ----
|
||||
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
|
||||
// gas irOptimized: 186766
|
||||
// gas irOptimized: 186550
|
||||
// gas legacy: 211149
|
||||
// gas legacyOptimized: 206054
|
||||
// data(uint256,uint256): 0x02, 0x02 -> 0x09
|
||||
|
@ -17,6 +17,6 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> 0
|
||||
// gas irOptimized: 157200
|
||||
// gas irOptimized: 157188
|
||||
// gas legacy: 188576
|
||||
// gas legacyOptimized: 183333
|
||||
|
@ -46,6 +46,6 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// f() -> true
|
||||
// gas irOptimized: 146936
|
||||
// gas irOptimized: 146756
|
||||
// gas legacy: 155961
|
||||
// gas legacyOptimized: 153588
|
||||
|
@ -17,6 +17,6 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> 5, 4
|
||||
// gas irOptimized: 225027
|
||||
// gas irOptimized: 224973
|
||||
// gas legacy: 233801
|
||||
// gas legacyOptimized: 232816
|
||||
|
@ -23,6 +23,6 @@ contract c {
|
||||
// compileToEwasm: also
|
||||
// ----
|
||||
// test() -> 3, 4
|
||||
// gas irOptimized: 189690
|
||||
// gas irOptimized: 189516
|
||||
// gas legacy: 215253
|
||||
// gas legacyOptimized: 212341
|
||||
|
@ -18,6 +18,6 @@ contract c {
|
||||
|
||||
// ----
|
||||
// test() -> 5, 4
|
||||
// gas irOptimized: 272950
|
||||
// gas irOptimized: 272893
|
||||
// gas legacy: 270834
|
||||
// gas legacyOptimized: 269960
|
||||
|
@ -15,6 +15,6 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// f() -> 0x20, 2, 0x40, 0xa0, 2, 0, 1, 2, 2, 3
|
||||
// gas irOptimized: 161777
|
||||
// gas irOptimized: 161735
|
||||
// gas legacy: 162278
|
||||
// gas legacyOptimized: 159955
|
||||
|
@ -19,6 +19,6 @@ contract c {
|
||||
// compileToEwasm: also
|
||||
// ----
|
||||
// test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000
|
||||
// gas irOptimized: 124910
|
||||
// gas irOptimized: 124640
|
||||
// gas legacy: 187414
|
||||
// gas legacyOptimized: 165659
|
||||
|
@ -21,6 +21,6 @@ contract c {
|
||||
// compileToEwasm: also
|
||||
// ----
|
||||
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x0
|
||||
// gas irOptimized: 293621
|
||||
// gas irOptimized: 293486
|
||||
// gas legacy: 303626
|
||||
// gas legacyOptimized: 301945
|
||||
|
@ -21,6 +21,6 @@ contract c {
|
||||
// compileToEwasm: also
|
||||
// ----
|
||||
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00
|
||||
// gas irOptimized: 273177
|
||||
// gas irOptimized: 273093
|
||||
// gas legacy: 276360
|
||||
// gas legacyOptimized: 275411
|
||||
|
@ -26,4 +26,4 @@ contract C {
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> 3, 3, 3, 1
|
||||
// gas irOptimized: 182237
|
||||
// gas irOptimized: 181997
|
||||
|
@ -16,7 +16,7 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// constructor()
|
||||
// gas irOptimized: 237351
|
||||
// gas irOptimized: 236265
|
||||
// gas legacy: 221315
|
||||
// gas legacyOptimized: 185247
|
||||
// f() -> 0
|
||||
|
@ -13,6 +13,6 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// f() -> 2, 3, 4
|
||||
// gas irOptimized: 110135
|
||||
// gas irOptimized: 109838
|
||||
// gas legacy: 126350
|
||||
// gas legacyOptimized: 120704
|
||||
|
@ -16,6 +16,6 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test1() -> true
|
||||
// gas irOptimized: 207928
|
||||
// gas irOptimized: 206428
|
||||
// gas legacy: 254905
|
||||
// gas legacyOptimized: 247415
|
||||
|
@ -14,7 +14,7 @@ contract c {
|
||||
// ----
|
||||
// storageEmpty -> 1
|
||||
// fill() ->
|
||||
// gas irOptimized: 519487
|
||||
// gas irOptimized: 519361
|
||||
// gas legacy: 521584
|
||||
// gas legacyOptimized: 517027
|
||||
// storageEmpty -> 0
|
||||
|
@ -16,7 +16,7 @@ contract c {
|
||||
// ----
|
||||
// storageEmpty -> 1
|
||||
// fill() -> 8
|
||||
// gas irOptimized: 123024
|
||||
// gas irOptimized: 123012
|
||||
// gas legacy: 121756
|
||||
// gas legacyOptimized: 120687
|
||||
// storageEmpty -> 0
|
||||
|
@ -18,7 +18,7 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> 38, 28, 18
|
||||
// gas irOptimized: 186370
|
||||
// gas irOptimized: 185650
|
||||
// gas legacy: 189492
|
||||
// gas legacyOptimized: 178318
|
||||
// storageEmpty -> 1
|
||||
|
@ -18,7 +18,7 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> 20, 10
|
||||
// gas irOptimized: 158020
|
||||
// gas irOptimized: 157570
|
||||
// gas legacy: 159279
|
||||
// gas legacyOptimized: 152937
|
||||
// storageEmpty -> 1
|
||||
|
@ -10,6 +10,6 @@ contract c {
|
||||
|
||||
// ----
|
||||
// test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000
|
||||
// gas irOptimized: 109310
|
||||
// gas irOptimized: 109301
|
||||
// gas legacy: 126702
|
||||
// gas legacyOptimized: 123422
|
||||
|
@ -16,7 +16,7 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> true
|
||||
// gas irOptimized: 176111
|
||||
// gas irOptimized: 175619
|
||||
// gas legacy: 224093
|
||||
// gas legacyOptimized: 205152
|
||||
// storageEmpty -> 1
|
||||
|
@ -15,7 +15,7 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() ->
|
||||
// gas irOptimized: 142636
|
||||
// gas irOptimized: 142528
|
||||
// gas legacy: 164430
|
||||
// gas legacyOptimized: 158513
|
||||
// storageEmpty -> 1
|
||||
|
@ -10,6 +10,6 @@ contract c {
|
||||
|
||||
// ----
|
||||
// test() -> 0x20, 33, 0x303030303030303030303030303030303030303030303030303030303030303, 0x0300000000000000000000000000000000000000000000000000000000000000
|
||||
// gas irOptimized: 108115
|
||||
// gas irOptimized: 108097
|
||||
// gas legacy: 125584
|
||||
// gas legacyOptimized: 122560
|
||||
|
@ -16,6 +16,6 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> 5, 4, 3, 3
|
||||
// gas irOptimized: 111448
|
||||
// gas irOptimized: 111406
|
||||
// gas legacy: 111838
|
||||
// gas legacyOptimized: 111128
|
||||
|
@ -15,6 +15,6 @@ contract c {
|
||||
}
|
||||
// ----
|
||||
// test() -> 0
|
||||
// gas irOptimized: 174126
|
||||
// gas irOptimized: 173456
|
||||
// gas legacy: 216790
|
||||
// gas legacyOptimized: 204003
|
||||
|
@ -27,14 +27,14 @@ contract C {
|
||||
// ----
|
||||
// l() -> 0
|
||||
// f(uint256,uint256): 42, 64 ->
|
||||
// gas irOptimized: 112476
|
||||
// gas irOptimized: 112470
|
||||
// gas legacy: 108105
|
||||
// gas legacyOptimized: 101987
|
||||
// l() -> 1
|
||||
// ll(uint256): 0 -> 43
|
||||
// a(uint256,uint256): 0, 42 -> 64
|
||||
// f(uint256,uint256): 84, 128 ->
|
||||
// gas irOptimized: 119064
|
||||
// gas irOptimized: 119058
|
||||
// gas legacy: 110325
|
||||
// gas legacyOptimized: 96331
|
||||
// l() -> 2
|
||||
|
@ -21,7 +21,7 @@ contract C {
|
||||
// ----
|
||||
// l() -> 0
|
||||
// g(uint256): 70 ->
|
||||
// gas irOptimized: 183584
|
||||
// gas irOptimized: 182534
|
||||
// gas legacy: 183811
|
||||
// gas legacyOptimized: 179218
|
||||
// l() -> 70
|
||||
|
@ -15,6 +15,6 @@ contract C {
|
||||
// ----
|
||||
// createEvent(uint256): 42 ->
|
||||
// ~ emit E(uint256[][]): 0x20, 0x02, 0x40, 0xa0, 0x02, 0x2a, 0x2b, 0x02, 0x2c, 0x2d
|
||||
// gas irOptimized: 185142
|
||||
// gas irOptimized: 185118
|
||||
// gas legacy: 187603
|
||||
// gas legacyOptimized: 184566
|
||||
|
@ -17,6 +17,6 @@ contract C {
|
||||
// ----
|
||||
// deposit() ->
|
||||
// ~ emit E(string,uint256[4]): #0xa7fb06bb999a5eb9aff9e0779953f4e1e4ce58044936c2f51c7fb879b85c08bd, #0xe755d8cc1a8cde16a2a31160dcd8017ac32d7e2f13215b29a23cdae40a78aa81
|
||||
// gas irOptimized: 333476
|
||||
// gas irOptimized: 332396
|
||||
// gas legacy: 388679
|
||||
// gas legacyOptimized: 374441
|
||||
|
@ -27,4 +27,4 @@ contract C {
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// f() -> 0
|
||||
// gas irOptimized: 111594
|
||||
// gas irOptimized: 111570
|
||||
|
@ -34,6 +34,6 @@ contract C {
|
||||
|
||||
// ----
|
||||
// f(bytes): 0x20, 0x5, "abcde" -> 0
|
||||
// gas irOptimized: 241890
|
||||
// gas irOptimized: 241872
|
||||
// gas legacy: 243341
|
||||
// gas legacyOptimized: 242454
|
||||
|
@ -16,38 +16,38 @@ contract C {
|
||||
// ----
|
||||
// test_indices(uint256): 1 ->
|
||||
// test_indices(uint256): 129 ->
|
||||
// gas irOptimized: 3021484
|
||||
// gas irOptimized: 3020710
|
||||
// gas legacy: 3071683
|
||||
// gas legacyOptimized: 3014415
|
||||
// test_indices(uint256): 5 ->
|
||||
// gas irOptimized: 722540
|
||||
// gas irOptimized: 722510
|
||||
// gas legacy: 719151
|
||||
// gas legacyOptimized: 716139
|
||||
// test_indices(uint256): 10 ->
|
||||
// gas irOptimized: 158407
|
||||
// gas irOptimized: 158347
|
||||
// gas legacy: 162657
|
||||
// gas legacyOptimized: 158422
|
||||
// test_indices(uint256): 15 ->
|
||||
// gas irOptimized: 173467
|
||||
// gas irOptimized: 173377
|
||||
// gas legacy: 179782
|
||||
// gas legacyOptimized: 173727
|
||||
// test_indices(uint256): 0xFF ->
|
||||
// gas irOptimized: 5681652
|
||||
// gas irOptimized: 5680122
|
||||
// gas legacy: 5780977
|
||||
// gas legacyOptimized: 5668997
|
||||
// test_indices(uint256): 1000 ->
|
||||
// gas irOptimized: 18208919
|
||||
// gas irOptimized: 18202919
|
||||
// gas legacy: 18602799
|
||||
// gas legacyOptimized: 18179744
|
||||
// test_indices(uint256): 129 ->
|
||||
// gas irOptimized: 5198552
|
||||
// gas irOptimized: 5197778
|
||||
// gas legacy: 5212013
|
||||
// gas legacyOptimized: 5157889
|
||||
// test_indices(uint256): 128 ->
|
||||
// gas irOptimized: 417500
|
||||
// gas irOptimized: 416732
|
||||
// gas legacy: 470568
|
||||
// gas legacyOptimized: 423768
|
||||
// test_indices(uint256): 1 ->
|
||||
// gas irOptimized: 726968
|
||||
// gas irOptimized: 726962
|
||||
// gas legacy: 721789
|
||||
// gas legacyOptimized: 720209
|
||||
|
@ -52,18 +52,18 @@ contract C {
|
||||
// ----
|
||||
// test_zeroed_indicies(uint256): 1 ->
|
||||
// test_zeroed_indicies(uint256): 5 ->
|
||||
// gas irOptimized: 165074
|
||||
// gas irOptimized: 165044
|
||||
// gas legacy: 166201
|
||||
// gas legacyOptimized: 163439
|
||||
// test_zeroed_indicies(uint256): 10 ->
|
||||
// gas irOptimized: 282677
|
||||
// gas irOptimized: 282617
|
||||
// gas legacy: 285088
|
||||
// gas legacyOptimized: 280012
|
||||
// test_zeroed_indicies(uint256): 15 ->
|
||||
// gas irOptimized: 405422
|
||||
// gas irOptimized: 405332
|
||||
// gas legacy: 409138
|
||||
// gas legacyOptimized: 401827
|
||||
// test_zeroed_indicies(uint256): 0xFF ->
|
||||
// gas irOptimized: 6404812
|
||||
// gas irOptimized: 6403282
|
||||
// gas legacy: 6466233
|
||||
// gas legacyOptimized: 6333077
|
||||
|
@ -0,0 +1,15 @@
|
||||
{
|
||||
let x := calldataload(0)
|
||||
let a := and(shl(x, 248), shl(x, 12))
|
||||
sstore(10, a)
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >byzantium
|
||||
// ----
|
||||
// step: expressionSimplifier
|
||||
//
|
||||
// {
|
||||
// {
|
||||
// sstore(10, shl(calldataload(0), 8))
|
||||
// }
|
||||
// }
|
Loading…
Reference in New Issue
Block a user