diff --git a/libyul/backends/evm/EVMMetrics.h b/libyul/backends/evm/EVMMetrics.h index 63e0d3c8f..00dad153b 100644 --- a/libyul/backends/evm/EVMMetrics.h +++ b/libyul/backends/evm/EVMMetrics.h @@ -43,7 +43,7 @@ public: GasMeter(EVMDialect const& _dialect, bool _isCreation, size_t _runs): m_dialect(_dialect), m_isCreation{_isCreation}, - m_runs(_runs) + m_runs(_isCreation? 1 : _runs) {} /// @returns the full combined costs of deploying and evaluating the expression. diff --git a/test/cmdlineTests/constant_optimizer_yul/args b/test/cmdlineTests/constant_optimizer_yul/args new file mode 100644 index 000000000..c42a0fcdd --- /dev/null +++ b/test/cmdlineTests/constant_optimizer_yul/args @@ -0,0 +1 @@ +--optimize --ir-optimized --optimize-runs 1000000 diff --git a/test/cmdlineTests/constant_optimizer_yul/err b/test/cmdlineTests/constant_optimizer_yul/err new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/test/cmdlineTests/constant_optimizer_yul/err @@ -0,0 +1 @@ + diff --git a/test/cmdlineTests/constant_optimizer_yul/input.sol b/test/cmdlineTests/constant_optimizer_yul/input.sol new file mode 100644 index 000000000..b3ce6632b --- /dev/null +++ b/test/cmdlineTests/constant_optimizer_yul/input.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-v3 +pragma solidity >= 0.0.0; +contract C { + constructor () { + assembly { + // This shl should not be evaluated for all values of optimize-runs + sstore(0, shl(180, 1)) + } + } + fallback() external { + assembly { + // This shl would be evaluated for high values of optimize-runs + sstore(0, shl(180, 1)) + } + } +} diff --git a/test/cmdlineTests/constant_optimizer_yul/output b/test/cmdlineTests/constant_optimizer_yul/output new file mode 100644 index 000000000..9a125bd36 --- /dev/null +++ b/test/cmdlineTests/constant_optimizer_yul/output @@ -0,0 +1,30 @@ +Optimized IR: +/******************************************************* + * WARNING * + * Solidity to Yul compilation is still EXPERIMENTAL * + * It can result in LOSS OF FUNDS or worse * + * !USE AT YOUR OWN RISK! * + *******************************************************/ + +object "C_12" { + code { + { + mstore(64, 128) + if callvalue() { revert(0, 0) } + sstore(0, shl(180, 1)) + let _1 := datasize("C_12_deployed") + codecopy(0, dataoffset("C_12_deployed"), _1) + return(0, _1) + } + } + object "C_12_deployed" { + code { + { + mstore(64, 128) + if callvalue() { revert(0, 0) } + sstore(0, 0x1000000000000000000000000000000000000000000000) + stop() + } + } + } +}