https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124937

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <[email protected]>:

https://gcc.gnu.org/g:3822120f4977e999269531c67f4678f2657aeb2f

commit r17-5015-g3822120f4977e999269531c67f4678f2657aeb2f
Author: Richard Biener <[email protected]>
Date:   Fri Oct 9 09:43:20 2026 +0200

    Convert XOR constant operand to outer_type in ifcombine

    When decode_field_reference decodes an equality test of the form
    (outer_type)(a ^ c) == 0 into a == c, it strips the conversion
    outer_type on the first pass (decoding the left-hand operand 'a')
    and stores outer_type for field sizing.  On the second pass
    (*pxorp == true, decoding the right-hand operand 'c'), if 'c' is an
    INTEGER_CST, it was left with its original unconverted type and width.

    This meant that if 'c' was wider than outer_type (e.g. a 16-bit constant
    cast to uint8_t), 'c' retained non-zero bits in the upper positions.
    In fold_truth_andor_for_ifcombine, because both operands' bitsizes had
    been adjusted to outer_type, rl_bitsize < rr_bitsize was false, leaving
    the constant unclipped.  The subsequent check for non-zero bits outside
    the field mask then erroneously concluded that the comparison was
    tautologically false and optimized the condition to 0.

    Fix this by converting exp to outer_type when decoding the right-hand
    XOR operand if outer_type is set and exp is an INTEGER_CST.

            PR tree-optimization/127447
            PR tree-optimization/125444
            PR tree-optimization/124937
            * gimple-fold.cc (decode_field_reference): Convert exp to
            outer_type when decoding an INTEGER_CST right-hand XOR operand.

            * gcc.dg/field-merge-28.c: New test.

Reply via email to