From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/111444 - avoid insertions when skipping defs
Date: Wed, 31 Jan 2024 13:43:00 +0100 (CET) [thread overview]
Message-ID: <20240131124300.GEqNViwk4eRWKZDRDC-6BiWeMhpO5c1ZqkjIGJi178E@z> (raw)
The following avoids inserting expressions for IPA CP discovered
equivalences into the VN hashtables when we are optimistically
skipping may-defs in the attempt to prove it's redundant.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/111444
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Do not use
vn_reference_lookup_2 when optimistically skipping may-defs.
* gcc.dg/torture/pr111444.c: New testcase.
---
gcc/testsuite/gcc.dg/torture/pr111444.c | 26 +++++++++++++++++++++++++
gcc/tree-ssa-sccvn.cc | 22 ++++++++++++---------
2 files changed, 39 insertions(+), 9 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr111444.c
diff --git a/gcc/testsuite/gcc.dg/torture/pr111444.c b/gcc/testsuite/gcc.dg/torture/pr111444.c
new file mode 100644
index 00000000000..e613f255803
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111444.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+
+int a = 3, d, e;
+int *b = &a;
+char c;
+short f;
+const int **g;
+static long h(int **i, int **j)
+{
+ const int *k[46];
+ const int **l = &k[5];
+ *j = &e;
+ g = l;
+ for (; d; d = d + 1)
+ ;
+ **i = 0;
+ return f;
+}
+int main()
+{
+ int *m = &a;
+ h(&m, &m);
+ c = *b;
+ if (c != 3)
+ __builtin_abort ();
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index f0fa718a723..9bed9b3cc69 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -2790,25 +2790,29 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
}
else
{
- tree *saved_last_vuse_ptr = data->last_vuse_ptr;
- /* Do not update last_vuse_ptr in vn_reference_lookup_2. */
- data->last_vuse_ptr = NULL;
tree saved_vuse = vr->vuse;
hashval_t saved_hashcode = vr->hashcode;
- void *res = vn_reference_lookup_2 (ref, gimple_vuse (def_stmt),
- data);
+ if (vr->vuse)
+ vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse);
+ vr->vuse = vuse_ssa_val (gimple_vuse (def_stmt));
+ if (vr->vuse)
+ vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse);
+ vn_reference_t vnresult = NULL;
+ /* Do not use vn_reference_lookup_2 since that might perform
+ expression hashtable insertion but this lookup crosses
+ a possible may-alias making such insertion conditionally
+ invalid. */
+ vn_reference_lookup_1 (vr, &vnresult);
/* Need to restore vr->vuse and vr->hashcode. */
vr->vuse = saved_vuse;
vr->hashcode = saved_hashcode;
- data->last_vuse_ptr = saved_last_vuse_ptr;
- if (res && res != (void *)-1)
+ if (vnresult)
{
- vn_reference_t vnresult = (vn_reference_t) res;
if (TREE_CODE (rhs) == SSA_NAME)
rhs = SSA_VAL (rhs);
if (vnresult->result
&& operand_equal_p (vnresult->result, rhs, 0))
- return res;
+ return vnresult;
}
}
}
--
2.35.3
reply other threads:[~2024-01-31 12:48 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=20240131124300.GEqNViwk4eRWKZDRDC-6BiWeMhpO5c1ZqkjIGJi178E@z \
--to=rguenther@suse.de \
--cc=gcc-patches@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: link
Be 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).