GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/ipa

Fix zero-extension check for signed bitfields in ifcombine

Correctly handles sign extensions for bitfields in conditional optimization.

This commit fixes an issue in the ifcombine optimization pass where signed bitfields were not being correctly zero-extended. Previously, a bug in checking sign bits led to incorrect evaluation of equality comparisons with sign-extended constants, causing some optimizations to fail. The fix adjusts how bitfield masks are interpreted to properly distinguish between zero-extensions and sign-extensions, ensuring correct optimization behavior.

In Details

The fold_truth_andor_for_ifcombine pass incorrectly handled sign extensions for bitfields. Previously, commit 91fa9c15cc4 misidentified certain signed bitfield operations as zero-extended due to the logic in decode_field_reference. This commit refactors decode_field_reference to return -1 for masks that zero out extension bits, 1 for sign extensions, and 0 otherwise. fold_truth_andor_for_ifcombine now uses these values to correctly identify sign-extended operations, preventing erroneous optimization of equality comparisons.

For Context
ifcombine
An optimization pass in GCC that combines conditional expressions, such as if (x && y) into a single condition, to simplify code and enable further optimizations.
bitfield
A data member of a struct or union that is allowed to use fewer than the natural number of bits for its type.
zero-extension
A process where a smaller integer type is converted to a larger integer type by filling the most significant bits with zeros.
sign-extension
A process where a smaller integer type is converted to a larger integer type by filling the most significant bits with copies of the original sign bit.
Filed Under: optimizationcompiler