Skip to content

Negative tuple elements produce inefficient code. #55453

Closed

Description

@jdharper
mannequin
BPO 11244
Nosy @rhettinger, @mdickinson, @pitrou, @bitdancer, @eltoder
Files
  • test_peepholer.patch: Patch to test_peephole that verifies expressions containing negative constants are optimized.
  • constfold.patch
  • constfold2.patch
  • fold-0.patch
  • fold-0.2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/mdickinson'
    closed_at = <Date 2011-03-23.18:20:49.447>
    created_at = <Date 2011-02-18.17:41:04.894>
    labels = ['performance']
    title = 'Negative tuple elements produce inefficient code.'
    updated_at = <Date 2011-03-23.18:20:49.446>
    user = 'https://bugs.python.org/jdharper'

    bugs.python.org fields:

    activity = <Date 2011-03-23.18:20:49.446>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2011-03-23.18:20:49.447>
    closer = 'mark.dickinson'
    components = []
    creation = <Date 2011-02-18.17:41:04.894>
    creator = 'jdharper'
    dependencies = []
    files = ['20787', '20790', '20897', '21073', '21083']
    hgrepos = []
    issue_num = 11244
    keywords = ['patch']
    message_count = 28.0
    messages = ['128795', '128801', '128805', '128806', '128809', '128810', '128812', '128817', '128825', '128841', '128844', '128876', '129429', '129430', '130529', '130550', '130576', '130579', '130582', '130583', '130640', '130641', '130642', '130665', '131068', '131069', '131901', '131902']
    nosy_count = 9.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'pitrou', 'nadeem.vawda', 'Arfrever', 'r.david.murray', 'jdharper', 'python-dev', 'eltoder']
    pr_nums = []
    priority = 'high'
    resolution = None
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue11244'
    versions = ['Python 3.1', 'Python 3.2', 'Python 3.3']

    Activity

    1. pitrou commented on Feb 25, 2011

      @pitrou
      Member

      This patch has tests and is also able to constant-fold tuples larger than 256 elements.

    2. pitrou commented on Feb 25, 2011

      @pitrou
      Member

      Forgot to attach new patch, sorry.

    3. eltoder commented on Mar 10, 2011

      eltodermannequin
      Mannequin

      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.

    4. mdickinson commented on Mar 11, 2011

      @mdickinson
      Member

      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.

    5. eltoder commented on Mar 11, 2011

      eltodermannequin
      Mannequin

      Mark, looks better now?

    6. eltoder commented on Mar 11, 2011

      eltodermannequin
      Mannequin

      (forgot parens around 0)

    7. python-dev commented on Mar 11, 2011

      python-devmannequin
      Mannequin

      New changeset 14205d0fee45 by Antoine Pitrou in branch 'default':
      Issue bpo-11244: The peephole optimizer is now able to constant-fold
      http://hg.python.org/cpython/rev/14205d0fee45

    8. pitrou commented on Mar 11, 2011

      @pitrou
      Member

      Ok, Eugene's patch is left to apply now. Can I assign this to you, Mark?

    9. rhettinger commented on Mar 11, 2011

      @rhettinger
      Contributor

      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.

    10. pitrou commented on Mar 11, 2011

      @pitrou
      Member

      Eugene's patch looks like a correct fix to the regression.

      No, it's orthogonal.

    11. eltoder commented on Mar 11, 2011

      eltodermannequin
      Mannequin

      Yes, my patch doesn't fix the regression, only a special case of -0.

    12. mdickinson commented on Mar 12, 2011

      @mdickinson
      Member

      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?

    13. eltoder commented on Mar 15, 2011

      eltodermannequin
      Mannequin

      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.

    14. pitrou commented on Mar 15, 2011

      @pitrou
      Member

      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) ;)

    15. python-dev commented on Mar 23, 2011

      python-devmannequin
      Mannequin

      New changeset ead9c1b9f547 by Mark Dickinson in branch 'default':
      Issue bpo-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

    16. mdickinson commented on Mar 23, 2011

      @mdickinson
      Member

      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.

    17. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    performancePerformance or resource usage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions