From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 175B23858D20; Sun, 11 Jun 2023 01:38:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 175B23858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-973bf581759so548900566b.0; Sat, 10 Jun 2023 18:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686447486; x=1689039486; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HBLU1Ag1MmAjSsS7Nt5cuW1+c1sSmlYu68a+hmmyr3Y=; b=UfKevOWH0K9GpVn7WzMvgXkTbBELDDd8MOHJvDEy9QvQkZ/OXqWXRpM5IOzHQVcaVJ xyjzJZIeGSbUOOOHjJ8BVrrjjzTI3tARbpEHWC+0kRnwY4i0fJfdI2L7dZWsf847Plpj 2PjSkfZ1icIckKcCbfQPs4fP/lqzhE8yijKeEffFGGK24E8vUktKthVpFxU4epTNSB+7 8J/F+fn+9tmSc/Utho8UFHFJmsr7rbJl0K1pWCdW4gQwnii9cfOOArXxb9UrLBpzJiJZ IaFu8jCIUV1tGUrdMOLEPAjqZFmW4DHP8jC/i/DP1PqNEW70Y3JdH9AwjECLOx8SoG/k Pkmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686447486; x=1689039486; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HBLU1Ag1MmAjSsS7Nt5cuW1+c1sSmlYu68a+hmmyr3Y=; b=DkA10JhGmAWo1tTRv2+wXjn8P3sGkwscFUOBeNXbXSpSk8d1r8U5Sn9fCqTsUQg8uP KywXsFU49yTTtI0IUMSnlHW7TnG0MpkWk4etGVO35he8g/M2pr7c53EmX24FGQmiAcNy kRYBdztDbS1EEDr44cXFYH8nfcmrigvFEYG7mm7HgCbQ+0gIRifplnfe7/x83XUixkfG 8adBrOAinH4AIbu/wwrrwcWwbkXgdVXLf63KT4XKUWeqg7vp5XXgQtFt0ZgreudUns/W 1t0XNxtVy349IikZoxoWGcrQSw0wPuTdJlgSByeF/qyQ84eHe+HefDVh5GcvKuuIL+D8 XYTg== X-Gm-Message-State: AC+VfDxzz7Qpm7W4SprPfHQ/lYEmHVg35zyIZ9/Fk6tXzL1k0C21qJ0A UIstCpkznNmA3jc3PQQHGKx4+4aw4JWA0HdenLQ= X-Google-Smtp-Source: ACHHUZ6nC0ANBYk86twiKz/Va3jC5zhJYrRU1iyAE0z+oWXqXN0sWCXkqVouSb2f/HPWV3aERcL6skYxzeXdkGXILzE= X-Received: by 2002:a17:907:1690:b0:965:cc76:7716 with SMTP id hc16-20020a170907169000b00965cc767716mr8012696ejc.76.1686447485402; Sat, 10 Jun 2023 18:38:05 -0700 (PDT) MIME-Version: 1.0 References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> <20230608015547.3432691-5-guojiufu@linux.ibm.com> In-Reply-To: <20230608015547.3432691-5-guojiufu@linux.ibm.com> From: David Edelsohn Date: Sat, 10 Jun 2023 21:37:53 -0400 Message-ID: Subject: Re: [PATCH 4/4] rs6000: build constant via li/lis;rldic To: Jiufu Guo Cc: gcc-patches@gcc.gnu.org, segher@kernel.crashing.org, linkw@gcc.gnu.org, bergner@linux.ibm.com Content-Type: multipart/alternative; boundary="0000000000004cc2cc05fdd0a727" X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: --0000000000004cc2cc05fdd0a727 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 7, 2023 at 9:56=E2=80=AFPM Jiufu Guo w= rote: > Hi, > > This patch checks if a constant is possible to be built by "li;rldic". > We only need to take care of "negative li", other forms do not need to > check. > For example, "negative lis" is just a "negative li" with an additional > shift. > > 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_rldic): New > function. > (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rldic. > This is okay. Do you have any measurement of how expensive it is to test all of these additional methods to generate a constant? How much does this affect the compile time? Thanks, David > > gcc/testsuite/ChangeLog: > > * gcc.target/powerpc/const-build.c: Add more tests. > --- > gcc/config/rs6000/rs6000.cc | 61 ++++++++++++++++++- > .../gcc.target/powerpc/const-build.c | 28 +++++++++ > 2 files changed, 88 insertions(+), 1 deletion(-) > > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index 2a3fa733b45..cd04b6b5c82 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -10387,6 +10387,64 @@ can_be_built_by_li_lis_and_rldicr (HOST_WIDE_INT > c, int *shift, > return false; > } > > +/* Check if value C can be built by 2 instructions: one is 'li', another > is > + rldic. > + > + If so, *SHIFT is set to the 'shift' operand of rldic; and *MASK is set > + to the mask value about the 'mb' operand of rldic; and return true. > + Return false otherwise. */ > + > +static bool > +can_be_built_by_li_and_rldic (HOST_WIDE_INT c, int *shift, HOST_WIDE_INT > *mask) > +{ > + /* There are 49 successive ones in the negative value of 'li'. */ > + int ones =3D 49; > + > + /* 1..1xx1..1: negative value of li --> 0..01..1xx0..0: > + right bits are shifted as 0's, and left 1's(and x's) are cleaned. = */ > + int tz =3D ctz_hwi (c); > + int lz =3D clz_hwi (c); > + int middle_ones =3D clz_hwi (~(c << lz)); > + if (tz + lz + middle_ones >=3D ones) > + { > + *mask =3D ((1LL << (HOST_BITS_PER_WIDE_INT - tz - lz)) - 1LL) << t= z; > + *shift =3D tz; > + return true; > + } > + > + /* 1..1xx1..1 --> 1..1xx0..01..1: some 1's(following x's) are cleaned. > */ > + int leading_ones =3D clz_hwi (~c); > + int tailing_ones =3D ctz_hwi (~c); > + int middle_zeros =3D ctz_hwi (c >> tailing_ones); > + if (leading_ones + tailing_ones + middle_zeros >=3D ones) > + { > + *mask =3D ~(((1ULL << middle_zeros) - 1ULL) << tailing_ones); > + *shift =3D tailing_ones + middle_zeros; > + return true; > + } > + > + /* xx1..1xx: --> xx0..01..1xx: some 1's(following x's) are cleaned. */ > + /* Get the position for the first bit of successive 1. > + The 24th bit would be in successive 0 or 1. */ > + HOST_WIDE_INT low_mask =3D (1LL << 24) - 1LL; > + int pos_first_1 =3D ((c & (low_mask + 1)) =3D=3D 0) > + ? clz_hwi (c & low_mask) > + : HOST_BITS_PER_WIDE_INT - ctz_hwi (~(c | low_mask)= ); > + middle_ones =3D clz_hwi (~c << pos_first_1); > + middle_zeros =3D ctz_hwi (c >> (HOST_BITS_PER_WIDE_INT - pos_first_1)); > + if (pos_first_1 < HOST_BITS_PER_WIDE_INT > + && middle_ones + middle_zeros < HOST_BITS_PER_WIDE_INT > + && middle_ones + middle_zeros >=3D ones) > + { > + *mask =3D ~(((1ULL << middle_zeros) - 1LL) > + << (HOST_BITS_PER_WIDE_INT - pos_first_1)); > + *shift =3D HOST_BITS_PER_WIDE_INT - pos_first_1 + middle_zeros; > + 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. */ > @@ -10435,7 +10493,8 @@ rs6000_emit_set_long_const (rtx dest, > HOST_WIDE_INT c) > } > 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)) > + || can_be_built_by_li_lis_and_rldicr (c, &shift, &mask) > + || can_be_built_by_li_and_rldic (c, &shift, &mask)) > { > temp =3D !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > unsigned HOST_WIDE_INT imm =3D (c | ~mask); > diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c > b/gcc/testsuite/gcc.target/powerpc/const-build.c > index 8c209921d41..b503ee31c7c 100644 > --- a/gcc/testsuite/gcc.target/powerpc/const-build.c > +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c > @@ -82,6 +82,29 @@ lis_rldicr_12 (void) > return 0x5310000ffffffff0LL; > } > > +long long NOIPA > +li_rldic_13 (void) > +{ > + return 0x000f853100000000LL; > +} > +long long NOIPA > +li_rldic_14 (void) > +{ > + return 0xffff853100ffffffLL; > +} > + > +long long NOIPA > +li_rldic_15 (void) > +{ > + return 0x800000ffffffff31LL; > +} > + > +long long NOIPA > +li_rldic_16 (void) > +{ > + return 0x800000000fffff31LL; > +} > + > struct fun arr[] =3D { > {li_rotldi_1, 0x7531000000000LL}, > {li_rotldi_2, 0x2100000000000064LL}, > @@ -95,11 +118,16 @@ struct fun arr[] =3D { > {li_rldicr_10, 0xffff8531fff00000LL}, > {li_rldicr_11, 0x21fffffffff00000LL}, > {lis_rldicr_12, 0x5310000ffffffff0LL}, > + {li_rldic_13, 0x000f853100000000LL}, > + {li_rldic_14, 0xffff853100ffffffLL}, > + {li_rldic_15, 0x800000ffffffff31LL}, > + {li_rldic_16, 0x800000000fffff31LL} > }; > > /* { dg-final { scan-assembler-times {\mrotldi\M} 6 } } */ > /* { dg-final { scan-assembler-times {\mrldicl\M} 3 } } */ > /* { dg-final { scan-assembler-times {\mrldicr\M} 3 } } */ > +/* { dg-final { scan-assembler-times {\mrldic\M} 4 } } */ > > int > main () > -- > 2.39.1 > > --0000000000004cc2cc05fdd0a727--