-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-114083: apply optimization of LOAD_CONST instructions to the whole CFG before optimize_basic_block. #114408
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
Conversation
…e CFG before optimize_basic_block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
There are a couple of things that could do with minor clarifications.
Python/flowgraph.c
Outdated
@@ -1479,16 +1493,12 @@ apply_static_swaps(basicblock *block, int i) | |||
} | |||
|
|||
static int | |||
optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts) | |||
basicblock_fold_load_const(PyObject *const_cache, basicblock *bb, PyObject *consts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"fold" has many meanings in CS.
Maybe fold_jumps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not only jumps. This function also fold LOAD_CONST + POP_TOP/RETURN_VALUE/TO_BOOL etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll call it optimize_load_const
instead of fold_load_const
.
When you're done making the requested changes, leave the comment: |
Misc/NEWS.d/next/Core and Builtins/2024-01-22-09-48-58.gh-issue-114083.hf1-ku.rst
Outdated
Show resolved
Hide resolved
…e-114083.hf1-ku.rst
I have made the requested changes; please review again. |
… whole CFG before optimize_basic_block. (python#114408)
… whole CFG before optimize_basic_block. (python#114408)
Fixes #114083.
Currently, folding LOAD_CONST + TO_BOOL + CONDITIONAL_JUMP into an unconditional JUMP occurs in the same pass as jump threading. For this code:
We try to thread the jump in block1 before we collapse block2 into an unconditional jump, so threading is not applied, and we can end up with a redundant jump.
This PR splits the folding of LOAD_CONST + the following instruction into a separate pass, before the pass that applies jump threading.