middle-end: Wrong code for a != b | (a|b) != 0. [PR126742]
Fixes incorrect optimization of bitwise operations involving inequality checks.
This commit corrects a flawed optimization in GCC’s middle-end related to bitwise operations. The compiler was incorrectly simplifying expressions like (a != b) | ((a|b) != 0) to ((a|b) == 0). The correct logical equivalence is (a != b) | ((a|b) != 0) simplifies to ((a|b) != 0). A test case was updated to more rigorously check the generated code for this specific pattern.
In Details
Corrects a logical error in match.pd that affected bitwise optimization rules. Specifically, the transformation for (a != b) | ((a|b) != 0) was inverted, incorrectly simplifying it to ((a|b) == 0) instead of the correct ((a|b) != 0). The original bug was introduced around revision 17.2886. The associated test case (gcc.dg/int-bwise-opt-2.c) was enhanced to verify the correctness of the resulting code rather than just the presence of certain patterns.
- middle-end
- The part of the compiler that performs optimizations on intermediate representations (like GIMPLE) after the frontend has parsed the source code and before the backend generates machine code.
- optimization rules
- Predefined patterns and transformations used by the compiler to simplify or improve code, such as algebraic identities or bitwise operation equivalences.
- bitwise operations
- Operations that manipulate individual bits of data, such as AND (
&), OR (|), XOR (^), and NOT (~). - GIMPLE
- GCC's Generic Intermediate Representation, a common three-address code format used for optimizations.