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 — JIT assembly optimizer leaves some redundant branches · Issue #139757 · python/cpython

JIT assembly optimizer leaves some redundant branches #139757

New issue
Copy link
New issue
Copy link
Closed
Closed
JIT assembly optimizer leaves some redundant branches#139757
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancementA feature request or enhancement

Description

@markshannon
markshannon
opened on Oct 8, 2025
Issue body actions

For AArch64 emit__GUARD_IS_TRUE_POP produces the following assembly code:

...
14: 54000041 b.ne 0x1c <_JIT_ENTRY+0x1c>
18: 14000002 b 0x20 <_JIT_ENTRY+0x20>
1c: 14000000 b 0x1c <_JIT_ENTRY+0x1c>
000000000000001c: R_AARCH64_JUMP26 _JIT_JUMP_TARGET

but it should, ideally, emit this:

14: 54000041 b.ne 0x14 <_JIT_ENTRY+0x14>
000000000000001c: R_AARCH64_CONDBR19 _JIT_JUMP_TARGET

This doesn't seem to be an issue for x86, possibly due to the way Clang is setup for AArch64, possibly just an artefact of llvm's code gen.
Either way, rather than rely on llvm eliminating these jumps we can do it in the JIT builder's assembly optimizer.
Currently we don't perform jump fusion, but it would be easy enough to do so.

Linked PRs

  • GH-139757: JIT: Remove redundant branches to jumps in the assembly optimizer #140800
  • gh-139757: Treat call specially in JIT assembly backend optimizer on x86-64 and AArch64 #142907
  • gh-139757: Add _GUARD_NOS_COMPACT_ASCII for compact ascii optimization #143332
  • gh-139757: Fix unintended bytecode specialization for non-ascii string #143352
  • gh-139757: Add BINARY_OP_SUBSCR_USTR_INT #143389

Activity

  1. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    topic-JIT
    and removed
    performancePerformance or resource usagePerformance or resource usage
    on Oct 8, 2025
  2. markshannon
    added a commit that references this issue on Dec 4, 2025

    GH-139757: Fix reference leaks introduced in GH-140800 (GH-142257)

    6825d5c
  3. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythonGH-139757: Fix reference leaks introduced in pythonGH-140800 (p…

    f3ecc76
  4. markshannon
    added a commit that references this issue on Dec 8, 2025

    GH-139757: JIT: Remove redundant branches to jumps in the assembly op…

    e0451ce
  5. Fidget-Spinner commented on Dec 17, 2025

    @Fidget-Spinner
    Fidget-Spinner
    on Dec 17, 2025
    Member
    More actions

    The introduction of _remove_unreachable broke the JIT + FT builds on x86-64.

    I get this error:

    0.	Program arguments: clang-21 --target=x86_64-unknown-linux-gnu -c -o /tmp/tmpbw0scowv/_LOAD_ATTR_WITH_HINT_r11.o /tmp/tmpbw0scowv/_LOAD_ATTR_WITH_HINT_r11.s
    Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
    
    

    Commenting it out fixes it.

  6. Fidget-Spinner commented on Dec 17, 2025

    @Fidget-Spinner
    Fidget-Spinner
    on Dec 17, 2025
    Member
    More actions

    Alright, I narrowed it down: for some stencils, there are more than one entry points, e.g. if PyStackRef_CLOSE is outlined, then a stencil may have two entry points (one _JIT_ENTRY, one PyStackRef_CLOSE).

    The problem with that is that we don't treat call PyStackRef_CLOSE as a jump to a live block. So this optimization breaks.

    A possible fix is to just treat all function entries as live.

  7. Fidget-Spinner
    added a commit that references this issue on Dec 17, 2025

    gh-139757: Treat call specially in JIT assembly backend optimizer on …

    8b64dd8
  8. corona10
    added 5 commits that reference this issue on Jan 1, 2026

    pythongh-139757: Add _GUARD_NOS_COMPACT_ASCII for compact ascii optim…

    54af89d

    Merge remote-tracking branch 'upstream/main' into pythongh-139757-gua…

    a86857d

    gh-139757: Add _GUARD_NOS_COMPACT_ASCII for compact ascii optimization (

    315f474

    pythongh-139757: Fix unintended BINARY_OP_SUBSCR_STR_INT for non-ASCII

    1b6fa3c

    gh-139757: Fix unintended bytecode specialization for non-ascii string (

    61f2ad9
  9. Fidget-Spinner
    added a commit that references this issue on Jan 4, 2026

    gh-139757: Add BINARY_OP_SUBSCR_USTR_INT (GH-143389)

    e6bfe4d
  10. thunder-coding
    added 3 commits that reference this issue on Feb 15, 2026

    pythongh-139757: Add _GUARD_NOS_COMPACT_ASCII for compact ascii optim…

    9438b06

    pythongh-139757: Fix unintended bytecode specialization for non-ascii…

    5c6da5c

    pythongh-139757: Add BINARY_OP_SUBSCR_USTR_INT (pythonGH-143389)

    b773aae
  11. markshannon commented on Mar 23, 2026

    @markshannon
    markshannon
    on Mar 23, 2026
    MemberAuthor
    More actions

    I think this is done

  12. markshannon
    closed this as completedon Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.