MATCH: Simplify min(clz/ctz) to clz/ctz of bitwise OR.
Simplifies min(clz(x), clz(y)) to clz(x | y) and min(ctz(x), ctz(y)) to ctz(x | y) in MATCH.
This commit introduces new simplification patterns to the GCC MATCH (Machine Description) system. It allows the compiler to replace expressions like min(clz(x), clz(y)) with clz(x | y) and min(ctz(x), ctz(y)) with ctz(x | y). This optimization can lead to more efficient code by reducing the number of operations required.
In Details
The match.pd file now includes patterns to simplify min(clz(x), clz(y)) to clz(x | y) and min(ctz(x), ctz(y)) to ctz(x | y). These transformations leverage the properties of bitwise OR and the definitions of count-leading-zeros (clz) and count-trailing-zeros (ctz) instructions. This optimization happens within the "match" pass, aiming to reduce instruction count and potentially improve performance on architectures where these bitwise operations are efficient, such as ARM and x86.
- MATCH
- A GCC pass that attempts to match C code patterns against a database of predefined machine-specific or general optimization rules, often involving instruction selection or algebraic simplification.
- clz
- Count Leading Zeros. An instruction or function that returns the number of zero bits preceding the most significant set bit in a binary representation of a number.
- ctz
- Count Trailing Zeros. An instruction or function that returns the number of zero bits following the least significant set bit in a binary representation of a number.
- bitwise OR
- A logical operation that combines two binary numbers bit by bit. The result bit is 1 if either of the corresponding input bits is 1; otherwise, it is 0.
- PR123311
- Problem Report 123311. Indicates that this change addresses a bug or feature request filed in GCC's bug tracking system.