Skip to content

gh-131798: JIT: optimize _LOAD_COMMON_CONSTANT - #146104

Merged
Fidget-Spinner merged 1 commit into
python:mainfrom
trdthg:trdthg/feature/jit-load-common-constant
Mar 19, 2026
Merged

gh-131798: JIT: optimize _LOAD_COMMON_CONSTANT#146104
Fidget-Spinner merged 1 commit into
python:mainfrom
trdthg:trdthg/feature/jit-load-common-constant

Conversation

@trdthg

@trdthgtrdthg commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Try to learn and make a small contribution :D

@bedevere-app

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.

@python-cla-bot

python-cla-botBot commented Mar 18, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@Fidget-SpinnerFidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this LGTM! Please remove the news entry, we don't need it as it's not a user facing code.

@trdthg
trdthgforce-pushed the trdthg/feature/jit-load-common-constant branch from 068d2bb to 19fc90fCompareMarch 18, 2026 11:40
@bedevere-app

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.

@Fidget-Spinner

Copy link
Copy Markdown
Member

_LOAD_COMMON_CONSTANT x86_64 dissasembly in jit_stencils-x86_64-unknown-linux-gnu.h:

 // 0000000000000000 <_JIT_ENTRY>:
// 0: 49 8b 47 10 movq 0x10(%r15), %rax
// 4: 48 b9 00 00 00 00 00 00 00 00 movabsq $0x0, %rcx
// 0000000000000006: R_X86_64_64 _JIT_OPARG
// e: 0f b7 c9 movzwl %cx, %ecx
// 11: 48 8b bc c8 60 68 03 00 movq 0x36860(%rax,%rcx,8), %rdi
// 19: 8b 07 movl (%rdi), %eax
// 1b: 85 c0 testl %eax, %eax
// 1d: 78 06 js 0x25 <_JIT_ENTRY+0x25>
// 1f: ff c0 incl %eax
// 21: 89 07 movl %eax, (%rdi)
// 23: eb 04 jmp 0x29 <_JIT_ENTRY+0x29>
// 25: 48 83 cf 01 orq $0x1, %rdi

I think this is prior to our CFG optimizations in the backend, so it's not 100% accurate, but pretty close.

_LOAD_CONST_INLINE_BORROW:

 // // _LOAD_CONST_INLINE_BORROW_r01.o: file format elf64-x86-64
// // Disassembly of section .text:
// // 0000000000000000 <_JIT_ENTRY>:
// 0: 48 bf 00 00 00 00 00 00 00 00 movabsq $0x0, %rdi
// 0000000000000002: R_X86_64_64 _JIT_OPERAND0
// a: 48 83 cf 01 orq $0x1, %rdi

This is a really nice reduction. Good job!

Comment threadLib/test/test_capi/test_opt.py Outdated
@trdthg
trdthgforce-pushed the trdthg/feature/jit-load-common-constant branch from 19fc90f to b37ec56CompareMarch 18, 2026 12:30
@Fidget-Spinner

Copy link
Copy Markdown
Member

We generally don't force push, because all PRs in CPython are squash-merged. So just push normal commits, thanks!

@Fidget-SpinnerFidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Once again, LGTM. Thanks for this!

@Fidget-Spinner
Fidget-Spinner merged commit 98977ca into python:mainMar 19, 2026
66 checks passed
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@trdthg@Fidget-Spinner@savannahostrowski