https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127762
--- Comment #2 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:bab00098c33a53a6dc36a6126c6226fe9bb2e15e commit r17-5016-gbab00098c33a53a6dc36a6126c6226fe9bb2e15e Author: Richard Biener <[email protected]> Date: Thu Oct 8 14:26:04 2026 +0200 Fix zero-extension check for signed bitfields in ifcombine In fold_truth_andor_for_ifcombine, when checking if a constant compared against a widened bitfield operand needs to be zero-extended rather than sign-extended, commit 91fa9c15cc4 incorrectly checked !ll_signbit and !rl_signbit. decode_field_reference only set signbit to true when the AND mask had precision greater than the field bitsize and had non-zero bits in the extension positions. When the mask precision was less than or equal to the field bitsize, signbit remained false (0) because no extension bits were tested. Because !ll_signbit / !rl_signbit was checked, any signed field with a mask of the same precision (e.g. c & ~0x3fc00) was incorrectly treated as zero-extended, even though the sign bit was preserved and the subsequent conversion to a wider type performed a sign extension. Consequently, equality comparisons with sign-extended constants were erroneously evaluated as false. Fix this by having decode_field_reference distinguish masks with extension bits that zero them out (returning -1) from masks that do not test extension bits (returning 0), and checking for signbit < 0 in fold_truth_andor_for_ifcombine. Only bail out on lr_signbit and rr_signbit when they are positive, so that masks that zero out extension bits on the right-hand operands do not prevent combination. PR tree-optimization/127762 * gimple-fold.cc (decode_field_reference): Change psignbit to int * and set it to 1 for sign extensions, -1 if all extension bits are clear, or 0 otherwise. (fold_truth_andor_for_ifcombine): Change ll_signbit, lr_signbit, rl_signbit, and rr_signbit to int. Check for signbit > 0 when including sign bit in test, and signbit < 0 when checking for zero-extension. Only reject positive lr_signbit and rr_signbit. * gcc.dg/field-merge-27.c: New test. * gcc.dg/field-merge-29.c: New test.
