Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra nonzero call for chained comparisons #1190

Closed
kmod opened this issue May 20, 2016 · 4 comments
Closed

Fix extra nonzero call for chained comparisons #1190

kmod opened this issue May 20, 2016 · 4 comments

Comments

@kmod
Copy link
Collaborator

kmod commented May 20, 2016

See compare_ordering.py

The issue is that for chanined comparisons (a < b < c), we do something like:

def chained_compare(a, b, c):
  t1 = a < b
  if not bool(t1):
    return t1
  else:
    t2 = b < c
    nonzero(t2)
    return t2

Where that final nonzero(t2) call is extraneous and should be removed.

@benhoyt
Copy link

benhoyt commented May 26, 2016

@kmod FYI, that link is broken. Should it be here?

@kmod
Copy link
Collaborator Author

kmod commented May 26, 2016

Oops yes, thanks :)

@sizeoftank
Copy link
Contributor

sizeoftank commented Jul 15, 2016

Hi @kmod
I found your comments in remapCompare() when I debugging for this issue.
So can we add a check to skip the last branch here? (is there any related code needed to change?)

    // TODO: this branch is unused for the last comparison
    AST_Branch* br = new AST_Branch();
    br->test = callNonzero(makeLoad(name, node));
    push_back(br);

    CFGBlock* was_block = curblock;
    CFGBlock* next_block = cfg->addBlock();
    CFGBlock* crit_break_block = cfg->addBlock();
    was_block->connectTo(next_block);
    was_block->connectTo(crit_break_block);

    br->iffalse = crit_break_block;
    br->iftrue = next_block;

    curblock = crit_break_block;
    pushJump(exit_block);

    curblock = next_block;

    left = right;

sizeoftank pushed a commit to sizeoftank/pyston_v1 that referenced this issue Jul 15, 2016
sizeoftank pushed a commit to sizeoftank/pyston_v1 that referenced this issue Jul 20, 2016
kmod added a commit that referenced this issue Jul 21, 2016
Fix extra nonzero call for chained comparisons #1190
@kmod
Copy link
Collaborator Author

kmod commented Jul 21, 2016

Closed via #1301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants