From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id E7B8A385626C; Thu, 5 May 2022 12:09:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E7B8A385626C Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Fix various other &MEM_REF folds X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 978d3670e25b488ac577ee439a8aba783cee3f41 X-Git-Newrev: 69d1babe4658e807e9bb9fbafb912af9d306a642 Message-Id: <20220505120933.E7B8A385626C@sourceware.org> Date: Thu, 5 May 2022 12:09:33 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 12:09:34 -0000 https://gcc.gnu.org/g:69d1babe4658e807e9bb9fbafb912af9d306a642 commit 69d1babe4658e807e9bb9fbafb912af9d306a642 Author: Richard Sandiford Date: Wed Apr 20 16:56:36 2022 +0100 Fix various other &MEM_REF folds A previous patch fixed a loose &MEM_REF -> POINTER_PLUS_EXPR fold in expand_simple_operations. This patch tries to fix possible instances of the same problem elsewhere. These changes are purely by inspection, so (a) I don't have any testcases that prove that the changes are needed and (b) there are likely to be other instances of the same problem that I missed. But I think the changes make sense on first principles, so I'd prefer to err on the side of having them rather than not. I tried various ways of adding a helper function for this, but all uses are just about different enough that the abstraction felt more awkward than useful. Diff: --- gcc/tree-ssa-phiopt.c | 2 ++ gcc/tree-ssa-sccvn.c | 7 ++++++- gcc/tree-stdarg.c | 37 +++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index dbe935527cb..77d0a8f28ff 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -881,6 +881,8 @@ jump_function_from_stmt (tree *arg, gimple *stmt) &offset); if (tem && TREE_CODE (tem) == MEM_REF + && useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (tem, 0)), + TREE_TYPE (*arg)) && known_eq (mem_ref_offset (tem) + offset, 0)) { *arg = TREE_OPERAND (tem, 0); diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 2adc2626b83..91d085b0adc 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1324,9 +1324,14 @@ vn_reference_maybe_forwprop_address (vec *ops, 0)))) return changed; + tree mem_base = TREE_OPERAND (addr_base, 0); + if (!useless_type_conversion_p (TREE_TYPE (mem_base), + TREE_TYPE (addr))) + return changed; + off += addr_offset; off += mem_ref_offset (addr_base); - op->op0 = TREE_OPERAND (addr_base, 0); + op->op0 = mem_base; } else { diff --git a/gcc/tree-stdarg.c b/gcc/tree-stdarg.c index c05fa3b2f00..6fb68a99948 100644 --- a/gcc/tree-stdarg.c +++ b/gcc/tree-stdarg.c @@ -106,6 +106,25 @@ reachable_at_most_once (basic_block va_arg_bb, basic_block va_start_bb) return ret; } +/* Check if EXP has the form &MEM(SSA_NAME + uhwi) and if it can be folded + to POINTER_PLUS_EXPR. Return the inner MEM_REF if so, + otherwise return null. */ + +static tree +foldable_addr_mem_expr (tree exp) +{ + if (ADDR_EXPR_P (exp) + && TREE_CODE (TREE_OPERAND (exp, 0)) == MEM_REF) + { + tree mem = TREE_OPERAND (exp, 0); + if (TREE_CODE (TREE_OPERAND (mem, 0)) == SSA_NAME + && tree_fits_uhwi_p (TREE_OPERAND (mem, 1)) + && useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (mem, 0)), + TREE_TYPE (exp))) + return mem; + } + return NULL_TREE; +} /* For statement COUNTER = RHS, if RHS is COUNTER + constant, return constant, otherwise return HOST_WIDE_INT_M1U. @@ -174,13 +193,10 @@ va_list_counter_bump (struct stdarg_info *si, tree counter, tree rhs, continue; } - if (ADDR_EXPR_CODE_P (rhs_code) - && TREE_CODE (TREE_OPERAND (rhs1, 0)) == MEM_REF - && TREE_CODE (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0)) == SSA_NAME - && tree_fits_uhwi_p (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1))) + if (tree mem = foldable_addr_mem_expr (rhs1)) { - ret += tree_to_uhwi (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1)); - lhs = TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0); + ret += tree_to_uhwi (TREE_OPERAND (mem, 1)); + lhs = TREE_OPERAND (mem, 0); continue; } @@ -241,13 +257,10 @@ va_list_counter_bump (struct stdarg_info *si, tree counter, tree rhs, continue; } - if (ADDR_EXPR_CODE_P (rhs_code) - && TREE_CODE (TREE_OPERAND (rhs1, 0)) == MEM_REF - && TREE_CODE (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0)) == SSA_NAME - && tree_fits_uhwi_p (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1))) + if (tree mem = foldable_addr_mem_expr (rhs1)) { - val -= tree_to_uhwi (TREE_OPERAND (TREE_OPERAND (rhs1, 0), 1)); - lhs = TREE_OPERAND (TREE_OPERAND (rhs1, 0), 0); + val -= tree_to_uhwi (TREE_OPERAND (mem, 1)); + lhs = TREE_OPERAND (mem, 0); continue; }