New issue 2883: Bytecode contains jump-to-unconditional-jump
https://bitbucket.org/pypy/pypy/issues/2883/bytecode-contains-jump-to-unconditional

Vincent Pelletier:

Found while comparing cPython 2.7.15 with pypy 6.0.0.
This seems suboptimal, any jump (conditional or not) jumping to an interrupted 
chain of unconditional jumps should be possible to simplify by updating 
original instruction to jump to the last element in that chain, modulo 
absolute/relative addressing considerations. In below example, 19 jump to 29 
which is an unconditional jump.

I tried poking at pypy/astcompiler/assemble.py:_resolve_block_targets but could 
not get good enough results. I am not sure all the code is visible to it 
(code-less blocks ?).

Also, "<n> JUMP <n+1>" (below, 29 jumps to 32) instructions should be possible 
to remove entirely (which may require updating anything jumping to that 
instruction).

$ python -c "import dis, t; dis.dis(t)" > cpython.t.pydis
$ pypy -c "import dis, t; dis.dis(t)" > pypy.t.pydis
$ diff -u cpython.t.pydis pypy.t.pydis
--- cpython.t.pydis     2018-09-09 06:03:51.763765156 +0000
+++ pypy.t.pydis        2018-09-09 06:04:02.987767118 +0000
@@ -16,12 +16,12 @@
  10          12 LOAD_GLOBAL              0 (bar)
              15 CALL_FUNCTION            0
              18 POP_TOP
-             19 JUMP_ABSOLUTE           32
+             19 JUMP_FORWARD             7 (to 29)
 
  12     >>   22 LOAD_GLOBAL              1 (baz)
              25 CALL_FUNCTION            0
              28 POP_TOP
-             29 JUMP_FORWARD             0 (to 32)
+        >>   29 JUMP_FORWARD             0 (to 32)
         >>   32 LOAD_CONST               0 (None)
              35 RETURN_VALUE
 
$ cat t.py
def bar():
    pass
 
def baz():
    pass
 
def foo(a, b):
  if a:
    if b:
        bar()
    else:
        baz()


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to