[issue11244] Negative tuple elements produce inefficient code.
Roundup Robot devnull@devnull added the comment: New changeset ead9c1b9f547 by Mark Dickinson in branch 'default': Issue #11244: Remove outdated peepholer check that was preventing the peepholer from folding -0 and -0.0. Thanks Eugene Toder for the patch. http://hg.python.org/cpython/rev/ead9c1b9f547 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Mark Dickinson dicki...@gmail.com added the comment: Fixed in 'default' branch. Note that the regression still exists in 3.2; I'm not sure that it's worth backporting the two fixes. -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- assignee: rhettinger - mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Eugene Toder elto...@gmail.com added the comment: Is anyone reviewing my patch? It's just 1 line long. Should it be moved to another issue? Though, technically, it's needed to address the regression in question: Python 3.1 folds -0, the current code still does not. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Eugene, according to Mark your patch is fine. It just needs someone to commit it. I would personally prefer to let Mark handle it, since he's our specialist in negative zeroes (and other numerical subtleties) ;) -- stage: patch review - commit review versions: +Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Mark Dickinson dicki...@gmail.com added the comment: Eugene's new patch looks good to me; +1 on applying it. Raymond, do you happen to remember why it was necessary to add the zero-check in the first place? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Changes by Nadeem Vawda nadeem.va...@gmail.com: -- nosy: +nvawda ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Mark Dickinson dicki...@gmail.com added the comment: fold-0.patch looks good to me, but why do you include tests only for the float case (-0.0) and not the integer case (-0)? Style nitpick: def negzero(): return -(1.0-1.0) should be on two source lines, not one. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Eugene Toder elto...@gmail.com added the comment: Mark, looks better now? -- Added file: http://bugs.python.org/file21082/fold-0.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Changes by Eugene Toder elto...@gmail.com: Removed file: http://bugs.python.org/file21082/fold-0.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Eugene Toder elto...@gmail.com added the comment: (forgot parens around 0) -- Added file: http://bugs.python.org/file21083/fold-0.2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Roundup Robot devnull@devnull added the comment: New changeset 14205d0fee45 by Antoine Pitrou in branch 'default': Issue #11244: The peephole optimizer is now able to constant-fold http://hg.python.org/cpython/rev/14205d0fee45 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Ok, Eugene's patch is left to apply now. Can I assign this to you, Mark? -- assignee: - mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Eugene's patch looks like a correct fix to the regression. I'll review further in the next couple of days. Antoine, we need to further discuss your checkin to the peephole optimizer. I believe it was inappropriate. -- assignee: mark.dickinson - rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Eugene's patch looks like a correct fix to the regression. No, it's orthogonal. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Eugene Toder elto...@gmail.com added the comment: Yes, my patch doesn't fix the regression, only a special case of -0. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Eugene Toder elto...@gmail.com added the comment: As discussed on the list, peephole refuses to fold -0. The reasons for this are unclear. Folding was disabled with this commit: http://hg.python.org/cpython/diff/660419bdb4ae/Python/compile.c Here's a trivial patch to enable the folding again, along with a test case. make test passes with the patch. The change is independent from Antoine's patches. -- nosy: +eltoder Added file: http://bugs.python.org/file21073/fold-0.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: This patch has tests and is also able to constant-fold tuples larger than 256 elements. -- stage: - patch review versions: +Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Forgot to attach new patch, sorry. -- Added file: http://bugs.python.org/file20897/constfold2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Mark Dickinson dicki...@gmail.com added the comment: Unassigning. I don't think that r82043 is the *real* culprit here; that bugfix just happened to expose a deficiency in the peepholer; one that's already present in other situations: dis.dis(lambda: 2*(3*4)) 1 0 LOAD_CONST 1 (2) 3 LOAD_CONST 4 (12) 6 BINARY_MULTIPLY 7 RETURN_VALUE dis.dis(lambda: (2*3)*4) 1 0 LOAD_CONST 5 (24) 3 RETURN_VALUE Antoine, does your patch take care of this case too? -- assignee: mark.dickinson - ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Le samedi 19 février 2011 à 10:45 +, Mark Dickinson a écrit : Mark Dickinson dicki...@gmail.com added the comment: Unassigning. I don't think that r82043 is the *real* culprit here; that bugfix just happened to expose a deficiency in the peepholer; one that's already present in other situations: dis.dis(lambda: 2*(3*4)) 1 0 LOAD_CONST 1 (2) 3 LOAD_CONST 4 (12) 6 BINARY_MULTIPLY 7 RETURN_VALUE dis.dis(lambda: (2*3)*4) 1 0 LOAD_CONST 5 (24) 3 RETURN_VALUE Antoine, does your patch take care of this case too? It should. Can you test? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Mark Dickinson dicki...@gmail.com added the comment: It should. Can you test? Ah, you're asking me to actually do some (minimal) work instead of just complaining? Yep, the patch tests fine over here (OS X 10.6), and fixes the 2*(3*4) case. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
New submission from Jeffrey Harper jhar...@yapdc.com: In Python 3.2, a tuple like (1,-2,3) will not be optimized into a constants at compile time. The tuple is built at run-time. Earlier versions of Python optimized these tuples at compile time. Here's an example program. # test.py from dis import dis def x(): return (1,2,3) def y(): return (1,-2,3) print (dis x:) dis(x) print() print(dis y:) dis(y) The compiler in 3.2rc3 produces code for function y() that builds the tuple at run-time while the tuple in x() is optimized at compile time. C:\tmpc:\python32\python --version Python 3.2rc3 C:\tmpc:\python32\python test.py dis x: 3 0 LOAD_CONST 4 ((1, 2, 3)) 3 RETURN_VALUE dis y: 4 0 LOAD_CONST 1 (1) 3 LOAD_CONST 4 (-2) 6 LOAD_CONST 3 (3) 9 BUILD_TUPLE 3 12 RETURN_VALUE However, under 3.1.3, the tuples in both functions are optimized at compile time. C:\tmpc:\python31\python test.py dis x: 3 0 LOAD_CONST 4 ((1, 2, 3)) 3 RETURN_VALUE dis y: 4 0 LOAD_CONST 4 ((1, -2, 3)) 3 RETURN_VALUE Although the compiled code produced 3.2rc3 is correct, it is much slower than the code generated by 3.1.3. -- messages: 128795 nosy: jdharper priority: normal severity: normal status: open title: Negative tuple elements produce inefficient code. type: performance versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Jeffrey Harper jhar...@yapdc.com added the comment: I have also determined that negative elements interfere with the frozenset optimization described in issue6690. http://bugs.python.org/issue6690. Here's an example program: # test.py from dis import dis def x(var): return var in {1,2,3} # Note curly braces. These are sets. def y(var): return var in {1,-2,3} print (dis x:) dis(x) print() print(dis y:) dis(y) Running this produces: C:\tmpc:\Python32\python.exe test.py dis x: 3 0 LOAD_FAST0 (var) 3 LOAD_CONST 4 (frozenset({1, 2, 3})) 6 COMPARE_OP 6 (in) 9 RETURN_VALUE dis y: 4 0 LOAD_FAST0 (var) 3 LOAD_CONST 1 (1) 6 LOAD_CONST 4 (-2) 9 LOAD_CONST 3 (3) 12 BUILD_SET3 15 COMPARE_OP 6 (in) 18 RETURN_VALUE -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
R. David Murray rdmur...@bitdance.com added the comment: I wonder if this has anything to do with issue 9011? -- nosy: +mark.dickinson, r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: The culprit is r82043: Issue #9011: Remove buggy and unnecessary ST-AST compilation code. -- assignee: - mark.dickinson nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: The problem is that the UNARY_NEGATIVE + LOAD_CONST optimization, which occurs first in bytecode order, inserts a NOP and prevents the tuple optimization to work. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Jeffrey Harper jhar...@yapdc.com added the comment: I think r82043 may also explain why 3.1.3 can fold the expression 2 * -3 into -6 while 3.2rc3 cannot. # test.py from dis import dis def y(): 2 * -3 print(dis y:) dis(y) C:\tmpc:\Python32\python.exe --version Python 3.2rc3 C:\tmpc:\Python32\python.exe test.py dis y: 3 0 LOAD_CONST 1 (2) 3 LOAD_CONST 3 (-3) 6 BINARY_MULTIPLY 7 POP_TOP 8 LOAD_CONST 0 (None) 11 RETURN_VALUE C:\tmpc:\Python31\python.exe --version Python 3.1.3 C:\tmpc:\Python31\python.exe test.py dis y: 3 0 LOAD_CONST 3 (-6) 3 POP_TOP 4 LOAD_CONST 0 (None) 7 RETURN_VALUE -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Ouch. Obviously test_peephole doesn't have enough tests... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: -- priority: normal - high ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Jeffrey Harper jhar...@yapdc.com added the comment: Here's a patch against the version of test_peepholer.py in 3.2rc3. It verifies that expressions like the following are optimized: 3*-4 (1,-2,3) a in {1,-2,3) -- keywords: +patch Added file: http://bugs.python.org/file20787/test_peepholer.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11244] Negative tuple elements produce inefficient code.
Antoine Pitrou pit...@free.fr added the comment: Here is a patch that enables advanced (recursive) constant folding. Example: python -c import dis; f=lambda x: x in {(3*-5)+(-1-6),(1,-2,3)*2,None};dis.dis(f) With 3.1: 1 0 LOAD_FAST0 (x) 3 LOAD_CONST 7 (-15) 6 LOAD_CONST 8 (-7) 9 BINARY_ADD 10 LOAD_CONST 10 ((1, -2, 3, 1, -2, 3)) 13 LOAD_CONST 11 (None) 16 BUILD_SET3 19 COMPARE_OP 6 (in) 22 RETURN_VALUE With 3.2+patch: 1 0 LOAD_FAST0 (x) 3 LOAD_CONST 14 (frozenset({None, -22, (1, -2, 3, 1, -2, 3)})) 6 COMPARE_OP 6 (in) 9 RETURN_VALUE -- Added file: http://bugs.python.org/file20790/constfold.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com