Simplify XORs of zero/one-valued comparisons
Compiler optimization pattern simplifies boolean XOR and equality expressions involving comparisons to zero, improving code efficiency.
The compiler’s pattern matching system (match.pd) has been enhanced to simplify complex boolean expressions involving XOR and equality operations on comparisons with zero. It can now transform patterns like (a == 0) ^ (b != 0) into simpler equivalent forms such as a == b, leading to more efficient generated code by reducing redundant comparisons and operations.
In Details
This patch enhances match.pd to recognize and simplify XOR and boolean equality patterns involving operands that are zero_one_valued_p. It introduces canonical transformations for patterns like (a == 0) ^ (b != 0) to a == b and (a == 0) == (b != 0) to a != b, among others. The update includes guarding against vector types and ensures regression tests verify the canonical XOR form.
- match.pd
- A file within GCC that defines pattern-matching rules used for optimizing intermediate representations. It allows the compiler to recognize specific code structures and replace them with equivalent, more efficient ones.
- XOR
- Exclusive OR, a logical bitwise operation. In boolean logic, it returns true if and only if the inputs differ.
- zero_one_valued_p
- A GCC internal predicate function that checks if a given expression evaluates to either zero or one. This is often true for boolean expressions or comparisons.
- tree-ssa
- SSA stands for Static Single Assignment form, an intermediate representation used by compilers. Tree-SSA is GCC's implementation of SSA based on its internal tree representation, enabling various optimizations.