Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Better constant narrowing in the JIT optimizer #130415

Open
Assignees
brandtbucher
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetopic-JITtype-featureA feature request or enhancement
@brandtbucher

Description

@brandtbucher

Please don't work on this. I'm planning on sprinting on this with new contributors at an event this weekend.

Currently, the JIT optimizer uses the_COMPARE_OP family,_CONTAINS_OP,_IS_OP, and the_TO_BOOL family to narrow thetypes of the input values and the type of the output value.

However, by "peeking ahead" and seeing how a value will be used, we can narrow these types to constants as well. As a simple example, consider_TO_BOOL_INT + _GUARD_IS_FALSE_CHECK on an unknown value. After the_TO_BOOL_INT, it can be narrowed to a known class,int (we do this today). However, after the_GUARD_IS_FALSE_CHECK, we can actually narrow it to a constant value,0.

An example implementation of this idea for_TO_BOOL_BOOL is here:main...brandtbucher:cpython:hack-night-to-bool-bool
 
I've divided this work into 3 "waves" of increasing complexity. Tasks inbold are probably a bit harder, tasks initalics are probably a bit easier.

Narrow types to constants in branches involving truthiness:

  • _TO_BOOL + _GUARD_IS_*_POPgh-130659
  • _TO_BOOL_BOOL + _GUARD_IS_*_POPgh-130659
  • _TO_BOOL_INT + _GUARD_IS_*_POPgh-130772
  • _TO_BOOL_LIST + _GUARD_IS_*_POP
  • _TO_BOOL_STR + _GUARD_IS_*_POPgh-130476

Narrow types to constants in branches involving comparisons with a constant:

  • _COMPARE_OP + _GUARD_IS_*_POP (==,!=)
  • _COMPARE_OP_FLOAT + _GUARD_IS_*_POP (==,!=)
  • _COMPARE_OP_INT + _GUARD_IS_*_POP (==,!=)
  • _COMPARE_OP_STR + _GUARD_IS_*_POP (==,!=)
  • _CONTAINS_OP + _GUARD_IS_*_POP (in,not in)
  • _IS_OP + _GUARD_IS_*_POP (is,is not)

Evaluate comparisons involving two constants:

This is related, but a bit more involved, since we need a way to pop two values from the stack and push a constant (_POP_TWO_LOAD_CONST_INLINE_BORROW). We should also teachremove_unneeded_uops about this new instruction.

  • _COMPARE_OP (==,!=,<,>,<=,>=)
  • _COMPARE_OP_FLOAT (==,!=,<,>,<=,>=)
  • _COMPARE_OP_INT (==,!=,<,>,<=,>=)gh-131489
  • _COMPARE_OP_STR (==,!=,<,>,<=,>=)
  • _CONTAINS_OP (in,not in)
  • _IS_OP (is,is not)

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetopic-JITtype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp