Skip to content

Commit efbd366

Browse files
added optimization. shl comes out from being distributed over and
1 parent c726453 commit efbd366

36 files changed

+94
-47
lines changed

libevmasm/RuleList.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
440440
Pattern B,
441441
Pattern,
442442
Pattern X,
443-
Pattern Y
443+
Pattern Y,
444+
Pattern Z
444445
)
445446
{
446447
using Word = typename Pattern::Word;
@@ -629,6 +630,12 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
629630
feasibilityFunction
630631
});
631632

633+
rules.push_back({
634+
// AND(SHL(Z, X), SHL(Z, Y)) -> SHL(Z, AND(X, Y))
635+
Builtins::AND(Builtins::SHL(Z, X), Builtins::SHL(Z, Y)),
636+
[=]() -> Pattern { return Builtins::SHL(Z, Builtins::AND(X, Y)); }
637+
});
638+
632639
rules.push_back({
633640
Builtins::BYTE(A, Builtins::SHL(B, X)),
634641
[=]() -> Pattern { return Builtins::BYTE(A.d() + B.d() / 8, X); },
@@ -823,7 +830,7 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList(
823830
rules += simplificationRuleListPart4_5(A, B, C, W, X);
824831
rules += simplificationRuleListPart5(_evmVersion.has_value(), A, B, C, W, X);
825832
rules += simplificationRuleListPart6(A, B, C, W, X);
826-
rules += simplificationRuleListPart7(A, B, C, W, X);
833+
rules += simplificationRuleListPart7(A, B, C, W, X, Y);
827834
rules += simplificationRuleListPart8(A, B, C, W, X);
828835

829836
if (_evmVersion.has_value())
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from opcodes import AND, SHL
2+
from rule import Rule
3+
from z3 import BitVec
4+
5+
"""
6+
Rule:
7+
AND(SHL(Z,X), SHL(Z,Y)) -> SHL(Z, AND(X,Y))
8+
"""
9+
10+
rule = Rule()
11+
12+
n_bits = 128
13+
14+
# Input vars
15+
X = BitVec('X', n_bits)
16+
Y = BitVec('Y', n_bits)
17+
Z = BitVec('Z', n_bits)
18+
19+
# Non optimized result
20+
nonopt = AND(SHL(Z,X), SHL(Z,Y))
21+
22+
# Optimized result
23+
opt = SHL(Z, AND(X,Y))
24+
25+
rule.check(nonopt, opt)

test/libsolidity/semanticTests/abiEncoderV1/struct/struct_storage_ptr.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ contract C {
2424
// ----
2525
// library: L
2626
// f() -> 8, 7, 1, 2, 7, 12
27-
// gas irOptimized: 166525
27+
// gas irOptimized: 166513
2828
// gas legacy: 169347
2929
// gas legacyOptimized: 167269

test/libsolidity/semanticTests/array/arrays_complex_from_and_to_storage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract Test {
1212
}
1313
// ----
1414
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
15-
// gas irOptimized: 186766
15+
// gas irOptimized: 186550
1616
// gas legacy: 211149
1717
// gas legacyOptimized: 206054
1818
// data(uint256,uint256): 0x02, 0x02 -> 0x09

test/libsolidity/semanticTests/array/byte_array_transitional_2.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ contract c {
1717
}
1818
// ----
1919
// test() -> 0
20-
// gas irOptimized: 157200
20+
// gas irOptimized: 157188
2121
// gas legacy: 188576
2222
// gas legacyOptimized: 183333

test/libsolidity/semanticTests/array/copying/array_copy_cleanup_uint40.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ contract C {
4646
}
4747
// ----
4848
// f() -> true
49-
// gas irOptimized: 146936
49+
// gas irOptimized: 146756
5050
// gas legacy: 155961
5151
// gas legacyOptimized: 153588

test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ contract c {
1717
}
1818
// ----
1919
// test() -> 5, 4
20-
// gas irOptimized: 225027
20+
// gas irOptimized: 224973
2121
// gas legacy: 233801
2222
// gas legacyOptimized: 232816

test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base_nested.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ contract c {
2323
// compileToEwasm: also
2424
// ----
2525
// test() -> 3, 4
26-
// gas irOptimized: 189690
26+
// gas irOptimized: 189516
2727
// gas legacy: 215253
2828
// gas legacyOptimized: 212341

test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_dynamic_dynamic.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ contract c {
1818

1919
// ----
2020
// test() -> 5, 4
21-
// gas irOptimized: 272950
21+
// gas irOptimized: 272893
2222
// gas legacy: 270834
2323
// gas legacyOptimized: 269960

test/libsolidity/semanticTests/array/copying/array_copy_storage_to_memory_nested.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ contract C {
1515
}
1616
// ----
1717
// f() -> 0x20, 2, 0x40, 0xa0, 2, 0, 1, 2, 2, 3
18-
// gas irOptimized: 161777
18+
// gas irOptimized: 161735
1919
// gas legacy: 162278
2020
// gas legacyOptimized: 159955

0 commit comments

Comments
 (0)