re PR target/26726 (-fivopts producing out of bounds array refs)
authorRichard Guenther <rguenther@suse.de>
Mon, 1 May 2006 15:07:25 +0000 (15:07 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 1 May 2006 15:07:25 +0000 (15:07 +0000)
2006-05-01  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/26726
* tree-ssa-loop-ivopts.c (idx_find_step): Mark source of the
problem ...
(find_interesting_uses_address): ... we work around here
by folding INDIRECT_REFs in the substituted base.

* g++.dg/tree-ssa/ivopts-1.C: New testcase.

From-SVN: r113414

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/ivopts-1.C [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c

index 99942ebc9397c145f56b06bb2e05b4b2ce5c6fa9..ac99122374bed03468eb40366e49b5e715193fcc 100644 (file)
@@ -1,3 +1,11 @@
+2006-05-01  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/26726
+       * tree-ssa-loop-ivopts.c (idx_find_step): Mark source of the
+       problem ...
+       (find_interesting_uses_address): ... we work around here
+       by folding INDIRECT_REFs in the substituted base.
+
 2006-05-01  Diego Novillo  <dnovillo@redhat.com>
 
        * omp-low.c (dump_omp_region): Add newlines.
index 1aeb5ac2a153c07548352ee7750a3b341b52739d..15c7c63268c2dbb73d1108e67c304a1e58bd487e 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-01  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/26726
+       * g++.dg/tree-ssa/ivopts-1.C: New testcase.
+
 2006-04-30  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.dg/Woverflow-1.c: New test case.
diff --git a/gcc/testsuite/g++.dg/tree-ssa/ivopts-1.C b/gcc/testsuite/g++.dg/tree-ssa/ivopts-1.C
new file mode 100644 (file)
index 0000000..b894552
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ivopts" } */
+
+struct Foo {
+  Foo() : s(1) {}
+  int s;
+};
+void foo(Foo&);
+void bar(void)
+{
+  Foo x[4];
+  foo(x[0]);
+}
+
+/* { dg-final { scan-tree-dump-not "-&x" "ivopts" } } */
+/* { dg-final { scan-tree-dump-not "offset: -4B" "ivopts" { xfail i?86-*-* x86_64-*-* } } } */
+/* { dg-final { scan-tree-dump-not "&x\\\[5\\\]" "ivopts" { xfail i?86-*-* x86_64-*-* } } } */
+/* { dg-final { cleanup-tree-dump "ivopts" } } */
index acc8c8a3da5e7a2d3993fe8698bb05a215ec6e90..75d54077a234c600c9350e1d13ab00ad59264306 100644 (file)
@@ -1376,6 +1376,9 @@ idx_find_step (tree base, tree *idx, void *data)
   if (!iv)
     return false;
 
+  /* XXX  We produce for a base of *D42 with iv->base being &x[0]
+         *&x[0], which is not folded and does not trigger the
+         ARRAY_REF path below.  */
   *idx = iv->base;
 
   if (!iv->step)
@@ -1547,6 +1550,17 @@ find_interesting_uses_address (struct ivopts_data *data, tree stmt, tree *op_p)
       gcc_assert (TREE_CODE (base) != MISALIGNED_INDIRECT_REF);
 
       base = build_fold_addr_expr (base);
+
+      /* Substituting bases of IVs into the base expression might
+        have caused folding opportunities.  */
+      if (TREE_CODE (base) == ADDR_EXPR)
+       {
+         tree *ref = &TREE_OPERAND (base, 0);
+         while (handled_component_p (*ref))
+           ref = &TREE_OPERAND (*ref, 0);
+         if (TREE_CODE (*ref) == INDIRECT_REF)
+           *ref = fold_indirect_ref (*ref);
+       }
     }
 
   civ = alloc_iv (base, step);