Fix compare and flags mode in APX ccmp pattern
Corrects the i386 APX ccmp pattern to accurately reflect comparisons and preserve condition flags for correct code generation.
This commit rectifies issues in the i386 APX ccmp pattern that incorrectly handled comparisons and condition flags. Previously, the pattern compared a value against zero, which only matched flags for EQ/NE conditions, leading to misfolds of ordered and unsigned conditions. It also failed to preserve the CC mode of previous comparisons and produced incorrect scc output. The fix ensures direct comparison of operands and correctly propagates the CC mode, resolving incorrect optimizations and code generation for conditional instructions.
In Details
The @ccmp<mode> pattern in i386 was flawed. It performed a compare-against-zero operation on (a - b), which only correctly mirrors the flags of cmp a, b for EQ/NE conditions. This caused simplify-rtx to misinterpret other condition flags. Additionally, the pattern incorrectly used a hardcoded (reg:CC FLAGS_REG) and lost the CC mode of the preceding comparison. The fix modifies the pattern to compare operands 2 and 3 directly and uses operand 5 to inherit the CC mode from the previous comparison, ensuring accurate condition flag propagation and correct use of conditional move instructi…
- APX
- Refers to AMD's Advanced Performance Extensions, a set of instruction set extensions for x86 processors.
- ccmp
- Conditional compare. An instruction that performs a comparison and sets condition flags based on the result.
- RTX
- Representation Tree. GCC's internal intermediate representation for code, used after parsing and before machine code generation.
- simplify-rtx
- A GCC optimization pass that simplifies the internal representation (RTX) of code, performing algebraic simplifications and constant folding.
- FLAGS_REG
- A special register in x86 architectures that holds the status flags resulting from arithmetic and logical operations (e.g., Zero Flag, Carry Flag, Sign Flag).
- CC mode
- In GCC's RTX, 'CC' mode refers to the mode used for condition codes or flags registers, distinguishing them from integer or floating-point modes.