Hi, gentle ping on this patch. Sashiko report: https://gcc.sashiko.dev/#/patchset/PA1PR08MB1123934E6C119A2E87711301FFE6E2%40PA1PR08MB11239.eurprd08.prod.outlook.com
________________________________ From: Daniel Petrovic <[email protected]> Sent: 29 October 2026 13:27 To: [email protected] <[email protected]> Cc: [email protected] <[email protected]>; [email protected] <[email protected]> Subject: [PATCH] match.pd: Fold (X | A) cmp C and (X ^ A) cmp C into X cmp C [PR115392] Hi, this patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115392 I’d appreciate the review. If A is known to lie in [0, 2^m-1], then X | A and X ^ A leave the bits of X at and above position m unchanged, so the comparison with C is decided by the high parts alone when the low m bits of C are: * all ones: fold (X op A) <= C and (X op A) > C to X <= C and X > C, * all zeros: fold (X op A) < C and (X op A) >= C to X < C and X >= C. A may be a constant or a range limited value, for example a bool, a masked value or a value with a known range. The fold is not done when A may touch the sign bit. gcc/ChangeLog: PR tree-optimization/115392 * match.pd: Fold (X | A) cmp C and (X ^ A) cmp C into X cmp C when A is known to be in [0, 2^m-1] and the low m bits of C are all ones (le, gt) or all zeros (lt, ge). gcc/testsuite/ChangeLog: PR tree-optimization/115392 * gcc.dg/tree-ssa/pr115392-1.c: New test. * gcc.dg/tree-ssa/pr115392-2.c: New test. * gcc.dg/tree-ssa/pr115392-3.c: New test. * gcc.dg/tree-ssa/pr115392-4.c: New test. * gcc.dg/tree-ssa/pr115392-5.c: New test. * gcc.dg/ipa/pr91088.c: Use a constant that the new fold does not simplify, so that the XOR is still visible to ipa-cp. Bootstrapped and regtested on x86_64-pc-linux-gnu with no regressions. Many thanks to Andrew Pinski and Jakub Jelinek for their contribution in generalizing the initial report. Thanks, Daniel
