On Mon, Jan 2, 2012 at 2:11 PM, Amker.Cheng <amker.ch...@gmail.com> wrote: > Thanks Richard, > > On Mon, Jan 2, 2012 at 8:33 PM, Richard Guenther > <richard.guent...@gmail.com> wrote: >> >> I've previously worked on changing GIMPLE_COND to no longer embed >> the comparison but carry a predicate SSA_NAME only (this is effectively >> what you do as pre-processing before SCCVN). It had some non-trivial >> fallout (for example PRE get's quite confused and ends up separating >> conditionals and jumps too far ...) so I didn't finish it. > Here changing GIMPLE_COND to no longer embed the comparison, > do you mean this only in fre/pre passes or in common? > If only in fre/pre passes, when and how these changed GIMPLE_COND > be changed back to normal ones? > If in common, won't this affects passes working on GIMPLE_COND, like > tree-ssa-forwprop.c?
Everywhere. I posted a patch early last year and changed COND_EXPRs on the RHS of an assignment later. >> >> A subset of all cases can be catched by simply looking up the >> N-ary at eliminate () time and re-writing the GIMPLE_COND to use >> the predicate - which might not actually be beneficial (but forwprop >> will undo not beneficial cases - hopefully). >> >> In the end I'd rather go the way changing the GIMPLE IL to not >> embed the comparison in the GIMPLE_COND - that reduces >> the amount of redundant way we can express the same thing. > Will you try to handle the reversion comparison case as mentioned > in my previous message? I guess this needs both sccvn and fre/pre's > work. It would be great to hear your thoughts on this. Well, with Index: gcc/tree-ssa-pre.c =================================================================== --- gcc/tree-ssa-pre.c (revision 182784) +++ gcc/tree-ssa-pre.c (working copy) @@ -4335,16 +4335,23 @@ eliminate (void) available value-numbers. */ else if (gimple_code (stmt) == GIMPLE_COND) { - tree op0 = gimple_cond_lhs (stmt); - tree op1 = gimple_cond_rhs (stmt); + tree op[2]; tree result; + vn_nary_op_t nary; - if (TREE_CODE (op0) == SSA_NAME) - op0 = VN_INFO (op0)->valnum; - if (TREE_CODE (op1) == SSA_NAME) - op1 = VN_INFO (op1)->valnum; + op[0] = gimple_cond_lhs (stmt); + op[1] = gimple_cond_rhs (stmt); + if (TREE_CODE (op[0]) == SSA_NAME) + op[0] = VN_INFO (op[0])->valnum; + if (TREE_CODE (op[1]) == SSA_NAME) + op[1] = VN_INFO (op[1])->valnum; result = fold_binary (gimple_cond_code (stmt), boolean_type_node, - op0, op1); + op[0], op[1]); + if (!result) + result = vn_nary_op_lookup_pieces (2, gimple_cond_code (stmt), + boolean_type_node, + op, &nary); + if (result && TREE_CODE (result) == INTEGER_CST) { if (integer_zerop (result)) @@ -4354,6 +4361,13 @@ eliminate (void) update_stmt (stmt); todo = TODO_cleanup_cfg; } + else if (result && TREE_CODE (result) == SSA_NAME) + { + gimple_cond_set_code (stmt, NE_EXPR); + gimple_cond_set_lhs (stmt, result); + gimple_cond_set_rhs (stmt, boolean_false_node); + update_stmt (stmt); + } } /* Visit indirect calls and turn them into direct calls if possible. */ you get the CSE (too simple patch, you need to check leaders properly). You can then add similar lookups for an inverted conditional. Richard. > Thanks > > -- > Best Regards.