public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Question on replacing .MASK_STORE with ternary expressions
@ 2023-10-25 15:24 Hanke Zhang
  2023-10-25 15:40 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Hanke Zhang @ 2023-10-25 15:24 UTC (permalink / raw)
  To: gcc

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?

Thanks
Hanke Zhang

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question on replacing .MASK_STORE with ternary expressions
  2023-10-25 15:24 Question on replacing .MASK_STORE with ternary expressions Hanke Zhang
@ 2023-10-25 15:40 ` Richard Biener
  2023-10-25 16:09   ` Hanke Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2023-10-25 15:40 UTC (permalink / raw)
  To: Hanke Zhang; +Cc: gcc



> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question on replacing .MASK_STORE with ternary expressions
  2023-10-25 15:40 ` Richard Biener
@ 2023-10-25 16:09   ` Hanke Zhang
  2023-10-25 16:51     ` Hanke Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Hanke Zhang @ 2023-10-25 16:09 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question on replacing .MASK_STORE with ternary expressions
  2023-10-25 16:09   ` Hanke Zhang
@ 2023-10-25 16:51     ` Hanke Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Hanke Zhang @ 2023-10-25 16:51 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-25 16:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-25 15:24 Question on replacing .MASK_STORE with ternary expressions Hanke Zhang
2023-10-25 15:40 ` Richard Biener
2023-10-25 16:09   ` Hanke Zhang
2023-10-25 16:51     ` Hanke Zhang

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).