-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deterministically choose memory slots for variables during stack-to-memory. #14311
Conversation
test/libyul/yulOptimizerTests/commonSubexpressionEliminator/trivial.yul
Outdated
Show resolved
Hide resolved
test/libyul/yulOptimizerTests/commonSubexpressionEliminator/trivial.yul
Outdated
Show resolved
Hide resolved
// mstore(0x0180, 9) | ||
// mstore(0x0240, 10) | ||
// mstore(0x0220, 11) | ||
// mstore(0x0100, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But is this expected? Shouldn't it start from 0x80
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record (we discussed this in the office) - the slots are just assigned in a different permutation, 0x80
occurs below - we need to check if this has any adverse effect, but it's potentially "just fine" - i.e. just a different, but equally valid order for assigning these slots.
The changes solve the issue. The new diff is below. For some reason markdown seems to not highlight word-diff. diff --git a/sourcify-irOptimized-cpp.txt b/hardhat-irOptimized-cpp.txt
index ad5253d..e9dfa64 100644
--- a/sourcify-irOptimized-cpp.txt
+++ b/hardhat-irOptimized-cpp.txt
@@ -1,24 +1,24 @@
-# 0 "sourcify-irOptimized.txt"
+# 0 "hardhat-irOptimized.txt"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
-# 1 "sourcify-irOptimized.txt"
-"/// @use-src 59:\"contracts/Comptroller/CompoundLens.sol\"
-object \"CompoundLens_20028\" {
+# 1 "hardhat-irOptimized.txt"
+"/// @use-src 67:\"contracts/Comptroller/CompoundLens.sol\"
+object \"CompoundLens_20799\" {
code {
{
let _1 := memoryguard(0x80)
mstore(64, _1)
if callvalue() { revert(0, 0) }
- let _2 := datasize(\"CompoundLens_20028_deployed\")
- codecopy(_1, dataoffset(\"CompoundLens_20028_deployed\"), _2)
+ let _2 := datasize(\"CompoundLens_20799_deployed\")
+ codecopy(_1, dataoffset(\"CompoundLens_20799_deployed\"), _2)
return(_1, _2)
}
}
- object \"CompoundLens_20028_deployed\" {
+ object \"CompoundLens_20799_deployed\" {
code {
{
@@ -274,7 +274,7 @@ object \"CompoundLens_20028\" {
finalize_allocation_31590(memPtr_6)
mstore(memPtr_6, expr_1)
- let expr_mpos := fun_mul_24356(memPtr_5, memPtr_6)
+ let expr_mpos := fun_mul_25127(memPtr_5, memPtr_6)
let memPtr_7 := mload(64)
finalize_allocation_31590(memPtr_7)
@@ -283,7 +283,7 @@ object \"CompoundLens_20028\" {
finalize_allocation_31590(memPtr_8)
mstore(memPtr_8, expr_4)
- let _26 := fun_mul_24356(memPtr_7, memPtr_8)
+ let _26 := fun_mul_25127(memPtr_7, memPtr_8)
let memPtr_9 := mload(64)
finalize_allocation_31590(memPtr_9)
@@ -306,7 +306,7 @@ object \"CompoundLens_20028\" {
finalize_allocation_31590(memPtr_11)
mstore(memPtr_11, var)
- let var_1 := div( mload( fun_mul_24376(memPtr_11, calldataload(68))), 0x0de0b6b3a7640000)
+ let var_1 := div( mload( fun_mul_25147(memPtr_11, calldataload(68))), 0x0de0b6b3a7640000)
let memPos_2 := mload(64)
mstore(memPos_2, _1)
@@ -1179,7 +1179,7 @@ object \"CompoundLens_20028\" {
finalize_allocation_31590(memPtr_27)
mstore(memPtr_27, expr_22)
- require_helper_stringliteral( iszero(gt(value, div( mload( fun_mul_24376( memPtr_27, expr_21)), 0x0de0b6b3a7640000))))
+ require_helper_stringliteral( iszero(gt(value, div( mload( fun_mul_25147( memPtr_27, expr_21)), 0x0de0b6b3a7640000))))
}
default
{
@@ -2252,7 +2252,7 @@ object \"CompoundLens_20028\" {
mstore(add(memPtr_1, 64), 0)
}
- function fun_cTokenMetadata(var_cToken_address) -> var_mpos
+ function fun_cTokenMetadata(var_cToken_19060_address) -> var_mpos
{
pop(allocate_and_zero_memory_struct_struct_CTokenMetadata())
@@ -2261,7 +2261,7 @@ object \"CompoundLens_20028\" {
mstore(_1, shl(224, 0x5fe3b567))
- let _2 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _1, 4, _1, 32)
+ let _2 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _1, 4, _1, 32)
if iszero(_2)
{
@@ -2325,7 +2325,7 @@ object \"CompoundLens_20028\" {
mstore(_7, shl(226, 0x2b1e1377))
- let _8 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _7, 4, _7, 32)
+ let _8 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _7, 4, _7, 32)
if iszero(_8)
{
@@ -2361,7 +2361,7 @@ object \"CompoundLens_20028\" {
mstore(_10, _11)
- let _12 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _10, 4, _10, 32)
+ let _12 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _10, 4, _10, 32)
if iszero(_12)
{
@@ -2395,7 +2395,7 @@ object \"CompoundLens_20028\" {
mstore(_14, _11)
- let _15 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _14, 4, _14, 32)
+ let _15 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _14, 4, _14, 32)
if iszero(_15)
{
@@ -2468,7 +2468,7 @@ object \"CompoundLens_20028\" {
let _20 := mload(64)
mstore(_20, shl(224, 0x8e8f294b))
- mstore( add(_20, 4), and( var_cToken_address, sub(shl(160, 1), 1)))
+ mstore( add(_20, 4), and( var_cToken_19060_address, sub(shl(160, 1), 1)))
let _21 := staticcall(gas(), and( expr, sub(shl(160, 1), 1)), _20, 36, _20, 96)
if iszero(_21)
@@ -2479,8 +2479,8 @@ object \"CompoundLens_20028\" {
revert(pos_6, returndatasize())
}
- let expr_18365_component := 0
- mstore(0x0200, expr_18365_component)
+ let expr_component := 0
+ mstore(0x0200, expr_component)
if _21
{
@@ -2491,7 +2491,7 @@ object \"CompoundLens_20028\" {
if slt(sub( add(_20, _22), _20), 96)
{
- revert( expr_18365_component, expr_18365_component)
+ revert( expr_component, expr_component)
}
let value0 := abi_decode_bool_fromMemory(_20)
@@ -2499,7 +2499,7 @@ object \"CompoundLens_20028\" {
pop(abi_decode_bool_fromMemory(add(_20, 64)))
- expr_18365_component := value0
+ expr_component := value0
mstore(0x0200, value1)
}
@@ -2518,37 +2518,37 @@ object \"CompoundLens_20028\" {
revert(pos_7, returndatasize())
}
- let expr_18375_mpos := 0
+ let expr_19146_mpos := 0
if _24
{
let _25 := returndatasize()
- returndatacopy(_23, expr_18375_mpos, _25)
+ returndatacopy(_23, expr_19146_mpos, _25)
finalize_allocation(_23, _25)
if slt(sub( add(_23, _25), _23), 32)
{
- revert( expr_18375_mpos, expr_18375_mpos)
+ revert( expr_19146_mpos, expr_19146_mpos)
}
let offset := mload(_23)
if gt(offset, 0xffffffffffffffff)
{
- revert( expr_18375_mpos, expr_18375_mpos)
+ revert( expr_19146_mpos, expr_19146_mpos)
}
if slt(sub( add(_23, _25), add(_23, offset)), 224)
{
- revert( expr_18375_mpos, expr_18375_mpos)
+ revert( expr_19146_mpos, expr_19146_mpos)
}
let memPtr := mload(64)
if or(gt(add(memPtr, 224), 0xffffffffffffffff), lt(add(memPtr, 224), memPtr))
{
- mstore( expr_18375_mpos, shl(224, 0x4e487b71))
+ mstore( expr_19146_mpos, shl(224, 0x4e487b71))
mstore( 4, 0x41)
- revert( expr_18375_mpos, 36)
+ revert( expr_19146_mpos, 36)
}
mstore(64, add(memPtr, 224))
mstore(memPtr, abi_decode_uint8_fromMemory(add(_23, offset)))
@@ -2556,7 +2556,7 @@ object \"CompoundLens_20028\" {
if gt(offset_1, 0xffffffffffffffff)
{
- revert( expr_18375_mpos, expr_18375_mpos)
+ revert( expr_19146_mpos, expr_19146_mpos)
}
mstore(add(memPtr, 32), abi_decode_string_fromMemory(add(add(_23, offset), offset_1), add(_23, _25)))
@@ -2568,7 +2568,7 @@ object \"CompoundLens_20028\" {
mstore(add(memPtr, 160), mload(add(add(_23, offset), 160)))
mstore(add(memPtr, 192), mload(add(add(_23, offset), 192)))
- expr_18375_mpos := memPtr
+ expr_19146_mpos := memPtr
}
mstore(0x0220, allocate_and_zero_memory_struct_struct_GroupInfo())
@@ -2577,7 +2577,7 @@ object \"CompoundLens_20028\" {
mstore(_26, shl(225, 0x7f4e2257))
- let _27 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _26, 4, _26, 32)
+ let _27 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _26, 4, _26, 32)
if iszero(_27)
{
@@ -2608,28 +2608,28 @@ object \"CompoundLens_20028\" {
switch expr_6
case 0 {
- let _29 := add(expr_18375_mpos, 128)
+ let _29 := add(expr_19146_mpos, 128)
mstore(mload(0x0220), mload( _29))
- mstore( add(mload(0x0220), 64), mload( add(expr_18375_mpos, 192)))
+ mstore( add(mload(0x0220), 64), mload( add(expr_19146_mpos, 192)))
mstore( add(mload(0x0220), 32), mload( _29))
}
default
{
- mstore(mload(0x0220), mload( add(expr_18375_mpos, 64)))
- mstore( add(mload(0x0220), 64), mload( add(expr_18375_mpos, 160)))
+ mstore(mload(0x0220), mload( add(expr_19146_mpos, 64)))
+ mstore( add(mload(0x0220), 64), mload( add(expr_19146_mpos, 160)))
- mstore( add(mload(0x0220), 32), mload( add(expr_18375_mpos, 96)))
+ mstore( add(mload(0x0220), 32), mload( add(expr_19146_mpos, 96)))
}
let _30 := mload(64)
mstore(_30, shl(224, 0xbd6d894d))
- let _31 := call(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), 0, _30, 4, _30, 32)
+ let _31 := call(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), 0, _30, 4, _30, 32)
if iszero(_31)
{
@@ -2661,7 +2661,7 @@ object \"CompoundLens_20028\" {
mstore(_33, shl(228, 0x0ae9d70b))
- let _34 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _33, 4, _33, 32)
+ let _34 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _33, 4, _33, 32)
if iszero(_34)
{
@@ -2693,7 +2693,7 @@ object \"CompoundLens_20028\" {
mstore(_36, shl(227, 0x1f1f3b45))
- let _37 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _36, 4, _36, 32)
+ let _37 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _36, 4, _36, 32)
if iszero(_37)
{
@@ -2725,7 +2725,7 @@ object \"CompoundLens_20028\" {
mstore(_39, shl(226, 0x05cee641))
- let _40 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _39, 4, _39, 32)
+ let _40 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _39, 4, _39, 32)
if iszero(_40)
{
@@ -2757,7 +2757,7 @@ object \"CompoundLens_20028\" {
mstore(_42, shl(227, 0x08f7a6e3))
- let _43 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _42, 4, _42, 32)
+ let _43 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _42, 4, _42, 32)
if iszero(_43)
{
@@ -2789,7 +2789,7 @@ object \"CompoundLens_20028\" {
mstore(_45, shl(224, 0x8f840ddd))
- let _46 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _45, 4, _45, 32)
+ let _46 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _45, 4, _45, 32)
if iszero(_46)
{
@@ -2821,7 +2821,7 @@ object \"CompoundLens_20028\" {
mstore(_48, shl(224, 0x18160ddd))
- let _49 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _48, 4, _48, 32)
+ let _49 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _48, 4, _48, 32)
if iszero(_49)
{
@@ -2853,7 +2853,7 @@ object \"CompoundLens_20028\" {
mstore(_51, shl(225, 0x1d8e90d1))
- let _52 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _51, 4, _51, 32)
+ let _52 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _51, 4, _51, 32)
if iszero(_52)
{
@@ -2885,7 +2885,7 @@ object \"CompoundLens_20028\" {
mstore(_54, shl(224, 0x313ce567))
- let _55 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _54, 4, _54, 32)
+ let _55 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _54, 4, _54, 32)
if iszero(_55)
{
@@ -2917,7 +2917,7 @@ object \"CompoundLens_20028\" {
mstore(_57, shl(225, 0x7f4e2257))
- let _58 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _57, 4, _57, 32)
+ let _58 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _57, 4, _57, 32)
if iszero(_58)
{
@@ -2949,7 +2949,7 @@ object \"CompoundLens_20028\" {
mstore(_60, shl(226, 0x2b1e1377))
- let _61 := staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), _60, 4, _60, 32)
+ let _61 := staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), _60, 4, _60, 32)
if iszero(_61)
{
@@ -2980,7 +2980,7 @@ object \"CompoundLens_20028\" {
let _63 := mload(64)
mstore(_63, shl(224, 0xa7e9613f))
- mstore( add(_63, 4), and( var_cToken_address, sub(shl(160, 1), 1)))
+ mstore( add(_63, 4), and( var_cToken_19060_address, sub(shl(160, 1), 1)))
let _64 := staticcall(gas(), and( expr_1, sub(shl(160, 1), 1)), _63, 36, _63, 32)
@@ -3013,7 +3013,7 @@ object \"CompoundLens_20028\" {
let _66 := mload(64)
mstore(_66, shl(224, 0x9cc7becf))
- mstore( add(_66, 4), and( var_cToken_address, sub(shl(160, 1), 1)))
+ mstore( add(_66, 4), and( var_cToken_19060_address, sub(shl(160, 1), 1)))
let _67 := staticcall(gas(), and( expr, sub(shl(160, 1), 1)), _66, 36, _66, 32)
@@ -3083,7 +3083,7 @@ object \"CompoundLens_20028\" {
mstore(mload(0x0140), shl(226, 0x131d060f))
- mstore(0x0100, staticcall(gas(), and( var_cToken_address, sub(shl(160, 1), 1)), mload(0x0140), 4, mload(0x0140), 32))
+ mstore(0x0100, staticcall(gas(), and( var_cToken_19060_address, sub(shl(160, 1), 1)), mload(0x0140), 4, mload(0x0140), 32))
if iszero(mload(0x0100))
{
@@ -3112,7 +3112,7 @@ object \"CompoundLens_20028\" {
}
mstore(0x80, mload(64))
finalize_allocation_31701(mload(0x80))
- mstore(mload(0x80), and( var_cToken_address, sub(shl(160, 1), 1)))
+ mstore(mload(0x80), and( var_cToken_19060_address, sub(shl(160, 1), 1)))
mstore( add(mload(0x80), 32), mload(0xc0))
mstore( add(mload(0x80), 64), mload(0x01a0))
mstore( add(mload(0x80), 96), mload(0x01e0))
@@ -3121,7 +3121,7 @@ object \"CompoundLens_20028\" {
mstore( add(mload(0x80), 192), expr_9)
mstore( add(mload(0x80), 224), expr_10)
mstore( add(mload(0x80), 256), expr_11)
- mstore( add(mload(0x80), 288), iszero(iszero(expr_18365_component)))
+ mstore( add(mload(0x80), 288), iszero(iszero(expr_component)))
mstore( add(mload(0x80), 320), and(var_underlyingAssetAddress, sub(shl(160, 1), 1)))
mstore( add(mload(0x80), 352), and( expr_12, 0xff))
mstore( add(mload(0x80), 384), var_underlyingDecimals)
@@ -3200,12 +3200,12 @@ object \"CompoundLens_20028\" {
mstore(add(memPtr_1, 224), _1)
}
- function fun_cTokenBalances(var_cToken_18578_address, var_account) -> var__mpos
+ function fun_cTokenBalances(var_cToken_address, var_account) -> var_19355_mpos
{
pop(allocate_and_zero_memory_struct_struct_CTokenBalances())
let _1 := sub(shl(160, 1), 1)
- let _2 := and( var_cToken_18578_address, _1)
+ let _2 := and( var_cToken_address, _1)
let _3 := 64
let _4 := mload(_3)
@@ -3534,10 +3534,10 @@ object \"CompoundLens_20028\" {
mstore( add(memPtr, 192), var_tokenBalance)
mstore( add(memPtr, 224), var_tokenAllowance)
- var__mpos := memPtr
+ var_19355_mpos := memPtr
}
- function fun_cTokenUnderlyingPrice(var_cToken_18739_address) -> var_18743_mpos
+ function fun_cTokenUnderlyingPrice(var_cToken_19510_address) -> var_19514_mpos
{
let _1 := 64
@@ -3552,7 +3552,7 @@ object \"CompoundLens_20028\" {
mstore(add(memPtr, _3), _2)
let _4 := sub(shl(160, 1), 1)
- let _5 := and( var_cToken_18739_address, _4)
+ let _5 := and( var_cToken_19510_address, _4)
let _6 := mload(_1)
@@ -3652,7 +3652,7 @@ object \"CompoundLens_20028\" {
mstore(memPtr_1, _5)
mstore( add(memPtr_1, _3), expr_2)
- var_18743_mpos := memPtr_1
+ var_19514_mpos := memPtr_1
}
function abi_decode_uint256t_uint256t_uint256_fromMemory(headStart, dataEnd) -> value0, value1, value2
@@ -4038,7 +4038,7 @@ object \"CompoundLens_20028\" {
r := div(x, y)
}
- function fun_mul_24356(var_a_mpos, var_b_mpos) -> var_24342_mpos
+ function fun_mul_25127(var_a_mpos, var_b_mpos) -> var_25113_mpos
{
let memPtr := mload(64)
@@ -4055,24 +4055,24 @@ object \"CompoundLens_20028\" {
finalize_allocation_31590(memPtr_1)
mstore(memPtr_1, r)
- var_24342_mpos := memPtr_1
+ var_25113_mpos := memPtr_1
}
- function fun_mul_24376(var_a_24359_mpos, var_b) -> var_24365_mpos
+ function fun_mul_25147(var_a_25130_mpos, var_b) -> var_25136_mpos
{
let memPtr := mload(64)
finalize_allocation_31590(memPtr)
mstore(memPtr, 0)
- let _1 := mload( var_a_24359_mpos)
+ let _1 := mload( var_a_25130_mpos)
let var := fun_mul(_1, var_b, copy_literal_to_memory_3e4a9c0e386509f7d51443819fe3039eb3974511fef3f90a0001815722534080())
let memPtr_1 := mload(64)
finalize_allocation_31590(memPtr_1)
mstore(memPtr_1, var)
- var_24365_mpos := memPtr_1
+ var_25136_mpos := memPtr_1
}
function copy_literal_to_memory_3e4a9c0e386509f7d51443819fe3039eb3974511fef3f90a0001815722534080() -> memPtr
@@ -4119,7 +4119,7 @@ object \"CompoundLens_20028\" {
var := product
}
- function fun_mul(var_a, var_b, var_errorMessage_mpos) -> var
+ function fun_mul(var_a, var_b, var_errorMessage_25251_mpos) -> var
{
let expr := iszero(var_a)
@@ -4146,7 +4146,7 @@ object \"CompoundLens_20028\" {
revert( 0x00, 0x24)
}
- require_helper_string( eq( checked_div_uint256(product, var_a), var_b), var_errorMessage_mpos)
+ require_helper_string( eq( checked_div_uint256(product, var_a), var_b), var_errorMessage_25251_mpos)
var := product
} |
011d6b0
to
89d821e
Compare
a129d8f
to
49cff79
Compare
…names that may depend on AST IDs.
49cff79
to
b7abd9b
Compare
So should we just merge this now :-)? |
This is the presumed cause of #14250 after looking at some diffs generated by @r0qs.
I'm pushing this as draft, s.t. we can check if this solves the issue - if so we can iron out the details.