bpo-41323: Perform 'peephole' optimizations directly on the CFG. (GH-… · python/cpython@6e8128f · GitHub
Skip to content

Commit 6e8128f

Browse files
authored
bpo-41323: Perform 'peephole' optimizations directly on the CFG. (GH-21517)
* Move 'peephole' optimizations into compile.c and perform them directly on the CFG.
1 parent ba18c0b commit 6e8128f

12 files changed

Lines changed: 4358 additions & 4577 deletions

Lib/test/test_dis.py

Lines changed: 0 additions & 4 deletions

Lib/test/test_peepholer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ def f(cond1, cond2):
416416
if cond1: return 4
417417
self.assertNotInBytecode(f, 'JUMP_FORWARD')
418418
# There should be one jump for the while loop.
419-
returns = [instr for instr in dis.get_instructions(f)
420-
if instr.opname == 'JUMP_ABSOLUTE']
421-
self.assertEqual(len(returns), 1)
419+
jumps = [instr for instr in dis.get_instructions(f)
420+
if 'JUMP' in instr.opname]
421+
self.assertEqual(len(jumps), 1)
422422
returns = [instr for instr in dis.get_instructions(f)
423423
if instr.opname == 'RETURN_VALUE']
424424
self.assertLessEqual(len(returns), 2)

Lib/test/test_sys_settrace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def test_jump_in_nested_finally_3(output):
948948
output.append(11)
949949
output.append(12)
950950

951-
@jump_test(5, 11, [2, 4], (ValueError, 'unreachable'))
951+
@jump_test(5, 11, [2, 4], (ValueError, 'after'))
952952
def test_no_jump_over_return_try_finally_in_finally_block(output):
953953
try:
954954
output.append(2)
@@ -1457,7 +1457,7 @@ async def test_jump_between_async_with_blocks(output):
14571457
async with asynctracecontext(output, 4):
14581458
output.append(5)
14591459

1460-
@jump_test(5, 7, [2, 4], (ValueError, "unreachable"))
1460+
@jump_test(5, 7, [2, 4], (ValueError, "after"))
14611461
def test_no_jump_over_return_out_of_finally_block(output):
14621462
try:
14631463
output.append(2)

Makefile.pre.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ PYTHON_OBJS= \
354354
Python/mysnprintf.o \
355355
Python/mystrtoul.o \
356356
Python/pathconfig.o \
357-
Python/peephole.o \
358357
Python/preconfig.o \
359358
Python/pyarena.o \
360359
Python/pyctype.o \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bytecode optimizations are performed directly on the control flow graph.
2+
This will result in slightly more compact code objects in some
3+
circumstances.

PCbuild/pythoncore.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@
460460
<ClCompile Include="..\Python\mysnprintf.c" />
461461
<ClCompile Include="..\Python\mystrtoul.c" />
462462
<ClCompile Include="..\Python\pathconfig.c" />
463-
<ClCompile Include="..\Python\peephole.c" />
464463
<ClCompile Include="..\Python\preconfig.c" />
465464
<ClCompile Include="..\Python\pyarena.c" />
466465
<ClCompile Include="..\Python\pyctype.c" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 1 addition & 4 deletions

0 commit comments

Comments
 (0)