GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
match.pd

match.pd: factor MSB OR-cascade out of clz_table_index

MSB OR-cascade logic refactored into reusable match patterns for clarity and future use.

The logic for generating the MSB OR-cascade, which sets all bits from 0 up to the most significant bit, has been refactored into two new match patterns: msb_or_cascade_32 and msb_or_cascade_64. The existing clz_table_index patterns for 32-bit and 64-bit integers are rewritten to use these new helpers. This change is a non-functional refactoring that improves code organization and prepares for a subsequent optimization.

In Details

The OR-cascade logic in match.pd used by clz_table_index has been factored into the new helper match patterns msb_or_cascade_32 and msb_or_cascade_64. This is a pure refactoring, preserving the existing functionality and constraints for integral types and precision. The existing patterns are rewritten to use these helpers, simplifying the definition of clz_table_index.

For Context
MSB
Most Significant Bit. The bit with the highest value in a binary number.
match.pd
A file containing pattern definitions for the GCC 'match' system, used for recognizing and optimizing specific instruction sequences.
clz_table_index
A pattern in match.pd likely used for count-leading-zeros (CLZ) optimization, which employs a table lookup after an MSB cascade.
Filed Under: refactoringmatch.pdoptimization