public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Max Filippov <jcmvbkbc@gmail.com>
To: "Takayuki 'January June' Suwa" <jjsuwa_sys3175@yahoo.co.jp>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2 4/4] xtensa: Improve constant synthesis for both integer and floating-point
Date: Sat, 11 Jun 2022 00:58:55 -0700	[thread overview]
Message-ID: <CAMo8BfLjnoMHeG0vtk2A6aYyNck9VuMjk_oP41ZrBe--P+nAnA@mail.gmail.com> (raw)
In-Reply-To: <200341ff-4907-c6da-07cb-86b9b4588f84@yahoo.co.jp>

Hi Suwa-san,

On Fri, Jun 10, 2022 at 8:28 AM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> This patch revises the previous implementation of constant synthesis.
>
> First, changed to use define_split machine description pattern and to run
> after reload pass, in order not to interfere some optimizations such as
> the loop invariant motion.
>
> Second, not only integer but floating-point is subject to processing.
>
> Third, several new synthesis patterns - when the constant cannot fit into
> a "MOVI Ax, simm12" instruction, but:
>
> I.   can be represented as a power of two minus one (eg. 32767, 65535 or
>       0x7fffffffUL)
>         => "MOVI(.N) Ax, -1" + "SRLI Ax, Ax, 1 ... 31" (or "EXTUI")
> II.  is between -34816 and 34559
>         => "MOVI(.N) Ax, -2048 ... 2047" + "ADDMI Ax, Ax, -32768 ... 32512"
> III. (existing case) can fit into a signed 12-bit if the trailing zero bits
>       are stripped
>         => "MOVI(.N) Ax, -2048 ... 2047" + "SLLI Ax, Ax, 1 ... 31"
>
> The above sequences consist of 5 or 6 bytes and have latency of 2 clock
> cycles,
> in contrast with "L32R Ax, <litpool>" (3 bytes and one clock latency,
> but may
> suffer additional one clock pipeline stall and implementation-specific
> InstRAM/ROM access penalty) plus 4 bytes of constant value.
>
> In addition, 3-instructions synthesis patterns (8 or 9 bytes, 3 clock
> latency)
> are also provided when optimizing for speed and L32R instruction has
> considerable access penalty:
>
> IV.  2-instructions synthesis (any of I ... III) followed by
>       "SLLI Ax, Ax, 1 ... 31"
> V.   2-instructions synthesis followed by either "ADDX[248] Ax, Ax, Ax"
>       or "SUBX8 Ax, Ax, Ax" (multiplying by 3, 5, 7 or 9)
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa-protos.h (xtensa_constantsynth):
>         New prototype.
>         * config/xtensa/xtensa.cc (xtensa_emit_constantsynth,
>         xtensa_constantsynth_2insn, xtensa_constantsynth_rtx_SLLI,
>         xtensa_constantsynth_rtx_ADDSUBX, xtensa_constantsynth):
>         New backend functions that process the abovementioned logic.
>         (xtensa_emit_move_sequence): Revert the previous changes.
>         * config/xtensa/xtensa.md: New split patterns for integer
>         and floating-point, as the frontend part.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/xtensa/constsynth_2insns.c: New.
>         * gcc.target/xtensa/constsynth_3insns.c: Ditto.
>         * gcc.target/xtensa/constsynth_double.c: Ditto.
> ---
>   gcc/config/xtensa/xtensa-protos.h             |   1 +
>   gcc/config/xtensa/xtensa.cc                   | 133 +++++++++++++++---
>   gcc/config/xtensa/xtensa.md                   |  50 +++++++
>   .../gcc.target/xtensa/constsynth_2insns.c     |  44 ++++++
>   .../gcc.target/xtensa/constsynth_3insns.c     |  24 ++++
>   .../gcc.target/xtensa/constsynth_double.c     |  11 ++
>   6 files changed, 247 insertions(+), 16 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.target/xtensa/constsynth_2insns.c
>   create mode 100644 gcc/testsuite/gcc.target/xtensa/constsynth_3insns.c
>   create mode 100644 gcc/testsuite/gcc.target/xtensa/constsynth_double.c

this change results in a bunch of ICEs in the tests like this:

during RTL pass: split2
gcc/gcc/testsuite/gcc.c-torture/compile/20120727-1.c: In function 'f':
gcc/gcc/testsuite/gcc.c-torture/compile/20120727-1.c:13:1: internal
compiler error: in gen_split_5, at config/xtensa/xtensa.md:1186
0x7b6fdb gen_split_5(rtx_insn*, rtx_def**)
       gcc/gcc/config/xtensa/xtensa.md:1186
0xa8f927 try_split(rtx_def*, rtx_insn*, int)
       gcc/gcc/emit-rtl.cc:3795
0xde5fe9 split_insn
       gcc/gcc/recog.cc:3384
0xdecde7 split_all_insns()
       gcc/gcc/recog.cc:3488
0xdecea8 execute
       gcc/gcc/recog.cc:4406

-- 
Thanks.
-- Max

  reply	other threads:[~2022-06-11  7:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10 15:26 Takayuki 'January June' Suwa
2022-06-11  7:58 ` Max Filippov [this message]
2022-06-11  8:31   ` Takayuki 'January June' Suwa
2022-06-11  8:49     ` Max Filippov
2022-06-11  9:05     ` Max Filippov
2022-06-11 10:24       ` [PATCH v3 " Takayuki 'January June' Suwa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMo8BfLjnoMHeG0vtk2A6aYyNck9VuMjk_oP41ZrBe--P+nAnA@mail.gmail.com \
    --to=jcmvbkbc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jjsuwa_sys3175@yahoo.co.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).