From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D01B1385800A; Thu, 25 Mar 2021 13:52:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D01B1385800A From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99755] failure to fold a conditional that's a subset of another expression Date: Thu, 25 Mar 2021 13:52: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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: 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: cc 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, 25 Mar 2021 13:52:18 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99755 Andrew Macleod changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #2 from Andrew Macleod --- f2 and f4 are "similar" when I look at whats going on with these. The interesting bits are bb3 and bb4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 3 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D i_9(D) int [2, +INF] j_10(D) int [3, +INF] Relational : (x_12 > i_9(D)) : x_12 =3D i_9(D) + 1; x_12 : int [3, +INF] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Imports: i_9(D) j_10(D) Exports: _4 _5 _6 i_9(D) j_10(D) _4 : i_9(D)(I) _5 : j_10(D)(I) _6 : _4 _5 i_9(D)(I) j_10(D)(I) i_9(D) int VARYING j_10(D) int VARYING : # x_8 =3D PHI _4 =3D i_9(D) =3D=3D 2; _5 =3D j_10(D) =3D=3D 3; _6 =3D _4 & _5; if (_6 !=3D 0) goto ; [INV] else goto ; [INV] x_8 : int [3, +INF] 4->5 (T) _4 : _Bool [1, 1] 4->5 (T) _5 : _Bool [1, 1] 4->5 (T) _6 : _Bool [1, 1] 4->5 (T) i_9(D) : int [2, 2] 4->5 (T) j_10(D) : int [3, 3] 4->7 (F) _6 : _Bool [0, 0] we have the ability to recompute stmts on edges when the dependencies chang= e. This currently applies only to range-ops enabled stmts. An extension to PH= IS and other non-range-ops is in the works. The gist being x_8 is directly dependant on x_11 and x_12. x_11 is undefin= ed, so it boils down to a dependency on x_12. x_12 in turn is dependant on i_9 which is a modified export from this block= .=20 So when recomputation is extended to PHIS, we should be able to see that i_9 has changed on this edge, and reevaluate x_12 for that edge, x_12 =3D i_9 + 1 --> [2,2] + 1 =3D=3D [3,3]=20 and feeding that into a PHI recalculation for the edge producing x_8 =3D PHI and then we'd resolve x_8 =3D [3,3] on the true edge, and the desired fold = should happen.=20 The other issue is that when we do recalculations, we currently only go back one degree of dependency for the sake of compilation speed... x_8's direct dependencies are that one degree.. I have not done experiments on more than one degree, but it may make sense to look back one degree for phi arguemnts= as well, which would then get cases like this.=20 It may also make sense instead to adjust the phi optimization pass to utili= ze ranger to do a more in-depth analysis of argument ranges and their dependen= cies and get it there.=20 I'll update this once I have enabled recomputation for phis, and have somet= hing more concrete.=