These are some minor improvements to tree-ssa-dse, in particular it adds
handling of the _CHK variants of the supported functions (memcpy,
memmove, memset).  It's just something I noticed while poking at 90883.

These don't trigger during bootstraps, but do in the testsuite.   The
tests that were changed were verified to make sure that the
removal/trimming of *_CHK calls were correct.  For example, some tests
in the c-torture/builtins directory do things like

  __builtin_memset_chk (...);
  abort ();

Since the memory locations are never read, DSE just removes the call.
This happened with enough regularity in the c-torture/execute/builtins
tests that I changed the .exp driver to add the -fno-tree-dse flag.  In
the other cases I just changed the affected tests.

Bootstrapped and regression tested  on x86_64, ppc64le, sparc64, others
will follow (aarch, ppc64, i686, etc).  It's built toolchains &
libraries and regression tested on a wide variety of other platforms as
well.


OK for the trunk?

jeff
        * tree-ssa-dse.c (initialize_ao_ref_for_dse): Handle _chk variants of
        memcpy, memmove and memset builtins.
        (maybe_trim_memstar_call): Likewise.

        * gcc.c-torture/execute/builtins/builtins.exp: Add -fno-tree-dse
        as DSE compromises several of these tests.
        * gcc.dg/builtin-stringop-chk-1.c: Similarly.
        * gcc.dg/memcpy-2.c: Similarly.
        * gcc.dg/pr40340-1.c: Similarly.
        * gcc.dg/pr40340-2.c: Similarly.
        * gcc.dg/pr40340-5.c: Similarly.

diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index aa998f416c7..82e6dbfeb96 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -98,6 +98,9 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write)
          case BUILT_IN_MEMCPY:
          case BUILT_IN_MEMMOVE:
          case BUILT_IN_MEMSET:
+         case BUILT_IN_MEMCPY_CHK:
+         case BUILT_IN_MEMMOVE_CHK:
+         case BUILT_IN_MEMSET_CHK:
            {
              tree size = NULL_TREE;
              if (gimple_call_num_args (stmt) == 3)
@@ -434,6 +437,8 @@ maybe_trim_memstar_call (ao_ref *ref, sbitmap live, gimple 
*stmt)
     {
     case BUILT_IN_MEMCPY:
     case BUILT_IN_MEMMOVE:
+    case BUILT_IN_MEMCPY_CHK:
+    case BUILT_IN_MEMMOVE_CHK:
       {
        int head_trim, tail_trim;
        compute_trims (ref, live, &head_trim, &tail_trim, stmt);
@@ -455,6 +460,7 @@ maybe_trim_memstar_call (ao_ref *ref, sbitmap live, gimple 
*stmt)
       }
 
     case BUILT_IN_MEMSET:
+    case BUILT_IN_MEMSET_CHK:
       {
        int head_trim, tail_trim;
        compute_trims (ref, live, &head_trim, &tail_trim, stmt);
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/builtins.exp 
b/gcc/testsuite/gcc.c-torture/execute/builtins/builtins.exp
index 5e899d5e31e..fb9d3ece181 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/builtins.exp
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/builtins.exp
@@ -37,7 +37,7 @@ load_lib c-torture.exp
 torture-init
 set-torture-options $C_TORTURE_OPTIONS {{}} $LTO_TORTURE_OPTIONS
 
-set additional_flags "-fno-tree-loop-distribute-patterns -fno-tracer"
+set additional_flags "-fno-tree-dse -fno-tree-loop-distribute-patterns 
-fno-tracer"
 if [istarget "powerpc-*-darwin*"] {
    lappend additional_flags "-Wl,-multiply_defined,suppress"
 }
diff --git a/gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c 
b/gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c
index afd07ddd08d..40cfa047290 100644
--- a/gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c
+++ b/gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c
@@ -1,7 +1,7 @@
 /* Test whether buffer overflow warnings for __*_chk builtins
    are emitted properly.  */
 /* { dg-do compile } */
-/* { dg-options "-O2 -Wno-format -std=gnu99 -ftrack-macro-expansion=0" } */
+/* { dg-options "-O2 -Wno-format -std=gnu99 -ftrack-macro-expansion=0 
-fno-tree-dse" } */
 // { dg-skip-if "packed attribute missing for t" { "epiphany-*-*" } }
 
 extern void abort (void);
diff --git a/gcc/testsuite/gcc.dg/memcpy-2.c b/gcc/testsuite/gcc.dg/memcpy-2.c
index 7f839d27abd..6ad887416e3 100644
--- a/gcc/testsuite/gcc.dg/memcpy-2.c
+++ b/gcc/testsuite/gcc.dg/memcpy-2.c
@@ -1,6 +1,6 @@
 /* PR middle-end/38454 */
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -fno-tree-dse" } */
 
 typedef __SIZE_TYPE__ size_t;
 
diff --git a/gcc/testsuite/gcc.dg/pr40340-1.c b/gcc/testsuite/gcc.dg/pr40340-1.c
index 8fbb206a21e..6307e064c3d 100644
--- a/gcc/testsuite/gcc.dg/pr40340-1.c
+++ b/gcc/testsuite/gcc.dg/pr40340-1.c
@@ -1,6 +1,6 @@
 /* PR middle-end/40340 */
 /* { dg-do compile } */
-/* { dg-options "-O2 -Wall -Wno-system-headers" } */
+/* { dg-options "-O2 -Wall -Wno-system-headers -fno-tree-dse" } */
 
 #include "pr40340.h"
 
diff --git a/gcc/testsuite/gcc.dg/pr40340-2.c b/gcc/testsuite/gcc.dg/pr40340-2.c
index 10083acd102..ea76e10082d 100644
--- a/gcc/testsuite/gcc.dg/pr40340-2.c
+++ b/gcc/testsuite/gcc.dg/pr40340-2.c
@@ -1,6 +1,6 @@
 /* PR middle-end/40340 */
 /* { dg-do compile } */
-/* { dg-options "-O2 -Wall -Wno-system-headers" } */
+/* { dg-options "-O2 -Wall -Wno-system-headers -fno-tree-dse" } */
 
 #include "pr40340.h"
 
diff --git a/gcc/testsuite/gcc.dg/pr40340-5.c b/gcc/testsuite/gcc.dg/pr40340-5.c
index 0e48a2ca943..99e58f2ab7f 100644
--- a/gcc/testsuite/gcc.dg/pr40340-5.c
+++ b/gcc/testsuite/gcc.dg/pr40340-5.c
@@ -1,6 +1,6 @@
 /* PR middle-end/40340 */
 /* { dg-do compile } */
-/* { dg-options "-O2 -Wall -Wsystem-headers -g" } */
+/* { dg-options "-O2 -Wall -Wsystem-headers -g -fno-tree-dse" } */
 
 #define TEST3
 #include "pr40340.h"

Reply via email to