aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-07-01 11:16:01 +0200
committerRichard Biener <rguenther@suse.de>2021-07-01 12:31:21 +0200
commit4a87605938428f6c4c62d5b92cfc183cd2b2554e (patch)
treea9478e77889df404fa204eefb4b1ff89a54167b1 /gcc
parenta3aaba68405751bae3f630669515b7ecdf77efa6 (diff)
downloadgcc-4a87605938428f6c4c62d5b92cfc183cd2b2554e.zip
gcc-4a87605938428f6c4c62d5b92cfc183cd2b2554e.tar.gz
gcc-4a87605938428f6c4c62d5b92cfc183cd2b2554e.tar.bz2
tree-optimization/101278 - handle self-use in DSE analysis
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. 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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr101278.c21
-rw-r--r--gcc/tree-ssa-dse.c10
2 files changed, 26 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr101278.c b/gcc/testsuite/gcc.dg/torture/pr101278.c
new file mode 100644
index 0000000..1d25658
--- /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 c3939a6..98daa8a 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))