GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
match Performance Win

match: Simplify sign tests for MIN and BIT_IOR

Optimizes comparisons involving MIN and bitwise OR operations by simplifying sign tests.

The match.pd patterns now simplify comparisons against zero for MIN(a, b) and a | b when b is known to be non-negative. These operations’ signs then depend solely on ‘a’, allowing optimization of MIN (a, b) cmp 0 and (a | b) cmp 0 to a cmp 0. This optimization is now performed earlier in the compilation process.

In Details

This commit modifies the match.pd file to introduce new patterns for optimizing expressions involving MIN and BIT_IOR operations when one operand is known to be non-negative. It aims to simplify (MIN (a, b)) cmp 0 and (a | b) cmp 0 to a cmp 0 by leveraging the non-negativity of b. This change allows for earlier optimization compared to existing RTL-level optimizations for (a | b) cmp 0 on some targets.

For Context
match.pd
A file in GCC containing patterns used by the 'match' pass, which identifies and optimizes specific code sequences.
BIT_IOR
Represents the bitwise OR operation (equivalent to | in C/C++).
RTL
Register Transfer Language, an intermediate representation used by GCC for code optimization.
Filed Under: optimizationcompiler