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 middle-end/111337] ICE in gimple-isel.cc for RISC-V port
Date: Tue, 12 Sep 2023 12:41:37 +0000	[thread overview]
Message-ID: <bug-111337-4-EaM1p1a3hm@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111337-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
(In reply to rguenther@suse.de from comment #6)
> On Tue, 12 Sep 2023, juzhe.zhong at rivai dot ai wrote:
> 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111337
> > 
> > --- Comment #5 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
> > Oh. I see.
> > 
> > 
> > (define_expand "@vcond_mask_<mode><mode>"
> >   [(match_operand:VB 0 "register_operand")
> >    (match_operand:VB 3 "register_operand")
> >    (match_operand:VB 1 "nonmemory_operand")
> >    (match_operand:VB 2 "register_operand")]
> >   "TARGET_VECTOR"
> >   {
> >    printf ("vcond_mask\n");
> >   })
> > 
> > I implemented this pattern which can address this issue....
> > 
> > Note that VB is VECTR_BOOL...
> > 
> > So, this is a more reasonable way to do. Is that right?
> 
> Ah, I suppose ISEL could special-case VECTOR_BOOLEAN_P COND_EXPR
> to expand to bitwise ops - it already does this, but only for
> non-vector-mode masks:
> 
>   /* Lower mask typed, non-vector mode VEC_COND_EXPRs to bitwise 
> operations.
>      Those can end up generated by folding and at least for integer mode 
> masks
>      we cannot expect vcond expanders to exist.  We lower a ? b : c
>      to (b & a) | (c & ~a).  */
>   if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (lhs))
>       && !VECTOR_MODE_P (mode))
>     {
>       gcc_assert (types_compatible_p (TREE_TYPE (op0), TREE_TYPE (op1)));
>       gimple_seq stmts = NULL;
>       tree type = TREE_TYPE (lhs);
>       location_t loc = gimple_location (stmt);
>       tree tem0 = gimple_build (&stmts, loc, BIT_AND_EXPR, type, op1, 
> op0);
>       tree tem1 = gimple_build (&stmts, loc, BIT_NOT_EXPR, type, op0);
>       tree tem2 = gimple_build (&stmts, loc, BIT_AND_EXPR, type, op2, 
> tem1);
>       tree tem3 = gimple_build (&stmts, loc, BIT_IOR_EXPR, type, tem0, 
> tem2);
>       gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
>       return gimple_build_assign (lhs, tem3);
>     }
> 
> that could be a viable expansion strathegy when the rest fails,
> but as you can see we need four stmts for this.  If you can
> think of a smarter, maybe even single-instruction, way for riscv
> then yes, handling the above pattern looks good.
> 
> I wonder whether SVE/GCN have those.

I have supported this pattern but also need 4 instructions:

(define_expand "@vcond_mask_<mode><mode>"
  [(match_operand:VB 0 "register_operand")
   (match_operand:VB 1 "register_operand")
   (match_operand:VB 2 "register_operand")
   (match_operand:VB 3 "register_operand")]
  "TARGET_VECTOR"
  {
    /* mask1 = operands[3] & operands[1].  */
    rtx mask1 = expand_binop (<MODE>mode, and_optab, operands[1],
                              operands[3], NULL_RTX, 0,
                              OPTAB_DIRECT);
    /* mask2 = ~operands[3] & operands[2].  */
    rtx inverse = expand_unop (<MODE>mode, one_cmpl_optab, operands[3],
                               NULL_RTX,
                               OPTAB_DIRECT);
    rtx mask2 = expand_binop (<MODE>mode, and_optab, operands[2],
                              inverse, NULL_RTX, 0,
                              OPTAB_DIRECT);
    /* result = mask1 | mask2.  */
    rtx result = expand_binop (<MODE>mode, ior_optab, mask1,
                               mask2, NULL_RTX, 0,
                               OPTAB_DIRECT);
    emit_move_insn (operands[0], result);
    DONE;
  })

  parent reply	other threads:[~2023-09-12 12:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08  8:39 [Bug c/111337] New: " juzhe.zhong at rivai dot ai
2023-09-08 14:55 ` [Bug c/111337] " rdapp at gcc dot gnu.org
2023-09-12 11:37 ` [Bug middle-end/111337] " rguenth at gcc dot gnu.org
2023-09-12 11:49 ` juzhe.zhong at rivai dot ai
2023-09-12 11:58 ` rguenther at suse dot de
2023-09-12 12:17 ` juzhe.zhong at rivai dot ai
2023-09-12 12:36 ` rguenther at suse dot de
2023-09-12 12:41 ` juzhe.zhong at rivai dot ai [this message]
2023-09-12 12:45 ` rdapp at gcc dot gnu.org
2023-09-12 12:50 ` juzhe.zhong at rivai dot ai
2023-09-12 12:53 ` rdapp at gcc dot gnu.org
2023-09-12 12:55 ` juzhe.zhong at rivai dot ai
2023-09-12 13:03 ` rdapp at gcc dot gnu.org
2023-09-12 14:16 ` rsandifo at gcc dot gnu.org
2023-09-12 20:47 ` cvs-commit at gcc dot gnu.org
2023-09-12 22:15 ` juzhe.zhong at rivai dot ai

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-111337-4-EaM1p1a3hm@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).