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 81C123858436 for ; Thu, 2 Sep 2021 12:51:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81C123858436 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 182CXvPC025548; Thu, 2 Sep 2021 08:51:37 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3atx7tha19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Sep 2021 08:51:37 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 182CXx7V025703; Thu, 2 Sep 2021 08:51:36 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 3atx7tha0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Sep 2021 08:51:36 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 182ClnGR020663; Thu, 2 Sep 2021 12:51:35 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma03wdc.us.ibm.com with ESMTP id 3atdxuagxy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Sep 2021 12:51:35 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 182CpY8Z13959624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Sep 2021 12:51:34 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 45D1428067; Thu, 2 Sep 2021 12:51:34 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE43828064; Thu, 2 Sep 2021 12:51:33 +0000 (GMT) Received: from pike (unknown [9.5.12.127]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTPS; Thu, 2 Sep 2021 12:51:33 +0000 (GMT) From: Jiufu Guo To: Richard Biener Cc: gcc-patches@gcc.gnu.org, amker.cheng@gmail.com, wschmidt@linux.ibm.com, segher@kernel.crashing.org, dje.gcc@gmail.com, jlaw@tachyum.com Subject: [PATCH V2] Set bound/cmp/control for until wrap loop. References: <20210830061535.146396-1-guojiufu@linux.ibm.com> <70ea087486feb85536100fa538c877f4@imap.linux.ibm.com> Date: Thu, 02 Sep 2021 20:51:30 +0800 In-Reply-To: (Richard Biener's message of "Tue, 31 Aug 2021 15:37:39 +0200 (CEST)") Message-ID: <7epmtri1il.fsf_-_@pike.rch.stglabs.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KY2Gm3HwEErn_Y4wEyJ18Ldq_CW2QMqA X-Proofpoint-GUID: vTttqUH0fVRO0ApvoPFURBuFB-VrvGX1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-09-02_04:2021-09-02, 2021-09-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 malwarescore=0 bulkscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109020076 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Sep 2021 12:51:40 -0000 Changes on V1: * Add more test case * Add comment for exit-condition transform * Removing duplicate setting on niter->control This patch reset niter->control, niter->bound and niter->cmp in number_of_iterations_until_wrap. Bootstrap and test pass on ppc64 and x86, and pass the test cases in PR. Is this ok for trunk? One thing, in this patch, the IVbase is still keep as biasing by 1 step. BR. Jiufu Guo gcc/ChangeLog: 2021-09-02 Jiufu Guo PR tree-optimization/102087 * tree-ssa-loop-niter.c (number_of_iterations_until_wrap): Update bound/cmp/control for niter. gcc/testsuite/ChangeLog: 2021-09-02 Jiufu Guo PR tree-optimization/102087 * gcc.dg/pr102087.c: New test. --- gcc/tree-ssa-loop-niter.c | 16 ++++++++++++++- gcc/testsuite/gcc.dg/pr102087.c | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr102087.c diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 7af92d1c893..75109407124 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -1482,7 +1482,7 @@ number_of_iterations_until_wrap (class loop *, tree type, affine_iv *iv0, affine_iv *iv1, class tree_niter_desc *niter) { tree niter_type = unsigned_type_for (type); - tree step, num, assumptions, may_be_zero; + tree step, num, assumptions, may_be_zero, span; wide_int high, low, max, min; may_be_zero = fold_build2 (LE_EXPR, boolean_type_node, iv1->base, iv0->base); @@ -1557,6 +1557,20 @@ number_of_iterations_until_wrap (class loop *, tree type, affine_iv *iv0, niter->control.no_overflow = false; + /* Update bound and exit condition as: + bound = niter * STEP + (IVbase - STEP). + { IVbase - STEP, +, STEP } != bound + Here, biasing IVbase by 1 step makes 'bound' be the value before wrap. + */ + niter->control.base = fold_build2 (MINUS_EXPR, niter_type, + niter->control.base, niter->control.step); + span = fold_build2 (MULT_EXPR, niter_type, niter->niter, + fold_convert (niter_type, niter->control.step)); + niter->bound = fold_build2 (PLUS_EXPR, niter_type, span, + fold_convert (niter_type, niter->control.base)); + niter->bound = fold_convert (type, niter->bound); + niter->cmp = NE_EXPR; + return true; } diff --git a/gcc/testsuite/gcc.dg/pr102087.c b/gcc/testsuite/gcc.dg/pr102087.c new file mode 100644 index 00000000000..fc60cbda066 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102087.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +unsigned __attribute__ ((noinline)) +foo (int *__restrict__ a, int *__restrict__ b, unsigned l, unsigned n) +{ + while (n < ++l) + *a++ = *b++ + 1; + return l; +} + +volatile int a[1]; +unsigned b; +int c; + +int +check () +{ + int d; + for (; b > 1; b++) + for (c = 0; c < 2; c++) + for (d = 0; d < 2; d++) + a[0]; + return 0; +} + +char **Gif_ClipImage_gfi_0; +int Gif_ClipImage_y, Gif_ClipImage_shift; +void +Gif_ClipImage () +{ + for (; Gif_ClipImage_y >= Gif_ClipImage_shift; Gif_ClipImage_y++) + Gif_ClipImage_gfi_0[Gif_ClipImage_shift] + = Gif_ClipImage_gfi_0[Gif_ClipImage_y]; +} -- 2.17.1