mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove swap after dup.
This commit is contained in:
parent
c90d3a3558
commit
080f33a72c
@ -10,6 +10,7 @@ Bugfixes:
|
|||||||
Compiler Features:
|
Compiler Features:
|
||||||
* Build System: Update internal dependency of jsoncpp to 1.9.3.
|
* Build System: Update internal dependency of jsoncpp to 1.9.3.
|
||||||
* Optimizer: Add rule to remove shifts inside the byte opcode.
|
* Optimizer: Add rule to remove shifts inside the byte opcode.
|
||||||
|
* Peephole Optimizer: Add rule to remove swap after dup.
|
||||||
|
|
||||||
|
|
||||||
### 0.6.11 (2020-07-07)
|
### 0.6.11 (2020-07-07)
|
||||||
|
@ -205,6 +205,30 @@ struct SwapComparison: SimplePeepholeOptimizerMethod<SwapComparison, 2>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Remove swapN after dupN
|
||||||
|
struct DupSwap: SimplePeepholeOptimizerMethod<DupSwap, 2>
|
||||||
|
{
|
||||||
|
static size_t applySimple(
|
||||||
|
AssemblyItem const& _dupN,
|
||||||
|
AssemblyItem const& _swapN,
|
||||||
|
std::back_insert_iterator<AssemblyItems> _out
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
SemanticInformation::isDupInstruction(_dupN) &&
|
||||||
|
SemanticInformation::isSwapInstruction(_swapN) &&
|
||||||
|
getDupNumber(_dupN.instruction()) == getSwapNumber(_swapN.instruction())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
*_out = _dupN;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct IsZeroIsZeroJumpI: SimplePeepholeOptimizerMethod<IsZeroIsZeroJumpI, 4>
|
struct IsZeroIsZeroJumpI: SimplePeepholeOptimizerMethod<IsZeroIsZeroJumpI, 4>
|
||||||
{
|
{
|
||||||
static size_t applySimple(
|
static size_t applySimple(
|
||||||
@ -357,7 +381,7 @@ bool PeepholeOptimiser::optimise()
|
|||||||
applyMethods(
|
applyMethods(
|
||||||
state,
|
state,
|
||||||
PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(),
|
PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(),
|
||||||
IsZeroIsZeroJumpI(), JumpToNext(), UnreachableCode(),
|
DupSwap(), IsZeroIsZeroJumpI(), JumpToNext(), UnreachableCode(),
|
||||||
TagConjunctions(), TruthyAnd(), Identity()
|
TagConjunctions(), TruthyAnd(), Identity()
|
||||||
);
|
);
|
||||||
if (m_optimisedItems.size() < m_items.size() || (
|
if (m_optimisedItems.size() < m_items.size() || (
|
||||||
|
1
test/cmdlineTests/dup_opt_peephole/args
Normal file
1
test/cmdlineTests/dup_opt_peephole/args
Normal file
@ -0,0 +1 @@
|
|||||||
|
--asm
|
5
test/cmdlineTests/dup_opt_peephole/err
Normal file
5
test/cmdlineTests/dup_opt_peephole/err
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
|
||||||
|
--> dup_opt_peephole/input.sol
|
||||||
|
|
||||||
|
Warning: Source file does not specify required compiler version!
|
||||||
|
--> dup_opt_peephole/input.sol
|
9
test/cmdlineTests/dup_opt_peephole/input.sol
Normal file
9
test/cmdlineTests/dup_opt_peephole/input.sol
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
fallback() external {
|
||||||
|
assembly {
|
||||||
|
let x := calldataload(0)
|
||||||
|
x := x
|
||||||
|
sstore(0, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
test/cmdlineTests/dup_opt_peephole/output
Normal file
54
test/cmdlineTests/dup_opt_peephole/output
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
======= dup_opt_peephole/input.sol:C =======
|
||||||
|
EVM assembly:
|
||||||
|
/* "dup_opt_peephole/input.sol":0:111 contract C {... */
|
||||||
|
mstore(0x40, 0x80)
|
||||||
|
callvalue
|
||||||
|
dup1
|
||||||
|
iszero
|
||||||
|
tag_1
|
||||||
|
jumpi
|
||||||
|
0x00
|
||||||
|
dup1
|
||||||
|
revert
|
||||||
|
tag_1:
|
||||||
|
pop
|
||||||
|
dataSize(sub_0)
|
||||||
|
dup1
|
||||||
|
dataOffset(sub_0)
|
||||||
|
0x00
|
||||||
|
codecopy
|
||||||
|
0x00
|
||||||
|
return
|
||||||
|
stop
|
||||||
|
|
||||||
|
sub_0: assembly {
|
||||||
|
/* "dup_opt_peephole/input.sol":0:111 contract C {... */
|
||||||
|
mstore(0x40, 0x80)
|
||||||
|
callvalue
|
||||||
|
dup1
|
||||||
|
iszero
|
||||||
|
tag_3
|
||||||
|
jumpi
|
||||||
|
0x00
|
||||||
|
dup1
|
||||||
|
revert
|
||||||
|
tag_3:
|
||||||
|
pop
|
||||||
|
/* "dup_opt_peephole/input.sol":74:75 0 */
|
||||||
|
0x00
|
||||||
|
/* "dup_opt_peephole/input.sol":61:76 calldataload(0) */
|
||||||
|
calldataload
|
||||||
|
/* "dup_opt_peephole/input.sol":100:101 x */
|
||||||
|
dup1
|
||||||
|
/* "dup_opt_peephole/input.sol":97:98 0 */
|
||||||
|
0x00
|
||||||
|
/* "dup_opt_peephole/input.sol":90:102 sstore(0, x) */
|
||||||
|
sstore
|
||||||
|
/* "dup_opt_peephole/input.sol":47:106 {... */
|
||||||
|
pop
|
||||||
|
/* "dup_opt_peephole/input.sol":0:111 contract C {... */
|
||||||
|
stop
|
||||||
|
|
||||||
|
auxdata: AUXDATA REMOVED
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user