From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CF5673858406; Mon, 10 Jan 2022 09:24:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF5673858406 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103802] [12 regression] recip-3.c fails after r12-6087 on Power m32 Date: Mon, 10 Jan 2022 09:24:36 +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, testsuite-fail X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de 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: 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: Mon, 10 Jan 2022 09:24:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103802 --- Comment #7 from rguenther at suse dot de --- On Fri, 7 Jan 2022, luoxhu at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103802 >=20 > --- Comment #6 from luoxhu at gcc dot gnu.org --- > (In reply to Richard Biener from comment #5) > > So the point is that P is invariant but we do not hoist it because it's > > computed in a (estimated) cold block? I notice that the condition is > > invariant, too, so > > in principle we could hoist as > >=20 > > if (d > 0.01) > > P =3D ( W < E ) ? (W - E)/d : (E - W)/d; > > for (i=3D0; i < 2; i++ ) > > if( d > 0.01 ) > > F[i] +=3D P; >=20 >=20 > Yes. But this loop only iterates twice, so bbs in loop is colder than > preheader. > -funswitch-loops should move the condition out of loop, but also need inc= rease > the loop iteration count: >=20 > "/home/luoxhu/workspace/gcc-master/gcc/testsuite/gcc.dg/tree-ssa/recip-3.= c:16:14: > note: Not unswitching, loop is not expected to iterate" >=20 > >=20 > > alternatively one might argue that invariant expressions (unconditional= ly > > computed or in a special way under invariant conditions) should be cost= ed > > differently. > >=20 > > I think best would be to restore the original intent of the testcase wh= ich > > was added with the fix for PRs 23109, 23948 and 24123. I suppose there > > we saw the invariant hoisted(?) and the loop unrolled so I would suggest > > to either apply the hoisting or the unrolling manually to the testcase. > > (just look at the PRs whether you get a better idea of the origin of the > > testcase). >=20 > To restore the original intent of the testcase, increase the loop count is > better than "either apply the hoisting or unrolling". Change it from "2"= to at > least "5" will turn the cold bb to hot bb, then the two divides could be > hoisted out in LIM pass again(Verified below change could both pass on > power-m32 and x86-i686): >=20 > (It is much reasonable than the other two directions as loop iteration co= unt is > not key for the test code.) >=20 > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c > b/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c > index 641c91e..a1d2d87 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/recip-3.c > @@ -1,7 +1,7 @@ > /* { dg-do compile } */ > /* { dg-options "-O1 -fno-trapping-math -funsafe-math-optimizations > -fdump-tree-recip" } */ >=20 > -double F[2] =3D { 0.0, 0.0 }, e; > +double F[5] =3D { 0.0, 0.0 }, e; >=20 > /* In this case the optimization is interesting. */ > float h () > @@ -13,7 +13,7 @@ float h () > d =3D 2.*e; > E =3D 1. - d; >=20 > - for( i=3D0; i < 2; i++ ) > + for( i=3D0; i < 5; i++ ) > if( d > 0.01 ) > { > P =3D ( W < E ) ? (W - E)/d : (E - W)/d; > @@ -23,4 +23,4 @@ float h () > F[0] +=3D E / d; > } >=20 > -/* { dg-final { scan-tree-dump-times " / " 5 "recip" } } */ > +/* { dg-final { scan-tree-dump-times " / " 1 "recip" } } */ That looks reasonable to me.=