From patchwork Thu Sep 2 09:57:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 1523580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=CiShGLGY; dkim-atps=neutral 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=) 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 4H0bwW2r0qz9sCD for ; Thu, 2 Sep 2021 19:58:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B6763857420 for ; Thu, 2 Sep 2021 09:58:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B6763857420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1630576710; bh=r80eDgHP4z5IGc1If1xkxf6UbUhPf1JfBTKtvrymS1E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CiShGLGYpBK7vPobLjSNtC4wO0uhxQC/FmH7V6Cymon4nR9WhG2MpGrNM+36vSk+w gGosOZ5NMPaz8nIuU2p/0up8Gj7v0aMz87mpTNoCCzVG6pK3aIYRm+KpSc3MaIgSOX rnauaz7bgecL0kHj06NF9tfESdJCFt1l8JC7KOpU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 1596C3858C60 for ; Thu, 2 Sep 2021 09:57:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1596C3858C60 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1829Y8M0088789; Thu, 2 Sep 2021 05:57:47 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3att97kag9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Sep 2021 05:57:47 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1829ZFM4091324; Thu, 2 Sep 2021 05:57:46 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 3att97kafq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Sep 2021 05:57:46 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1829pu9K020992; Thu, 2 Sep 2021 09:57:45 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04fra.de.ibm.com with ESMTP id 3atdxwr0rb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Sep 2021 09:57:44 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1829vfih41222580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Sep 2021 09:57:41 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E2A7A4057; Thu, 2 Sep 2021 09:57:41 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD29AA4053; Thu, 2 Sep 2021 09:57:39 +0000 (GMT) Received: from pike.rch.stglabs.ibm.com (unknown [9.5.12.127]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 2 Sep 2021 09:57:39 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] avoid transform at run until wrap comparesion Date: Thu, 2 Sep 2021 17:57:39 +0800 Message-Id: <20210902095739.192089-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: i9c2_cd7KVyl2ojalTOIkmKzx2egvW0E X-Proofpoint-GUID: v76g8YooEVyR9RiRgY6yJDWK8z1Zik1d X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-09-02_03:2021-09-01, 2021-09-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=547 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 adultscore=0 clxscore=1015 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109020059 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_H4, 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" When transform {iv0.base, iv0.step} LT/LE {iv1.base, iv1.step} to {iv0.base, iv0.step - iv1.step} LT/LE {iv1.base, 0} There would be error if 'iv0.step - iv1.step' in negative, for which means run until wrap/overflow. For example: {1, +, 1} <= {4, +, 3} => {1, +, -2} <= {4, +, 0} This patch avoid this kind transform. Bootstrap and regtest pass on ppc64le. Is this ok for trunk? BR. Jiufu gcc/ChangeLog: 2021-09-02 Jiufu Guo PR tree-optimization/102131 * tree-ssa-loop-niter.c (number_of_iterations_cond): Avoid transform until wrap condition gcc/testsuite/ChangeLog: 2021-09-02 Jiufu Guo PR tree-optimization/102131 * gcc.dg/pr102131.c: New test. --- gcc/tree-ssa-loop-niter.c | 18 +++++++++ gcc/testsuite/gcc.dg/pr102131.c | 69 +++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr102131.c diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 7af92d1c893..52ce517af89 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -1866,6 +1866,24 @@ number_of_iterations_cond (class loop *loop, || !iv0->no_overflow || !iv1->no_overflow)) return false; + /* GT/GE has been transformed to LT/LE already. + cmp_code could be LT, LE or NE + + For LE/LT transform + {iv0.base, iv0.step} LT/LE {iv1.base, iv1.step} + to + {iv0.base, iv0.step - iv1.step} LT/LE {iv1.base, 0} + Negative iv0.step - iv1.step means decreasing until wrap, + then the transform is not accurate. + + For example: + {1, +, 1} <= {4, +, 3} + is not same with + {1, +, -2} <= {4, +, 0} + */ + if ((code == LE_EXPR || code == LT_EXPR) && tree_int_cst_sign_bit (step)) + return false; + iv0->step = step; if (!POINTER_TYPE_P (type)) iv0->no_overflow = false; diff --git a/gcc/testsuite/gcc.dg/pr102131.c b/gcc/testsuite/gcc.dg/pr102131.c new file mode 100644 index 00000000000..0fcfaa132da --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102131.c @@ -0,0 +1,69 @@ +/* { dg-do run } */ + +unsigned int a; +int +fun1 () +{ + unsigned b = 0; + int c = 1; + for (; b < 3; b++) + { + while (c < b) + __builtin_abort (); + for (a = 0; a < 3; a++) + c++; + } + return 0; +} + +unsigned b; +int +fun2 () +{ + unsigned c = 0; + for (a = 0; a < 2; a++) + for (b = 0; b < 2; b++) + if (++c < a) + __builtin_abort (); + return 0; +} + +int +fun3 (void) +{ + unsigned a, b, c = 0; + for (a = 0; a < 10; a++) + { + for (b = 0; b < 2; b++) + { + c++; + if (c < a) + { + __builtin_abort (); + } + } + } + return 0; +} + +int +fun4 () +{ + unsigned i; + for (i = 0; i < 3; ++i) + { + if (i > i * 2) + __builtin_abort (); + } + return 0; +} + +int +main () +{ + fun1 (); + fun2 (); + fun3 (); + fun4 (); + return 0; +}