Skip to content

Improve macOS AArch64 JIT stencils by relaxing GOT loads #157435

Description

@lgeiger

Proposal:

The AArch64 JIT has support for optimising pairs of instructions that load an address through the global offset table (GOT).
On Linux, the JIT optimiser recognises assembly like:

adrp x9, :got:__PyRuntime
ldr  x9, [x9, :got_lo12:__PyRuntime]

_re_large_const_1 = re.compile(
r"\s*(?P<instruction>adrp)\s+(?P<register>x\d\d?),.*:got:(?P<value>[_A-Za-z0-9]+).*"
)
_re_large_const_2 = re.compile(
r"\s*(?P<instruction>ldr)\s+(?P<register>x\d\d?),.*:got_lo12:(?P<value>[_A-Za-z0-9]+).*"
)

On macOS, Clang uses a different syntax recognised by the Mach-O linker:

adrp x9, __PyRuntime@GOTPAGE
ldr  x9, [x9, __PyRuntime@GOTPAGEOFF]

We can add support for this using the existing patch_aarch64_33rx() function just by adjusting the regex which would enable the same optimisation we already use on Linux:

adrp x9, <__PyRuntime page>
add  x9, x9, <page offset>

This is a natural followup to #157040. I have a small patch ready once jit development is unblocked.

Benchmark:

On my M5 MacBook Pro this shows a 1.16% improvement on the pyperformance suite though results are very noisy. Probably best to re-run with the official benchmarking runners.

Expand for full benchmarking results

Image

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

#148598, #148501, #157040 /cc @diegorusso

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions