Issue 237983
Summary [AArch64] Redundant pointer comparison and select before a load
Labels new issue
Assignees
Reporter bagrorg
    Clang emits `cmp` and `csel` for a pointer selection equivalent to `a == b ? a : b`, then loads through the selected pointer. The result is always `b`. GCC loads directly through `b`, avoiding the comparison and select.

[Reproducer on Compiler Explorer](https://godbolt.org/z/dKjEYG58h): includes C++ source and **original and patched Clang-generated assembly**. The patched assembly follows GCC’s direct load, preserving the later equality check needed for conditional state updates.

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 |
|---:|---:|---:|
| 1.9088 ns/conversion | 1.8745 ns/conversion | 1.7956 ns/conversion |

Originally observed in [simdjson’s scalar access](https://github.com/simdjson/simdjson/blob/3b2870d822b1797cfebb368cd76df0413a7016bb/include/simdjson/generic/ondemand/value_iterator-inl.h#L1041-L1047), revision `3b2870d822b1797cfebb368cd76df0413a7016bb`.

This assembly change reduced elapsed time by **1.11–2.57%** in affected simdjson benchmarks.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to