Increase memcmp inlining threshold for word-sized comparisons.
Optimizes memcmp inlining for word-sized comparisons on i386 to match SSE2 thresholds.
This commit increases the threshold for inlining memcmp when performing word-sized comparisons on i386 architectures, particularly when SSE2 is not fully utilized or configured. Previously, the compiler inlined memcmp only up to 32 bytes for 64-bit and 16 bytes for 32-bit targets due to overheads. By adjusting the cost model to treat word-sized pieces more efficiently, the inlining thresholds are now raised to 64 bytes for 64-bit and 32 bytes for 32-bit, aligning them with SSE2 behavior and potentially improving performance for small memory copies.
In Details
This patch targets PR 128035 and optimizes the memcmp inlining heuristic for i386 architectures when COMPARE_MAX_PIECES is equal to UNITS_PER_WORD. This scenario occurs when SSE2 is unavailable or not fully configured. In such cases, each word-sized piece gets its own compare and branch, leading to a limited inlining depth (32 bytes for x86-64, 16 for IA32). The change modifies the cost estimation: it uses a branch ratio of 2 for word-mode pieces and halves the SIZE parameter when optimizing for speed. This effectively makes the cost comparable to SSE2 double-word compares, thereby in…
- memcmp
- A standard C library function that compares two blocks of memory.
- Inlining
- A compiler optimization technique where the code of a called function is inserted directly at the call site, eliminating function call overhead.
- i386
- Refers to the x86 instruction set architecture, commonly associated with Intel processors starting from the Intel 80386.
- SSE2
- Streaming SIMD Extensions 2, a set of CPU instructions for accelerating multimedia and signal processing tasks, including vectorized memory operations.
- UNITS_PER_WORD
- A configuration constant indicating how many processor words (e.g., 32-bit or 64-bit units) fit into a larger vector unit or align with a specific hardware constraint.