From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6D63A3858410; Wed, 17 Nov 2021 04:59:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D63A3858410 From: "navidrahimi at microsoft dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98956] Failure to optimize out boolean left shift Date: Wed, 17 Nov 2021 04:59:41 +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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: navidrahimi at microsoft dot com 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: cc 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: Wed, 17 Nov 2021 04:59:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98956 Navid Rahimi changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |navidrahimi at microsoft d= ot com --- Comment #3 from Navid Rahimi --- I am sending a patch for this: /* cmp : =3D=3D, !=3D */ /* ((B0 << CST) cmp 0) -> B0 cmp 0 */ (for cmp (eq ne) (simplify (cmp (lshift (convert @0) INTEGER_CST@1) integer_zerop@2) (if (TREE_CODE (TREE_TYPE (@0)) =3D=3D BOOLEAN_TYPE) (cmp @0 @2)))) This does not apply to other arithmetic operations (at least it is not verifiable). and for cases that it does apply to other arithmetic operators, GCC already produces optimized code. You can play with the codegen I link below: Codegen: https://compiler-explorer.com/z/nj4PTrecW Proof: https://alive2.llvm.org/ce/z/jyJAoS=