]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/71083 (Unaligned bit-field address when predictive...
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 12 Aug 2016 18:56:30 +0000 (18:56 +0000)
committerBernd Edlinger <edlinger@gcc.gnu.org>
Fri, 12 Aug 2016 18:56:30 +0000 (18:56 +0000)
2016-08-12  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        Backport from mainline
        2016-08-11  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        PR tree-optimization/71083
        * tree-predcom.c (ref_at_iteration): Correctly align the
        reference type.

testsuite:
2016-08-12  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        Backport from mainline
        2016-08-11  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        PR tree-optimization/71083
        * gcc.c-torture/execute/pr71083.c: New test.
        * gnat.dg/loop_optimization23.adb: New test.
        * gnat.dg/loop_optimization23_pkg.ads: New test.
        * gnat.dg/loop_optimization23_pkg.adb: New test.

From-SVN: r239424

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr71083.c [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_optimization23.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_optimization23_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_optimization23_pkg.ads [new file with mode: 0644]
gcc/tree-predcom.c

index d6d59efacecb60932a3d7427fc696df124328b6b..5600b02ab75859638f11bd126eaf408e52713391 100644 (file)
@@ -1,3 +1,12 @@
+2016-08-12  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       Backport from mainline
+       2016-08-11  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR tree-optimization/71083
+       * tree-predcom.c (ref_at_iteration): Correctly align the
+       reference type.
+
 2016-08-08  Georg-Johann Lay  <avr@gjlay.de>
 
        Backport from 2016-07-29 trunk r238863.
index 9cab5cc7317a3390e708a5cc25eebdf439daf16e..0d93655666f490c82e5e32010b3bd3e79936fef2 100644 (file)
@@ -1,3 +1,14 @@
+2016-08-12  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       Backport from mainline
+       2016-08-11  Bernd Edlinger  <bernd.edlinger@hotmail.de>
+
+       PR tree-optimization/71083
+       * gcc.c-torture/execute/pr71083.c: New test.
+       * gnat.dg/loop_optimization23.adb: New test.
+       * gnat.dg/loop_optimization23_pkg.ads: New test.
+       * gnat.dg/loop_optimization23_pkg.adb: New test.
+
 2016-08-11  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        Backport from trunk.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr71083.c b/gcc/testsuite/gcc.c-torture/execute/pr71083.c
new file mode 100644 (file)
index 0000000..0574434
--- /dev/null
@@ -0,0 +1,43 @@
+struct lock_chain {
+  unsigned int irq_context: 2,
+    depth: 6,
+    base: 24;
+};
+
+__attribute__((noinline, noclone))
+struct lock_chain * foo (struct lock_chain *chain)
+{
+  int i;
+  for (i = 0; i < 100; i++)
+    {
+      chain[i+1].base = chain[i].base;
+    }
+  return chain;
+}
+
+struct lock_chain1 {
+  char x;
+  unsigned short base;
+} __attribute__((packed));
+
+__attribute__((noinline, noclone))
+struct lock_chain1 * bar (struct lock_chain1 *chain)
+{
+  int i;
+  for (i = 0; i < 100; i++)
+    {
+      chain[i+1].base = chain[i].base;
+    }
+  return chain;
+}
+
+struct lock_chain test [101];
+struct lock_chain1 test1 [101];
+
+int
+main ()
+{
+  foo (test);
+  bar (test1);
+  return 0;
+}
diff --git a/gcc/testsuite/gnat.dg/loop_optimization23.adb b/gcc/testsuite/gnat.dg/loop_optimization23.adb
new file mode 100644 (file)
index 0000000..4f3af50
--- /dev/null
@@ -0,0 +1,14 @@
+-- { dg-do run }
+-- { dg-options "-O3" }
+-- PR tree-optimization/71083
+with Loop_Optimization23_Pkg;
+use Loop_Optimization23_Pkg;
+procedure Loop_Optimization23 is
+  Test : ArrayOfStructB;
+begin
+  Test (0).b.b := 9999;
+  Foo (Test);
+  if Test (100).b.b /= 9999 then
+    raise Program_Error;
+  end if;
+end;
diff --git a/gcc/testsuite/gnat.dg/loop_optimization23_pkg.adb b/gcc/testsuite/gnat.dg/loop_optimization23_pkg.adb
new file mode 100644 (file)
index 0000000..a5fc90d
--- /dev/null
@@ -0,0 +1,11 @@
+-- { dg-do compile }
+-- { dg-options "-O3" }
+-- PR tree-optimization/71083
+package body Loop_Optimization23_Pkg is
+  procedure Foo (X : in out ArrayOfStructB) is
+  begin
+    for K in 0..99 loop
+      X (K+1).b.b := X (K).b.b;
+    end loop;
+  end Foo;
+end Loop_Optimization23_Pkg;
diff --git a/gcc/testsuite/gnat.dg/loop_optimization23_pkg.ads b/gcc/testsuite/gnat.dg/loop_optimization23_pkg.ads
new file mode 100644 (file)
index 0000000..016ad82
--- /dev/null
@@ -0,0 +1,17 @@
+-- PR tree-optimization/71083
+package Loop_Optimization23_Pkg is
+  type Nibble is mod 2**4;
+  type Int24  is mod 2**24;
+  type StructA is record
+    a : Nibble;
+    b : Int24;
+  end record;
+  pragma Pack(StructA);
+  type StructB is record
+    a : Nibble;
+    b : StructA;
+  end record;
+  pragma Pack(StructB);
+  type ArrayOfStructB is array(0..100) of StructB;
+  procedure Foo (X : in out ArrayOfStructB);
+end Loop_Optimization23_Pkg;
index 03a38b4de842c74834227f566dde033f21d8ec1a..8f6a75ec9427d309971b44cd6800b240ff7e0f3d 100644 (file)
@@ -252,6 +252,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-affine.h"
 #include "tree-inline.h"
 #include "wide-int-print.h"
+#include "builtins.h"
 
 /* The maximum number of iterations between the considered memory
    references.  */
@@ -1424,6 +1425,8 @@ ref_at_iteration (data_reference_p dr, int iter, gimple_seq *stmts)
   addr = force_gimple_operand_1 (unshare_expr (addr), stmts,
                                 is_gimple_mem_ref_addr, NULL_TREE);
   tree alias_ptr = fold_convert (reference_alias_ptr_type (DR_REF (dr)), coff);
+  tree type = build_aligned_type (TREE_TYPE (DR_REF (dr)),
+                                 get_object_alignment (DR_REF (dr)));
   /* While data-ref analysis punts on bit offsets it still handles
      bitfield accesses at byte boundaries.  Cope with that.  Note that
      we cannot simply re-apply the outer COMPONENT_REF because the
@@ -1435,12 +1438,11 @@ ref_at_iteration (data_reference_p dr, int iter, gimple_seq *stmts)
     {
       tree field = TREE_OPERAND (DR_REF (dr), 1);
       return build3 (BIT_FIELD_REF, TREE_TYPE (DR_REF (dr)),
-                    build2 (MEM_REF, DECL_BIT_FIELD_TYPE (field),
-                            addr, alias_ptr),
+                    build2 (MEM_REF, type, addr, alias_ptr),
                     DECL_SIZE (field), bitsize_zero_node);
     }
   else
-    return fold_build2 (MEM_REF, TREE_TYPE (DR_REF (dr)), addr, alias_ptr);
+    return fold_build2 (MEM_REF, type, addr, alias_ptr);
 }
 
 /* Get the initialization expression for the INDEX-th temporary variable