From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4ED903857C68; Fri, 4 Jun 2021 22:18:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ED903857C68 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/58073] Suboptimal optimisation of ((x & 0x70) == 0x00 || (x & 0x70) == 0x10 || (x & 0x70) == 0x20) on x86_64 Date: Fri, 04 Jun 2021 22:18:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jun 2021 22:18:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D58073 --- Comment #6 from Andrew Pinski --- #define shift 4 return ((mask(d) =3D=3D (0x0 << shift)) || (mask(d) =3D=3D (0x1 << shift)) || (mask(d) =3D=3D (0x2 << shift))); static inline unsigned mask(const struct dentry *dentry) { return dentry->d_flags & (0x7 << shift); } ifcombine does: _4 =3D _5 & 112; // this was already there. _8 =3D _4 =3D=3D 16; _7 =3D _4 =3D=3D 0; _9 =3D _7 | _8; _10 =3D _4 =3D=3D 32; _11 =3D _9 | _10; Which is correct. reassoc1 does: _4 =3D _5 & 112; _8 =3D _4 =3D=3D 16; _1 =3D _4 & 4294967279; // -17 or ~16 _13 =3D _1 =3D=3D 0; _7 =3D _4 =3D=3D 0; _10 =3D _4 =3D=3D 32; _11 =3D _10 | _13; and that is where it messes up, it misses reassocation of all three ands together. And _4 & 4294967279 removes bit 7 from the original and. Final output: _4 =3D _5 & 112; // 0b1110000 _1 =3D _5 & 96; // 0b1100000 _13 =3D _1 =3D=3D 0; // 0b0000000 _10 =3D _4 =3D=3D 32;// 0b0100000 _11 =3D _10 | _13; So we need have another pattern for something like this: (bit_ior (cmp (bit_and @0 INTEGER_CST@2) INTEGER_CST@3) (cmp (bit_and @0 INTEGER_CST@4) INTEGER_CST@5)) And maybe even one like this (which will solve the issue sooner): (bit_ior (cmp (bit_and @0 INTEGER_CST@2) INTEGER_CST@3) (cmp @0 INTEGER_CST@5)))=