The following gets rid of SCCVNs valueize_expr which was used on GENERIC expressions built via vn_get_expr_for which is used for stmt combining via fold (yeah, I know ...). The odd way was that it first folded and built the expression and then valueized it (and not folding again), resulting in uncanonicalized (if not unsimplified - but that's unlikely) trees which may lead to missed foldings when combining two of those later.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. (yeah, the gimple folding via pattern description gets rid of all this) Richard. 2014-05-08 Richard Biener <rguent...@suse.de> * tree-ssa-sccvn.c (vn_get_expr_for): Valueize operands before folding the expression. (valueize_expr): Remove. (visit_reference_op_load): Do not valueize the result of vn_get_expr_for. (simplify_binary_expression): Likewise. (simplify_unary_expression): Likewise. Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 210202) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -414,8 +416,8 @@ vn_get_expr_for (tree name) if (!is_gimple_assign (def_stmt)) return vn->valnum; - /* FIXME tuples. This is incomplete and likely will miss some - simplifications. */ + /* Note that we can valueize here because we clear the cached + simplified expressions after each optimistic iteration. */ code = gimple_assign_rhs_code (def_stmt); switch (TREE_CODE_CLASS (code)) { @@ -427,20 +429,21 @@ vn_get_expr_for (tree name) 0)) == SSA_NAME) expr = fold_build1 (code, gimple_expr_type (def_stmt), - TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0)); + vn_valueize (TREE_OPERAND + (gimple_assign_rhs1 (def_stmt), 0))); break; case tcc_unary: expr = fold_build1 (code, gimple_expr_type (def_stmt), - gimple_assign_rhs1 (def_stmt)); + vn_valueize (gimple_assign_rhs1 (def_stmt))); break; case tcc_binary: expr = fold_build2 (code, gimple_expr_type (def_stmt), - gimple_assign_rhs1 (def_stmt), - gimple_assign_rhs2 (def_stmt)); + vn_valueize (gimple_assign_rhs1 (def_stmt)), + vn_valueize (gimple_assign_rhs2 (def_stmt))); break; case tcc_exceptional: @@ -2759,7 +2762,6 @@ defs_to_varying (gimple stmt) } static bool expr_has_constants (tree expr); -static tree valueize_expr (tree expr); /* Visit a copy between LHS and RHS, return true if the value number changed. */ @@ -2900,7 +2902,7 @@ visit_reference_op_load (tree lhs, tree || TREE_CODE (val) == VIEW_CONVERT_EXPR) && TREE_CODE (TREE_OPERAND (val, 0)) == SSA_NAME) { - tree tem = valueize_expr (vn_get_expr_for (TREE_OPERAND (val, 0))); + tree tem = vn_get_expr_for (TREE_OPERAND (val, 0)); if ((CONVERT_EXPR_P (tem) || TREE_CODE (tem) == VIEW_CONVERT_EXPR) && (tem = fold_unary_ignore_overflow (TREE_CODE (val), @@ -3210,26 +3214,6 @@ stmt_has_constants (gimple stmt) return false; } -/* Replace SSA_NAMES in expr with their value numbers, and return the - result. - This is performed in place. */ - -static tree -valueize_expr (tree expr) -{ - switch (TREE_CODE_CLASS (TREE_CODE (expr))) - { - case tcc_binary: - TREE_OPERAND (expr, 1) = vn_valueize (TREE_OPERAND (expr, 1)); - /* Fallthru. */ - case tcc_unary: - TREE_OPERAND (expr, 0) = vn_valueize (TREE_OPERAND (expr, 0)); - break; - default:; - } - return expr; -} - /* Simplify the binary expression RHS, and return the result if simplified. */ @@ -3250,7 +3234,7 @@ simplify_binary_expression (gimple stmt) if (VN_INFO (op0)->has_constants || TREE_CODE_CLASS (code) == tcc_comparison || code == COMPLEX_EXPR) - op0 = valueize_expr (vn_get_expr_for (op0)); + op0 = vn_get_expr_for (op0); else op0 = vn_valueize (op0); } @@ -3259,7 +3243,7 @@ simplify_binary_expression (gimple stmt) { if (VN_INFO (op1)->has_constants || code == COMPLEX_EXPR) - op1 = valueize_expr (vn_get_expr_for (op1)); + op1 = vn_get_expr_for (op1); else op1 = vn_valueize (op1); } @@ -3321,7 +3305,7 @@ simplify_unary_expression (gimple stmt) orig_op0 = op0; if (VN_INFO (op0)->has_constants) - op0 = valueize_expr (vn_get_expr_for (op0)); + op0 = vn_get_expr_for (op0); else if (CONVERT_EXPR_CODE_P (code) || code == REALPART_EXPR || code == IMAGPART_EXPR @@ -3330,7 +3314,7 @@ simplify_unary_expression (gimple stmt) { /* We want to do tree-combining on conversion-like expressions. Make sure we feed only SSA_NAMEs or constants to fold though. */ - tree tem = valueize_expr (vn_get_expr_for (op0)); + tree tem = vn_get_expr_for (op0); if (UNARY_CLASS_P (tem) || BINARY_CLASS_P (tem) || TREE_CODE (tem) == VIEW_CONVERT_EXPR