Fix vector comparison mode in simplify-rtx for LoongArch
Corrects how vector comparisons are handled in simplify-rtx, fixing incorrect folding of floating-point comparisons on LoongArch.
An issue in GCC’s simplify-rtx pass caused incorrect handling of subreg’d vector comparisons involving floating-point operands and integer masks. The simplify_subreg function incorrectly passed the mode of the comparison result instead of the mode of the operands to simplify_gen_relational. This led to incorrect folding of NaN behavior in operations like unordered, which was then propagated via fwprop and a bit-cast on LoongArch, resulting in incorrect code. The fix ensures the correct operand mode is used for the comparison.
In Details
The simplify_context::simplify_subreg function in simplify-rtx.cc incorrectly passed INNERMODE (the mode of the comparison result, e.g., V4SI) as the comparison mode argument to simplify_gen_relational. This argument should be the mode of the operands (e.g., V4SF). For floating-point comparisons with integer masks, this caused simplify_const_relational_operation to incorrectly honor NaNs based on V4SI instead of V4SF. On LoongArch, this led to incorrect folding and subsequent issues with fwprop and bit-casts. The fix passes VOIDmode instead, allowing the mode to be derived…
- simplify-rtx
- A GCC optimization pass that simplifies RTL (Register Transfer Language) expressions.
- RTL
- Register Transfer Language, an intermediate representation used internally by GCC.
- subreg
- A subregister, which is a part of a larger register. In GCC, it's represented by the
subregconstruct in RTL. - vector comparison
- A comparison operation performed on multiple elements of a vector simultaneously.
- MODE
- Refers to the data type or format of a value in GCC's RTL, e.g., SF (single-precision float), DI (double integer).
- LoongArch
- A CPU architecture developed in China.
- fwprop
- Forward propagation, an optimization technique where values are propagated through the code.