Commit 316b2a2d by Richard Sandiford Committed by Richard Sandiford

Check array indices in object_address_invariant_in_loop_p (PR 84357)

object_address_invariant_in_loop_p ignored ARRAY_REF indices on
the basis that:

	  /* Index of the ARRAY_REF was zeroed in analyze_indices, thus we only
	     need to check the stride and the lower bound of the reference.  */

That was true back in 2007 when the code was added:

static void
dr_analyze_indices (struct data_reference *dr, struct loop *nest)
{
  [...]
  while (handled_component_p (aref))
    {
      if (TREE_CODE (aref) == ARRAY_REF)
        {
          op = TREE_OPERAND (aref, 1);
          access_fn = analyze_scalar_evolution (loop, op);
          access_fn = resolve_mixers (nest, access_fn);
          VEC_safe_push (tree, heap, access_fns, access_fn);

          TREE_OPERAND (aref, 1) = build_int_cst (TREE_TYPE (op), 0);
        }

      aref = TREE_OPERAND (aref, 0);
    }

but the assignment was removed a few years ago.  We were therefore
treating "two->arr[i]" and "three->arr[i]" as loop invariant.

2018-02-14  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	PR tree-optimization/84357
	* tree-data-ref.c (object_address_invariant_in_loop_p): Check
	operand 1 of an ARRAY_REF too.

gcc/testsuite/
	PR tree-optimization/84357
	* gcc.dg/vect/pr84357.c: New test.

From-SVN: r257657
parent 06e97270
2018-02-14 Richard Sandiford <richard.sandiford@linaro.org>
PR tree-optimization/84357
* tree-data-ref.c (object_address_invariant_in_loop_p): Check
operand 1 of an ARRAY_REF too.
2018-02-14 Oleg Endo <olegendo@gcc.gnu.org> 2018-02-14 Oleg Endo <olegendo@gcc.gnu.org>
PR target/83831 PR target/83831
......
2018-02-14 Richard Sandiford <richard.sandiford@linaro.org>
PR tree-optimization/84357
* gcc.dg/vect/pr84357.c: New test.
2018-02-14 Oleg Endo <olegendo@gcc.gnu.org> 2018-02-14 Oleg Endo <olegendo@gcc.gnu.org>
PR target/83831 PR target/83831
......
/* { dg-do compile } */
/* { dg-additional-options "-Wall" } */
#define COUNT 32
typedef struct s1 {
unsigned char c;
} s1;
typedef struct s2
{
char pad;
s1 arr[COUNT];
} s2;
typedef struct s3 {
s1 arr[COUNT];
} s3;
s2 * get_s2();
s3 * gActiveS3;
void foo()
{
s3 * three = gActiveS3;
s2 * two = get_s2();
for (int i = 0; i < COUNT; i++)
{
two->arr[i].c = three->arr[i].c;
}
}
...@@ -2200,13 +2200,10 @@ object_address_invariant_in_loop_p (const struct loop *loop, const_tree obj) ...@@ -2200,13 +2200,10 @@ object_address_invariant_in_loop_p (const struct loop *loop, const_tree obj)
{ {
if (TREE_CODE (obj) == ARRAY_REF) if (TREE_CODE (obj) == ARRAY_REF)
{ {
/* Index of the ARRAY_REF was zeroed in analyze_indices, thus we only for (int i = 1; i < 4; ++i)
need to check the stride and the lower bound of the reference. */ if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (obj, i),
if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (obj, 2), loop->num))
loop->num) return false;
|| chrec_contains_symbols_defined_in_loop (TREE_OPERAND (obj, 3),
loop->num))
return false;
} }
else if (TREE_CODE (obj) == COMPONENT_REF) else if (TREE_CODE (obj) == COMPONENT_REF)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment