[Bug tree-optimization/101650] (len | N) == len is transformed to len & N != 0
"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]> Tue, 04 Aug 2026 03:48:44 +0000
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101650 --- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <[email protected]>: https://gcc.gnu.org/g:372d44c5611ecce9144c985a849ca06f108289fe commit r17-2916-g372d44c5611ecce9144c985a849ca06f108289fe Author: Avinal Kumar <[email protected]> Date: Mon Aug 3 21:48:01 2026 -0600 [PATCH] match: Simplify `(A | C) =3D=3D A` to `(A & C) !=3D 0` when C i= s power of 2 [PR101650] The expression (A | C) =3D=3D A tests if all the bits in C are already = set in A. When C is a power of 2, this is equivalent to (A & C) !=3D 0 whi= ch avoids OR and compares against 0 instead of original value thus optimizing the comparison. Similarly (A | C) !=3D A can be optimized to (A & C) =3D=3D 0. --- Bootstrapped and ran full test suite on x86_64 Fedora Linux. Output for this particular patch test: cat gcc/testsuite/gcc/gcc.sum | grep bitcmp-7 PASS: gcc.dg/tree-ssa/bitcmp-7.c (test for excess errors) PASS: gcc.dg/tree-ssa/bitcmp-7.c scan-tree-dump-not optimized "\\| 4" PASS: gcc.dg/tree-ssa/bitcmp-7.c scan-tree-dump-times optimized " & 4" 2 I also included some whitespace changes in some comments. Please let me know if they should be a separate change. PR tree-optimization/101650 gcc/ChangeLog: * match.pd: Simplify (A | C) =3D=3D A to (A & C) !=3D 0 when C = is power of 2. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/bitcmp-7.c: New test. Signed-off-by: Avinal Kumar <[email protected]>=