From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 799993858D20; Sun, 11 Jun 2023 01:27:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 799993858D20 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-x62f.google.com with SMTP id a640c23a62f3a-977e83d536fso448375566b.3; Sat, 10 Jun 2023 18:27:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686446852; x=1689038852; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1dltrb0XCIVF07mtkBJfZQFWb6orth5SK9TlrzzAZbY=; b=Doaean3Zh+sxT+GGnU5ErMrd60e1R+Dn3RiKx/GoHjxvdyBQP1ibLN6rybDgs7P3fP auN2rHhiZonNkHpTEvBpFnY5MlrZC/OKrWBZoiViI7EF6shx0esO6rdyxjCZ0j1BES2S hTDIZfjl+PK8Vx7zX85BdQf9uI0ZIhyU3egZqp/BcawSpB47gudd0Y6/ZY0I64Wi9juF AYKiJvGWfS1qQzZ3JhfYrb7A8BKFXgy7IMuZqvYmOjji4uWv+ET6nO8t2+fhPF70P0u2 lvx5syx5k/zVqcuzBVobMMIXXO3k/exsFFkS/W4P/bPCqdKkxEilJ4lSX1ml72m6dHmz hqeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686446852; x=1689038852; 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=1dltrb0XCIVF07mtkBJfZQFWb6orth5SK9TlrzzAZbY=; b=UxRAwcNVnCgj6c0N+l4gEAdFwmqouzVEIacKsxHdQgyF+IEzKxoSHvLB3xyVRWED/l L84UZDLtS/99HGy1HQhC+bYhJ44WXGOrxeA6z6azv46uA6FakO59NuZdEsXpXx50xke9 TFrQE0oqkuBbjWGx7thmv4rrGGtAiGvvJoM9FvFgFJ/+h4q/ojSLnmpFJZwmi5qBl1Eh C/bQQL+DRSb88UQt1jRChH2bMnuRpnW3W6JzuQue2ZfH9W8rIi7MtDDGLL8mJ5uyx4ly tJBzFAEoOCdJMx1KuRpbZbGUBLyUoAW/VZGOXG1JEjBsBdQ3tgMLsZsDqsD4ofWifWDS MobQ== X-Gm-Message-State: AC+VfDxnKwZaayJf1jxRsRA4eNtUn5nNkr82w3eTzNTruBxH54tGz27x DxrpTyom3ba+D6z9+G0Zpjbtz2vahgYVQUle8fI= X-Google-Smtp-Source: ACHHUZ7eGf+ddFflST5TFCYPfuBBg+McEkWyL4+4gadhLBszVV5d0qc632KigBtFvlng9ztuayOz7zc0vKDpXfgfcEw= X-Received: by 2002:a17:906:d54a:b0:96f:5902:8c4d with SMTP id cr10-20020a170906d54a00b0096f59028c4dmr5282478ejc.27.1686446852014; Sat, 10 Jun 2023 18:27:32 -0700 (PDT) MIME-Version: 1.0 References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> <20230608015547.3432691-4-guojiufu@linux.ibm.com> In-Reply-To: <20230608015547.3432691-4-guojiufu@linux.ibm.com> From: David Edelsohn Date: Sat, 10 Jun 2023 21:27:20 -0400 Message-ID: Subject: Re: [PATCH 3/4] rs6000: build constant via li/lis;rldicl/rldicr 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="0000000000008c054c05fdd08152" X-Spam-Status: No, score=-7.3 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: --0000000000008c054c05fdd08152 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 left/right cleaned on a rotat= ed > value from a negative value of "li/lis". If so, we can build the constant > 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): New > function. > (can_be_built_by_li_lis_and_rldicr): New function. > (rs6000_emit_set_long_const): Call > can_be_built_by_li_lis_and_rldicr and > can_be_built_by_li_lis_and_rldicl. > This is okay. See below. 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 | 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_INT > 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 set > 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 leading > 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. > + || 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 set > 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 tailing > 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/testsuite/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 () > -- > 2.39.1 > > --0000000000008c054c05fdd08152--