Issue 237996
Summary [AArch64] Register copy followed by post-index load instead of separate load and pointer update
Labels
Assignees
Reporter bagrorg
    When both the original and advanced pointer are needed, Clang copies the pointer and uses a post-index load on the copy: `mov; ldr [...] #4`. GCC loads directly through the original pointer and computes the advanced pointer separately with `add`. Both sequences use two instructions, but GCC’s avoids making the load depend on the register copy.

[Reproducer on Compiler Explorer](https://godbolt.org/z/dPcnTMxea): includes C++ source and **original and patched Clang-generated assembly**. The patched assembly follows GCC’s separate load and pointer update.

Tested configuration:

- **Clang:** 24.0.0git, LLVM `cd3be30dcbabdf92067782b62dd5f3d995fd5d23`
- **GCC:** 16.0.1 20260322, `r16-8246-g569ace1fa50`
- **Hardware/OS:** Neoverse V3, Linux AArch64
- **Flags:** `-O3 -DNDEBUG -std=c++17 -mcpu=neoverse-v3`

Measurements:

| Clang — original assembly | Clang — patched assembly | GCC |
|---:|---:|---:|
| 2.0705 ns/token advance | 1.7889 ns/token advance | 1.7835 ns/token advance |

Originally observed in [simdjson’s cursor advancement](https://github.com/simdjson/simdjson/blob/3b2870d822b1797cfebb368cd76df0413a7016bb/include/simdjson/generic/ondemand/token_iterator-inl.h#L26-L28), revision `3b2870d822b1797cfebb368cd76df0413a7016bb`.

This assembly change reduced elapsed time by **0.40–0.99%** in simdjson benchmarks with a measurable improvement.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to