Combine vector comparisons against zero
Optimizes vector comparisons by combining pairs of comparisons against zero.
This commit introduces optimizations for vector comparisons in GCC’s match.pd pattern matching system. It combines pairs of vector comparisons against zero, leveraging the identity (A == 0) & (B == 0) <=> (A | B) == 0. This applies to both equality and inequality, and handles cases where operands differ in signedness. The optimization is demonstrated with an aarch64 example and includes a new test case.
In Details
The match.pd optimization rule now handles vector integer comparisons more effectively. It recognizes that a lane-wise AND of two zero-comparisons is equivalent to a single zero-comparison on the bitwise OR of the operands. This rule is extended to cover signed and unsigned comparisons, as well as their De Morgan duals. A new helper function, vector_nop_conversion_p, is introduced to manage cases where operands might require view conversions before comparison, improving generated code for vector operations.
- match.pd
- A file containing pattern matching rules used by GCC's optimization passes to recognize and transform specific code sequences.
- vector integer
- A data type representing multiple integer values that can be operated on in parallel by a single instruction.
- lane
- An individual element within a vector data type. For example, a 4-element vector of integers has 4 lanes.
- De Morgan dual
- In logic, De Morgan's laws describe how to distribute negation over conjunction (AND) and disjunction (OR). For example, NOT (A AND B) is equivalent to (NOT A) OR (NOT B).