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

Simplify conditional bitwise OR patterns involving bitmasks.

Compiler patterns now simplify more conditional bitwise OR operations.

This commit expands the match.pd patterns to unconditionally simplify more conditional bitwise OR operations. It introduces new patterns to handle cases where a bit is checked and then set if not present, or where a bitmask is tested against itself. These simplifications apply when the bit is derived from a left shift (e.g., 1 << val) or when a full bitmask is involved, allowing the compiler to replace conditional logic with direct bitwise OR operations, thereby improving code efficiency.

In Details

Adds new patterns to match.pd to handle conditional bitwise OR operations more aggressively. These patterns recognize specific conditional structures involving bit tests (A & BIT) and bitmasks (A & MASK) combined with bitwise OR (A | BIT or A | MASK), and convert them into unconditional bitwise OR operations. This is an extension of previous work (PR64567) to cover more complex bitmask scenarios and conditional outcomes, avoiding the introduction of unnecessary complexity or data loss.

For Context
match.pd
A file containing patterns used by GCC's pattern matching engine to recognize and optimize specific code structures during compilation.
Bitwise OR
A logical operation that compares corresponding bits of two operands. If either bit is 1, the resulting bit is 1; otherwise, it is 0.
Bitmask
A value used in bitwise operations to manipulate individual bits of a data word. It typically consists of a sequence of bits, where certain bits are set to 1 to select corresponding bits in another value, and others are 0.
Conditional bitwise OR
A pattern where a bitwise OR operation is performed only if certain conditions related to bit manipulation are met.
Filed Under: optimizationpattern matchingbitwise operations