public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Matthew Malcomson <matmal01@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Fix various other &MEM_REF folds Date: Thu, 5 May 2022 12:09:33 +0000 (GMT) [thread overview] Message-ID: <20220505120933.E7B8A385626C@sourceware.org> (raw) https://gcc.gnu.org/g:69d1babe4658e807e9bb9fbafb912af9d306a642 commit 69d1babe4658e807e9bb9fbafb912af9d306a642 Author: Richard Sandiford <richard.sandiford@arm.com> 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<vn_reference_op_s> *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<SSA_NAME, uhwi>. 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; }
reply other threads:[~2022-05-05 12:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220505120933.E7B8A385626C@sourceware.org \ --to=matmal01@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).