public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "juzhe.zhong at rivai dot ai" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/114714] [RISC-V][RVV] ICE: insn does not satisfy its constraints (postreload)
Date: Mon, 22 Apr 2024 22:16:31 +0000	[thread overview]
Message-ID: <bug-114714-4-KvRwn6yhQO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114714-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114714

JuzheZhong <juzhe.zhong at rivai dot ai> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |juzhe.zhong at rivai dot ai

--- Comment #6 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
(In reply to Robin Dapp from comment #5)
> Did anybody do some further investigation here?  Juzhe messaged me that this
> PR is the original reason for the reversal but I don't yet understand why
> the register filters don't encompass the full semantics of RVV overlap.
> 
> I looked into the test case and what happens is that, in order to determine
> the validity of the alternatives, riscv_get_v_regno_alignment is first being
> called with an M2 mode.  Our destination is actually a (subreg:RVVM2SI
> (reg:RVVM4SI ...) 0), though.  I suppose lra/reload check whether a
> non-subreg destination also works and hands us a (reg:RVVM4SI ...) as
> operand[0].  We pass this to riscv_get_v_regno_alignment which, for an LMUL4
> mode, returns 4, thus wrongly enabling the W42 alternatives.
> A W42 alternative permits hard regs % 4 == 2, which causes us to eventually
> choose vr2 as destination and source.  Once the constraints are actually
> checked we have a mismatch as none of the alternatives work.
> 
> Now I'm not at all sure how lra/reload use operand[0] here but this can
> surely be found out.  A quick and dirty hack (attached) that checks the
> insn's destination mode instead of operand[0]'s mode gets rid of the ICE and
> doesn't cause regressions.
> 
> I suppose we're too far ahead with the reversal already but I'd really have
> preferred more details.  Maybe somebody has had in-depth look but it just
> wasn't posted yet?
> 
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -6034,6 +6034,22 @@ riscv_get_v_regno_alignment (machine_mode mode)
>    return lmul;
>  }
>  
> +int
> +riscv_get_dest_alignment (rtx_insn *insn, rtx operand)
> +{
> +  const_rtx set = 0;
> +  if (GET_CODE (PATTERN (insn)) == SET)
> +    {
> +      set = PATTERN (insn);
> +      rtx op = SET_DEST (set);
> +      return riscv_get_v_regno_alignment (GET_MODE (op));
> +    }
> +  else
> +    {
> +      return riscv_get_v_regno_alignment (GET_MODE (operand));
> +    }
> +}
> +
>  /* Define ASM_OUTPUT_OPCODE to do anything special before
>     emitting an opcode.  */
>  const char *
> diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
> index ce1ee6b9c5e..5113daf2ac7 100644
> --- a/gcc/config/riscv/riscv.md
> +++ b/gcc/config/riscv/riscv.md
> @@ -550,15 +550,15 @@ (define_attr "group_overlap_valid" "no,yes"
>           (const_string "yes")
>  
>           (and (eq_attr "group_overlap" "W21")
> -             (match_test "riscv_get_v_regno_alignment (GET_MODE
> (operands[0])) != 2"))
> +             (match_test "riscv_get_dest_alignment (insn, operands[0]) !=
> 2"))
>          (const_string "no")
>  
>           (and (eq_attr "group_overlap" "W42")
> -             (match_test "riscv_get_v_regno_alignment (GET_MODE
> (operands[0])) != 4"))
> +             (match_test "riscv_get_dest_alignment (insn, operands[0]) !=
> 4"))
>          (const_string "no")
>  
>           (and (eq_attr "group_overlap" "W84")
> -             (match_test "riscv_get_v_regno_alignment (GET_MODE
> (operands[0])) != 8"))
> +             (match_test "riscv_get_dest_alignment (insn, operands[0]) !=
> 8"))
>          (const_string "no")

This hack looks good to me. But we already reverted multiple patches (Sorry for
that).

And I think we eventually need to revert them and support register group
overlap 
in another optimal way (Extend constraint for RVV in IRA/LRA).

  parent reply	other threads:[~2024-04-22 22:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-14 16:49 [Bug target/114714] New: " schwab@linux-m68k.org
2024-04-15  1:34 ` [Bug target/114714] " pan2.li at intel dot com
2024-04-15 10:30 ` pan2.li at intel dot com
2024-04-15 13:47 ` kito at gcc dot gnu.org
2024-04-15 14:09 ` pan2.li at intel dot com
2024-04-22 12:56 ` rdapp at gcc dot gnu.org
2024-04-22 22:16 ` juzhe.zhong at rivai dot ai [this message]
2024-04-25 10:14 ` cvs-commit at gcc dot gnu.org

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=bug-114714-4-KvRwn6yhQO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).