From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9A61F3858D37; Fri, 28 Jul 2023 07:51:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A61F3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690530712; bh=9cVKv/UXkMsPBPwQfezle0zWGR5n9mIfh4mtME3STZI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VEPaNZ40j9KLK/jVVuXhwRw2TK+y8bZglm36FPBFfNp08TKcmX+jLfKDjCHTOiAtF JM5Qwhtk0cliYidlsEOCI7uUtbUpFl4vsS+0YsxyvdDeBJpTTCrkKzFDzaMRaiz5Lg QgqGPwxFMKLpHm08V0sEpXCYW0E3f0gv4AMXBbm4= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106923] [13 Regression] ICE in eliminate_unnecessary_stmts, at tree-ssa-dce.cc:1512 since r13-2518-ga262f969d6fd936f Date: Fri, 28 Jul 2023 07:51:51 +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: 13.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: hubicka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106923 --- Comment #7 from CVS Commits --- The master branch has been updated by Jan Hubicka : https://gcc.gnu.org/g:b24acae8f4d315a5b071ffc2574ce91c7a0800ca commit r14-2850-gb24acae8f4d315a5b071ffc2574ce91c7a0800ca Author: Jan Hubicka Date: Fri Jul 28 09:48:34 2023 +0200 loop-split improvements, part 2 this patch fixes profile update in the first case of loop splitting. The pass still gives up on very basic testcases: __attribute__ ((noinline,noipa)) void test1 (int n) { if (n <=3D 0 || n > 100000) return; for (int i =3D 0; i <=3D n; i++) { if (i < n) do_something (); if (a[i]) do_something2(); } } Here I needed to do the conditoinal that enforces sane value range of n. The reason is that it gives up on: !number_of_iterations_exit (loop1, exit1, &niter, false, true) and without the conditonal we get assumption that n>=3D0 and not INT_MA= X. I think from overflow we shold derive that INT_MAX test is not needed a= nd since the loop does nothing for n<0 it is also just an paranoia. I am not sure how to fix this though :(. In general the pass does not really need to compute iteration count. It only needs to know what direction = the IVs go so it can detect tests that fires in first part of iteration space. Rich, any idea what the correct test should be? In testcase: for (int i =3D 0; i < 200; i++) if (i < 150) do_something (); else do_something2 (); the old code did wrong update of the exit condition probabilities. We know that first loop iterates 150 times and the second loop 50 times and we get it by simply scaling loop body by the probability of inner t= est. With the patch we now get: [count: 1000]: [count: 150000]: <- loop 1 correctly iterates 149 times # i_10 =3D PHI do_something (); i_7 =3D i_10 + 1; if (i_7 <=3D 149) goto ; [99.33%] else goto ; [0.67%] [count: 149000]: goto ; [100.00%] [count: 1000]: # i_15 =3D PHI [count: 49975]: <- loop 2 should iterate 50 times but we are slightly wrong # i_3 =3D PHI do_something2 (); i_14 =3D i_3 + 1; if (i_14 !=3D 200) goto ; [98.00%] else goto ; [2.00%] [count: 48975]: goto ; [100.00%] [count: 1000]: <- this test is always true becuase it is reached form bb 3 # i_18 =3D PHI if (i_18 !=3D 200) goto ; [99.95%] else goto ; [0.05%] [count: 1000]: return; The reason why we are slightly wrong is the condtion in bb17 that is always true but the pass does not konw it. Rich any idea how to do that? I think connect_loops should work out the cas where the loop exit conditon is never satisfied at the time the splitted condition fails for first time. Before patch on hmmer we get a lot of mismatches: Profile report here claims: dump id |static mismat|dynamic mismatch=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20 | |in count |in count |time=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 | lsplit | 5 +5| 8151850567 +8151850567| 531506481006=20=20= =20=20=20=20 +57.9%| ldist | 9 +4| 15345493501 +7193642934| 606848841056=20=20= =20=20=20=20 +14.2%| ifcvt | 10 +1| 15487514871 +142021370| 689469797790=20=20= =20=20=20=20 +13.6%| vect | 35 +25| 17558425961 +2070911090| 517375405715=20=20= =20=20=20=20 -25.0%| cunroll | 42 +7| 16898736178 -659689783| 452445796198=20=20= =20=20=20=20=20 -4.9%| loopdone| 33 -9| 2678017188 -14220718990| 330969127663=20=20= =20=20=20=20=20=20=20=20=20=20 | tracer | 34 +1| 2678018710 +1522| 330613415364=20=20= =20=20=20=20=20 +0.0%| fre | 33 -1| 2676980249 -1038461| 330465677073=20=20= =20=20=20=20=20 -0.0%| expand | 28 -5| 2497468467=20=20 -179511782|--------------------------| With patch lsplit | 0 | 0 | 328723360744=20=20= =20=20=20=20=20 -2.3%| ldist | 0 | 0 | 396193562452=20=20= =20=20=20=20 +20.6%| ifcvt | 1 +1| 71010686 +71010686| 478743508522=20=20= =20=20=20=20 +20.8%| vect | 14 +13| 697518955 +626508269| 299398068323=20=20= =20=20=20=20 -37.5%| cunroll | 13 -1| 489349408 -208169547| 257777839725=20=20= =20=20=20=20 -10.5%| loopdone| 11 -2| 402558559 -86790849| 201010712702=20=20= =20=20=20=20=20=20=20=20=20=20 | tracer | 13 +2| 402977200 +418641| 200651036623=20=20= =20=20=20=20=20 +0.0%| fre | 13 | 402622146 -355054| 200344398654=20=20= =20=20=20=20=20 -0.2%| expand | 11 -2| 333608636=20=20=20 -69013510|--------------------------| So no mismatches for lsplit and ldist and also lsplit thinks it improves speed by 2.3% rather than regressig it by 57%. Update is still not perfect since we do not work out that the second lo= op never iterates. Ifcft wrecks profile by desing since it insert conditonals with both ar= ms 100% that will be eliminated later after vect. It is not clear to me what happens in vect though. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: PR middle-end/106923 * tree-ssa-loop-split.cc (connect_loops): Change probability of the test preconditioning second loop to very_likely. (fix_loop_bb_probability): Handle correctly case where on of the arms of the conditional is empty. (split_loop): Fold the test guarding first condition to see if it is constant true; Set correct entry block probabilities of the split loops; determine correct loop eixt probabilities. gcc/testsuite/ChangeLog: PR middle-end/106293 * gcc.dg/tree-prof/loop-split-1.c: New test. * gcc.dg/tree-prof/loop-split-2.c: New test. * gcc.dg/tree-prof/loop-split-3.c: New test.=