public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Andrew Pinski <pinskia@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH v2] RISC-V: Produce better code with complex constants [PR95632] [PR106602]
Date: Sun, 5 Mar 2023 12:07:47 -0700	[thread overview]
Message-ID: <c2f42750-37de-8d53-b5dc-9b2f0aa665bb@gmail.com> (raw)
In-Reply-To: <CA+=Sn1npRH781+XNxJ5=y3ghob_LZHCu43qH--2PiaFgVPSaWA@mail.gmail.com>



On 3/5/23 12:03, Andrew Pinski wrote:
> On Sun, Mar 5, 2023 at 10:14 AM Jeff Law via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>>
>>
>>
>> On 2/23/23 14:23, Andrew Pinski via Gcc-patches wrote:
>>> On Fri, Dec 9, 2022 at 10:25 AM Raphael Moreira Zinsly
>>> <rzinsly@ventanamicro.com> wrote:
>>>>
>>>> Changes since v1:
>>>>           - Fixed formatting issues.
>>>>           - Added a name to the define_insn_and_split pattern.
>>>>           - Set the target on the 'dg-do compile' in pr106602.c.
>>>>           - Removed the rv32 restriction in pr95632.c.
>>>>
>>>> -- >8 --
>>>>
>>>> Due to RISC-V limitations on operations with big constants combine
>>>> is failing to match such operations and is not being able to
>>>> produce optimal code as it keeps splitting them.  By pretending we
>>>> can do those operations we can get more opportunities for
>>>> simplification of surrounding instructions.
>>>>
>>>> 2022-12-06  Raphael Moreira Zinsly  <rzinsly@ventanamicro.com>
>>>>               Jeff Law  <jlaw@ventanamicro.com>
>>>>
>>>> gcc/Changelog:
>>>>           PR target/95632
>>>>           PR target/106602
>>>>           * config/riscv/riscv.md: New pattern to simulate complex
>>>>           const_int loads.
>>>>
>>>> gcc/testsuite/ChangeLog:
>>>>           * gcc.target/riscv/pr95632.c: New test.
>>>>           * gcc.target/riscv/pr106602.c: New test.
>>>> ---
>>>>    gcc/config/riscv/riscv.md                 | 15 +++++++++++++++
>>>>    gcc/testsuite/gcc.target/riscv/pr106602.c | 14 ++++++++++++++
>>>>    gcc/testsuite/gcc.target/riscv/pr95632.c  | 15 +++++++++++++++
>>>>    3 files changed, 44 insertions(+)
>>>>    create mode 100644 gcc/testsuite/gcc.target/riscv/pr106602.c
>>>>    create mode 100644 gcc/testsuite/gcc.target/riscv/pr95632.c
>>>>
>>>> diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
>>>> index df57e2b0b4a..b0daa4b19eb 100644
>>>> --- a/gcc/config/riscv/riscv.md
>>>> +++ b/gcc/config/riscv/riscv.md
>>>> @@ -1667,6 +1667,21 @@
>>>>                         MAX_MACHINE_MODE, &operands[3], TRUE);
>>>>    })
>>>>
>>>> +;; Pretend to have the ability to load complex const_int in order to get
>>>> +;; better code generation around them.
>>>> +(define_insn_and_split "*mvconst_internal"
>>>> +  [(set (match_operand:GPR 0 "register_operand" "=r")
>>>> +    (match_operand:GPR 1 "splittable_const_int_operand" "i"))]
>>>> +  "cse_not_expected"
>>>
>>> This is just way broken. This should be combined with the normal move
>>> instructions and just be a define_split.
>>> See PR 108892 for a testcase which shows this breaking how the
>>> register allocator thinks it should work.
>> I'm pretty sure that won't work.  You need them exposed as a define_insn
>> so that they can act as a bridge pattern for combine.  You don't want to
>> expose before combine as that'll regress things in a variety of other
>> ways.  You don't want the bridge form to survive after splitting.  Hence
>> define_insn_and_split.
>>
>> I haven't looked at that bug in detail, but Raphael and I certainly will.
> 
> So the register allocator does not know how to handle if there are two
> different patterns which are to be used but differ by
> constraints/predicats. This is especially true for mov instructions
> which this is.
The define_insn_and_split for this case shouldn't be available for the 
allocator.  If it is, then that's the source of the problem.  We may 
have missed something in the predicates.

> What I am saying is the "*movdi_64bit" and "*movsi_internal" patterns
> should handle the same instruction as the above and still have a
> define_split.
Perhaps but I think that's independent of the problem you're bumping up 
against.  Also note that by the time we're in the allocator we have to 
be more careful as we can't allocate new pseudos.


> 
> Take a look at how aarch64 handles this here. It has one pattern for
> the move but it is a define_insn_and_split still. This is explicitly
> to handle the case you are doing really.
> "*movsi_aarch64" and "*movdi_aarch64" .
Will do.
Jeff

      reply	other threads:[~2023-03-05 19:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 18:25 Raphael Moreira Zinsly
2022-12-16 17:19 ` Jeff Law
2022-12-27 23:32 ` Jeff Law
2023-02-23 21:23 ` Andrew Pinski
2023-03-05 18:13   ` Jeff Law
2023-03-05 19:03     ` Andrew Pinski
2023-03-05 19:07       ` Jeff Law [this message]

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=c2f42750-37de-8d53-b5dc-9b2f0aa665bb@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=pinskia@gmail.com \
    /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).