From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 874433858D28; Fri, 1 Apr 2022 09:51:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 874433858D28 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104645] [12 Regression] i ? i % 2 : 0 not optimized anymore Date: Fri, 01 Apr 2022 09:51: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: 12.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: P1 X-Bugzilla-Assigned-To: pinskia at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.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 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: Fri, 01 Apr 2022 09:51:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104645 --- Comment #5 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:d9c03fc27d8147a9401a29739694b214df48a9a2 commit r12-7952-gd9c03fc27d8147a9401a29739694b214df48a9a2 Author: Jakub Jelinek Date: Fri Apr 1 11:50:41 2022 +0200 phiopt: Improve value_replacement [PR104645] The following patch fixes the P1 regression by reusing existing value_replacement code. That function already has code to handle simple preparation statements (casts, and +,&,|,^ binary assignments) before a final binary assignment (which can be much wider range of ops). When we have e.g. if (y_3(D) =3D=3D 0) goto ; else goto ; : y_4 =3D y_3(D) & 31; _1 =3D (int) y_4; _6 =3D x_5(D) r<< _1; : # _2 =3D PHI the preparation statements y_4 =3D y_3(D) & 31; and _1 =3D (int) y_4; are handled by constant evaluation, passing through y_3(D) =3D 0 initially and propagating that through the assignments with checking that UB isn't invoked. But the final _6 =3D x_5(D) r<< _1; assign is handled differently, either through neutral_element_p or absorbing_element_p. In the first function below we now have: [local count: 1073741824]: if (i_2(D) !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870913]: _3 =3D i_2(D) & 1; iftmp.0_4 =3D (int) _3; [local count: 1073741824]: # iftmp.0_1 =3D PHI where in GCC 11 we had: : if (i_3(D) !=3D 0) goto ; [INV] else goto ; [INV] : i.1_1 =3D (int) i_3(D); iftmp.0_5 =3D i.1_1 & 1; : # iftmp.0_2 =3D PHI Current value_replacement can handle the latter as the last stmt of middle_bb is a binary op that in this case satisfies absorbing_element_p. But the former we can't handle, as the last stmt in middle_bb is a cast. The patch makes it work in that case by pretending all of middle_bb are the preparation statements and there is no binary assign at the end, so everything is handled through the constant evaluation. We simply set at the start of middle_bb the lhs of comparison virtually to the rhs, propagate it through and at the end see if virtually the arg0 of the PHI is equal to arg1 of it. For GCC 13, I think we just should throw away all the neutral/absorbing element stuff and do the constant evaluation of the whole middle_bb and handle that way all the ops we currently handle in neutral/absorbing element. 2022-04-01 Jakub Jelinek PR tree-optimization/104645 * tree-ssa-phiopt.cc (value_replacement): If assign has CONVERT_EXPR_CODE_P rhs_code, treat it like a preparation statement with constant evaluation. * gcc.dg/tree-ssa/pr104645.c: New test.=