From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7C74F3972030; Thu, 10 Dec 2020 13:17:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C74F3972030 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/91384] [8/9/10/11 Regression] Compare with negation is not eliminated Date: Thu, 10 Dec 2020 13:17:47 +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: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 8.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: Thu, 10 Dec 2020 13:17:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D91384 --- Comment #10 from Richard Biener --- But then void foo (void); void bar (void); int test (int a) { if (a) foo (); else bar (); return -a; } is not optimized either (the usual argument - the user could have written it in the way the compiler canonicalizes). On RTL where the CCs are appearant that's a LCM / PRE problem with the compare anticipating the zero flag here and the negate computing it. That makes it profitable to move the negate and eliminate the CC flag compute with it (for the testcase above). On the original case where we have int test (int a) { int r =3D -a; if (a) foo (); else bar (); return r; } that's more a local CSE opportunity (though of course for this modified testcase we sink the -a compute to the return, re-creating the first case in this comment). As it is only RTL representing CC at all this is really a RTL global optimization issue in the end. GIMPLE can only help to a limited extent and all missed canonicalization (like if we add a single_use check) eventually leads to missed global CSE opportunities.=