From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7ABA73858D37; Wed, 19 Jan 2022 12:44:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7ABA73858D37 From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103721] [12 regression] wrong code generated for loop with conditional since r12-4790-g4b3a325f07acebf4 Date: Wed, 19 Jan 2022 12:44:20 +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: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: aldyh at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned 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: Wed, 19 Jan 2022 12:44:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103721 --- Comment #6 from Aldy Hernandez --- Please bear with me, as I'm coming up to speed, and my head hurts from all these equivalences. The problem seems to be what Jeff mentioned in comment #4. We think _5 =3D=3D _6, which makes the conditional in BB9 always false. Th= is allows us to thread 8->9->7: [local count: 1073741824]: # searchVolume_5 =3D PHI # currentVolume_6 =3D PHI _2 =3D searchVolume_5 !=3D currentVolume_6; _3 =3D searchVolume_5 !=3D 0; _4 =3D _2 & _3; if (_4 !=3D 0) goto ; [89.00%] else goto ; [11.00%] With --param=3Dthreader-debug=3Dall we can see the threader registering the= path: [1] Registering jump thread: (8, 9) incoming edge; (9, 7) nocopy;=20 The bits immediately preceding it are the solver in action for the proposed path. Of particular interest is: path_range_query: compute_ranges for path: 8->9 Registering value_relation (currentVolume_8 =3D=3D searchVolume_5) (bb8) at currentVolume_8 =3D PHI range_defined_in_block (BB8) for currentVolume_8 is int [-INF, -1][1, +INF] from bb9: Registering killing_def (path_oracle) searchVolume_5 Registering value_relation (path_oracle) (searchVolume_11 =3D=3D searchVol= ume_5) (bb8) from bb9: Registering killing_def (path_oracle) currentVolume_6 Registering value_relation (path_oracle) (currentVolume_8 =3D=3D currentVo= lume_6) (bb8) range_defined_in_block (BB9) for searchVolume_5 is int [0, 1] range_defined_in_block (BB9) for currentVolume_6 is int [-INF, -1][1, +INF] path_oracle: Equivalence set : [searchVolume_5, currentVolume_6, currentVolume_8] Equivalence set : [currentVolume_6] Equivalence set : [searchVolume_5, searchVolume_11] Equivalence set : [searchVolume_5] Notice the entry at the top of the path_oracle equivalence queue: Equivalence set : [searchVolume_5, currentVolume_6, currentVolume_8] The sequence of events that got us here is the following: 1. When calculating the PHIs for the path, we start at BB8, which triggers a global ranger's range_of_expr. We do this, to see if there's anything the global ranger knows on entry to the path. This in turn registers an equiv = for _8 =3D=3D _5 in the *root* oracle (not the path specific one): Registering value_relation (currentVolume_8 =3D=3D searchVolume_5) (bb8) at currentVolume_8 =3D PHI 2. Then in BB9 we set up the following path specific equiv: Registering value_relation (path_oracle) (currentVolume_8 =3D=3D currentVo= lume_6) (bb8) Since the root oracle has _8 =3D=3D _5, this means we "know" that _8 =3D=3D= _6 =3D=3D _5 in the path. Shit rolls downhill from here.=