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 29E4A3858D32; Tue, 13 Jun 2023 03:32:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29E4A3858D32 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 35D3JBBf002865; Tue, 13 Jun 2023 03:32:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type : content-transfer-encoding; s=pp1; bh=9XeujmX5k35O725qIL7IyHu5S+fuy9rxrsEuc/7M2w0=; b=hfay2S4Dxtaj1XpVdVyu7hqnssMK+55Hg8V6Jco0qqGMugb82TQhBeZGg5JAlbRabNBT O8Vsmyf2LBHOTycmAXm855L/8Khf908blTXEDWQmVCHn+kiK9YU3trl2nwGVV0S06dFS l9wqc+N8PyxkuRjLxbIJ+C0yP6EkWulvs0ocizKT0MxOlBu8dtHsSRpTEP2kzrnELjgs DXgfAsUYA636+DBNSIYjR7sGLjlP5Sh6h1UUPHij6lplrXWe22YrBG/9HfCMpc5qa128 yK6b3kjwl4vBBWcTsknIwR4iW/YN0Bbe4KW2GZ54pKv44kWJixlLDkdg4pWyTzSeWJkP lg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r6ges065j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 03:32:57 +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 35D3MUOi012191; Tue, 13 Jun 2023 03:32:56 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r6ges065e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 03:32:56 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35D17V9P014572; Tue, 13 Jun 2023 03:32:56 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([9.208.129.118]) by ppma02wdc.us.ibm.com (PPS) with ESMTPS id 3r4gt5edky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 03:32:56 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35D3WstS63242540 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Jun 2023 03:32:55 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95DDF58067; Tue, 13 Jun 2023 03:32:54 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7751D58065; Tue, 13 Jun 2023 03:32:54 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTPS; Tue, 13 Jun 2023 03:32:54 +0000 (GMT) From: Jiufu Guo To: David Edelsohn Cc: gcc-patches@gcc.gnu.org, segher@kernel.crashing.org, linkw@gcc.gnu.org, bergner@linux.ibm.com Subject: Re: [PATCH 3/4] rs6000: build constant via li/lis;rldicl/rldicr In-Reply-To: (David Edelsohn's message of "Sat, 10 Jun 2023 21:27:20 -0400") References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> <20230608015547.3432691-4-guojiufu@linux.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Tue, 13 Jun 2023 11:32:52 +0800 Message-ID: <7n7cs8c9zv.fsf@ltcden2-lp1.aus.stglabs.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: bxt-PVIUsIxrOl1j-qyDmCmH7f9IUuhn X-Proofpoint-GUID: lHBm9rT_8gnoQtPPyZOftOtxIwekXM6x 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-12_18,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 priorityscore=1501 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130025 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, David Edelsohn writes: >=20=20 > On Wed, Jun 7, 2023 at 9:56=E2=80=AFPM Jiufu Guo = wrote: > > Hi, > > This patch checks if a constant is possible left/right cleaned on a rota= ted > value from a negative value of "li/lis". If so, we can build the consta= nt > through "li/lis ; rldicl/rldicr". > > 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_lis_and_rldicl): N= ew > function. > (can_be_built_by_li_lis_and_rldicr): New function. > (rs6000_emit_set_long_const): Call can_be_built_by_li_lis_and_rl= dicr and > can_be_built_by_li_lis_and_rldicl. > > This is okay. See below. > > Thanks, David > >=20=20 >=20=20 > gcc/testsuite/ChangeLog: > > * gcc.target/powerpc/const-build.c: Add more tests. > --- > gcc/config/rs6000/rs6000.cc | 61 ++++++++++++++++++- > .../gcc.target/powerpc/const-build.c | 44 +++++++++++++ > 2 files changed, 104 insertions(+), 1 deletion(-) > > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index 03cd9d5e952..2a3fa733b45 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -10332,6 +10332,61 @@ can_be_built_by_li_lis_and_rotldi (HOST_WIDE_IN= T c, int *shift, > return false; > } > > +/* Check if value C can be built by 2 instructions: one is 'li or lis', > + another is rldicl. > + > + If so, *SHIFT is set to the shift operand of rldicl, and *MASK is se= t to > + the mask operand of rldicl, and return true. > + Return false otherwise. */ > + > +static bool > +can_be_built_by_li_lis_and_rldicl (HOST_WIDE_INT c, int *shift, > + HOST_WIDE_INT *mask) > +{ > + /* Leading zeros may be cleaned by rldicl with a mask. Change leadin= g zeros > + to ones and then recheck it. */ > + int lz =3D clz_hwi (c); > + HOST_WIDE_INT unmask_c > + =3D c | (HOST_WIDE_INT_M1U << (HOST_BITS_PER_WIDE_INT - lz)); > + int n; > + if (can_be_rotated_to_negative_li (unmask_c, &n) > > using can_be_rotated_to_lowbits (~unmask_c, 15, &n) > > Maybe Segher would want the abstraction, but it seems more wasteful to > me. Thanks! I would update accordingly :) BR, Jeff (Jiufu) Guo >=20=20 > + || can_be_rotated_to_negative_lis (unmask_c, &n)) > + { > + *mask =3D HOST_WIDE_INT_M1U >> lz; > + *shift =3D n =3D=3D 0 ? 0 : HOST_BITS_PER_WIDE_INT - n; > + return true; > + } > + > + return false; > +} > + > +/* Check if value C can be built by 2 instructions: one is 'li or lis', > + another is rldicr. > + > + If so, *SHIFT is set to the shift operand of rldicr, and *MASK is se= t to > + the mask operand of rldicr, and return true. > + Return false otherwise. */ > + > +static bool > +can_be_built_by_li_lis_and_rldicr (HOST_WIDE_INT c, int *shift, > + HOST_WIDE_INT *mask) > +{ > + /* Tailing zeros may be cleaned by rldicr with a mask. Change tailin= g zeros > + to ones and then recheck it. */ > + int tz =3D ctz_hwi (c); > + HOST_WIDE_INT unmask_c =3D c | ((HOST_WIDE_INT_1U << tz) - 1); > + int n; > + if (can_be_rotated_to_negative_li (unmask_c, &n) > + || can_be_rotated_to_negative_lis (unmask_c, &n)) > + { > + *mask =3D HOST_WIDE_INT_M1U << tz; > + *shift =3D 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. */ > @@ -10378,7 +10433,9 @@ 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_lis_and_rotldi (c, &shift, &mask)) > + else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &mask) > + || can_be_built_by_li_lis_and_rldicl (c, &shift, &mask) > + || can_be_built_by_li_lis_and_rldicr (c, &shift, &mask)) > { > temp =3D !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > unsigned HOST_WIDE_INT imm =3D (c | ~mask); > @@ -10387,6 +10444,8 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_= INT c) > emit_move_insn (temp, GEN_INT (imm)); > if (shift !=3D 0) > temp =3D gen_rtx_ROTATE (DImode, temp, GEN_INT (shift)); > + if (mask !=3D HOST_WIDE_INT_M1) > + temp =3D gen_rtx_AND (DImode, temp, GEN_INT (mask)); > emit_move_insn (dest, temp); > } > else if (ud3 =3D=3D 0 && ud4 =3D=3D 0) > diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsu= ite/gcc.target/powerpc/const-build.c > index c38a1dd91f2..8c209921d41 100644 > --- a/gcc/testsuite/gcc.target/powerpc/const-build.c > +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c > @@ -46,6 +46,42 @@ lis_rotldi_6 (void) > return 0x5310000ffffffff8LL; > } > > +long long NOIPA > +li_rldicl_7 (void) > +{ > + return 0x3ffffffa1LL; > +} > + > +long long NOIPA > +li_rldicl_8 (void) > +{ > + return 0xff8531ffffffffLL; > +} > + > +long long NOIPA > +lis_rldicl_9 (void) > +{ > + return 0x00ff85310000ffffLL; > +} > + > +long long NOIPA > +li_rldicr_10 (void) > +{ > + return 0xffff8531fff00000LL; > +} > + > +long long NOIPA > +li_rldicr_11 (void) > +{ > + return 0x21fffffffff00000LL; > +} > + > +long long NOIPA > +lis_rldicr_12 (void) > +{ > + return 0x5310000ffffffff0LL; > +} > + > struct fun arr[] =3D { > {li_rotldi_1, 0x7531000000000LL}, > {li_rotldi_2, 0x2100000000000064LL}, > @@ -53,9 +89,17 @@ struct fun arr[] =3D { > {li_rotldi_4, 0x21ffffffffffff94LL}, > {lis_rotldi_5, 0xffff85310000ffffLL}, > {lis_rotldi_6, 0x5310000ffffffff8LL}, > + {li_rldicl_7, 0x3ffffffa1LL}, > + {li_rldicl_8, 0xff8531ffffffffLL}, > + {lis_rldicl_9, 0x00ff85310000ffffLL}, > + {li_rldicr_10, 0xffff8531fff00000LL}, > + {li_rldicr_11, 0x21fffffffff00000LL}, > + {lis_rldicr_12, 0x5310000ffffffff0LL}, > }; > > /* { dg-final { scan-assembler-times {\mrotldi\M} 6 } } */ > +/* { dg-final { scan-assembler-times {\mrldicl\M} 3 } } */ > +/* { dg-final { scan-assembler-times {\mrldicr\M} 3 } } */ > > int > main () > --=20 > 2.39.1