[issue22358] Unnecessary JUMP_FORWARD(0) (NOP) in if statements without else or elif

2014-09-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This is a duplicate of issue11471.

Explicit check for NULL is not needed because the asdl_seq_LEN() macro checks 
its argument for NULL.

--
resolution:  - duplicate
stage:  - resolved
status: open - closed
superseder:  - If without else generates redundant jump
versions:  -Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22358
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22358] Unnecessary JUMP_FORWARD(0) (NOP) in if statements without else or elif

2014-09-07 Thread Attila Fazekas

New submission from Attila Fazekas:

The following example function compiles to bytecode which contains,
an unnecessary JUMP_FORWARD 0 instruction:

def func():
if a: pass

Actual:
dis.dis(func)
  2   0 LOAD_GLOBAL  0 (a)
  3 POP_JUMP_IF_FALSE9
  6 JUMP_FORWARD 0 (to 9)
9 LOAD_CONST   0 (None)
 12 RETURN_VALUE  

Expected:
dis.dis(func)
  2   0 LOAD_GLOBAL  0 (a)
  3 POP_JUMP_IF_FALSE6
6 LOAD_CONST   0 (None)
  9 RETURN_VALUE

The above JUMP_FORWARD instruction increases the code size and also has a 
negative performance effect.
I do not see any reason to have the extra NOP in the byte code in this case.

***

The attached patch removes this NOP generation from the code compilation part, 
so it will take effect by default.

I had a little trouble when the code compiled from ast,
because the If.orelse had a different content. (NULL vs. zero sizes asdl_seq)

* The generated Assembly code updated in dis unit test.
* The compilation test updated to test a real 'if' by using a variable in the 
condition. (The True and False is not a variable anymore)

--
components: Interpreter Core
files: python_nop_ifelse.patch
keywords: patch
messages: 226547
nosy: Attila.Fazekas
priority: normal
severity: normal
status: open
title: Unnecessary JUMP_FORWARD(0) (NOP) in if statements without else or elif
type: performance
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file36569/python_nop_ifelse.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22358
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22358] Unnecessary JUMP_FORWARD(0) (NOP) in if statements without else or elif

2014-09-07 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22358
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22358] Unnecessary JUMP_FORWARD(0) (NOP) in if statements without else or elif

2014-09-07 Thread Jesús Cea Avión

Jesús Cea Avión added the comment:

What about the peephole optimizer?.

--
nosy: +jcea

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22358
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com