From: Richard Biener Date: Mon, 12 Dec 2022 07:56:41 +0000 (+0100) Subject: Revert parts of ADDR_EXPR/CONSTRUCTOR treatment change in match.pd X-Git-Tag: upstream/13.1.0~2636 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49bf49bb6174734879adcba7fb340c1c8f5dd253;p=platform%2Fupstream%2Fgcc.git Revert parts of ADDR_EXPR/CONSTRUCTOR treatment change in match.pd This reverts the part that substitutes from the definition of an SSA name to the capture, thus ADDR_EXPR@0 eventually yielding &y_1->a[i_2] instead of _3. That's because I didn't think of how to deal with substituting @0 in the result pattern. So the following re-instantiates the SSA def CONSTRUCTOR handling and in the ADDR_EXPR helpers used by match.pd handles SSA names defined to ADDR_EXPRs transparently. * genmatch.cc (dt_simplify::gen): Revert last change. * match.pd: Revert simplification of CONSTUCTOR leaf handling. (&x cmp SSA_NAME): Handle ADDR_EXPR in SSA defs. * fold-const.cc (split_address_to_core_and_offset): Handle ADDR_EXPRs in SSA defs. (address_compare): Likewise. --- diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index e80be80..e4c43fb 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -16344,6 +16344,11 @@ split_address_to_core_and_offset (tree exp, poly_int64 bitsize; location_t loc = EXPR_LOCATION (exp); + if (TREE_CODE (exp) == SSA_NAME) + if (gassign *def = dyn_cast (SSA_NAME_DEF_STMT (exp))) + if (gimple_assign_rhs_code (def) == ADDR_EXPR) + exp = gimple_assign_rhs1 (def); + if (TREE_CODE (exp) == ADDR_EXPR) { core = get_inner_reference (TREE_OPERAND (exp, 0), &bitsize, pbitpos, @@ -16628,6 +16633,10 @@ address_compare (tree_code code, tree type, tree op0, tree op1, tree &base0, tree &base1, poly_int64 &off0, poly_int64 &off1, bool generic) { + if (TREE_CODE (op0) == SSA_NAME) + op0 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op0)); + if (TREE_CODE (op1) == SSA_NAME) + op1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op1)); gcc_checking_assert (TREE_CODE (op0) == ADDR_EXPR); gcc_checking_assert (TREE_CODE (op1) == ADDR_EXPR); base0 = get_addr_base_and_unit_offset (TREE_OPERAND (op0, 0), &off0); diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index f53e61a..b56c177 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -3607,26 +3607,14 @@ dt_simplify::gen (FILE *f, int indent, bool gimple, int depth ATTRIBUTE_UNUSED) if (s->capture_max >= 0) { char opname[20]; - fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = {", - s->capture_max + 1); + fprintf_indent (f, indent, "tree captures[%u] ATTRIBUTE_UNUSED = { %s", + s->capture_max + 1, indexes[0]->get_name (opname)); - for (int i = 0; i <= s->capture_max; ++i) + for (int i = 1; i <= s->capture_max; ++i) { if (!indexes[i]) break; - const char *opstr = indexes[i]->get_name (opname); - expr *e = dyn_cast (indexes[i]->op); - fputs (i == 0 ? " " : ", ", f); - if (e && gimple - /* Transparently handle picking up CONSTRUCTOR and ADDR_EXPR - leafs if they appear in a separate definition. */ - && (*e->operation == CONSTRUCTOR - || *e->operation == ADDR_EXPR)) - fprintf (f, "(TREE_CODE (%s) == SSA_NAME " - "? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (%s)) : %s)", - opstr, opstr, opstr); - else - fprintf (f, "%s", opstr); + fprintf (f, ", %s", indexes[i]->get_name (opname)); } fprintf (f, " };\n"); } diff --git a/gcc/match.pd b/gcc/match.pd index 3517605..fdba583 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3936,7 +3936,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (view_convert CONSTRUCTOR@0) (with - { tree ctor = @0; } + { tree ctor = (TREE_CODE (@0) == SSA_NAME + ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); } (switch (if (CONSTRUCTOR_NELTS (ctor) == 0) { build_zero_cst (type); }) @@ -5735,19 +5736,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* SSA names are canonicalized to 2nd place. */ (cmp addr@0 SSA_NAME@1) (with - { poly_int64 off; tree base; } + { + poly_int64 off; tree base; + tree addr = (TREE_CODE (@0) == SSA_NAME + ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); + } /* A local variable can never be pointed to by the default SSA name of an incoming parameter. */ (if (SSA_NAME_IS_DEFAULT_DEF (@1) && TREE_CODE (SSA_NAME_VAR (@1)) == PARM_DECL - && (base = get_base_address (TREE_OPERAND (@0, 0))) + && (base = get_base_address (TREE_OPERAND (addr, 0))) && TREE_CODE (base) == VAR_DECL && auto_var_in_fn_p (base, current_function_decl)) (if (cmp == NE_EXPR) { constant_boolean_node (true, type); } { constant_boolean_node (false, type); }) /* If the address is based on @1 decide using the offset. */ - (if ((base = get_addr_base_and_unit_offset (TREE_OPERAND (@0, 0), &off)) + (if ((base = get_addr_base_and_unit_offset (TREE_OPERAND (addr, 0), &off)) && TREE_CODE (base) == MEM_REF && TREE_OPERAND (base, 0) == @1) (with { off += mem_ref_offset (base).force_shwi (); } @@ -7302,7 +7307,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) == tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (@0)))))))) (with { - tree ctor = @0; + tree ctor = (TREE_CODE (@0) == SSA_NAME + ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); tree eltype = TREE_TYPE (TREE_TYPE (ctor)); unsigned HOST_WIDE_INT width = tree_to_uhwi (TYPE_SIZE (eltype)); unsigned HOST_WIDE_INT n = tree_to_uhwi (@1); @@ -7950,7 +7956,8 @@ and, /* Fold reduction of a single nonzero element constructor. */ (for reduc (IFN_REDUC_PLUS IFN_REDUC_IOR IFN_REDUC_XOR) (simplify (reduc (CONSTRUCTOR@0)) - (with { tree ctor = @0; + (with { tree ctor = (TREE_CODE (@0) == SSA_NAME + ? gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)) : @0); tree elt = ctor_single_nonzero_element (ctor); } (if (elt && !HONOR_SNANS (type) @@ -8169,7 +8176,8 @@ and, (match vec_same_elem_p CONSTRUCTOR@0 - (if (uniform_vector_p (@0)))) + (if (TREE_CODE (@0) == SSA_NAME + && uniform_vector_p (gimple_assign_rhs1 (SSA_NAME_DEF_STMT (@0)))))) (match vec_same_elem_p @0