From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1594C3858C83; Thu, 2 Mar 2023 22:46:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1594C3858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677797195; bh=5tEPcFFB9tfwmUACg/SrHHW7XjUz4QG+SQkZKHnyBLw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GlE70Jlifiluz9P/O3XK1pkkZUxWGULmN/kiN3XuBH77j9DFpyqChf6tPr2boBUmy tRmlJZpeCS6agKLKGHuHzUWv7wTOOsE2oikq/7BjxiTbQzjIizPm8+D6MRHghVoyyA O++PFqTdLvVLtLMSQlq10I9VFaPC97cm3A87l49Y= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/108992] Regression: Branch direction canonicalization leads to pointless tail duplication / CSE/sinking by inverting branch Date: Thu, 02 Mar 2023 22:46:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: resolution bug_status 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108992 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #4 from Andrew Pinski --- I suspect this is not a bug, GCC tries to optimze the fast path into straig= ht line code without any waste of space. In the first case GCC predicts that the cond is going to be true 66% of the time because there is comparison against 0 prediction going in the heurstic= s. For the first testcase if you do: void use(int *); void use2(int *); void foo(bool cond, int * p) { if (__builtin_expect(cond, 1)) { use(p); } use2(p); } Then you get the result you want. Adding the builtin_expect for the second case you get the same too. Basically GCC is pushing what it thinks as cold code away from the original path.=