------- Comment #8 from pinskia at gcc dot gnu dot org 2008-05-07 17:21 ------- Fix it: [andrew-pinskis-computer:local/gcc/gcc] apinski% svn diff Index: tree-ssa-forwprop.c =================================================================== --- tree-ssa-forwprop.c (revision 135021) +++ tree-ssa-forwprop.c (working copy) @@ -132,6 +132,16 @@ along with GCC; see the file COPYING3. res = VIEW_CONVERT_EXPR<type1>(type2var)
Or + ptr = (type1*)&type2var; + *ptr = res + + Will get turned into (if type1 and type2 are the same size + and neither have volatile on them and is not a scalar): + VIEW_CONVERT_EXPR<type1>(type2var) = res + FIXME: The last constraint is not needed if DECL_GIMPLE_REG_P is expended + to all types + + Or ptr = &x[0]; ptr2 = ptr + <constant>; @@ -573,6 +583,7 @@ forward_propagate_addr_expr_1 (tree name { tree lhs, rhs, array_ref; tree *rhsp, *lhsp; + bool in_reference_lhs = false; gcc_assert (TREE_CODE (def_rhs) == ADDR_EXPR); @@ -602,7 +613,10 @@ forward_propagate_addr_expr_1 (tree name ADDR_EXPR will not appear on the LHS. */ lhsp = &GIMPLE_STMT_OPERAND (use_stmt, 0); while (handled_component_p (*lhsp)) - lhsp = &TREE_OPERAND (*lhsp, 0); + { + lhsp = &TREE_OPERAND (*lhsp, 0); + in_reference_lhs = true; + } lhs = *lhsp; /* Now see if the LHS node is an INDIRECT_REF using NAME. If so, @@ -617,6 +631,43 @@ forward_propagate_addr_expr_1 (tree name TREE_TYPE (TREE_OPERAND (def_rhs, 0)))) { *lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0)); + lhs = *lhsp; + fold_stmt_inplace (use_stmt); + tidy_after_forward_propagate_addr (use_stmt); + + /* Continue propagating into the RHS if this was not the only use. */ + if (single_use_p) + return true; + } + + /* Now see if the LHS node is an INDIRECT_REF using NAME. If so, + propagate the ADDR_EXPR into the use of NAME and try to + create a VCE for the result. */ + if (TREE_CODE (lhs) == INDIRECT_REF + && TREE_OPERAND (lhs, 0) == name + && TYPE_SIZE (TREE_TYPE (lhs)) + && TYPE_SIZE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) + /* Function decls should not be used for VCE either as it could be + a function descriptor that we want and not the actual function code. */ + && TREE_CODE (TREE_OPERAND (def_rhs, 0)) != FUNCTION_DECL + /* We should not convert volatile loads to non volatile loads. */ + && !TYPE_VOLATILE (TREE_TYPE (lhs)) + && !TYPE_VOLATILE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) + && operand_equal_p (TYPE_SIZE (TREE_TYPE (lhs)), + TYPE_SIZE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))), 0) + /* Check for aggregate types so we don't end up with a SSA_NAME inside + a VIEW_CONVERT_EXPR on the lhs. + FIXME: this can go away when DECL_GIMPLE_REG_P is extended for all + scalar types. */ + && (AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) + || TREE_CODE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) == VECTOR_TYPE + || TREE_CODE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) == COMPLEX_TYPE)) + { + tree new_lhs = unshare_expr (TREE_OPERAND (def_rhs, 0)); + /* Use build1 here as we not produce a right hand side so we need to keep + around the VCE. */ + new_lhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), new_lhs); + *lhsp = new_lhs; fold_stmt_inplace (use_stmt); tidy_after_forward_propagate_addr (use_stmt); @@ -673,9 +724,10 @@ forward_propagate_addr_expr_1 (tree name if (TREE_CODE (new_rhs) != VIEW_CONVERT_EXPR) { block_stmt_iterator bsi = bsi_for_stmt (use_stmt); - new_rhs = force_gimple_operand_bsi (&bsi, new_rhs, true, NULL, true, BSI_SAME_STMT); - /* As we change the deference to a SSA_NAME, we need to return false to make sure that - the statement does not get removed. */ + new_rhs = force_gimple_operand_bsi (&bsi, new_rhs, true, NULL, true, + BSI_SAME_STMT); + /* As we change the deference to a SSA_NAME, we need to return false + to make sure that the statement does not get removed. */ res = false; } *rhsp = new_rhs; -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot gnu |pinskia at gcc dot gnu dot |dot org |org Status|NEW |ASSIGNED http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36143