Skip to content

bpo-37271: Optimize bytecode multiple times until it cannot be optimized further #14068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,32 @@ def f(cond, true_value, false_value):

def test_elim_jump_to_uncond_jump(self):
# POP_JUMP_IF_FALSE to JUMP_FORWARD --> POP_JUMP_IF_FALSE to non-jump
# JUMP_FORWARD to JUMP_FORWARD --> JUMP_FORWARD to non-jump
def f():
if a:
# Intentionally use two-line expression to test issue37213.
if (c
or d):
foo()
if b:
# Intentionally use two-line expression to test issue37213.
if (c
or d):
foo()
else:
bar()
else:
baz()
self.check_jump_targets(f)

def test_elim_jump_to_uncond_jump2(self):
# POP_JUMP_IF_FALSE to JUMP_ABSOLUTE --> POP_JUMP_IF_FALSE to non-jump
# JUMP_FORWARD to JUMP_ABSOLUTE --> JUMP_FORWARD to non-jump
def f():
while a:
# Intentionally use two-line expression to test issue37213.
if (c
or d):
a = foo()
if b:
# Intentionally use two-line expression to test issue37213.
if (c
or d):
a = foo()
else:
a = bar()
self.check_jump_targets(f)

def test_elim_jump_to_uncond_jump3(self):
Expand Down Expand Up @@ -370,7 +378,7 @@ def f(cond1, cond2):
# There should be one jump for the while loop.
returns = [instr for instr in dis.get_instructions(f)
if instr.opname == 'JUMP_ABSOLUTE']
self.assertEqual(len(returns), 1)
self.assertEqual(len(returns), 0)
returns = [instr for instr in dis.get_instructions(f)
if instr.opname == 'RETURN_VALUE']
self.assertLessEqual(len(returns), 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The peephole optimizer now does multiple runs until the resulting bytecode
cannot be optimized further. Patch by Pablo Galindo.
Loading