On Thu, Oct 29, 2026 at 5:27 AM Daniel Petrovic <[email protected]> wrote: > > 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.
Just FYI, I prefered to be called Andrea rather than Andrew. Thanks, Andrea > > > > Thanks, > Daniel > >
