@@ -146,6 +146,35 @@ struct OpStop: SimplePeepholeOptimizerMethod<OpStop>
146
146
}
147
147
};
148
148
149
+ struct OpReturnRevert : SimplePeepholeOptimizerMethod<OpReturnRevert>
150
+ {
151
+ static bool applySimple (
152
+ AssemblyItem const & _op,
153
+ AssemblyItem const & _push,
154
+ AssemblyItem const & _pushOrDup,
155
+ AssemblyItem const & _returnRevert,
156
+ std::back_insert_iterator<AssemblyItems> _out
157
+ )
158
+ {
159
+ if (
160
+ (_returnRevert == Instruction::RETURN || _returnRevert == Instruction::REVERT) &&
161
+ _push.type () == Push &&
162
+ (_pushOrDup.type () == Push || _pushOrDup == dupInstruction (1 ))
163
+ )
164
+ if (
165
+ (_op.type () == Operation && !instructionInfo (_op.instruction ()).sideEffects ) ||
166
+ _op.type () == Push
167
+ )
168
+ {
169
+ *_out = _push;
170
+ *_out = _pushOrDup;
171
+ *_out = _returnRevert;
172
+ return true ;
173
+ }
174
+ return false ;
175
+ }
176
+ };
177
+
149
178
struct DoubleSwap : SimplePeepholeOptimizerMethod<DoubleSwap>
150
179
{
151
180
static size_t applySimple (AssemblyItem const & _s1, AssemblyItem const & _s2, std::back_insert_iterator<AssemblyItems>)
@@ -459,7 +488,7 @@ bool PeepholeOptimiser::optimise()
459
488
while (state.i < m_items.size ())
460
489
applyMethods (
461
490
state,
462
- PushPop (), OpPop (), OpStop (), DoublePush (), DoubleSwap (), CommutativeSwap (), SwapComparison (),
491
+ PushPop (), OpPop (), OpStop (), OpReturnRevert (), DoublePush (), DoubleSwap (), CommutativeSwap (), SwapComparison (),
463
492
DupSwap (), IsZeroIsZeroJumpI (), EqIsZeroJumpI (), DoubleJump (), JumpToNext (), UnreachableCode (),
464
493
TagConjunctions (), TruthyAnd (), Identity ()
465
494
);
0 commit comments