GCC and Clang Leave 64-bit Division on Fast Path at -O2

tetsuoai · x · 2026-08-21

Benchmarking the agenc-arena C11 region allocator revealed that both GCC 13 and Clang 18 leave a 64-bit hardware division on the fast path at -O2. The article presents the C source, the resulting assembly, and the fix. The issue stems from an overflow guard where PTRDIFFMAX / size should simplify to a sign test when count is 1, yet the compiler fails to eliminate the expensive division.

Original post →

More from Infra

Infra channel →