Issue 237925
Summary [AArch64] Conditional selects delay a dependent load instead of branching on invalid input
Labels new issue
Assignees
Reporter bagrorg
    Clang uses `cset` and two `csel` instructions to conditionally advance a pointer and initialize a value, then checks for invalid input later. The next load depends on the selected pointer. GCC branches immediately on invalid input, allowing the valid path to use the advanced pointer and value directly.

[Reproducer on Compiler Explorer](https://godbolt.org/z/jK53ajGs6): includes C++ source and saved **original** and **patched** Clang assembly. The patched assembly follows GCC’s early-error branch, replacing the conditional selections and removing the redundant later check.

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`, no LTO

Measurements:

| Original Clang | Patched Clang | GCC |
|---:|---:|---:|
| 1.4319 ns/number | 1.3222 ns/number | 1.3270 ns/number |

Originally observed in [simdjson’s number parsing](https://github.com/simdjson/simdjson/blob/3b2870d822b1797cfebb368cd76df0413a7016bb/include/simdjson/generic/numberparsing.h#L1331-L1348), revision `3b2870d822b1797cfebb368cd76df0413a7016bb`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to