i386: Prevent volatile memory compare reordering before reload
Fixes reordering of volatile memory reads in compares to prevent issues in kernel code relying on strict access order.
This commit prevents the GCC combine pass from generating compares that reorder volatile memory accesses. Previously, volatile loads could be incorrectly reordered by the register allocator when forming compare instructions, potentially altering the intended sequence of read operations. This change ensures that volatile memory accesses maintain their specified order, crucial for code like the Linux kernel that relies on strict read ordering.
In Details
The i386 'combine' pass could merge two volatile loads into a single compare instruction (e.g., (compare (mem/v x) (mem/v y))). Because the machine-dependent compare patterns accepted volatile memory operands before reload, and the register allocator arbitrarily ordered them, the sequence point between volatile accesses could be lost. This commit modifies the insn conditions for @ccmp, cmp, and cmp_minus_1 to reject cases where both operands are volatile memory references, thus preserving the order of volatile accesses.
- volatile
- A keyword that instructs the compiler not to optimize away or reorder memory accesses, ensuring that each access is performed exactly as specified in the code. This is often used for memory-mapped hardware or shared memory accessed by multiple threads/processes.
- combine pass
- A GCC optimization pass that attempts to merge multiple machine instructions into a single, more efficient instruction where possible.
- reload
- In register allocation, the process of loading values from memory into registers when they are needed and storing them back to memory when they are modified. 'Before reload' refers to a state in the compilation pipeline before register allocation is complete.
- RA (Register Allocator)
- The part of the compiler responsible for assigning program variables to hardware registers to minimize memory access.
- insn condition
- A pattern matching condition within a GCC machine description file that determines when a specific instruction template can be used.