Last active
June 29, 2020 16:26
-
-
Save hrkrshnn/5d054ed71e068fbd02e9ead9599a6af9 to your computer and use it in GitHub Desktop.
LoopInvariantCodeMotion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Arraysum { | |
uint256[] values; | |
function sumArray() public view returns(uint) { | |
uint sum = 0; | |
for(uint i = 0; i < values.length; i++) | |
sum += values[i]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u /tmp/optimized1.yul /tmp/optimized.yul | |
--- /tmp/optimized1.yul 2020-06-29 21:47:13.459262630 +0530 | |
+++ /tmp/optimized.yul 2020-06-29 21:47:15.511249787 +0530 | |
@@ -227,15 +227,15 @@ | |
if slt(add(calldatasize(), not(3)), _1) { revert(_1, _1) } | |
let vloc_sum := _1 | |
let vloc_i := _1 | |
+ let _2 := sload(_1) | |
for { } | |
- 1 | |
+ lt(vloc_i, _2) | |
{ | |
vloc_i := increment_t_uint256(vloc_i) | |
} | |
{ | |
- if iszero(lt(vloc_i, sload(_1))) { break } | |
- let _2, _3 := storage_array_index_access_t_array$_t_uint256_$dyn_storage(_1, vloc_i) | |
- vloc_sum := checked_add_t_uint256(vloc_sum, extract_from_storage_value_dynamict_uint256(sload(_2), _3)) | |
+ let _3, _4 := storage_array_index_access_t_array$_t_uint256_$dyn_storage(_1, vloc_i) | |
+ vloc_sum := checked_add_t_uint256(vloc_sum, extract_from_storage_value_dynamict_uint256(sload(_3), _4)) | |
} | |
let memPos := allocateMemory(_1) | |
return(memPos, sub(abi_encode_tuple_t_uint256__to_t_uint256__fromStack(memPos, _1), memPos)) | |
Diff finished. Mon Jun 29 21:54:34 2020 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment