https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64601
--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> --- I am testing the following hack, I hope there will be at least 1 failure in the testsuite that will help me understand why it is wrong. It bootstraps and gives accesses like MEM[(struct _Vector_impl *)v_4(D)]._M_start. > struct B { int i; int j; }; > struct B b; > int *p = &((struct A *)&b)->i; > *p = 0; Hmmm, yeah, that's ugly... I wish it weren't legal... I'll have to play with it to see exactly how bad it is... Thanks for the example. --- tree-ssa-forwprop.c (revision 219694) +++ tree-ssa-forwprop.c (working copy) @@ -777,20 +777,41 @@ forward_propagate_addr_expr_1 (tree name new_def_rhs); else if (is_gimple_min_invariant (new_def_rhs)) gimple_assign_set_rhs_with_ops (use_stmt_gsi, NOP_EXPR, new_def_rhs); else return false; gcc_assert (gsi_stmt (*use_stmt_gsi) == use_stmt); update_stmt (use_stmt); return true; } + /* *&X -> X. */ + if (TREE_CODE (lhs) == MEM_REF + && TREE_OPERAND (lhs, 0) == name + && integer_zerop (TREE_OPERAND (lhs, 1)) + && useless_type_conversion_p (TREE_TYPE (lhs), + TREE_TYPE (TREE_OPERAND (def_rhs, 0)))) + { + gimple_assign_set_lhs (use_stmt, unshare_expr (TREE_OPERAND (def_rhs, 0))); + tidy_after_forward_propagate_addr (use_stmt); + return true; + } + else if (TREE_CODE (rhs) == MEM_REF + && TREE_OPERAND (rhs, 0) == name + && integer_zerop (TREE_OPERAND (rhs, 1)) + && useless_type_conversion_p (TREE_TYPE (rhs), + TREE_TYPE (TREE_OPERAND (def_rhs, 0)))) + { + gimple_assign_set_rhs1 (use_stmt, unshare_expr (TREE_OPERAND (def_rhs, 0))); + tidy_after_forward_propagate_addr (use_stmt); + return true; + } /* Now strip away any outer COMPONENT_REF/ARRAY_REF nodes from the LHS. ADDR_EXPR will not appear on the LHS. */ tree *lhsp = gimple_assign_lhs_ptr (use_stmt); while (handled_component_p (*lhsp)) lhsp = &TREE_OPERAND (*lhsp, 0); lhs = *lhsp; /* Now see if the LHS node is a MEM_REF using NAME. If so, propagate the ADDR_EXPR into the use of NAME and fold the result. */ if (TREE_CODE (lhs) == MEM_REF