From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 2596E3858D1E; Thu, 7 Sep 2023 10:00:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2596E3858D1E 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 (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3879cbZ7000988; Thu, 7 Sep 2023 10:00:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : content-type : mime-version; s=pp1; bh=RqrBT3hROPoCaXHSyka62PAMrN58kBXMTeyX7dHyZ+I=; b=RpAwgwGMgF0m7S4NAop2AZHQhYgsHoZWWMhFEqN15JNUmK6p9EwBE0hS+05C9QWXEnyA MAQuexBQ7C8ElR2yrzdxrjcWbNgUTS4DScNivqOVferv0omkNWoWo0o17RPM0YUPpCCY IW+ykltYG46ul+6XpbRYuwXEvIejkiCo9EVMvhsqhzaDkrprMAkr/Tq23wkjyE9s9wz+ HXAVhI0trB7CWRCHhxTY9BJwMMtQK+Qx6laaAKocbPDsxIjIr+pvWWW1P8tst7awW0HH wbsoY+Yj/16GqZfZPoqY7actrC3hEnQsv1LmTVNF0W3CiiIKVXEbe51xLjJ4HnmzgN4w eQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sybvkrp7c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Sep 2023 10:00:35 +0000 Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3879ct4N002298; Thu, 7 Sep 2023 10:00:34 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sybvkrp6w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Sep 2023 10:00:34 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3877qNgC001615; Thu, 7 Sep 2023 09:31:05 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3svfct2v09-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Sep 2023 09:31:05 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3879V5Qp21692822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Sep 2023 09:31:05 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F6C758065; Thu, 7 Sep 2023 09:31:05 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 47DD858069; Thu, 7 Sep 2023 09:31:05 +0000 (GMT) Received: from genoa (unknown [9.40.192.157]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTPS; Thu, 7 Sep 2023 09:31:05 +0000 (GMT) From: Jiufu Guo To: segher@kernel.crashing.org Cc: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com Subject: Re: [PATCH V5 1/4] rs6000: build constant via li;rotldi References: <20230824010834.1525563-1-guojiufu@linux.ibm.com> Date: Thu, 07 Sep 2023 17:31:02 +0800 In-Reply-To: <20230824010834.1525563-1-guojiufu@linux.ibm.com> (Jiufu Guo's message of "Thu, 24 Aug 2023 09:08:34 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vX7arD_zAANzHcj3LUPa5xBiVfV76vrs X-Proofpoint-GUID: MUcYJazV7j3GSNvofExywVgBivNBlNcn X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-07_01,2023-09-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 spamscore=0 suspectscore=0 impostorscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309070084 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP 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, Gentle ping... BR, Jeff (Jiufu Guo) Jiufu Guo writes: > Hi, > > If a constant is possible to be rotated to/from a positive or negative > value which "li" can generated, then "li;rotldi" can be used to build > the constant. > > Compare with the previous version: > https://gcc.gnu.org/pipermail/gcc-patches/2023-July/623528.html > This patch just did minor changes to the comments according to previous > review. > > Bootstrap and regtest pass on ppc64{,le}. > > Is this ok for trunk? > > > BR, > Jeff (Jiufu) > > gcc/ChangeLog: > > * config/rs6000/rs6000.cc (can_be_built_by_li_and_rotldi): New function. > (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi. > > gcc/testsuite/ChangeLog: > > * gcc.target/powerpc/const-build.c: New test. > --- > gcc/config/rs6000/rs6000.cc | 47 +++++++++++++-- > .../gcc.target/powerpc/const-build.c | 57 +++++++++++++++++++ > 2 files changed, 98 insertions(+), 6 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/powerpc/const-build.c > > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index 42f49e4a56b..acc332acc05 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -10258,6 +10258,31 @@ rs6000_emit_set_const (rtx dest, rtx source) > return true; > } > > +/* Check if value C can be built by 2 instructions: one is 'li', another is > + 'rotldi'. > + > + If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK > + is set to the mask operand of rotldi(rldicl), and return true. > + Return false otherwise. */ > + > +static bool > +can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift, > + HOST_WIDE_INT *mask) > +{ > + /* If C or ~C contains at least 49 successive zeros, then C can be rotated > + to/from a positive or negative value that 'li' is able to load. */ > + int n; > + if (can_be_rotated_to_lowbits (c, 15, &n) > + || can_be_rotated_to_lowbits (~c, 15, &n)) > + { > + *mask = HOST_WIDE_INT_M1; > + *shift = HOST_BITS_PER_WIDE_INT - n; > + return true; > + } > + > + return false; > +} > + > /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode. > Output insns to set DEST equal to the constant C as a series of > lis, ori and shl instructions. */ > @@ -10266,15 +10291,14 @@ static void > rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) > { > rtx temp; > + int shift; > + HOST_WIDE_INT mask; > HOST_WIDE_INT ud1, ud2, ud3, ud4; > > ud1 = c & 0xffff; > - c = c >> 16; > - ud2 = c & 0xffff; > - c = c >> 16; > - ud3 = c & 0xffff; > - c = c >> 16; > - ud4 = c & 0xffff; > + ud2 = (c >> 16) & 0xffff; > + ud3 = (c >> 32) & 0xffff; > + ud4 = (c >> 48) & 0xffff; > > if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) > || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) > @@ -10305,6 +10329,17 @@ 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)) > + { > + temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > + unsigned HOST_WIDE_INT imm = (c | ~mask); > + imm = (imm >> shift) | (imm << (HOST_BITS_PER_WIDE_INT - shift)); > + > + emit_move_insn (temp, GEN_INT (imm)); > + if (shift != 0) > + temp = gen_rtx_ROTATE (DImode, temp, GEN_INT (shift)); > + emit_move_insn (dest, temp); > + } > else if (ud3 == 0 && ud4 == 0) > { > temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsuite/gcc.target/powerpc/const-build.c > new file mode 100644 > index 00000000000..69b37e2bb53 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c > @@ -0,1 +1,57 @@ > +/* { dg-do run } */ > +/* { dg-options "-O2 -save-temps" } */ > +/* { dg-require-effective-target has_arch_ppc64 } */ > + > +/* Verify that two instructions are successfully used to build constants. > + One insn is li, another is rotate: rldicl. */ > + > +#define NOIPA __attribute__ ((noipa)) > + > +struct fun > +{ > + long long (*f) (void); > + long long val; > +}; > + > +long long NOIPA > +li_rotldi_1 (void) > +{ > + return 0x7531000000000LL; > +} > + > +long long NOIPA > +li_rotldi_2 (void) > +{ > + return 0x2100000000000064LL; > +} > + > +long long NOIPA > +li_rotldi_3 (void) > +{ > + return 0xffff8531ffffffffLL; > +} > + > +long long NOIPA > +li_rotldi_4 (void) > +{ > + return 0x21ffffffffffff94LL; > +} > + > +struct fun arr[] = { > + {li_rotldi_1, 0x7531000000000LL}, > + {li_rotldi_2, 0x2100000000000064LL}, > + {li_rotldi_3, 0xffff8531ffffffffLL}, > + {li_rotldi_4, 0x21ffffffffffff94LL}, > +}; > + > +/* { dg-final { scan-assembler-times {\mrotldi\M} 4 } } */ > + > +int > +main () > +{ > + for (int i = 0; i < sizeof (arr) / sizeof (arr[0]); i++) > + if ((*arr[i].f) () != arr[i].val) > + __builtin_abort (); > + > + return 0; > +}