@@ -1049,6 +1049,142 @@ BOOST_AUTO_TEST_CASE(clear_unreachable_code_eof, *boost::unit_test::precondition
1049
1049
}
1050
1050
}
1051
1051
1052
+ BOOST_AUTO_TEST_CASE (is_zero_is_zero_rjumpi, *boost::unit_test::precondition (onEOF()))
1053
+ {
1054
+ AssemblyItems items{
1055
+ u256 (1 ),
1056
+ Instruction::ISZERO,
1057
+ Instruction::ISZERO,
1058
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 1 )),
1059
+ u256 (0 ),
1060
+ Instruction::SLOAD,
1061
+ AssemblyItem (Tag, 1 ),
1062
+ };
1063
+
1064
+ AssemblyItems expectation{
1065
+ u256 (1 ),
1066
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 1 )),
1067
+ u256 (0 ),
1068
+ Instruction::SLOAD,
1069
+ AssemblyItem (Tag, 1 ),
1070
+ };
1071
+
1072
+ PeepholeOptimiser peepOpt (items, solidity::test::CommonOptions::get ().evmVersion ());
1073
+ BOOST_REQUIRE (peepOpt.optimise ());
1074
+ BOOST_CHECK_EQUAL_COLLECTIONS (
1075
+ items.begin (), items.end (),
1076
+ expectation.begin (), expectation.end ()
1077
+ );
1078
+ }
1079
+
1080
+ BOOST_AUTO_TEST_CASE (equal_is_zero_rjumpi, *boost::unit_test::precondition (onEOF()))
1081
+ {
1082
+ AssemblyItems items{
1083
+ u256 (1 ),
1084
+ u256 (2 ),
1085
+ Instruction::EQ,
1086
+ Instruction::ISZERO,
1087
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 1 )),
1088
+ u256 (0 ),
1089
+ Instruction::SLOAD,
1090
+ AssemblyItem (Tag, 1 ),
1091
+ };
1092
+
1093
+ AssemblyItems expectation{
1094
+ u256 (1 ),
1095
+ u256 (2 ),
1096
+ Instruction::SUB,
1097
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 1 )),
1098
+ u256 (0 ),
1099
+ Instruction::SLOAD,
1100
+ AssemblyItem (Tag, 1 ),
1101
+ };
1102
+
1103
+ PeepholeOptimiser peepOpt (items, solidity::test::CommonOptions::get ().evmVersion ());
1104
+ BOOST_REQUIRE (peepOpt.optimise ());
1105
+ BOOST_CHECK_EQUAL_COLLECTIONS (
1106
+ items.begin (), items.end (),
1107
+ expectation.begin (), expectation.end ()
1108
+ );
1109
+ }
1110
+
1111
+ BOOST_AUTO_TEST_CASE (double_rjump, *boost::unit_test::precondition (onEOF()))
1112
+ {
1113
+ AssemblyItems items{
1114
+ u256 (1 ),
1115
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 1 )),
1116
+ AssemblyItem::relativeJumpTo (AssemblyItem (Tag, 2 )),
1117
+ AssemblyItem (Tag, 1 ),
1118
+ u256 (0 ),
1119
+ Instruction::SLOAD,
1120
+ AssemblyItem (Tag, 2 ),
1121
+ };
1122
+
1123
+ AssemblyItems expectation{
1124
+ u256 (1 ),
1125
+ Instruction::ISZERO,
1126
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 2 )),
1127
+ AssemblyItem (Tag, 1 ),
1128
+ u256 (0 ),
1129
+ Instruction::SLOAD,
1130
+ AssemblyItem (Tag, 2 ),
1131
+ };
1132
+
1133
+ PeepholeOptimiser peepOpt (items, solidity::test::CommonOptions::get ().evmVersion ());
1134
+ BOOST_REQUIRE (peepOpt.optimise ());
1135
+ BOOST_CHECK_EQUAL_COLLECTIONS (
1136
+ items.begin (), items.end (),
1137
+ expectation.begin (), expectation.end ()
1138
+ );
1139
+ }
1140
+
1141
+ BOOST_AUTO_TEST_CASE (rjump_to_next, *boost::unit_test::precondition (onEOF()))
1142
+ {
1143
+ AssemblyItems items{
1144
+ AssemblyItem::relativeJumpTo (AssemblyItem (Tag, 1 )),
1145
+ AssemblyItem (Tag, 1 ),
1146
+ u256 (0 ),
1147
+ Instruction::SLOAD,
1148
+ };
1149
+
1150
+ AssemblyItems expectation{
1151
+ AssemblyItem (Tag, 1 ),
1152
+ u256 (0 ),
1153
+ Instruction::SLOAD,
1154
+ };
1155
+
1156
+ PeepholeOptimiser peepOpt (items, solidity::test::CommonOptions::get ().evmVersion ());
1157
+ BOOST_REQUIRE (peepOpt.optimise ());
1158
+ BOOST_CHECK_EQUAL_COLLECTIONS (
1159
+ items.begin (), items.end (),
1160
+ expectation.begin (), expectation.end ()
1161
+ );
1162
+ }
1163
+
1164
+ BOOST_AUTO_TEST_CASE (rjumpi_to_next, *boost::unit_test::precondition (onEOF()))
1165
+ {
1166
+ AssemblyItems items{
1167
+ AssemblyItem::conditionalRelativeJumpTo (AssemblyItem (Tag, 1 )),
1168
+ AssemblyItem (Tag, 1 ),
1169
+ u256 (0 ),
1170
+ Instruction::SLOAD,
1171
+ };
1172
+
1173
+ AssemblyItems expectation{
1174
+ Instruction::POP,
1175
+ AssemblyItem (Tag, 1 ),
1176
+ u256 (0 ),
1177
+ Instruction::SLOAD,
1178
+ };
1179
+
1180
+ PeepholeOptimiser peepOpt (items, solidity::test::CommonOptions::get ().evmVersion ());
1181
+ BOOST_REQUIRE (peepOpt.optimise ());
1182
+ BOOST_CHECK_EQUAL_COLLECTIONS (
1183
+ items.begin (), items.end (),
1184
+ expectation.begin (), expectation.end ()
1185
+ );
1186
+ }
1187
+
1052
1188
BOOST_AUTO_TEST_CASE (deduplicateNextTagBlockSize3)
1053
1189
{
1054
1190
AssemblyItems items{
0 commit comments