From patchwork Fri Jul 9 02:07:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 1502819 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=8.43.85.97; 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=GsPc4G0V; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4GLc5F2hNhz9sWX for ; Fri, 9 Jul 2021 12:08:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26E233AAAC19 for ; Fri, 9 Jul 2021 02:08:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26E233AAAC19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1625796492; bh=iNrIQKncmgw6lFAM/WjietseM8F3XdDQqP2uDAp3x4I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=GsPc4G0Vxge/Q8TNEs2Br49oGuEAWD4l/R8NL9vhBNC5rgQCVLBMYPSkohXBhaOAO 7His6seNHbfoHxH8JYh8fP8SuJ/s7KihzgdiHmKsUTKhPZ29ASyY3wcpZR/sABuWfZ /Gc+RVaczmxosvszUYyfiL3TQFgCjqN8pgHSYQMk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 2DB223858D3C for ; Fri, 9 Jul 2021 02:07:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DB223858D3C Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16923TVm074842; Thu, 8 Jul 2021 22:07:26 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 39p1yc3tkt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jul 2021 22:07:25 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16923USn074958; Thu, 8 Jul 2021 22:07:25 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 39p1yc3tkc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jul 2021 22:07:25 -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 16922mnc009393; Fri, 9 Jul 2021 02:07:23 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04fra.de.ibm.com with ESMTP id 39jfh8ha6n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 02:07:23 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16927Kkc13959548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 02:07:20 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E40211C04C; Fri, 9 Jul 2021 02:07:20 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48FC811C04A; Fri, 9 Jul 2021 02:07:19 +0000 (GMT) Received: from pike.rch.stglabs.ibm.com (unknown [9.5.12.127]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 02:07:19 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Check type size for doloop iv on BITS_PER_WORD [PR61837] Date: Fri, 9 Jul 2021 10:07:18 +0800 Message-Id: <20210709020718.177302-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: V3cJw11oQBiQB213zGFNOvVoanODv73X X-Proofpoint-ORIG-GUID: ue8PEyWW2HQ8TdMS6L-m9lvv1ET_8qx_ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_01:2021-07-09, 2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 malwarescore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090006 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 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, jlaw@tachyum.com, wschmidt@linux.ibm.com, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Currently, doloop.xx variable is using the type as niter which may shorter than word size. For some cases, it may be better to use word size type. For example, on some 64bit system, to access 32bit niter, subreg maybe used. Then using 64bit type would not need to use subreg if the value can be present in both 32bit and 64bit. This patch updates doloop iv to BIT_PER_WORD size if it is fine. Bootstrap and regtest pass on powerpc64le and x86, is this ok for trunk? BR. Jiufu gcc/ChangeLog: 2021-07-08 Jiufu Guo PR target/61837 * tree-ssa-loop-ivopts.c (add_iv_candidate_for_doloop): Update iv on BITS_PER_WORD for niter. gcc/testsuite/ChangeLog: 2021-07-08 Jiufu Guo PR target/61837 * gcc.target/powerpc/pr61837.c: New test. --- gcc/testsuite/gcc.target/powerpc/pr61837.c | 16 ++++++++++++++++ gcc/tree-ssa-loop-ivopts.c | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr61837.c diff --git a/gcc/testsuite/gcc.target/powerpc/pr61837.c b/gcc/testsuite/gcc.target/powerpc/pr61837.c new file mode 100644 index 00000000000..dc44eb9cb41 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr61837.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +void foo(int *p1, long *p2, int s) +{ + int n, v, i; + + v = 0; + for (n = 0; n <= 100; n++) { + for (i = 0; i < s; i++) + if (p2[i] == n) + p1[i] = v; + v += 88; + } +} + +/* { dg-final { scan-assembler-not {\mrldicl\M} } } */ diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 12a8a49a307..c3c2f97918d 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -5690,6 +5690,16 @@ add_iv_candidate_for_doloop (struct ivopts_data *data) tree base = fold_build2 (PLUS_EXPR, ntype, unshare_expr (niter), build_int_cst (ntype, 1)); + + /* Use type in word size may fast. */ + if (TYPE_PRECISION (ntype) < BITS_PER_WORD + && TYPE_PRECISION (long_unsigned_type_node) == BITS_PER_WORD + && wi::ltu_p (niter_desc->max, wi::to_widest (TYPE_MAX_VALUE (ntype)))) + { + ntype = long_unsigned_type_node; + base = fold_convert (ntype, base); + } + add_candidate (data, base, build_int_cst (ntype, -1), true, NULL, NULL, true); }