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

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