* [PATCH] tree-optimization/101278 - handle self-use in DSE analysis
@ 2021-07-01 10:31 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-07-01 10:31 UTC (permalink / raw)
To: gcc-patches
DSE store classification short-cuts the to-be classified stmt itself
from chaining but fails to first check whether the store uses itself
which can be the case when it is a call with the LHS also passed by
value as argument.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
2021-07-01 Richard Biener <rguenther@suse.de>
PR tree-optimization/101278
* tree-ssa-dse.c (dse_classify_store): First check for
uses, then ignore stmt for chaining purposes.
* gcc.dg/torture/pr101278.c: New testcase.
---
gcc/testsuite/gcc.dg/torture/pr101278.c | 21 +++++++++++++++++++++
gcc/tree-ssa-dse.c | 10 +++++-----
2 files changed, 26 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr101278.c
diff --git a/gcc/testsuite/gcc.dg/torture/pr101278.c b/gcc/testsuite/gcc.dg/torture/pr101278.c
new file mode 100644
index 00000000000..1d25658f37d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr101278.c
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+
+struct X { int counter; };
+
+struct X __attribute__((noipa)) foo (struct X x)
+{
+ x.counter++;
+ if (x.counter == 5)
+ __builtin_exit (0);
+ return x;
+}
+
+int
+main ()
+{
+ struct X x;
+ x.counter = 0;
+ for (int i = 0; i < 10; ++i)
+ x = foo (x);
+ __builtin_abort ();
+}
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index c3939a6417f..98daa8ab24c 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -813,15 +813,11 @@ dse_classify_store (ao_ref *ref, gimple *stmt,
break;
}
- /* We have visited ourselves already so ignore STMT for the
- purpose of chaining. */
- if (use_stmt == stmt)
- ;
/* In simple cases we can look through PHI nodes, but we
have to be careful with loops and with memory references
containing operands that are also operands of PHI nodes.
See gcc.c-torture/execute/20051110-*.c. */
- else if (gimple_code (use_stmt) == GIMPLE_PHI)
+ if (gimple_code (use_stmt) == GIMPLE_PHI)
{
/* If we already visited this PHI ignore it for further
processing. */
@@ -861,6 +857,10 @@ dse_classify_store (ao_ref *ref, gimple *stmt,
fail = true;
break;
}
+ /* We have visited ourselves already so ignore STMT for the
+ purpose of chaining. */
+ else if (use_stmt == stmt)
+ ;
/* If this is a store, remember it as we possibly need to walk the
defs uses. */
else if (gimple_vdef (use_stmt))
--
2.26.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-01 10:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 10:31 [PATCH] tree-optimization/101278 - handle self-use in DSE analysis Richard Biener
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).