From e06f0ff9f8df758cfd03e9995311f2d6a540d1d4 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Mon, 5 May 2008 09:10:43 -0700 Subject: tree-ssa-forwprop.c (forward_propagate_addr_expr_1): If we have the same size types for... 2008-05-05 Andrew Pinski * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): If we have the same size types for the indirect reference on the rhs, then create a VCE. 2008-05-05 Andrew Pinski * gcc.dg/tree-ssa/forwprop-5.c: New testcase. * gcc.dg/tree-ssa/forwprop-6.c: New testcase. * gcc.dg/tree-ssa/forwprop-7.c: New testcase. * gcc.dg/tree-ssa/forwprop-8.c: New testcase. * gcc.dg/tree-ssa/forwprop-9.c: New testcase. From-SVN: r134947 --- gcc/tree-ssa-forwprop.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'gcc/tree-ssa-forwprop.c') diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index e6402ad..9fbf58d 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -124,6 +124,14 @@ along with GCC; see the file COPYING3. If not see res = x->y->z; Or + ptr = (type1*)&type2var; + res = *ptr + + Will get turned into (if type1 and type2 are the same size + and neither have volatile on them): + res = VIEW_CONVERT_EXPR(type2var) + + Or ptr = &x[0]; ptr2 = ptr + ; @@ -642,6 +650,37 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, tree use_stmt, return true; } + /* Now see if the RHS node is an INDIRECT_REF using NAME. If so, + propagate the ADDR_EXPR into the use of NAME and try to + create a VCE and fold the result. */ + if (TREE_CODE (rhs) == INDIRECT_REF + && TREE_OPERAND (rhs, 0) == name + && TYPE_SIZE (TREE_TYPE (rhs)) + && TYPE_SIZE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) + /* We should not convert volatile loads to non volatile loads. */ + && !TYPE_VOLATILE (TREE_TYPE (rhs)) + && !TYPE_VOLATILE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))) + && operand_equal_p (TYPE_SIZE (TREE_TYPE (rhs)), + TYPE_SIZE (TREE_TYPE (TREE_OPERAND (def_rhs, 0))), 0)) + { + bool res = true; + tree new_rhs = unshare_expr (TREE_OPERAND (def_rhs, 0)); + new_rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs), new_rhs); + /* If we have folded the VCE, then we have to create a new statement. */ + 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. */ + res = false; + } + *rhsp = new_rhs; + fold_stmt_inplace (use_stmt); + tidy_after_forward_propagate_addr (use_stmt); + return res; + } + /* If the use of the ADDR_EXPR is not a POINTER_PLUS_EXPR, there is nothing to do. */ if (TREE_CODE (rhs) != POINTER_PLUS_EXPR -- cgit v1.1