gimple-ssa-store-merging.c: Include gimplify-me.h.
authorRichard Biener <rguenther@suse.de>
Wed, 2 Nov 2016 15:00:48 +0000 (15:00 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 2 Nov 2016 15:00:48 +0000 (15:00 +0000)
2016-11-02  Richard Biener  <rguenther@suse.de>

* gimple-ssa-store-merging.c: Include gimplify-me.h.
(imm_store_chain_info::output_merged_stores): Force base_addr
to be proper GIMPLE for a MEM_REF address.
(pass_store_merging::execute): Restrict negative bitpos
handling to non-MEM_REF bases.  Remove TREE_THIS_VOLATILE
check.  Take into account non-NULL_TREE offset if the base
is already addressable.

* gcc.dg/store_merging_8.c: New testcase.

From-SVN: r241796

gcc/ChangeLog
gcc/gimple-ssa-store-merging.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/store_merging_8.c [new file with mode: 0644]

index 76b90a889a50300f1ea15a418d9bd54507a9d0eb..241ff78d55593e15f375a4ef4157318a07056400 100644 (file)
@@ -1,3 +1,13 @@
+2016-11-02  Richard Biener  <rguenther@suse.de>
+
+       * gimple-ssa-store-merging.c: Include gimplify-me.h.
+       (imm_store_chain_info::output_merged_stores): Force base_addr
+       to be proper GIMPLE for a MEM_REF address.
+       (pass_store_merging::execute): Restrict negative bitpos
+       handling to non-MEM_REF bases.  Remove TREE_THIS_VOLATILE
+       check.  Take into account non-NULL_TREE offset if the base
+       is already addressable.
+
 2016-11-26  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * config/aarch64/aarch64-simd.md (aarch64_crypto_sha1hv4si):
index 081620e50f603e2de8ed962aec6c619890ce1e33..1bca4a137583dc0a66cec4196bbcfb646cae30dd 100644 (file)
 #include "tree-cfg.h"
 #include "tree-eh.h"
 #include "target.h"
+#include "gimplify-me.h"
 
 /* The maximum size (in bits) of the stores this pass should generate.  */
 #define MAX_STORE_BITSIZE (BITS_PER_WORD)
@@ -1127,6 +1128,8 @@ imm_store_chain_info::output_merged_store (merged_store_group *group)
   unsigned int i;
   bool fail = false;
 
+  tree addr = force_gimple_operand_1 (unshare_expr (base_addr), &seq,
+                                     is_gimple_mem_ref_addr, NULL_TREE);
   FOR_EACH_VEC_ELT (split_stores, i, split_store)
     {
       unsigned HOST_WIDE_INT try_size = split_store->size;
@@ -1137,7 +1140,7 @@ imm_store_chain_info::output_merged_store (merged_store_group *group)
 
       tree int_type = build_nonstandard_integer_type (try_size, UNSIGNED);
       int_type = build_aligned_type (int_type, align);
-      tree dest = fold_build2 (MEM_REF, int_type, base_addr,
+      tree dest = fold_build2 (MEM_REF, int_type, addr,
                               build_int_cst (offset_type, try_pos));
 
       tree src = native_interpret_expr (int_type,
@@ -1366,15 +1369,10 @@ pass_store_merging::execute (function *fun)
                                       &unsignedp, &reversep, &volatilep);
              /* As a future enhancement we could handle stores with the same
                 base and offset.  */
-             bool invalid = offset || reversep || bitpos < 0
+             bool invalid = reversep
                             || ((bitsize > MAX_BITSIZE_MODE_ANY_INT)
                                  && (TREE_CODE (rhs) != INTEGER_CST))
-                            || !rhs_valid_for_store_merging_p (rhs)
-               /* An access may not be volatile itself but base_addr may be
-                  a volatile decl i.e. MEM[&volatile-decl].  The hashing for
-                  tree_operand_hash won't consider such stores equal to each
-                  other so we can't track chains on them.  */
-                            || TREE_THIS_VOLATILE (base_addr);
+                            || !rhs_valid_for_store_merging_p (rhs);
 
              /* We do not want to rewrite TARGET_MEM_REFs.  */
              if (TREE_CODE (base_addr) == TARGET_MEM_REF)
@@ -1398,7 +1396,32 @@ pass_store_merging::execute (function *fun)
              /* get_inner_reference returns the base object, get at its
                 address now.  */
              else
-               base_addr = build_fold_addr_expr (base_addr);
+               {
+                 if (bitpos < 0)
+                   invalid = true;
+                 base_addr = build_fold_addr_expr (base_addr);
+               }
+
+             if (! invalid
+                 && offset != NULL_TREE)
+               {
+                 /* If the access is variable offset then a base
+                    decl has to be address-taken to be able to
+                    emit pointer-based stores to it.
+                    ???  We might be able to get away with
+                    re-using the original base up to the first
+                    variable part and then wrapping that inside
+                    a BIT_FIELD_REF.  */
+                 tree base = get_base_address (base_addr);
+                 if (! base
+                     || (DECL_P (base)
+                         && ! TREE_ADDRESSABLE (base)))
+                   invalid = true;
+                 else
+                   base_addr = build2 (POINTER_PLUS_EXPR,
+                                       TREE_TYPE (base_addr),
+                                       base_addr, offset);
+               }
 
              struct imm_store_chain_info **chain_info
                = m_stores.get (base_addr);
index e475c0e2606bda81a1d314ff0aa7ad20a5cb34f4..6ca1e69a0974defb5fb3fb6ec753d24f84870abf 100644 (file)
@@ -1,3 +1,7 @@
+2016-11-02  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/store_merging_8.c: New testcase.
+
 2016-11-02  Fritz O. Reese <fritzoreese@gmail.com>
 
        * gfortran.dg/warn_argument_mismatch_1.f90: New test.
diff --git a/gcc/testsuite/gcc.dg/store_merging_8.c b/gcc/testsuite/gcc.dg/store_merging_8.c
new file mode 100644 (file)
index 0000000..15e80c7
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target non_strict_align } */
+/* { dg-options "-O2 -fdump-tree-store-merging" } */
+
+struct baz {
+  struct bar {
+      int a;
+      char b;
+      char c;
+      char d;
+      char e;
+      char f;
+      char g;
+  } a[4];
+} x;
+struct baz *xx = &x;
+
+void
+foo1 (int i)
+{
+  x.a[i].b = 0;
+  x.a[i].a = 0;
+  x.a[i].c = 0;
+  x.a[i].d = 0;
+  x.a[i].e = 0;
+}
+
+void
+foo2 (int i)
+{
+  x.a[i].b = 0;
+  x.a[i].a = 0;
+  x.a[i].c = 1;
+  x.a[i].d = 0;
+  x.a[i].e = 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } } */