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 <hkzhang...@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.guent...@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 via email to