mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9546 from ethereum/expToShift
Optimization rule: Replace exp by shl.
This commit is contained in:
commit
306fef334b
@ -14,7 +14,7 @@ Compiler Features:
|
||||
* Yul Optimizer: Inline into functions further down in the call graph first.
|
||||
* Yul Optimizer: Try to simplify function names.
|
||||
* Yul IR Generator: Report source locations related to unimplemented features.
|
||||
|
||||
* Optimizer: Optimize ``exp`` when base is 0, 1 or 2.
|
||||
|
||||
Bugfixes:
|
||||
* Code generator: Fix internal error on stripping dynamic types from return parameters on EVM versions without ``RETURNDATACOPY``.
|
||||
|
@ -615,12 +615,13 @@ std::vector<SimplificationRule<Pattern>> evmRuleList(
|
||||
Pattern,
|
||||
Pattern,
|
||||
Pattern,
|
||||
Pattern,
|
||||
Pattern X,
|
||||
Pattern,
|
||||
Pattern
|
||||
)
|
||||
{
|
||||
using Builtins = typename Pattern::Builtins;
|
||||
using Word = typename Pattern::Word;
|
||||
std::vector<SimplificationRule<Pattern>> rules;
|
||||
|
||||
if (_evmVersion.hasSelfBalance())
|
||||
@ -629,6 +630,20 @@ std::vector<SimplificationRule<Pattern>> evmRuleList(
|
||||
[]() -> Pattern { return Instruction::SELFBALANCE; }
|
||||
});
|
||||
|
||||
rules.emplace_back(
|
||||
Builtins::EXP(0, X),
|
||||
[=]() -> Pattern { return Builtins::ISZERO(X); }
|
||||
);
|
||||
rules.emplace_back(
|
||||
Builtins::EXP(1, X),
|
||||
[=]() -> Pattern { return Word(1); }
|
||||
);
|
||||
if (_evmVersion.hasBitwiseShifting())
|
||||
rules.emplace_back(
|
||||
Builtins::EXP(2, X),
|
||||
[=]() -> Pattern { return Builtins::SHL(X, 1); }
|
||||
);
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
{
|
||||
let t := calldataload(0)
|
||||
sstore(0, exp(0, t))
|
||||
sstore(1, exp(1, t))
|
||||
sstore(2, exp(2, t))
|
||||
// The following should not be simplified
|
||||
sstore(3, exp(8, t))
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=constantinople
|
||||
// ----
|
||||
// step: expressionSimplifier
|
||||
//
|
||||
// {
|
||||
// let _1 := 0
|
||||
// let t := calldataload(_1)
|
||||
// sstore(_1, iszero(t))
|
||||
// sstore(1, 1)
|
||||
// let _8 := 2
|
||||
// sstore(_8, shl(t, 1))
|
||||
// sstore(3, exp(8, t))
|
||||
// }
|
Loading…
Reference in New Issue
Block a user