This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR86017


The following fixes the testcase in PR86017 where failure to
inline-expand single-byte memsets on GIMPLE causes us to miss
store-merging opportunities.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2018-06-01  Richard Biener  <rguenther@suse.de>

	PR middle-end/86017
	* gimple-fold.c (var_decl_component_p): Also allow offsetted
	vars wrapped in MEM_REFs.

	* gcc.dg/tree-ssa/pr86017.c: New testcase.

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 261055)
+++ gcc/gimple-fold.c	(working copy)
@@ -632,7 +632,9 @@ var_decl_component_p (tree var)
   tree inner = var;
   while (handled_component_p (inner))
     inner = TREE_OPERAND (inner, 0);
-  return SSA_VAR_P (inner);
+  return (DECL_P (inner)
+	  || (TREE_CODE (inner) == MEM_REF
+	      && TREE_CODE (TREE_OPERAND (inner, 0)) == ADDR_EXPR));
 }
 
 /* If the SIZE argument representing the size of an object is in a range
Index: gcc/testsuite/gcc.dg/tree-ssa/pr86017.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr86017.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr86017.c	(working copy)
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-store-merging" } */
+
+void f (void*);
+
+void g (void)
+{
+  char a[8];
+  __builtin_memset (a, 0, 8);
+
+  f (a);
+}
+
+void h (void)
+{
+  char a[8];
+  __builtin_memset (a, 0, 1);
+  __builtin_memset (a + 1, 0, 1);
+  __builtin_memset (a + 2, 0, 1);
+  __builtin_memset (a + 3, 0, 1);
+  __builtin_memset (a + 4, 0, 1);
+  __builtin_memset (a + 5, 0, 1);
+  __builtin_memset (a + 6, 0, 1);
+  __builtin_memset (a + 7, 0, 1);
+
+  f (a);
+}
+
+/* { dg-final { scan-tree-dump "Merged into 1 stores" "store-merging" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]