> 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