re PR tree-optimization/83337 (ICE at -O3 x86_64-linux-gnu: in interpret_rhs_expr...
authorJakub Jelinek <jakub@redhat.com>
Sun, 10 Dec 2017 10:39:56 +0000 (11:39 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sun, 10 Dec 2017 10:39:56 +0000 (11:39 +0100)
PR tree-optimization/83337
* gimple-loop-interchange.cc (compute_access_stride): Handle bitfield DRs
properly.

* gcc.dg/tree-ssa/loop-interchange-14.c: New test.
* gcc.dg/tree-ssa/loop-interchange-15.c: New test.

From-SVN: r255528

gcc/ChangeLog
gcc/gimple-loop-interchange.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-14.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-15.c [new file with mode: 0644]

index 5d9bf77..3e7d9a4 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/83337
+       * gimple-loop-interchange.cc (compute_access_stride): Handle bitfield DRs
+       properly.
+
 2017-12-09  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/83338
index 3f7c54f..301b511 100644 (file)
@@ -1291,6 +1291,30 @@ compute_access_stride (struct loop *loop_nest, struct loop *loop,
   gcc_assert (loop == bb->loop_father);
 
   tree ref = DR_REF (dr);
+  if (TREE_CODE (ref) == COMPONENT_REF
+      && DECL_BIT_FIELD (TREE_OPERAND (ref, 1)))
+    {
+      /* We can't take address of bitfields.  If the bitfield is at constant
+        offset from the start of the struct, just use address of the
+        struct, for analysis of the strides that shouldn't matter.  */
+      if (!TREE_OPERAND (ref, 2)
+         || TREE_CODE (TREE_OPERAND (ref, 2)) == INTEGER_CST)
+       ref = TREE_OPERAND (ref, 0);
+      /* Otherwise, if we have a bit field representative, use that.  */
+      else if (DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (ref, 1))
+              != NULL_TREE)
+       {
+         tree repr = DECL_BIT_FIELD_REPRESENTATIVE (TREE_OPERAND (ref, 1));
+         ref = build3 (COMPONENT_REF, TREE_TYPE (repr), TREE_OPERAND (ref, 0),
+                       repr, TREE_OPERAND (ref, 2));
+       }
+      /* Otherwise punt.  */
+      else
+       {
+         dr->aux = strides;
+         return;
+       }
+    }
   tree scev_base = build_fold_addr_expr (ref);
   tree scev = analyze_scalar_evolution (loop, scev_base);
   scev = instantiate_scev (loop_preheader_edge (loop_nest), loop, scev);
index 3812d5f..fcd31bb 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/83337
+       * gcc.dg/tree-ssa/loop-interchange-14.c: New test.
+       * gcc.dg/tree-ssa/loop-interchange-15.c: New test.
+
 2017-12-09  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/82934
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-14.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-14.c
new file mode 100644 (file)
index 0000000..7c71ae4
--- /dev/null
@@ -0,0 +1,60 @@
+/* PR tree-optimization/83337 */
+/* { dg-do run { target int32plus } } */
+/* { dg-options "-O2 -floop-interchange -fdump-tree-linterchange-details" } */
+
+/* Copied from graphite/interchange-5.c */
+
+#define DEBUG 0
+#if DEBUG
+#include <stdio.h>
+#endif
+
+#define N 100
+#define M 1111
+struct S { int a : 3; int b : 17; int c : 12; };
+struct S A[N][M];
+
+static int __attribute__((noinline))
+foo (void)
+{
+  int i, j;
+
+  for( i = 0; i < M; i++)
+    for( j = 0; j < N; j++)
+      A[j][i].b = 5 * A[j][i].b;
+
+  return A[0][0].b + A[N-1][M-1].b;
+}
+
+extern void abort ();
+
+static void __attribute__((noinline))
+init (int i)
+{
+  int j;
+
+  for (j = 0; j < M; j++)
+    A[i][j].b = 2;
+}
+
+int
+main (void)
+{
+  int i, j, res;
+
+  for (i = 0; i < N; i++)
+    init (i);
+
+  res = foo ();
+
+#if DEBUG
+  fprintf (stderr, "res = %d \n", res);
+#endif
+
+  if (res != 20)
+    abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Loop_pair<outer:., inner:.> is interchanged" 1 "linterchange"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-15.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-15.c
new file mode 100644 (file)
index 0000000..420880e
--- /dev/null
@@ -0,0 +1,53 @@
+/* PR tree-optimization/83337 */
+/* { dg-do run { target int32plus } } */
+/* { dg-options "-O2 -floop-interchange" } */
+
+/* Copied from graphite/interchange-5.c */
+
+#define DEBUG 0
+#if DEBUG
+#include <stdio.h>
+#endif
+
+#define N 100
+#define M 1111
+
+extern void abort ();
+
+static void __attribute__((noipa))
+foo (int n)
+{
+  int i, j;
+  struct S { char d[n]; int a : 3; int b : 17; int c : 12; };
+  struct S A[N][M];
+
+  for (i = 0; i < N; i++)
+    {
+      asm volatile ("" : : "g" (&A[0][0]) : "memory");
+      for (j = 0; j < M; j++)
+       A[i][j].b = 2;
+    }
+  asm volatile ("" : : "g" (&A[0][0]) : "memory");
+
+  for (i = 0; i < M; i++)
+    for (j = 0; j < N; j++)
+      A[j][i].b = 5 * A[j][i].b;
+
+  asm volatile ("" : : "g" (&A[0][0]) : "memory");
+  int res = A[0][0].b + A[N-1][M-1].b;
+
+#if DEBUG
+  fprintf (stderr, "res = %d \n", res);
+#endif
+
+  if (res != 20)
+    abort ();
+}
+
+int
+main (void)
+{
+  foo (1);
+  foo (8);
+  return 0;
+}