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

Reject merging compares that test the same bit differently

Compiler optimization rejects flawed comparison merging to prevent miscompilation.

The compiler’s ifcombine pass previously merged comparison operations that tested the same bit in different ways, leading to incorrect code generation for certain edge cases involving negative numbers. This change adds a check to reject such merges, ensuring that if bits are tested by both comparisons, they are tested consistently. New test cases are included to cover these scenarios.

In Details

In fold_truth_andor_for_ifcombine, the logic for merging conditional comparisons was too permissive. It allowed combining comparisons that used different masks for the same bit, where one tested for equality (bit set in both operands) and the other for inequality (bit set in one operand only). This could lead to incorrect results when sign bits were involved. The fix rejects such conflicting merges, preventing miscompilation.

Filed Under: optimizationbugfix