From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CB303858406; Mon, 28 Feb 2022 22:32:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CB303858406 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/91384] [9/10/11/12 Regression] Compare with negation is not eliminated Date: Mon, 28 Feb 2022 22:32:58 +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: 9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: roger at nextmovesoftware dot com X-Bugzilla-Target-Milestone: 9.5 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: Mon, 28 Feb 2022 22:32:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D91384 --- Comment #16 from CVS Commits --- The master branch has been updated by Roger Sayle : https://gcc.gnu.org/g:28068d1115648adcc08ae57372170f3277915a0d commit r12-7417-g28068d1115648adcc08ae57372170f3277915a0d Author: Roger Sayle Date: Mon Feb 28 22:30:27 2022 +0000 PR tree-optimization/91384: peephole2 to eliminate testl after negl. This patch is my proposed solution to PR tree-optimization/91384 which = is a missed-optimization/code quality regression on x86_64. The problemat= ic idiom is "if (r =3D -a)" which is equivalent to both "r =3D -a; if (r != =3D 0)" and alternatively "r =3D -a; if (a !=3D 0)". In this particular case, = on x86_64, we prefer to use the condition codes from the negation, rather than require an explicit testl instruction. Unfortunately, combine can't help, as it doesn't attempt to merge pairs of instructions that share the same operand(s), only pairs/triples of instructions where the result of each instruction feeds the next. But I doubt there's sufficient benefit to attempt this kind of "combination" (that wouldn't already be caught by the tree-ssa passes). Fortunately, it's relatively easy to fix this up (addressing the regression) during peephole2 to eliminate the unnecessary testl in: movl %edi, %ebx negl %ebx testl %edi, %edi je .L2 2022-02-28 Roger Sayle gcc/ChangeLog PR tree-optimization/91384 * config/i386/i386.md (peephole2): Eliminate final testl insn from the sequence *movsi_internal, *negsi_1, *cmpsi_ccno_1 by transforming using *negsi_2 for the negation. gcc/testsuite/ChangeLog PR tree-optimization/91384 * gcc.target/i386/pr91384.c: New test case.=