From patchwork Mon Aug 30 06:15:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 1522060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=m6WZu2cE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gyg7t2bb4z9sRf for ; Mon, 30 Aug 2021 16:16:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56889385843D for ; Mon, 30 Aug 2021 06:16:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56889385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1630304196; bh=xvMlJHKfVKhgF/rxuhANrupIw2Env0QLEbw327Ncyww=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=m6WZu2cEOiwqJwg4yCHs1rNlNbiWfU5ilpQqLc1ebENnQpk9so5dpDTjVN97kYnHo ul/3nwYMysln+z5VT9hpRITovapEMEFP4GG19+qcJRwbK8gM/ngp2Y0yWP3uyjLNk2 STsLIJm6jYzpx+HrH/2YCt79Z5tJ02fJRIM/ybEQ= 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 5AE8C3858C3B for ; Mon, 30 Aug 2021 06:15:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5AE8C3858C3B Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17U62ktq018340; Mon, 30 Aug 2021 02:15:44 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3arrtg1bgu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Aug 2021 02:15:44 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17U631Sc018958; Mon, 30 Aug 2021 02:15:43 -0400 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 3arrtg1bg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Aug 2021 02:15:43 -0400 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 17U6BSUr002335; Mon, 30 Aug 2021 06:15:41 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3aqcs8ttwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Aug 2021 06:15:41 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17U6FbPg51642830 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Aug 2021 06:15:37 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6EF9342074; Mon, 30 Aug 2021 06:15:37 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 410594203F; Mon, 30 Aug 2021 06:15:36 +0000 (GMT) Received: from pike.rch.stglabs.ibm.com (unknown [9.5.12.127]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 30 Aug 2021 06:15:36 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Set bound/cmp/control for until wrap loop. Date: Mon, 30 Aug 2021 14:15:35 +0800 Message-Id: <20210830061535.146396-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: oNfaDdO3r-7mNVOupgtrFDs-jKVdMis2 X-Proofpoint-ORIG-GUID: FPUtZmueJwrx6HOnbuiaW1xUy9AWw67C X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-08-30_02:2021-08-27, 2021-08-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=770 malwarescore=0 phishscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108300038 X-Spam-Status: No, score=-11.9 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-Patchwork-Original-From: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo Cc: rguenther@suse.de, segher@kernel.crashing.org, wschmidt@linux.ibm.com, jlaw@tachyum.com, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, In patch r12-3136, niter->control, niter->bound and niter->cmp are derived from number_of_iterations_lt. While for 'until wrap condition', the calculation in number_of_iterations_lt is not align the requirements on the define of them and requirements in determine_exit_conditions. This patch calculate niter->control, niter->bound and niter->cmp in number_of_iterations_until_wrap. The ICEs in the PR are pass with this patch. Bootstrap and reg-tests pass on ppc64/ppc64le and x86. Is this ok for trunk? BR. Jiufu Guo --- gcc/tree-ssa-loop-niter.c | 14 +++++++++++++- gcc/testsuite/gcc.dg/pr102087.c | 25 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/vect/pr101145_3.c | 4 +++- 3 files changed, 41 insertions(+), 2 deletions(-) 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..747f04d3ce0 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); @@ -1513,6 +1513,8 @@ number_of_iterations_until_wrap (class loop *, tree type, affine_iv *iv0, low = wi::to_wide (iv0->base); else low = min; + + niter->control = *iv1; } /* {base, -C} < n. */ else if (tree_int_cst_sign_bit (iv0->step) && integer_zerop (iv1->step)) @@ -1533,6 +1535,8 @@ number_of_iterations_until_wrap (class loop *, tree type, affine_iv *iv0, high = wi::to_wide (iv1->base); else high = max; + + niter->control = *iv0; } else return false; @@ -1556,6 +1560,14 @@ number_of_iterations_until_wrap (class loop *, tree type, affine_iv *iv0, niter->assumptions, assumptions); niter->control.no_overflow = false; + 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..ef1f9f5cba9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102087.c @@ -0,0 +1,25 @@ +/* { 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; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr101145_3.c b/gcc/testsuite/gcc.dg/vect/pr101145_3.c index 99289afec0b..40cb0240aaa 100644 --- a/gcc/testsuite/gcc.dg/vect/pr101145_3.c +++ b/gcc/testsuite/gcc.dg/vect/pr101145_3.c @@ -1,5 +1,6 @@ /* { dg-require-effective-target vect_int } */ /* { dg-options "-O3 -fdump-tree-vect-details" } */ + #define TYPE int * #define MIN ((TYPE)0) #define MAX ((TYPE)((long long)-1)) @@ -10,4 +11,5 @@ #include "pr101145.inc" -/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" } } */ +/* pointer size may not be vectorized, checking niter is ok. */ +/* { dg-final { scan-tree-dump "Symbolic number of iterations is" "vect" } } */