From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 48D57384607B for ; Thu, 12 Nov 2020 03:03:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 48D57384607B Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AC32cPI030963; Wed, 11 Nov 2020 22:03:22 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 34rjnp8g38-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 22:03:22 -0500 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0AC33Lta038476; Wed, 11 Nov 2020 22:03:21 -0500 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 34rjnp8g2x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Nov 2020 22:03:21 -0500 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AC32wYw016621; Thu, 12 Nov 2020 03:03:20 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma05wdc.us.ibm.com with ESMTP id 34nk79ecvw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Nov 2020 03:03:20 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AC33K4012190428 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Nov 2020 03:03:20 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6F4E12405C; Thu, 12 Nov 2020 03:03:19 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8DD1E124053; Thu, 12 Nov 2020 03:03:19 +0000 (GMT) Received: from genoa (unknown [9.40.192.157]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTPS; Thu, 12 Nov 2020 03:03:19 +0000 (GMT) From: Jiufu Guo To: gcc-patches@gcc.gnu.org Cc: wschmidt@linux.ibm.com, segher@kernel.crashing.org, dje.gcc@gmail.com, hubicka@ucw.cz Subject: Re: [PATCH 2/2] reset edge probibility and BB-count for peeled/unrolled loop References: <20201009101242.2478660-1-guojiufu@linux.ibm.com> <20201009101242.2478660-2-guojiufu@linux.ibm.com> Date: Thu, 12 Nov 2020 11:03:16 +0800 In-Reply-To: <20201009101242.2478660-2-guojiufu@linux.ibm.com> (guojiufu@linux.ibm.com's message of "Fri, 9 Oct 2020 18:12:42 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-11_12:2020-11-10, 2020-11-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011120017 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2020 03:03:24 -0000 guojiufu writes: Hi Honza, all, Just want to ping this for review. Original messages: [PATCH 2/2] https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555872.html [PATCH 1/2] https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555871.html Thanks, Jiufu Guo. > Hi, > PR68212 mentioned that the COUNT of unrolled loop was not correct, and > comments of this PR also mentioned that loop become 'cold'. > > This patch fixes the wrong COUNT/PROB of unrolled loop. And the > patch handles the case where unrolling in unreliable count number can > cause a loop to no longer look hot and therefor not get aligned. This > patch scale by profile_probability::likely () if unrolled count gets > unrealistically small. > > Bootstrap/regtest on powerpc64le with no new regressions. Ok for trunk? > > Jiufu Guo > > gcc/ChangeLog: > 2020-10-09 Jiufu Guo > Pat Haugen > > PR rtl-optimization/68212 > * cfgloopmanip.c (duplicate_loop_to_header_edge): Reset probablity > of unrolled/peeled loop. > > testsuite/ChangeLog: > 2020-10-09 Jiufu Guo > Pat Haugen > PR rtl-optimization/68212 > * gcc.dg/pr68212.c: New test. > > > --- > gcc/cfgloopmanip.c | 31 +++++++++++++++++++++++++++++-- > gcc/testsuite/gcc.dg/pr68212.c | 13 +++++++++++++ > 2 files changed, 42 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr68212.c > > diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c > index b0ca82a67fd..d3c95498402 100644 > --- a/gcc/cfgloopmanip.c > +++ b/gcc/cfgloopmanip.c > @@ -1260,14 +1260,30 @@ duplicate_loop_to_header_edge (class loop *loop, edge e, > /* If original loop is executed COUNT_IN times, the unrolled > loop will account SCALE_MAIN_DEN times. */ > scale_main = count_in.probability_in (scale_main_den); > + > + /* If we are guessing at the number of iterations and count_in > + becomes unrealistically small, reset probability. */ > + if (!(count_in.reliable_p () || loop->any_estimate)) > + { > + profile_count new_count_in = count_in.apply_probability (scale_main); > + profile_count preheader_count = loop_preheader_edge (loop)->count (); > + if (new_count_in.apply_scale (1, 10) < preheader_count) > + scale_main = profile_probability::likely (); > + } > + > scale_act = scale_main * prob_pass_main; > } > else > { > + profile_count new_loop_count; > profile_count preheader_count = e->count (); > - for (i = 0; i < ndupl; i++) > - scale_main = scale_main * scale_step[i]; > scale_act = preheader_count.probability_in (count_in); > + /* Compute final preheader count after peeling NDUPL copies. */ > + for (i = 0; i < ndupl; i++) > + preheader_count = preheader_count.apply_probability (scale_step[i]); > + /* Subtract out exit(s) from peeled copies. */ > + new_loop_count = count_in - (e->count () - preheader_count); > + scale_main = new_loop_count.probability_in (count_in); > } > } > > @@ -1383,6 +1399,17 @@ duplicate_loop_to_header_edge (class loop *loop, edge e, > scale_bbs_frequencies (new_bbs, n, scale_act); > scale_act = scale_act * scale_step[j]; > } > + > + /* Need to update PROB of exit edge and corresponding COUNT. */ > + if (orig && is_latch && (!bitmap_bit_p (wont_exit, j + 1)) > + && bbs_to_scale) > + { > + edge new_exit = new_spec_edges[SE_ORIG]; > + profile_count new_count = new_exit->src->count; > + profile_count exit_count = loop_preheader_edge (loop)->count (); > + profile_probability prob = exit_count.probability_in (new_count); > + recompute_loop_frequencies (loop, prob); > + } > } > free (new_bbs); > free (orig_loops); > diff --git a/gcc/testsuite/gcc.dg/pr68212.c b/gcc/testsuite/gcc.dg/pr68212.c > new file mode 100644 > index 00000000000..e0cf71d5202 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr68212.c > @@ -0,0 +1,13 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fno-tree-vectorize -funroll-loops --param max-unroll-times=4 -fdump-rtl-alignments" } */ > + > +void foo(long int *a, long int *b, long int n) > +{ > + long int i; > + > + for (i = 0; i < n; i++) > + a[i] = *b; > +} > + > +/* { dg-final { scan-rtl-dump-times "internal loop alignment added" 1 "alignments"} } */ > +