From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] PR tree-optimization/109417 - Check if dependency is valid before using in may_recompute_p.
Date: Wed, 5 Apr 2023 16:10:25 -0400 [thread overview]
Message-ID: <a1a81da3-99ab-482e-14aa-59a8f1025ffe@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 679 bytes --]
When a statement is first processed, any SSA_NAMEs that are dependencies
are cached for quick future access.
if we ;later rewrite the statement (say propagate a constant into it),
its possible the ssa-name in this cache is no longer active. Normally
this is not a problem, but the changed to may_recompute_p forgot to take
that into account, and was checking a dependency from the cache that was
in the SSA_NAME_FREE_LIST. It thus had no SSA_NAME_DEF_STMT when we were
expecting one.
This patch simply rejects dependencies from consideration if they are in
the free list.
Bootstrapping on x86_64-pc-linux-gnu and presuming no regressio0ns, OK
for trunk?
Andrew
[-- Attachment #2: 417.diff --]
[-- Type: text/x-patch, Size: 1919 bytes --]
commit ecd86e159e8499feb387bc4d99bd37a5fd6a0d68
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Wed Apr 5 15:59:38 2023 -0400
Check if dependency is valid before using in may_recompute_p.
When the IL is rewritten after a statement has been processed and
dependencies cached, its possible that an ssa-name in the dependency
cache is no longer in the IL. Check this before trying to recompute.
PR tree-optimization/109417
gcc/
* gimple-range-gori.cc (gori_compute::may_recompute_p): Check if
dependency is in SSA_NAME_FREE_LIST.
gcc/testsuite/
* gcc.dg/pr109417.c: New.
diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index 5f4313b27dd..6e2f9533038 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -1314,7 +1314,9 @@ gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
tree dep2 = depend2 (name);
// If the first dependency is not set, there is no recomputation.
- if (!dep1)
+ // Dependencies reflect original IL, not current state. Check if the
+ // SSA_NAME is still valid as well.
+ if (!dep1 || SSA_NAME_IN_FREE_LIST (dep1))
return false;
// Don't recalculate PHIs or statements with side_effects.
diff --git a/gcc/testsuite/gcc.dg/pr109417.c b/gcc/testsuite/gcc.dg/pr109417.c
new file mode 100644
index 00000000000..15711dbbafe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109417.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int printf(const char *, ...);
+int c, d, *e, f[1][2], g;
+int main() {
+ int h = 0, *a = &h, **b[1] = {&a};
+ while (e)
+ while (g) {
+ L:
+ for (h = 0; h < 2; h++) {
+ while (d)
+ for (*e = 0; *e < 1;)
+ printf("0");
+ while (c)
+ ;
+ f[g][h] = 0;
+ }
+ }
+ if (h)
+ goto L;
+ return 0;
+}
+
next reply other threads:[~2023-04-05 20:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 20:10 Andrew MacLeod [this message]
2023-04-05 21:52 ` Jeff Law
2023-04-11 9:21 ` Richard Biener
2023-04-24 13:51 ` Andrew MacLeod
2023-04-25 7:17 ` Richard Biener
2023-04-26 2:34 ` Jeff Law
2023-04-26 19:26 ` [COMMITTED 1/5] PR tree-optimization/109417 - Don't save ssa-name pointer in dependency cache Andrew MacLeod
2023-04-06 10:38 ` [PATCH] PR tree-optimization/109417 - Check if dependency is valid before using in may_recompute_p Jakub Jelinek
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=a1a81da3-99ab-482e-14aa-59a8f1025ffe@redhat.com \
--to=amacleod@redhat.com \
--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).