From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 1ED363858D32; Fri, 2 Jun 2023 14:22:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1ED363858D32 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-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f50470d77cso2872237e87.0; Fri, 02 Jun 2023 07:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685715772; x=1688307772; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=YyqI42cE1NQ0aA+eZL6tlayqpDimPxLG5D3EU1WyNK4=; b=pCgcO8bm9M/idfh84tuZHKYGDKxijMFfyTDH07y40+YOBMTPRrHJxZZ7xvgp7G5ZDf 8QwuD9+1F/9up6ksp8+YULuoEizdYhe3Urg+rePZO6BrXdx11iZdm1+IlPwQ1HWr0LFx 3pgwiIYlL/1m/1gMFfR1LSxlSkakYNzWwIhuYUFqgpjie+VkhGIGsoYza3x2b3c9wyzi Sou54NbfLGIuw+DkGLDW8X/vj2ANAlgrg5OtbexElUMVRqWzYaJgjCV8Q5uIA2qI9hnf DXVZ+GQDo/N3TkZGpTjFYIaimkwac3m6Jlrp5lhHtjhmKGsU3Wrdrtwo66J8cEphYQ8U DLEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685715772; x=1688307772; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YyqI42cE1NQ0aA+eZL6tlayqpDimPxLG5D3EU1WyNK4=; b=lWwWTfB4/sdhwwIXBozLYZgC/d32dCfIOVeJfiVabJjNMDdv7qNRcVY3GGPO9PKzNT Uvuio1NsisQIPeAlrcPqlmRPvxaYiXUDu5RmJVKoy3ndPzRBDvKQ6r6KvVoOjuf1q+FK RYtVFmR2E9/M47yfiJFZAx0EvfKsCz12CZaPsFRstMRQzEGjoKsdJ8wukY7N3VIxLoas pEGQE9pvqGJMxyIBatHJuNVVGZ+N2YxNqLMh/JpW44bXQ+EvRS1YqtHTOeEqhIdh1D1m xvsiEqpgq8h9cExVClIw5WVlXyGt0WIy5K8VYV+PKyCNzbpcjwTd/WWiFUKvvfT6+tI0 WQmg== X-Gm-Message-State: AC+VfDzts5Y1cprMibO6TAhEBBi/QpiCy89H8hXWi/FeCOlY3H/+LTlz YPEwPQmAP3t+m+46EAXZyKHO395PgYuumO2vNWU= X-Google-Smtp-Source: ACHHUZ6mSn27cjw7Z7/LThMx7hajD/MO8+7KtLpBXIIeJSYU6fN1Og8ZwG+IfIUdiXnnCis7hsR1Dhcul0Gqb7WfMzE= X-Received: by 2002:a05:6512:14f:b0:4f4:ca61:82bb with SMTP id m15-20020a056512014f00b004f4ca6182bbmr1941258lfo.45.1685715772073; Fri, 02 Jun 2023 07:22:52 -0700 (PDT) MIME-Version: 1.0 From: David Edelsohn Date: Fri, 2 Jun 2023 10:22:40 -0400 Message-ID: Subject: Re: [PATCH 1/4] rs6000: build constant via li;rotldi To: Jiufu Guo Cc: GCC Patches , Segher Boessenkool , linkw@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000c96c4005fd264924" X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,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: --000000000000c96c4005fd264924 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Jiufu * config/rs6000/rs6000.cc (can_be_rotated_to_possitive_li): New function. (can_be_rotated_to_negative_li): New function. (can_be_built_by_li_and_rotldi): New function. (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi. In English the word "positive" contains one "s", not two. Please correct throughout the patches. Also a style issue, comments before a function should be followed by a blank line. > +/* Check if C can be rotated to a possitive value which 'li' instruction positive > + is able to load. If so, set *ROT to the number by which C is rotated, > + and return true. Return false otherwise. */ Add a blank line here > +static bool > +can_be_rotated_to_possitive_li (HOST_WIDE_INT c, int *rot) positive > +{ > + /* 49 leading zeros and 15 lowbits on the possitive value low bits, positive > + generated by 'li' instruction. */ > + 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. > + > + 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, > + HOST_WIDE_INT *mask) > +{ > + int n; > + if (can_be_rotated_to_possitive_li (c, &n) > + || can_be_rotated_to_negative_li (c, &n)) > + { > + *mask =3D HOST_WIDE_INT_M1; > + *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. */ > @@ -10246,15 +10285,14 @@ static void> rs6000_emit_set_long_const (rtx d= est, HOST_WIDE_INT c)> {> rtx temp;> + int shift;> + HOST_WIDE_INT ma= sk;> HOST_WIDE_INT ud1, ud2, ud3, ud4;> > ud1 =3D c & 0xffff;> - c = =3D c >> 16;> - ud2 =3D c & 0xffff;> - c =3D c >> 16;> - ud3 =3D c & 0xf= fff;> - c =3D c >> 16;> - ud4 =3D c & 0xffff;> + ud2 =3D (c >> 16) & 0xf= fff;> + ud3 =3D (c >> 32) & 0xffff;> + ud4 =3D (c >> 48) & 0xffff;> > = if ((ud4 =3D=3D 0xffff && ud3 =3D=3D 0xffff && ud2 =3D=3D 0xffff && (ud1 &= 0x8000))> || (ud4 =3D=3D 0 && ud3 =3D=3D 0 && ud2 =3D=3D 0 && ! (ud= 1 & 0x8000)))> @@ -10278,6 +10316,19 @@ rs6000_emit_set_long_const (rtx des= t, HOST_WIDE_INT c)> emit_move_insn (dest, gen_rtx_XOR (DImode, temp= ,> GEN_INT ((ud2 ^ 0xffff) << 16)));> }> + else if (can_be_bui= lt_by_li_and_rotldi (c, &shift, &mask))> + {> + temp =3D !can_creat= e_pseudo_p () ? dest : gen_reg_rtx (DImode);> + unsigned HOST_WIDE_INT= imm =3D (c | ~mask);> + imm =3D (imm >> shift) | (imm << (HOST_BITS_P= ER_WIDE_INT - shift));> +> + emit_move_insn (temp, GEN_INT (imm));> + = if (shift !=3D 0)> + temp =3D gen_rtx_ROTATE (DImode, temp, GEN_INT (s= hift));> + if (mask !=3D HOST_WIDE_INT_M1) How is mask !=3D HOST_WIDE_INT_M1? The call to can_by_built_by_li_and_rotldi() set it to that value and it is not modified in the interim statements. > + 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)> = {> temp =3D !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); Thanks, David --000000000000c96c4005fd264924--