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

bpo-42615: Delete redundant jump instructions that only bypass empty blocks #23733

Merged
merged 8 commits into from
Dec 16, 2020

Conversation

OxyMagnesium
Copy link
Contributor

@OxyMagnesium OxyMagnesium commented Dec 10, 2020

Currently, the deletion of unreachable blocks results in jump instructions that used to jump over said blocks, but now simply point to the next line (the next non-empty block in the CFG). These jump instructions do nothing and should be deleted.

This can be achieved by checking if the jump instruction at the end of any given block points to the next non-empty block reached through normal flow control (i.e. by following the b_next pointers until a non-empty block is found). If it does, then that means it is redundant, and can be deleted by decrementing b_used for that block.

Confirmed that the extra jump in the proof of concept code is gone after this change. Casual non-scientific performance testing of the proof of concept code showed about a 3% performance increase averaged over 5 runs.

Also ran the test module, and all tests that could be run passed. Some random scripts I had lying around also worked flawlessly.

Proof of concept: https://pastebin.com/eRe7WThj
Disassembler output: https://imgur.com/a/jIAtoGt

https://bugs.python.org/issue42615

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@OmG-117

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test, please.

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, apart from one comment.
importlib.h will need regenerating.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@OxyMagnesium
Copy link
Contributor Author

OxyMagnesium commented Dec 15, 2020

Just to be clear, I'll need to merge in other recent changes to compile.c that affected importlib.h generation, right? There's no changes to it as of the current status of this branch.

@markshannon
Copy link
Member

Great.
I'll merge this once you've merged in the latest changes and regenerated importlib.
You can add yourself to the Misc/ACKS file, if you want.

@OxyMagnesium
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@markshannon: please review the changes made to this pull request.

@markshannon
Copy link
Member

That's great. Thanks for the contribution.

@markshannon markshannon merged commit c71581c into python:master Dec 16, 2020
@OxyMagnesium OxyMagnesium deleted the fix-redundant-jumps branch December 16, 2020 14:42
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…blocks (pythonGH-23733)

* Delete jump instructions that bypass empty blocks

* Add news entry

* Explicitly check for unconditional jump opcodes

Using the is_jump function results in the inclusion of instructions like
returns for which this optimization is not really valid. So, instead
explicitly check that the instruction is an unconditional jump.

* Handle conditional jumps, delete jumps gracefully

* Ensure b_nofallthrough and b_reachable are valid

* Add test for redundant jumps

* Regenerate importlib.h and edit Misc/ACKS

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

Successfully merging this pull request may close these issues.

4 participants