re PR tree-optimization/86492 (store-merging wrong-code)
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Jul 2018 07:39:33 +0000 (09:39 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 12 Jul 2018 07:39:33 +0000 (09:39 +0200)
PR tree-optimization/86492
* gimple-ssa-store-merging.c
(imm_store_chain_info::coalesce_immediate_stores): Call
check_no_overlap even for the merge_overlapping case.  Formatting fix.

* gcc.c-torture/execute/pr86492.c: New test.

From-SVN: r262576

gcc/ChangeLog
gcc/gimple-ssa-store-merging.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr86492.c [new file with mode: 0644]

index c36a8a83c264a4e388ce09052431974f73ea79d8..415aca314b6c373b77f8aa8819831853ab91efef 100644 (file)
@@ -1,3 +1,10 @@
+2018-07-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/86492
+       * gimple-ssa-store-merging.c
+       (imm_store_chain_info::coalesce_immediate_stores): Call
+       check_no_overlap even for the merge_overlapping case.  Formatting fix.
+
 2018-07-12  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/86479
index 6d7e0ebe717d7be8d5a16222addac07c27fc3c7b..0ae45817347ff456393abd38f331cafca090e657 100644 (file)
@@ -2702,7 +2702,12 @@ imm_store_chain_info::coalesce_immediate_stores ()
        {
          /* Only allow overlapping stores of constants.  */
          if (info->rhs_code == INTEGER_CST
-             && merged_store->stores[0]->rhs_code == INTEGER_CST)
+             && merged_store->stores[0]->rhs_code == INTEGER_CST
+             && check_no_overlap (m_store_info, i, INTEGER_CST,
+                                  MAX (merged_store->last_order, info->order),
+                                  MAX (merged_store->start
+                                       + merged_store->width,
+                                       info->bitpos + info->bitsize)))
            {
              merged_store->merge_overlapping (info);
              goto done;
@@ -2732,10 +2737,8 @@ imm_store_chain_info::coalesce_immediate_stores ()
              info->ops_swapped_p = true;
            }
          if (check_no_overlap (m_store_info, i, info->rhs_code,
-                               MAX (merged_store->last_order,
-                                    info->order),
-                               MAX (merged_store->start
-                                    + merged_store->width,
+                               MAX (merged_store->last_order, info->order),
+                               MAX (merged_store->start + merged_store->width,
                                     info->bitpos + info->bitsize)))
            {
              /* Turn MEM_REF into BIT_INSERT_EXPR for bit-field stores.  */
index d68cccf3d0b2a6a35a1144a7c31a94d6e5058163..5992e0d56d4bfa2a56a4b6e050461f7dd54e74ed 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/86492
+       * gcc.c-torture/execute/pr86492.c: New test.
+
 2018-07-12  Richard Biener  <rguenther@suse.de>
 
        PR c/86453
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr86492.c b/gcc/testsuite/gcc.c-torture/execute/pr86492.c
new file mode 100644 (file)
index 0000000..049563d
--- /dev/null
@@ -0,0 +1,34 @@
+/* PR tree-optimization/86492 */
+
+union U
+{
+  unsigned int r;
+  struct S
+  {
+    unsigned int a:12;
+    unsigned int b:4;
+    unsigned int c:16;
+  } f;
+};
+
+__attribute__((noipa)) unsigned int
+foo (unsigned int x)
+{
+  union U u;
+  u.r = 0;
+  u.f.c = x;
+  u.f.b = 0xe;
+  return u.r;
+}
+
+int
+main ()
+{
+  union U u;
+  if (__CHAR_BIT__ * __SIZEOF_INT__ != 32 || sizeof (u.r) != sizeof (u.f))
+    return 0;
+  u.r = foo (0x72);
+  if (u.f.a != 0 || u.f.b != 0xe || u.f.c != 0x72)
+    __builtin_abort ();
+  return 0;
+}