GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-130415: Optimize JIT path for _TO_BOOL_INT branching by Klaus117 · Pull Request #130477 · python/cpython

Conversation

@Klaus117

@Klaus117 Klaus117 commented Feb 22, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@brandtbucher
Thanks for the help.

  • Issue: Better constant narrowing in the JIT optimizer #130415

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Klaus117
optimize for int=0 branching. move to correct branch
76793af
@Klaus117
Klaus117 requested a review from Fidget-Spinner as a code owner February 22, 2025 22:57
@ghost

ghost commented Feb 22, 2025 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Feb 22, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting review label Feb 22, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Feb 22, 2025
Better constant narrowing in the JIT optimizer #130415
Closed
13 of 17 tasks
@brandtbucher brandtbucher self-assigned this Feb 22, 2025
@blurb-it
📜🤖 Added by blurb_it.
c647e39
@brandtbucher brandtbucher added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT labels Feb 22, 2025
brandtbucher
brandtbucher requested changes Feb 22, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_opt.py Outdated
trace = []
for i in range(n):
# f is always (int) 0, but we can only prove that it's a integer:
f = i - i # at this point python knows f is an int, but doesnt know that it is 0 (we know it is 0 though)

@brandtbucher brandtbucher Feb 22, 2025

Copy link
Copy Markdown
Member

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.

Can you rename f in this function to zero?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_capi/test_opt.py Outdated
Comment on lines +1471 to +1500
# def test_narrow_type_to_constant_bool_true(self):
# def f(n):
# trace = []
# for i in range(n):
# # f is always True, but we can only prove that it's a bool:
# f = i != TIER2_THRESHOLD
# trace.append("A")
# if f: # Kept.
# trace.append("B")
# if not f: # Removed!
# trace.append("X")
# trace.append("C")
# if f: # Removed!
# trace.append("D")
# trace.append("E")
# trace.append("F")
# if not f: # Removed!
# trace.append("X")
# trace.append("G")
# return trace

# trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
# self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD)
# self.assertIsNotNone(ex)
# uops = get_opnames(ex)
# # Only one guard remains:
# self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 0)
# self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 1)
# # But all of the appends we care about are still there:
# self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))

@brandtbucher brandtbucher Feb 22, 2025

Copy link
Copy Markdown
Member

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.

Can you remove this commented test?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-02-22-23-03-13.gh-issue-130415.ibOV6B.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer_bytecodes.c Outdated
Comment on lines +422 to +425
// else if (next_opcode == _GUARD_IS_TRUE_POP) {
// sym_set_const(value, Py_True);
// res = sym_new_type(ctx, &PyBool_Type);
// }

@brandtbucher brandtbucher Feb 22, 2025

Copy link
Copy Markdown
Member

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.

Suggested change
// else if (next_opcode == _GUARD_IS_TRUE_POP) {
// sym_set_const(value, Py_True);
// res = sym_new_type(ctx, &PyBool_Type);
// }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/optimizer_bytecodes.c Outdated
// removed and the narrowed value to be invalid:
if (next_opcode == _GUARD_IS_FALSE_POP) {
sym_set_const(value, Py_GetConstant(Py_CONSTANT_ZERO));
res = sym_new_type(ctx, &PyLong_Type);

@brandtbucher brandtbucher Feb 22, 2025

Copy link
Copy Markdown
Member

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.

This is always a boolean, since it's the output of the _TO_BOOL op.

Suggested change
res = sym_new_type(ctx, &PyLong_Type);
res = sym_new_type(ctx, &PyBool_Type);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Feb 22, 2025
@bedevere-app

bedevere-app Bot commented Feb 22, 2025

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Klaus117 and others added 2 commits February 22, 2025 15:17
@Klaus117 @brandtbucher
Update Misc/NEWS.d/next/Core_and_Builtins/2025-02-22-23-03-13.gh-issu…
a1139cf
…e-130415.ibOV6B.rst

Co-authored-by: Brandt Bucher <[email protected]>
@Klaus117
address code review. remove commented code. better names.
b1702f2
@brandtbucher brandtbucher changed the title GH-130415 optimize JIT path for _TO_BOOL_INT int=0 branching. GH-130415: Optimize JIT path for _TO_BOOL_INT branching Feb 22, 2025
brandtbucher
brandtbucher reviewed Feb 22, 2025
View reviewed changes
Comment thread Lib/test/test_capi/test_opt.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher
Remove redundant comment
debc65d
brandtbucher
brandtbucher approved these changes Feb 22, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels Feb 22, 2025
@markshannon

markshannon commented Feb 24, 2025

Copy link
Copy Markdown
Member

Thanks for the contribution. Unfortunately this has a critical flaw.
See #130476 (comment) for the same problem with that PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented Mar 3, 2025

Copy link
Copy Markdown
Member

Closing in favor of #130477.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher brandtbucher closed this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brandtbucher brandtbucher brandtbucher approved these changes
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@brandtbucher brandtbucher

Labels

awaiting merge interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage topic-JIT

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Klaus117 @markshannon @brandtbucher
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.