@@ -555,28 +555,47 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
555555 }
556556 break ;
557557 case _POP_TOP :
558+ case _POP_TOP_LOAD_CONST_INLINE :
559+ case _POP_TOP_LOAD_CONST_INLINE_BORROW :
560+ case _POP_TWO_LOAD_CONST_INLINE_BORROW :
561+ optimize_pop_top_again :
558562 {
559563 _PyUOpInstruction * last = & buffer [pc - 1 ];
560564 while (last -> opcode == _NOP ) {
561565 last -- ;
562566 }
563- if (last -> opcode == _LOAD_CONST_INLINE ||
564- last -> opcode == _LOAD_CONST_INLINE_BORROW ||
565- last -> opcode == _LOAD_FAST ||
566- last -> opcode == _LOAD_FAST_BORROW ||
567- last -> opcode == _COPY
568- ) {
569- last -> opcode = _NOP ;
570- buffer [pc ].opcode = _NOP ;
571- }
572- if (last -> opcode == _REPLACE_WITH_TRUE ) {
573- last -> opcode = _NOP ;
567+ switch (last -> opcode ) {
568+ case _POP_TWO_LOAD_CONST_INLINE_BORROW :
569+ last -> opcode = _POP_TOP ;
570+ goto optimize_pop_top_again ;
571+ case _POP_TOP_LOAD_CONST_INLINE :
572+ case _POP_TOP_LOAD_CONST_INLINE_BORROW :
573+ last -> opcode = _NOP ;
574+ goto optimize_pop_top_again ;
575+ case _COPY :
576+ case _LOAD_CONST_INLINE :
577+ case _LOAD_CONST_INLINE_BORROW :
578+ case _LOAD_FAST :
579+ case _LOAD_FAST_BORROW :
580+ case _LOAD_SMALL_INT :
581+ last -> opcode = _NOP ;
582+ if (opcode == _POP_TOP ) {
583+ opcode = buffer [pc ].opcode = _NOP ;
584+ }
585+ else if (opcode == _POP_TOP_LOAD_CONST_INLINE ) {
586+ opcode = buffer [pc ].opcode = _LOAD_CONST_INLINE ;
587+ }
588+ else if (opcode == _POP_TOP_LOAD_CONST_INLINE_BORROW ) {
589+ opcode = buffer [pc ].opcode = _LOAD_CONST_INLINE_BORROW ;
590+ }
591+ else {
592+ assert (opcode == _POP_TWO_LOAD_CONST_INLINE_BORROW );
593+ opcode = buffer [pc ].opcode = _POP_TOP_LOAD_CONST_INLINE_BORROW ;
594+ goto optimize_pop_top_again ;
595+ }
574596 }
575- break ;
597+ _Py_FALLTHROUGH ;
576598 }
577- case _JUMP_TO_TOP :
578- case _EXIT_TRACE :
579- return pc + 1 ;
580599 default :
581600 {
582601 /* _PUSH_FRAME doesn't escape or error, but it
@@ -591,7 +610,11 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
591610 buffer [last_set_ip ].opcode = _SET_IP ;
592611 last_set_ip = -1 ;
593612 }
613+ break ;
594614 }
615+ case _JUMP_TO_TOP :
616+ case _EXIT_TRACE :
617+ return pc + 1 ;
595618 }
596619 }
597620 Py_UNREACHABLE ();
0 commit comments