public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hanke Zhang <hkzhang455@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: Question on replacing .MASK_STORE with ternary expressions
Date: Thu, 26 Oct 2023 00:51:20 +0800	[thread overview]
Message-ID: <CAM_DAs__yXy7dPBZaJGFbJYnz2h=HfVggAVutjym58Pd7vUG8A@mail.gmail.com> (raw)
In-Reply-To: <CAM_DAs81+d7RBnS3-Z+d6oAsASLEqr6GtvtibBrdLALZ_dThzA@mail.gmail.com>

Hi RIchard:

Sorry about the previous mail. I made a mistake that I forgot the
MEM_REF requires two parameters.

After changing to the code here, everything is fine.

tree deref = build1 (MEM_REF , TREE_TYPE (deref_ssa), addr,
build_int_cst (TREE_TYPE (addr), 0));
// ...
tree indirect_ref = build1 (MEM_REF , TREE_TYPE (deref_ssa), addr,
build_int_cst (TREE_TYPE (addr), 0));

Thanks so much for your advice! That helps me a lot! :)

Thanks
Hanke Zhang

Hanke Zhang <hkzhang455@gmail.com> 于2023年10月26日周四 00:09写道:

>
> Hi Richard:
>
> I think I need to get the value that 'addr' points to, is MEM_REF really right?
>
> And I try to replace INDIRECT_REF with MEM_REF like this:
>
> tree deref = build1 (MEM_REF , TREE_TYPE (deref_ssa), addr);
> // ...
> tree indirect_ref = build1 (MEM_REF , TREE_TYPE (deref_ssa), addr);
>
> And the error is different, I think that means the type is not fit.
>
> 0x7afca4 build1(tree_code, tree_node*, tree_node*)
>         ../../gcc/tree.cc:4968
> 0xe8292b replace_mask_store()
>         ../../gcc/tree-if-conv.cc:3486
> 0xe8a03d execute
>         ../../gcc/tree-if-conv.cc:3563
> 0xe8a03d execute
>         ../../gcc/tree-if-conv.cc:3549
>
> Richard Biener <richard.guenther@gmail.com> 于2023年10月25日周三 23:40写道:
> >
> >
> >
> > > Am 25.10.2023 um 17:25 schrieb Hanke Zhang via Gcc <gcc@gcc.gnu.org>:
> > >
> > > Hi, I got a gimple relative question.
> > >
> > > I'm trying to replace the .MASK_STORE with a ternary expression in
> > > pass_ifcvt like below:
> > >
> > > .MASK_STORE(addr, align, mask, value) => *addr = mask ? value : *addr;
> > >
> > > But when I do this, I'm stucked. The addr here is a SSA_NAME of
> > > course. When I try to get the value that 'addr' points to through a
> > > SSA_NAME as lhs like the code below, GCC reports an error.
> > >
> > > // get MASK_STORE
> > > gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
> > > tree addr = gimple_call_arg (stmt, 0);
> > > tree mask = gimple_call_arg (stmt, 2);
> > > tree rhs = gimple_call_arg (stmt, 3);
> > >
> > > // deref_ssa = *addr
> > > tree deref_ssa = create_tmp_reg_or_ssa_name (TREE_TYPE (rhs), NULL);
> > > tree deref = build1 (INDIRECT_REF, TREE_TYPE (deref_ssa), addr);
> > > gimple *stmt1 = gimple_build_assign(deref_ssa, deref);
> > >
> > > // ssa1 = mask ? deref_ssa : rhs
> > > tree cond = build3 (COND_EXPR, TREE_TYPE (rhs), mask, rhs, deref_ssa);
> > > tree ssa1 = create_tmp_reg_or_ssa_name (TREE_TYPE (rhs), NULL);
> > > gimple *stmt2 = gimple_build_assign(ssa1, cond);
> > >
> > > // *addr = ssa1
> > > tree indirect_ref = build1 (INDIRECT_REF, TREE_TYPE (deref_ssa), addr);
> > > gimple *stmt3 = gimple_build_assign(indirect_ref, ssa1);
> > >
> > > // insert stmts
> > > gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT);
> > > gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT);
> > > gsi_insert_before (&gsi, stmt3, GSI_SAME_STMT);
> > >
> > > // remove the origin MASK_STORE
> > > gsi_remove (&gsi, true);
> > >
> > > The error:
> > >
> > > _588 = *_589;
> > > _587 = _136 ? _272 : _588;
> > > *_589 = _587;
> > > unhandled expression in get_expr_operands():
> > > <indirect_ref 0x7f25f5299880
> > >    type <real_type 0x7f25f57a12a0 float SF
> > >        size <integer_cst 0x7f25f5781e40 constant 32>
> > >        unit-size <integer_cst 0x7f25f5781e58 constant 4>
> > >        align:32 warn_if_not_align:0 symtab:0 alias-set 8
> > > canonical-type 0x7f25f57a12a0 precision:32
> > >        pointer_to_this <pointer_type 0x7f25f57a1888>>
> > >
> > >    arg:0 <ssa_name 0x7f25f4fbc948
> > >        type <pointer_type 0x7f25f57a1888 type <real_type 0x7f25f57a12a0 float>
> > >            public unsigned DI
> > >            size <integer_cst 0x7f25f5781c00 constant 64>
> > >            unit-size <integer_cst 0x7f25f5781c18 constant 8>
> > >            align:64 warn_if_not_align:0 symtab:0 alias-set 20
> > > structural-equality>
> > >
> > >        def_stmt _589 = &IMAGPART_EXPR <_452->amplitude>;
> > >        version:589
> > >        ptr-info 0x7f25f5716f18>>
> > >
> > > Is there a way to fix this?
> >
> > You need to use a MEM_REF , not an INDIRECT_REF
> >
> > > Thanks
> > > Hanke Zhang

      reply	other threads:[~2023-10-25 16:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25 15:24 Hanke Zhang
2023-10-25 15:40 ` Richard Biener
2023-10-25 16:09   ` Hanke Zhang
2023-10-25 16:51     ` Hanke Zhang [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='CAM_DAs__yXy7dPBZaJGFbJYnz2h=HfVggAVutjym58Pd7vUG8A@mail.gmail.com' \
    --to=hkzhang455@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=richard.guenther@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).