re PR tree-optimization/78189 (movaps generated for unaligned store in aligned struct...
authorRichard Biener <rguenther@suse.de>
Mon, 7 Nov 2016 08:05:08 +0000 (08:05 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 7 Nov 2016 08:05:08 +0000 (08:05 +0000)
2016-11-07  Richard Biener  <rguenther@suse.de>

PR tree-optimization/78189
* tree-vect-data-refs.c (vect_compute_data_ref_alignment): Fix
alignment computation.

* g++.dg/torture/pr78189.C: New testcase.

From-SVN: r241892

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr78189.C [new file with mode: 0644]
gcc/tree-vect-data-refs.c

index 71f3066c2dbc808fa063c58961a89c1951ec7548..960ea67b0bc3c3ece1c3910d2bdcb9e1bef2aa82 100644 (file)
@@ -1,3 +1,9 @@
+2016-11-07  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78189
+       * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Fix
+       alignment computation.
+
 2016-11-06  Kugan Vivekanandarajah  <kuganv@linaro.org>
 
        * ipa-cp.c (ipcp_bits_lattice::meet_with): Remove unreachable code.
index 0a88fcd75c6690412006b9709c26584bf8d7fd85..e0a1c8e77a57c70de90917e92261cb6978a6667c 100644 (file)
@@ -1,3 +1,8 @@
+2016-11-07  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78189
+       * g++.dg/torture/pr78189.C: New testcase.
+
 2016-11-06  David Edelsohn  <dje.gcc@gmail.com>
 
        * gcc.dg/Wtrampolines.c: XFAIL AIX.
diff --git a/gcc/testsuite/g++.dg/torture/pr78189.C b/gcc/testsuite/g++.dg/torture/pr78189.C
new file mode 100644 (file)
index 0000000..9b65d2b
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+/* { dg-additional-options "-ftree-slp-vectorize -fno-vect-cost-model" } */
+
+#include <cstddef>
+
+struct A
+{
+  void * a;
+  void * b;
+};
+
+struct alignas(16) B
+{
+  void * pad;
+  void * misaligned;
+  void * pad2;
+
+  A a;
+
+  void Null();
+};
+
+void B::Null()
+{
+  a.a = nullptr;
+  a.b = nullptr;
+}
+
+void __attribute__((noinline,noclone))
+NullB(void * misalignedPtr)
+{
+  B* b = reinterpret_cast<B*>(reinterpret_cast<char *>(misalignedPtr) - offsetof(B, misaligned));
+  b->Null();
+}
+
+int main()
+{
+  B b;
+  NullB(&b.misaligned);
+  return 0;
+}
index 9346cfeafd25cc068080ecd4768ba7ad7a7e80ac..b03cb1ec637c427f215cd6408707d7e46b6e0764 100644 (file)
@@ -773,10 +773,25 @@ vect_compute_data_ref_alignment (struct data_reference *dr)
   base = ref;
   while (handled_component_p (base))
     base = TREE_OPERAND (base, 0);
+  unsigned int base_alignment;
+  unsigned HOST_WIDE_INT base_bitpos;
+  get_object_alignment_1 (base, &base_alignment, &base_bitpos);
+  /* As data-ref analysis strips the MEM_REF down to its base operand
+     to form DR_BASE_ADDRESS and adds the offset to DR_INIT we have to
+     adjust things to make base_alignment valid as the alignment of
+     DR_BASE_ADDRESS.  */
   if (TREE_CODE (base) == MEM_REF)
-    base = build2 (MEM_REF, TREE_TYPE (base), base_addr,
-                  build_int_cst (TREE_TYPE (TREE_OPERAND (base, 1)), 0));
-  unsigned int base_alignment = get_object_alignment (base);
+    {
+      base_bitpos -= mem_ref_offset (base).to_short_addr () * BITS_PER_UNIT;
+      base_bitpos &= (base_alignment - 1);
+    }
+  if (base_bitpos != 0)
+    base_alignment = base_bitpos & -base_bitpos;
+  /* Also look at the alignment of the base address DR analysis
+     computed.  */
+  unsigned int base_addr_alignment = get_pointer_alignment (base_addr);
+  if (base_addr_alignment > base_alignment)
+    base_alignment = base_addr_alignment;
 
   if (base_alignment >= TYPE_ALIGN (TREE_TYPE (vectype)))
     DR_VECT_AUX (dr)->base_element_aligned = true;