[issue32477] Move jumps optimization from the peepholer to the compiler
Serhiy Storchaka
report at bugs.python.org
Thu Mar 7 10:44:58 EST 2019
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
After analyzing the difference between bytecodes generated by the current peepholer and the new optimizer I have found that he peepholer do not optimizes jumps in case of some multiline expressions. For example:
[x
for x in a if x]
1 0 BUILD_LIST 0
2 LOAD_FAST 0 (.0)
>> 4 FOR_ITER 12 (to 18)
2 6 STORE_FAST 1 (x)
8 LOAD_FAST 1 (x)
10 POP_JUMP_IF_FALSE 16
1 12 LOAD_FAST 1 (x)
14 LIST_APPEND 2
>> 16 JUMP_ABSOLUTE 4
>> 18 RETURN_VALUE
if x:
if (y and
z):
foo()
else:
bar()
1 0 LOAD_NAME 0 (x)
2 POP_JUMP_IF_FALSE 20
2 4 LOAD_NAME 1 (y)
6 POP_JUMP_IF_FALSE 18
3 8 LOAD_NAME 2 (z)
2 10 POP_JUMP_IF_FALSE 18
4 12 LOAD_NAME 3 (foo)
14 CALL_FUNCTION 0
16 POP_TOP
>> 18 JUMP_FORWARD 6 (to 26)
6 >> 20 LOAD_NAME 4 (bar)
22 CALL_FUNCTION 0
24 POP_TOP
>> 26 LOAD_CONST 0 (None)
28 RETURN_VALUE
It preserves jumps to jump instructions. I do not know the cause. All works with single-line expressions.
The new optimizer does not have this bug.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32477>
_______________________________________
More information about the Python-bugs-list
mailing list