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

GH-109214: _SET_IP before _PUSH_FRAME (but not _POP_FRAME) #111001

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented Oct 17, 2023

#110755 inadvertently allowed the tier two optimizer to remove instruction pointer updates before frame pushes, which breaks the following return. This updates remove_unneeded_uops to recognize _PUSH_FRAME as a uop that requires an up-to-date instruction pointer on the frame.

While investigating this, I realized that we actually don't need to set the instruction pointer before returning from a frame (since the frame is unlinked and torn down immediately after). So I've also removed _SAVE_CURRENT_IP from both of the return opcodes, which is a nice little win for tier one.

Also, remove some dead code and comment/assert a non-obvious bit of code during trace projection.

@brandtbucher brandtbucher added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 17, 2023
@brandtbucher brandtbucher self-assigned this Oct 17, 2023
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I can't say I am less happy with this than with the situation before the bug was introduced, but I am also not sure I am happier. It feels as if the various special uops SET_IP, SAVE_CURRENT_IP, POP/PUSH_FRAME can still use more work (not in this PR though).

case OPARG_SET_IP: // op==_SET_IP; oparg=next instr
case OPARG_SET_IP: // uop=_SET_IP; oparg=next_instr-1
// The number of caches is smuggled in via offset:
assert(offset == _PyOpcode_Caches[_PyOpcode_Deopt[opcode]]);
Copy link
Member

Choose a reason for hiding this comment

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

If this is always it, why do we need to smuggle it in via offset? Also it's beginning to look like the offset should just be made one larger in the code generator, so we can drop the ugly + 1 on line 654 above.

@brandtbucher
Copy link
Member Author

I agree with your comments. I'll land this now to unblock tier two, and work on a follow-up PR to clean up this IP stuff further.

@brandtbucher brandtbucher merged commit e5168ff into python:main Oct 24, 2023
32 checks passed
@gvanrossum
Copy link
Member

I agree with your comments. I'll land this now to unblock tier two, and work on a follow-up PR to clean up this IP stuff further.

Maybe wait until Irit's PR lands. It touches on all these things.

@brandtbucher
Copy link
Member Author

Okay, I will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants