From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DECA83858D39; Fri, 3 Nov 2023 09:40:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DECA83858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699004419; bh=5zLTfzM7V2CirBPRjQ7iBoVphlKfgM5TzWKGv9JiOCw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fZpPtF1hFCkIqLFhecX5TkD5OWNUNx41kfSc4rGbqfCPt3G4SwbXy4r930eH2swVG 2zYqIwoXE1tttVfNKdr8CGyifslj5MkDOrVTaAtiNXCHhsGwCdple5EkuC24KAGX7I eHu5qkS4w5x4PpmIkJ3LRcztPcvgxh2kzFDlLdRQ= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112310] [14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu since r14-1161-g5476de2618f Date: Fri, 03 Nov 2023 09:40:18 +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: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112310 --- Comment #3 from Richard Biener --- Hm. It's more complicated, we cannot keep the intersection of expressions = here as seen by the added testcase int foo (int flag, int * __restrict a, int * __restrict b) { int res; if (flag) res =3D *a + *b; else { res =3D *a; *a =3D 1; res +=3D *b; } return res; } here we expect to hoist the *a and *b load and the addition. But while we can make the loads have the same expression, the adds will inevitably differ as we do not have valueized operands there. So what happens is that we have multiple expressions for the same value we'd like to hoist, and currently by r14-1161-g5476de2618f we're picking the "first". For the case in this PR it's the "wrong" one, but we can't easily decide which one is correct. For the bug we have {nop_expr,iftmp.1_43} (0028) and {mult_expr,p.5_7,2022160547} (0028) where the first depends on {mult_expr,_4,2022160547} (0033) and the second depends on {nop_expr,_4} (0007) - both are not values we intended to hoist but we'd generate them anyway via create_expression_by_pieces. So instead of forcing the expressions to be the same on all paths as it was before r14-1161-g5476de2618f we can go and check whether the resulting set of expressions to hoist is self-consistent, in that it contains all dependent expressions we'd have to hoist. That also ensures we can truly eliminate the whole computation on both paths (consider the dependent expressions to be live). Ideally we'd keep the union of the expressions from both paths like compute_antic does and then we can pick the representation that fulfills the constraints.=