Skip to content

gh-131798: JIT: optimize _LOAD_COMMON_CONSTANT#146104

Open
trdthg wants to merge 1 commit intopython:mainfrom
trdthg:trdthg/feature/jit-load-common-constant
Open

gh-131798: JIT: optimize _LOAD_COMMON_CONSTANT#146104
trdthg wants to merge 1 commit intopython:mainfrom
trdthg:trdthg/feature/jit-load-common-constant

Conversation

@trdthg
Copy link

@trdthg trdthg commented Mar 18, 2026

Try to learn and make a small contribution :D

@bedevere-app
Copy link

bedevere-app bot commented Mar 18, 2026

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
Copy link

python-cla-bot bot commented Mar 18, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

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 trdthg force-pushed the trdthg/feature/jit-load-common-constant branch from 068d2bb to 19fc90f Compare March 18, 2026 11:40
@bedevere-app
Copy link

bedevere-app bot commented Mar 18, 2026

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
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!

@trdthg trdthg force-pushed the trdthg/feature/jit-load-common-constant branch from 19fc90f to b37ec56 Compare March 18, 2026 12:30
@Fidget-Spinner
Copy link
Member

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

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

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!

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