From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD3A33858408; Fri, 7 Jan 2022 07:40:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD3A33858408 From: "luoxhu at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103802] [12 regression] recip-3.c fails after r12-6087 on Power m32 Date: Fri, 07 Jan 2022 07:40:30 +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: luoxhu at gcc dot gnu.org 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: Fri, 07 Jan 2022 07:40:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103802 --- 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; 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 incre= ase the loop iteration count: "/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 > alternatively one might argue that invariant expressions (unconditionally > computed or in a special way under invariant conditions) should be costed > differently. >=20 > I think best would be to restore the original intent of the testcase which > 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). 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" t= o 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): (It is much reasonable than the other two directions as loop iteration coun= t is not key for the test code.) 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" } */ -double F[2] =3D { 0.0, 0.0 }, e; +double F[5] =3D { 0.0, 0.0 }, e; /* In this case the optimization is interesting. */ float h () @@ -13,7 +13,7 @@ float h () d =3D 2.*e; E =3D 1. - d; - 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; } -/* { dg-final { scan-tree-dump-times " / " 5 "recip" } } */ +/* { dg-final { scan-tree-dump-times " / " 1 "recip" } } */=