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 E0E9E3857B9B; Thu, 8 Jun 2023 01:55:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0E9E3857B9B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3581kB07017091; Thu, 8 Jun 2023 01:55:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=tYB9sSX8DgnVDY/qOM+dtTaVvffnzAWKgVCXy6lcMno=; b=XaBnOhU/NnQvMCYMpFr3EbFVoatqhiVmEUdQqDaChQqL0bWvLfWgjzS/vae701geJRHY 1JA/7oNjbeXllgVYq3S6eRoN+b9DfVw1dVR6Hwsjv/4uQv1P7FkpwWsplYL7i6fSEDYM D7faLygpbnpQBGOhdttCIL0M1sdiDdoG6S46tBgMPOuFzqm7YWcYFw07a/fLyS+cXXft t5MrMKRbK7vaeO2X6F+o4KPkAWUboPgotgddWmLbhRcikYkZ3PkrFwFotZ8pBIfz8G0e VpDC0RAXBpht18J3lrEHosj0WoF8c7MzOXt5bR0kOXRanHo88n4y2ZGirTuKyJcQltIy kw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35m7g5qn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:58 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3581nxgO027539; Thu, 8 Jun 2023 01:55:58 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35m7g5px-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 357NGJe8028917; Thu, 8 Jun 2023 01:55:55 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3r2a77gyp0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:55 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3581tqsh18678294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2023 01:55:52 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 327602004B; Thu, 8 Jun 2023 01:55:52 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0BBFA20043; Thu, 8 Jun 2023 01:55:51 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 8 Jun 2023 01:55:50 +0000 (GMT) From: Jiufu Guo To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 2/4] rs6000: build constant via lis;rotldi Date: Thu, 8 Jun 2023 09:55:45 +0800 Message-Id: <20230608015547.3432691-3-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230608015547.3432691-1-guojiufu@linux.ibm.com> References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mAEhwF1yek56ReiTRwlFVpxz29FuGvu0 X-Proofpoint-ORIG-GUID: oOQnxutJkoY2sbM-99ia2PM434tLZD_q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_13,2023-06-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 phishscore=0 impostorscore=0 clxscore=1015 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306080010 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, This patch checks if a constant is possible to be rotated to/from a negative value from "lis". If so, we could use "lis;rotldi" to build it. The positive value of "lis" does not need to be analyzed. Because if a constant can be rotated from the positive value of "lis", it also can be rotated from a positive value of "li". Bootstrap and regtest pass on ppc64{,le}. Is this ok for trunk? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/rs6000.cc (can_be_rotated_to_negative_lis): New function. (can_be_built_by_li_and_rotldi): Rename to ... (can_be_built_by_li_lis_and_rotldi): ... this function. (rs6000_emit_set_long_const): Call can_be_built_by_li_lis_and_rotldi. gcc/testsuite/ChangeLog: * gcc.target/powerpc/const-build.c: Add more tests. --- gcc/config/rs6000/rs6000.cc | 42 ++++++++++++++++--- .../gcc.target/powerpc/const-build.c | 16 ++++++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 1dd0072350a..03cd9d5e952 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10278,19 +10278,51 @@ can_be_rotated_to_negative_li (HOST_WIDE_INT c, int *rot) return can_be_rotated_to_lowbits (~c, 15, rot); } -/* Check if value C can be built by 2 instructions: one is 'li', another is - rotldi. +/* Check if C can be rotated to a negative value which 'lis' instruction is + able to load: 1..1xx0..0. If so, set *ROT to the number by which C is + rotated, and return true. Return false otherwise. */ + +static bool +can_be_rotated_to_negative_lis (HOST_WIDE_INT c, int *rot) +{ + /* case a. 1..1xxx0..01..1: up to 15 x's, at least 16 0's. */ + int leading_ones = clz_hwi (~c); + int tailing_ones = ctz_hwi (~c); + int middle_zeros = ctz_hwi (c >> tailing_ones); + if (middle_zeros >= 16 && leading_ones + tailing_ones >= 33) + { + *rot = HOST_BITS_PER_WIDE_INT - tailing_ones; + return true; + } + + /* case b. xx0..01..1xx: some of 15 x's (and some of 16 0's) are + rotated over the highest bit. */ + int pos_one = clz_hwi ((c << 16) >> 16); + middle_zeros = ctz_hwi (c >> (HOST_BITS_PER_WIDE_INT - pos_one)); + int middle_ones = clz_hwi (~(c << pos_one)); + if (middle_zeros >= 16 && middle_ones >= 33) + { + *rot = pos_one; + return true; + } + + return false; +} + +/* Check if value C can be built by 2 instructions: one is 'li or lis', + another is rotldi. If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK is set to -1, and return true. Return false otherwise. */ static bool -can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift, +can_be_built_by_li_lis_and_rotldi (HOST_WIDE_INT c, int *shift, HOST_WIDE_INT *mask) { int n; if (can_be_rotated_to_positive_li (c, &n) - || can_be_rotated_to_negative_li (c, &n)) + || can_be_rotated_to_negative_li (c, &n) + || can_be_rotated_to_negative_lis (c, &n)) { *mask = HOST_WIDE_INT_M1; *shift = HOST_BITS_PER_WIDE_INT - n; @@ -10346,7 +10378,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) emit_move_insn (dest, gen_rtx_XOR (DImode, temp, GEN_INT ((ud2 ^ 0xffff) << 16))); } - else if (can_be_built_by_li_and_rotldi (c, &shift, &mask)) + else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &mask)) { temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); unsigned HOST_WIDE_INT imm = (c | ~mask); diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsuite/gcc.target/powerpc/const-build.c index 70f095f6bf2..c38a1dd91f2 100644 --- a/gcc/testsuite/gcc.target/powerpc/const-build.c +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c @@ -34,14 +34,28 @@ li_rotldi_4 (void) return 0x21ffffffffffff94LL; } +long long NOIPA +lis_rotldi_5 (void) +{ + return 0xffff85310000ffffLL; +} + +long long NOIPA +lis_rotldi_6 (void) +{ + return 0x5310000ffffffff8LL; +} + struct fun arr[] = { {li_rotldi_1, 0x7531000000000LL}, {li_rotldi_2, 0x2100000000000064LL}, {li_rotldi_3, 0xffff8531ffffffffLL}, {li_rotldi_4, 0x21ffffffffffff94LL}, + {lis_rotldi_5, 0xffff85310000ffffLL}, + {lis_rotldi_6, 0x5310000ffffffff8LL}, }; -/* { dg-final { scan-assembler-times {\mrotldi\M} 4 } } */ +/* { dg-final { scan-assembler-times {\mrotldi\M} 6 } } */ int main () -- 2.39.1