i386: Change the sign of a float in memory in place
Optimizes in-memory floating-point sign changes on x86 by using bit manipulation instead of loads and stores.
This commit introduces a new pattern for the i386 architecture that modifies the sign of floating-point numbers directly in memory. Instead of loading the value into an SSE register, performing a bitwise operation, and storing it back, the compiler now uses instructions like btr (bit test and reset) or bts (bit test and set) to flip the sign bit in memory. This is more efficient as it avoids unnecessary memory accesses and register usage, especially for operations like fabs(*p) or x = -x when applied to memory locations. It also preserves the behavior for signaling NaNs when using x87 math, unlike previous SSE-based operations.
In Details
This patch adds new instruction patterns to the i386 backend for optimizing in-memory floating-point negation and absolute value operations. Previously, these were expanded using load-operate-store sequences involving SSE registers (e.g., movsd, xorpd). The new patterns target memory operands directly, using bit manipulation instructions (btr, bts, btc) to flip the sign bit (bit 63 for DFmode, bit 31 for SFmode) in the memory word itself. This is enabled via a new (set (mem) (abs/neg (mem))) pattern that is split after reload. It specifically handles SFmode and DFmode on 64-bit in…
- i386
- The Intel 80386 processor, a 32-bit extension of the earlier x86 architecture. GCC's i386 backend targets this and later compatible processors.
- SSE
- Streaming SIMD Extensions. A set of CPU instructions that allow for single-instruction, multiple-data (SIMD) operations, particularly for floating-point and integer data.
- x87
- A family of math coprocessors for x86 architectures, providing floating-point arithmetic capabilities.
- DFmode
- GCC's internal mode for representing double-precision (64-bit) floating-point numbers.
- SFmode
- GCC's internal mode for representing single-precision (32-bit) floating-point numbers.
- signaling NaN
- A type of NaN that, when operated upon, should raise an exception (e.g., floating-point invalid operation). This is contrasted with a quiet NaN, which typically does not raise an exception.
- reload
- A phase in GCC's back-end processing where the compiler ensures that all values that need to be in registers are assigned to specific physical registers, often involving spilling values to memory if not enough registers are available.