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-126902: Strength reduce _CHECK_FUNCTION #126856

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Nov 15, 2024

Small PR to strength reduce _CHECK_FUNCTION so it reads from operand instead of reading from the frame struct. This prevents _CHECK_FUNCTION from interfering with the partial evaluation later on. It interferes because once we remove the frame, there is no frame->func_obj to check anymore.

An added benefit is that the "burned in" version is also cheaper as it doesn't have to read from the frame struct, rather reading from the instruction itself in the JIT.

@Fidget-Spinner
Copy link
Member Author

@markshannon would you prefer this as its own PR, or would you prefer I merge this into the function inlining PR that I will be doing later?

@Fidget-Spinner
Copy link
Member Author

Sorry I realized this is logically incorrect.

@Fidget-Spinner Fidget-Spinner changed the title gh-120619: Hoist _CHECK_FUNCTION to frame sequence when possible gh-120619: Strength reduce _CHECK_FUNCTION Nov 16, 2024
@markshannon
Copy link
Member

I think I've said this before, but please link to an appropriate issue.

Why are you doing this? The issue doesn't explain it at all.

@Fidget-Spinner Fidget-Spinner changed the title gh-120619: Strength reduce _CHECK_FUNCTION gh-126902: Strength reduce _CHECK_FUNCTION Nov 16, 2024
@Fidget-Spinner
Copy link
Member Author

Fidget-Spinner commented Nov 16, 2024

@markshannon the issue is right, just too broad. I've created a smaller issue to further explain why we need this for partial evaluation at #126902

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.

I think it would be better to use the symbol for the function, rather than a reference in the optimizer.

Include/internal/pycore_optimizer.h Outdated Show resolved Hide resolved
@@ -1515,9 +1515,33 @@ def test_jit_error_pops(self):
with self.assertRaises(TypeError):
{item for item in items}

def test_global_guard_strength_reduced_if_possible(self):
Copy link
Member

Choose a reason for hiding this comment

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

It would be nicer (not necessarily in this PR) if we created tracelets directly, rather than this complex approach.

Python/bytecodes.c Outdated Show resolved Hide resolved
Python/optimizer_bytecodes.c Outdated Show resolved Hide resolved
@bedevere-app
Copy link

bedevere-app bot commented Dec 5, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be put in the comfy chair!

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.

I'd like to replace NULL with sym_new_unknown when f_funcobj is not known.
Otherwise, LGTM.

Python/optimizer_analysis.c Outdated Show resolved Hide resolved
Include/internal/pycore_optimizer.h Outdated Show resolved Hide resolved
@@ -4941,6 +4941,12 @@ dummy_func(
DEOPT_IF(func->func_version != func_version);
}

tier2 op(_CHECK_FUNCTION_UNMODIFIED, (func_version/2, callable_p/4 --)) {
assert(PyFunction_Check(callable_p));
PyFunctionObject *func = (PyFunctionObject *)callable_p;
Copy link
Member

@markshannon markshannon Dec 6, 2024

Choose a reason for hiding this comment

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

What guarantee is there that func == frame->f_funcobj?

Copy link
Member Author

@Fidget-Spinner Fidget-Spinner Dec 8, 2024

Choose a reason for hiding this comment

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

It's constant propagated (and frames shouldn't be able to swap out f_funcobj on the fly like that). To be sure I added a runtime assert.

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

Successfully merging this pull request may close these issues.

2 participants