Message ID | 20211123055145.475825-1-luoxhu@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B5813858405 for <patchwork@sourceware.org>; Tue, 23 Nov 2021 05:52:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B5813858405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637646760; bh=TG5B+aA548bYR4u6txbYZHocSq2adrzhnKK6Rf77inI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=adaKdm9lJW0eGY+wS8pe7DGIJEEgRXpxbnAlBRyb0leDn4tauQt2nWHknfpPgPDf8 Ut/5mNOjx6joizfgrrEIxyCAKh/vvJl3eVdYSxmASFxAnoqnMnZapqPYrF/LTuqrg7 3L1A+rq3FA8voAVr9f3AMs4ITnZrA+OBnsRnEixo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 311E23858405; Tue, 23 Nov 2021 05:52:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 311E23858405 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AN5N1WZ003993; Tue, 23 Nov 2021 05:52:09 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3cgt3kgbun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Nov 2021 05:52:09 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AN5ptrd028720; Tue, 23 Nov 2021 05:52:09 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3cgt3kgbu4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Nov 2021 05:52:09 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AN5l62u026984; Tue, 23 Nov 2021 05:52:06 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3cernakyxm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Nov 2021 05:52:03 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AN5pvXm39977234 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Nov 2021 05:51:57 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D62B42064; Tue, 23 Nov 2021 05:51:57 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A0C284203F; Tue, 23 Nov 2021 05:51:55 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 23 Nov 2021 05:51:55 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix incorrect loop exit edge probability [PR103270] Date: Mon, 22 Nov 2021 23:51:45 -0600 Message-Id: <20211123055145.475825-1-luoxhu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NNrt6QgaSeXKFVrgJ_eBXHejcqISY1vZ X-Proofpoint-ORIG-GUID: IsYcA49DsaXqjypRLrALmeZwXB-P5tIG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-23_01,2021-11-22_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=730 suspectscore=0 priorityscore=1501 spamscore=0 adultscore=0 malwarescore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111230027 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Xionghu Luo via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Xionghu Luo <luoxhu@linux.ibm.com> Cc: segher@kernel.crashing.org, Xionghu Luo <luoxhu@linux.ibm.com>, hubicka@kam.mff.cuni.cz, wschmidt@linux.ibm.com, linkw@gcc.gnu.org, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
Fix incorrect loop exit edge probability [PR103270]
|
|
Commit Message
Xionghu Luo
Nov. 23, 2021, 5:51 a.m. UTC
r12-4526 cancelled jump thread path rotates loop. It exposes a issue in profile-estimate when predict_extra_loop_exits, outer loop's exit edge is marked as inner loop's extra loop exit and set with incorrect prediction, then a hot inner loop will become cold loop finally through optimizations, this patch ignores the EDGE_DFS_BACK edge when searching extra exit edges to avoid unexpected predict_edge. gcc/ChangeLog: PR middle-end/103270 * predict.c (predict_extra_loop_exits): Ignore EDGE_DFS_BACK edge. gcc/ChangeLog: PR middle-end/103270 * predict.c (predict_extra_loop_exits): New. --- gcc/predict.c | 4 ++++ 1 file changed, 4 insertions(+)
Comments
On 2021/11/23 13:51, Xionghu Luo wrote: > r12-4526 cancelled jump thread path rotates loop. It exposes a issue in > profile-estimate when predict_extra_loop_exits, outer loop's exit edge > is marked as inner loop's extra loop exit and set with incorrect > prediction, then a hot inner loop will become cold loop finally through > optimizations, this patch ignores the EDGE_DFS_BACK edge when searching > extra exit edges to avoid unexpected predict_edge. > > gcc/ChangeLog: > > PR middle-end/103270 > * predict.c (predict_extra_loop_exits): Ignore EDGE_DFS_BACK edge. > > gcc/ChangeLog: > > PR middle-end/103270 > * predict.c (predict_extra_loop_exits): New. > --- > gcc/predict.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/gcc/predict.c b/gcc/predict.c > index 68b11135680..1ae8ccff72c 100644 > --- a/gcc/predict.c > +++ b/gcc/predict.c > @@ -1910,6 +1910,10 @@ predict_extra_loop_exits (edge exit_edge) > continue; > if ((check_value_one ^ integer_onep (val)) == 1) > continue; > + if (e->flags & EDGE_DFS_BACK) > + continue; Sorry, made a mistake before send the patch, #if 0 #endif should be removed... > if (EDGE_COUNT (e->src->succs) != 1) > { > predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN); >
On Tue, Nov 23, 2021 at 6:52 AM Xionghu Luo <luoxhu@linux.ibm.com> wrote: > > r12-4526 cancelled jump thread path rotates loop. It exposes a issue in > profile-estimate when predict_extra_loop_exits, outer loop's exit edge > is marked as inner loop's extra loop exit and set with incorrect > prediction, then a hot inner loop will become cold loop finally through > optimizations, this patch ignores the EDGE_DFS_BACK edge when searching > extra exit edges to avoid unexpected predict_edge. Not sure how outer vs. inner loop exit correlates with EDGE_DFS_BACK, I have expected a check based on which loop is exited by the edge instead? A backedge should never be an exit, no? Note that the profile pass does not yet mark backedges so EDGE_DFS_BACK settings are unreliable. Richard. > > gcc/ChangeLog: > > PR middle-end/103270 > * predict.c (predict_extra_loop_exits): Ignore EDGE_DFS_BACK edge. > > gcc/ChangeLog: > > PR middle-end/103270 > * predict.c (predict_extra_loop_exits): New. > --- > gcc/predict.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/gcc/predict.c b/gcc/predict.c > index 68b11135680..1ae8ccff72c 100644 > --- a/gcc/predict.c > +++ b/gcc/predict.c > @@ -1910,6 +1910,10 @@ predict_extra_loop_exits (edge exit_edge) > continue; > if ((check_value_one ^ integer_onep (val)) == 1) > continue; > +#if 0 > + if (e->flags & EDGE_DFS_BACK) > + continue; > +#endif > if (EDGE_COUNT (e->src->succs) != 1) > { > predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN); > -- > 2.25.1 >
> On Tue, Nov 23, 2021 at 6:52 AM Xionghu Luo <luoxhu@linux.ibm.com> wrote: > > > > r12-4526 cancelled jump thread path rotates loop. It exposes a issue in > > profile-estimate when predict_extra_loop_exits, outer loop's exit edge > > is marked as inner loop's extra loop exit and set with incorrect > > prediction, then a hot inner loop will become cold loop finally through > > optimizations, this patch ignores the EDGE_DFS_BACK edge when searching > > extra exit edges to avoid unexpected predict_edge. > > Not sure how outer vs. inner loop exit correlates with EDGE_DFS_BACK, > I have expected a check based on which loop is exited by the edge instead? > A backedge should never be an exit, no? > > Note that the profile pass does not yet mark backedges so EDGE_DFS_BACK > settings are unreliable. So we have two nested loops and an exit which goes from inner loop and exists both loops. While processing outer loop we set pretty high exit probability that is not good for inner loop? I guess we could just check if exit edge source basic block has same loop depth as the loop we ar eprocesing? Honza > > Richard. > > > > > gcc/ChangeLog: > > > > PR middle-end/103270 > > * predict.c (predict_extra_loop_exits): Ignore EDGE_DFS_BACK edge. > > > > gcc/ChangeLog: > > > > PR middle-end/103270 > > * predict.c (predict_extra_loop_exits): New. > > --- > > gcc/predict.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/gcc/predict.c b/gcc/predict.c > > index 68b11135680..1ae8ccff72c 100644 > > --- a/gcc/predict.c > > +++ b/gcc/predict.c > > @@ -1910,6 +1910,10 @@ predict_extra_loop_exits (edge exit_edge) > > continue; > > if ((check_value_one ^ integer_onep (val)) == 1) > > continue; > > +#if 0 > > + if (e->flags & EDGE_DFS_BACK) > > + continue; > > +#endif > > if (EDGE_COUNT (e->src->succs) != 1) > > { > > predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN); > > -- > > 2.25.1 > >
diff --git a/gcc/predict.c b/gcc/predict.c index 68b11135680..1ae8ccff72c 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -1910,6 +1910,10 @@ predict_extra_loop_exits (edge exit_edge) continue; if ((check_value_one ^ integer_onep (val)) == 1) continue; +#if 0 + if (e->flags & EDGE_DFS_BACK) + continue; +#endif if (EDGE_COUNT (e->src->succs) != 1) { predict_paths_leading_to_edge (e, PRED_LOOP_EXTRA_EXIT, NOT_TAKEN);