@@ -248,8 +248,8 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart4(
248
248
249
249
template <class Pattern >
250
250
std::vector<SimplificationRule<Pattern>> simplificationRuleListPart4_5 (
251
- Pattern,
252
- Pattern,
251
+ Pattern A ,
252
+ Pattern B ,
253
253
Pattern,
254
254
Pattern X,
255
255
Pattern Y
@@ -266,13 +266,17 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart4_5(
266
266
{Builtins::OR (Y, Builtins::OR (X, Y)), [=]{ return Builtins::OR (X, Y); }},
267
267
{Builtins::OR (Builtins::OR (Y, X), Y), [=]{ return Builtins::OR (Y, X); }},
268
268
{Builtins::OR (Y, Builtins::OR (Y, X)), [=]{ return Builtins::OR (Y, X); }},
269
+ {Builtins::SIGNEXTEND (X, Builtins::SIGNEXTEND (X, Y)), [=]() { return Builtins::SIGNEXTEND (X, Y); }},
270
+ {Builtins::SIGNEXTEND (A, Builtins::SIGNEXTEND (B, X)), [=]() {
271
+ return Builtins::SIGNEXTEND (A.d () < B.d () ? A.d () : B.d (), X);
272
+ }},
269
273
};
270
274
}
271
275
272
276
template <class Pattern >
273
277
std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5 (
274
278
Pattern A,
275
- Pattern,
279
+ Pattern B ,
276
280
Pattern,
277
281
Pattern X,
278
282
Pattern
@@ -314,6 +318,31 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart5(
314
318
[=]() { return A.d () >= Pattern::WordSize / 8 ; }
315
319
});
316
320
321
+ // Replace SIGNEXTEND(A, X), A >= 31 with ID
322
+ rules.push_back ({
323
+ Builtins::SIGNEXTEND (A, X),
324
+ [=]() -> Pattern { return X; },
325
+ [=]() { return A.d () >= Pattern::WordSize / 8 - 1 ; }
326
+ });
327
+ rules.push_back ({
328
+ Builtins::AND (A, Builtins::SIGNEXTEND (B, X)),
329
+ [=]() -> Pattern { return Builtins::AND (A, X); },
330
+ [=]() {
331
+ return
332
+ B.d () < Pattern::WordSize / 8 - 1 &&
333
+ (A.d () & ((u256 (1 ) << static_cast <size_t >((B.d () + 1 ) * 8 )) - 1 )) == A.d ();
334
+ }
335
+ });
336
+ rules.push_back ({
337
+ Builtins::AND (Builtins::SIGNEXTEND (B, X), A),
338
+ [=]() -> Pattern { return Builtins::AND (A, X); },
339
+ [=]() {
340
+ return
341
+ B.d () < Pattern::WordSize / 8 - 1 &&
342
+ (A.d () & ((u256 (1 ) << static_cast <size_t >((B.d () + 1 ) * 8 )) - 1 )) == A.d ();
343
+ }
344
+ });
345
+
317
346
for (auto instr: {
318
347
Instruction::ADDRESS,
319
348
Instruction::CALLER,
@@ -597,6 +626,24 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
597
626
}
598
627
});
599
628
629
+ rules.push_back ({
630
+ Builtins::SHL (A, Builtins::SIGNEXTEND (B, X)),
631
+ [=]() -> Pattern { return Builtins::SIGNEXTEND ((A.d () >> 3 ) + B.d (), Builtins::SHL (A, X)); },
632
+ [=] { return (A.d () & 7 ) == 0 && A.d () <= Pattern::WordSize && B.d () <= Pattern::WordSize / 8 ; }
633
+ });
634
+
635
+ rules.push_back ({
636
+ Builtins::SIGNEXTEND (A, Builtins::SHR (B, X)),
637
+ [=]() -> Pattern { return Builtins::SAR (B, X); },
638
+ [=] {
639
+ return
640
+ B.d () % 8 == 0 &&
641
+ B.d () <= Pattern::WordSize &&
642
+ A.d () <= Pattern::WordSize &&
643
+ (Pattern::WordSize - B.d ()) / 8 == A.d () + 1 ;
644
+ }
645
+ });
646
+
600
647
return rules;
601
648
}
602
649
0 commit comments