MIPS fixes uninitialized operand use in sync operations
This patch corrects uninitialized operand use in MIPS RTL templates for atomic synchronization operations, preventing incorrect code generation.
The MIPS backend for GCC had a subtle bug in its atomic synchronization RTL templates (sync_old_<optab>_12 and sync_new_<optab>_12). When an instruction’s RTL template had multiple elements, leading to a parallel expression, an operand (register 1, the output) was being used before its value was officially set. This could lead to incorrect code generation, sometimes resulting in unexpected arithmetic. The patch reorders the operand usage to ensure values are set before being read.
In Details
In GCC's MIPS backend, define_insn RTL templates for atomic synchronization operations (sync_old_<optab><mode> and sync_new_<optab><mode>) incorrectly used operand 1 (the output register) in a match_dup before its value was computed within the parallel expression. This violates the 'all values computed first, then all side-effects performed' rule for parallels, particularly evident when optimization folded (plus (0) (val)) to (val). The fix changes (match_dup 0) to (match_dup 1) and clarifies the source for memory sets to ensure correct operand dependency and prevent unintende…
For Context
When GCC compiles code for processors like MIPS, it uses an internal representation called RTL (Register Transfer Language) to define how instructions work. For complex operations, like atomic updates (which are crucial for multi-threaded programming), an instruction might involve several steps that are designed to happen effectively at the same time, known as a "parallel expression." This commit fixes a bug where, in some atomic operations on MIPS, the compiler was trying to use the result of one of these steps before that result was actually computed. This could lead to incorrect calculations or errors in the final machine code. The fix ensures that all values are properly computed before they are used, so the atomic operations work as expected.