Simplify-rtx: Handle (X & C) | ((X^Y) & ~C) -> X ^ (Y & ~C) transformation.
Extends simplify-rtx to handle the expression `(X & C) | ((X^Y) & ~C)` and simplify it to `X ^ (Y & ~C)`, resulting in optimized code.
This commit generalizes existing code in simplify-rtx.cc to handle the expression (X & C) | ((X^Y) & ~C) and simplify it to X ^ (Y & ~C). This transformation improves code generation by replacing a sequence of logical operations with a single XOR operation, particularly on RISC-V. A new test case validates the optimization.
In Details
The simplify_rtx pass in GCC's RTL (Register Transfer Language) optimizer attempts to simplify expressions before code generation. This commit extends simplify_context::simplify_binary_operation_1 in simplify-rtx.cc to handle the case of (X & C) | ((X^Y) & ~C). The existing code already handled IOR, but not XOR. The new test gcc.target/riscv/pr93504.c demonstrates the transformation.
For Context
Compilers perform various optimizations to improve the efficiency of generated code. One stage of optimization involves simplifying complex expressions into simpler, equivalent forms. This commit adds a new simplification rule to GCC that transforms a specific pattern of bitwise AND, OR, and XOR operations into a single XOR operation. This simplification can lead to more efficient machine code, especially on architectures like RISC-V.