GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/match.pd Performance Win

Match.pd: Add pattern for `(A>>bool) == 0 -> (unsigned)A <= bool`.

The compiler can now transform `(A>>bool) == 0` into `(unsigned)A <= bool`, potentially improving performance.

A new pattern is added to match.pd that transforms (A>>bool) == 0 into (unsigned)A <= bool and (A>>bool) != 0 -> (unsigned)A > bool. This transformation can improve performance by allowing the compiler to generate more efficient code for certain bit manipulation operations. The pattern is gated with #if GIMPLE and the result of the right shift is marked as ‘single_use’.

In Details

match.pd defines peephole optimizations on GIMPLE IR in GCC. This commit adds a new pattern that transforms a right bit shift followed by a comparison to zero into an unsigned comparison. This optimization can be beneficial in scenarios where the unsigned comparison is more efficient than the original sequence of operations. The use of single_use on the rshift result indicates that the result is only used once, which can further aid optimization.

For Context

Compilers often perform peephole optimizations to improve code efficiency by replacing small sequences of instructions with faster equivalents. This commit adds a new optimization pattern to GCC that transforms a right bit shift followed by a comparison to zero, into an unsigned comparison. This can allow the compiler to generate more efficient code, particularly when dealing with bit manipulation operations, as unsigned comparisons can sometimes be faster than the original sequence of instructions.

Filed Under: optimizationbit manipulation