From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7361F385BF99; Wed, 7 Apr 2021 12:46:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7361F385BF99 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99956] loop interchange fails when altering bwaves inner loop Date: Wed, 07 Apr 2021 12:46:25 +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: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: 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, 07 Apr 2021 12:46:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99956 --- Comment #3 from Richard Biener --- Sth as simple (and brute-force) as the following fixes this. Somehow SCEV must already know the "point of failure" though and eventually always instantiating from loop to loop_nest in steps might be more efficient than trying all possibilities on failure (or maybe we should do that on failure). diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc index f45b9364644..215587a8406 100644 --- a/gcc/gimple-loop-interchange.cc +++ b/gcc/gimple-loop-interchange.cc @@ -1320,7 +1320,14 @@ compute_access_stride (class loop *loop_nest, class = loop *loop, } tree scev_base =3D build_fold_addr_expr (ref); tree scev =3D analyze_scalar_evolution (loop, scev_base); - scev =3D instantiate_scev (loop_preheader_edge (loop_nest), loop, scev); + tree orig_scev =3D scev; + scev =3D instantiate_scev (loop_preheader_edge (loop_nest), loop, orig_s= cev); + while (chrec_contains_undetermined (scev) && loop_nest !=3D loop) + { + loop_nest =3D loop_nest->inner; + scev =3D instantiate_scev (loop_preheader_edge (loop_nest), + loop, orig_scev); + } if (! chrec_contains_undetermined (scev)) { tree sl =3D scev;=