]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/96565 - improve DSE with paths ending in noreturn
authorRichard Biener <rguenther@suse.de>
Wed, 26 Aug 2020 06:44:59 +0000 (08:44 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 27 Aug 2020 06:07:34 +0000 (08:07 +0200)
This improves DSEs stmt walking by not considering a DEF without
uses for further processing (and thus giving up when there's two
paths to follow).

2020-08-26  Richard Biener  <rguenther@suse.de>

PR tree-optimization/96565
* tree-ssa-dse.c (dse_classify_store): Remove defs with
no uses from further processing.

* gcc.dg/tree-ssa/ssa-dse-40.c: New testcase.
* gcc.dg/builtin-object-size-4.c: Adjust.

gcc/testsuite/gcc.dg/builtin-object-size-4.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c [new file with mode: 0644]
gcc/tree-ssa-dse.c

index c22654dea2a2c97cdd47b8d7d140ebc2a1b7c15b..9f159e36a0f5a3390594914be8e6826e1eaf5203 100644 (file)
@@ -170,6 +170,9 @@ test1 (void *q, int x)
   r = (char *) L"abcd\0efg";
   if (__builtin_object_size (r + 2, 3) != sizeof (L"abcd\0efg") - 2)
     abort ();
+  /* Prevent DSE from removing calls that prevent bad combining of
+     addresses and offsets.  */
+  asm volatile ("" : : "g" (&a));
 }
 
 size_t l1 = 1;
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c
new file mode 100644 (file)
index 0000000..36f69c0
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-dse1-details" } */
+
+_Bool g(void);
+
+void f(int x)
+{
+  char arr[x];
+
+  arr[0] = 0;
+
+  if (g())
+    __builtin_abort();
+}
+
+/* { dg-final { scan-tree-dump "Deleted dead store" "dse1" } } */
index cc93f559286b465028f61d27b85dd0b380e9b297..76eed06f17f0eec070f77d6404fc62c21760f3f7 100644 (file)
@@ -898,6 +898,17 @@ dse_classify_store (ao_ref *ref, gimple *stmt,
                *by_clobber_p = false;
              defs.unordered_remove (i);
            }
+         /* If the path ends here we do not need to process it further.
+            This for example happens with calls to noreturn functions.  */
+         else if (gimple_code (def) != GIMPLE_PHI
+                  && has_zero_uses (gimple_vdef (def)))
+           {
+             /* But if the store is to global memory it is definitely
+                not dead.  */
+             if (ref_may_alias_global_p (ref))
+               return DSE_STORE_LIVE;
+             defs.unordered_remove (i);
+           }
          /* In addition to kills we can remove defs whose only use
             is another def in defs.  That can only ever be PHIs of which
             we track a single for simplicity reasons (we fail for multiple
This page took 0.078614 seconds and 5 git commands to generate.