From df0f6bbb3aa701b7d42aeefdf014eb73e9332d92 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sun, 10 Dec 2017 11:39:56 +0100 Subject: [PATCH] re PR tree-optimization/83337 (ICE at -O3 x86_64-linux-gnu: in interpret_rhs_expr, at tree-scalar-evolution.c:1775) 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 | 6 ++ gcc/gimple-loop-interchange.cc | 24 ++++++++ gcc/testsuite/ChangeLog | 6 ++ .../gcc.dg/tree-ssa/loop-interchange-14.c | 60 +++++++++++++++++++ .../gcc.dg/tree-ssa/loop-interchange-15.c | 53 ++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-14.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-15.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5d9bf779c8c..3e7d9a4ecc1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-12-10 Jakub Jelinek + + PR tree-optimization/83337 + * gimple-loop-interchange.cc (compute_access_stride): Handle bitfield DRs + properly. + 2017-12-09 Jakub Jelinek PR tree-optimization/83338 diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc index 3f7c54f5971..301b511cdad 100644 --- a/gcc/gimple-loop-interchange.cc +++ b/gcc/gimple-loop-interchange.cc @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3812d5f98c4..fcd31bb12a1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-12-10 Jakub Jelinek + + 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 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 index 00000000000..7c71ae4c4af --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-14.c @@ -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 +#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 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 index 00000000000..420880e8fc9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-15.c @@ -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 +#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; +} -- 2.30.2