Simplify ``x + y == y`` into ``x == 0``
GCC now simplifies ``x + y == y`` into ``x == 0``, potentially improving code generation on RISC-V.
GCC now simplifies expressions of the form x + y == y into x == 0. This optimization can remove unnecessary arithmetic instructions. The patch also fixes a missed side_effects_p check and a typo in a constant definition, improving the robustness of the transformation.
In Details
This commit modifies GCC's RTL simplifier. The change uses rtx_equal_p for comparison rather than pointer equality, checks for !side_effects_p on the dropped operand, and uses CONST0_RTX instead of const0_rtx. This pattern showed up in spec2017's S_regmatch benchmark.
For Context
Compilers often perform algebraic simplifications to reduce code size and improve performance. This commit teaches GCC to recognize and simplify a specific pattern: when adding two values and comparing the result to one of the original values, compilers can often deduce that the other original value must have been zero. In other words, x + y == y implies x == 0.