[issue2260] conditional jump to a POP_TOP optimization

Paul Pogonyshev report at bugs.python.org
Sun Mar 9 16:39:37 CET 2008


Paul Pogonyshev <pogonyshev at gmx.net> added the comment:

Also, this is the reason for while() in the patch.  Consider this function:

def bar(a, b, c):
    if a:
        if b:
            if c:
                return 'true'

Before the patch:
 11           0 LOAD_FAST                0 (a)
              3 JUMP_IF_FALSE           27 (to 33)
              6 POP_TOP

 12           7 LOAD_FAST                1 (b)
             10 JUMP_IF_FALSE           16 (to 29)
             13 POP_TOP

 13          14 LOAD_FAST                2 (c)
             17 JUMP_IF_FALSE            5 (to 25)
             20 POP_TOP

 14          21 LOAD_CONST               1 ('true')
             24 RETURN_VALUE
        >>   25 POP_TOP
             26 JUMP_ABSOLUTE           34
        >>   29 POP_TOP
             30 JUMP_FORWARD             1 (to 34)
        >>   33 POP_TOP
        >>   34 LOAD_CONST               0 (None)
             37 RETURN_VALUE

After:
 11           0 LOAD_FAST                0 (a)
              3 JUMP_IF_FALSE           27 (to 33)
              6 POP_TOP

 12           7 LOAD_FAST                1 (b)
             10 JUMP_IF_FALSE           20 (to 33)
             13 POP_TOP

 13          14 LOAD_FAST                2 (c)
             17 JUMP_IF_FALSE           13 (to 33)
             20 POP_TOP

 14          21 LOAD_CONST               1 ('true')
             24 RETURN_VALUE
             25 POP_TOP
             26 JUMP_ABSOLUTE           34
             29 POP_TOP
             30 JUMP_FORWARD             1 (to 34)
        >>   33 POP_TOP
        >>   34 LOAD_CONST               0 (None)
             37 RETURN_VALUE

Without the while(), target for jump at offset 17 wouldn't be optimized,
because "jump to unconditional jump" optimization hasn't been done yet:
it is farther in the code.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2260>
__________________________________


More information about the Python-bugs-list mailing list