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

Convert XOR constant operand to outer_type in ifcombine

Ensures correct optimization of XOR operations involving type conversions.

This commit fixes an issue in the ifcombine optimization pass where XOR operations involving type conversions were not optimized correctly. When a constant operand had a wider type than the outer type after a conversion, it retained upper bits. This led to incorrect assumptions about the comparison’s result, causing the optimization to erroneously deem the condition false. The fix ensures the constant operand is converted to the outer type, allowing correct optimization.

In Details

In fold_truth_andor_for_ifcombine, when processing (outer_type)(a ^ c) == 0 and decoding c as an INTEGER_CST, its type and width were not adjusted to outer_type if outer_type was set. This led to rl_bitsize < rr_bitsize being false even when the constant c's original type was wider than outer_type. The subsequent check for non-zero bits outside the field mask then erroneously concluded the comparison was false. This patch converts exp to outer_type for INTEGER_CSTs when outer_type is set.

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.
outer_type
In the context of GCC's internal representation, this refers to the type of the expression that encloses a subexpression, particularly relevant during type conversions and bitfield operations.
INTEGER_CST
GCC's internal representation for an integer constant value.
Filed Under: optimizationcompiler