Issue 237995
Summary [AArch64] Missed shift folding into ORR across a bitwise mask
Labels new issue
Assignees
Reporter bagrorg
     Clang emits `lsr; and; orr` for a masked shift followed by a bitwise OR. GCC applies the equivalent mask before shifting, allowing the shift to fold into `orr ..., lsr #4` and eliminating one instruction.

[Reproducer on Compiler Explorer](https://godbolt.org/z/Mr8br3Pvo): includes C++ source and **original and patched Clang-generated assembly**. The patched assembly follows GCC’s mask placement and shifted-register ORR.

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 |
|---:|---:|---:|
| 3.5758 ns/validation | 3.2729 ns/validation | 3.4199 ns/validation |

Originally observed in [simdjson’s eight-digit validation](https://github.com/simdjson/simdjson/blob/3b2870d822b1797cfebb368cd76df0413a7016bb/include/simdjson/generic/numberparsing.h#L578-L591), revision `3b2870d822b1797cfebb368cd76df0413a7016bb`.

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

Reply via email to