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

Do not strip conversions on bit test masks in ifcombine

Fixes incorrect widening of variables during bitwise comparison optimization.

A bug in the ifcombine pass incorrectly stripped narrowing conversions from variables used in bitwise AND operations. This led to the compiler widening the variable and ORing in unwanted bits, causing miscompilation. The fix modifies how bit tests are recognized, prioritizing direct operand matching before considering conversions, thus preventing the resurrection of truncated bits and ensuring correct program behavior.

In Details

The recognize_bits_test function in tree-ssa-ifcombine.cc incorrectly stripped narrowing conversions from operands of BIT_AND_EXPR. This was problematic when rhs1 was the mask and rhs2 was the value, especially if rhs1 had a conversion. If commutativity was later used to swap operands, the stripped conversion caused ifcombine_ifandif to widen rhs2 based on rhs1's original wider type, introducing incorrect bits. The fix ensures conversions are only looked through after direct matching fails, and only on the names, not the masks themselves.

Filed Under: optimizationbugfix