-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-131798: Small improvements to remove_unneeded_uops
#134554
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
@@ -617,7 +618,7 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size) | |||
while (op_skip[last->opcode]) { | |||
last--; | |||
} | |||
if (op_without_push[last->opcode]) { | |||
if (op_without_push[last->opcode] && op_without_pop[opcode]) { | |||
last->opcode = op_without_push[last->opcode]; | |||
opcode = buffer[pc].opcode = op_without_pop[opcode]; |
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.
When we are here, we know that op_without_pop[opcode] || op_without_pop_null[opcode]
is true. But we should also make sure that op_without_pop[opcode]
itself is true, otherwise it is possible to accidentally write 0
as the opcode.
I read the code but just checking that I understand it right: |
Yes, that's exactly the case! This allows us to optimize for instance:
into just
|
|
_CHECK_PERIODIC
to the list of skipped instructions. I believe this is safe to do since this instruction does not modify the stack. It is also relatively common so I think it's worth it to skip it.