public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Fix PR tree-optimization/49771
@ 2011-07-19  8:24 Ira Rosen
  2011-07-19  9:49 ` Richard Guenther
  2011-07-20 19:47 ` Ulrich Weigand
  0 siblings, 2 replies; 35+ messages in thread
From: Ira Rosen @ 2011-07-19  8:24 UTC (permalink / raw)
  To: gcc-patches; +Cc: Patch Tracking

Hi,

The vectorizer performs the following alias checks for data-refs with
unknown dependence:

((store_ptr_0 + store_segment_length_0) <= load_ptr_0)
  || (load_ptr_0 + load_segment_length_0) <= store_ptr_0))

where segment_length is data-ref's step in the loop multiplied by the
loop's number of iterations (in the general case). For invariant
data-refs segment_length is 0, since the step is 0. This creates
incorrect check for:

  for (i = 0; i < 1000; i++)
    for (j = 0; j < 1000; j++)
       a[j] = a[i] + 1;

We check:

&a + 4000 <= &a + i*4
|| &a + i*4 <= &a

and the second check is wrong for i=0.

This patch makes segment_length to be sizeof (data-ref type) in case
of zero step, changing the checks into

&a + 4000 <= &a + i*4
|| &a + i*4 + 4 <= &a

Bootstrapped and tested on powerpc64-suse-linux.
Committed revision 176434.

Ira

ChangeLog:

   PR tree-optimization/49771
   * tree-vect-loop-manip.c (vect_vfa_segment_size): In case of
   zero step, set segment length to the size of the data-ref's type.

testsuite/ChangeLog:

   PR tree-optimization/49771
   * gcc.dg/vect/pr49771.c: New test.

Index: tree-vect-loop-manip.c
===================================================================
--- tree-vect-loop-manip.c      (revision 176433)
+++ tree-vect-loop-manip.c      (working copy)
@@ -2356,9 +2356,14 @@ static tree
 vect_vfa_segment_size (struct data_reference *dr, tree length_factor)
 {
   tree segment_length;
-  segment_length = size_binop (MULT_EXPR,
-                              fold_convert (sizetype, DR_STEP (dr)),
-                              fold_convert (sizetype, length_factor));
+
+  if (!compare_tree_int (DR_STEP (dr), 0))
+    segment_length = TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr)));
+  else
+    segment_length = size_binop (MULT_EXPR,
+                                 fold_convert (sizetype, DR_STEP (dr)),
+                                 fold_convert (sizetype, length_factor));
+
   if (vect_supportable_dr_alignment (dr, false)
         == dr_explicit_realign_optimized)
     {
Index: testsuite/gcc.dg/vect/pr49771.c
===================================================================
--- testsuite/gcc.dg/vect/pr49771.c     (revision 0)
+++ testsuite/gcc.dg/vect/pr49771.c     (revision 0)
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <stdarg.h>
+
+static int a[1000];
+
+int
+foo (void)
+{
+  int j;
+  int i;
+  for (i = 0; i < 1000; i++)
+    for (j = 0; j < 1000; j++)
+      a[j] = a[i] + 1;
+  return a[0];
+}
+
+int
+main (void)
+{
+  int res = foo ();
+  if (res != 1999)
+    abort ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2011-08-23 14:40 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-19  8:24 [patch] Fix PR tree-optimization/49771 Ira Rosen
2011-07-19  9:49 ` Richard Guenther
2011-07-19 14:01   ` Ira Rosen
2011-07-19 14:03     ` Richard Guenther
2011-07-20 19:47 ` Ulrich Weigand
2011-07-21 12:54   ` Ira Rosen
2011-07-24 14:32     ` Ira Rosen
2011-07-24 18:46       ` Richard Guenther
2011-07-25  9:44         ` Ulrich Weigand
2011-07-25 10:08           ` Richard Guenther
2011-07-25 11:26             ` Ira Rosen
2011-07-25 11:41               ` Richard Guenther
2011-07-25 12:33                 ` Ira Rosen
2011-07-25 13:01                   ` Richard Guenther
2011-07-25 13:07                     ` Richard Guenther
2011-07-25 13:47                       ` Ulrich Weigand
2011-07-25 14:01                         ` Richard Guenther
2011-07-25 14:10                           ` Richard Guenther
2011-07-25 14:14                             ` Richard Guenther
2011-07-25 14:54                               ` Ulrich Weigand
2011-07-25 14:59                                 ` Richard Guenther
2011-07-25 16:12                                   ` Ulrich Weigand
2011-07-26  8:25                                     ` Richard Guenther
2011-07-26  8:59                                       ` Andrew Pinski
2011-07-26 14:23                                       ` Ulrich Weigand
2011-07-26 14:25                                         ` Michael Matz
2011-07-26 16:18                                           ` Merge alignments from coalesced SSA pointers Michael Matz
2011-07-26 17:23                                             ` Michael Matz
2011-08-08 16:34                                               ` Ulrich Weigand
2011-08-09 12:01                                                 ` Michael Matz
2011-08-12 16:41                                                   ` [rfa] Set alignment of pseudos via get_pointer_alignment Michael Matz
2011-08-12 22:53                                                     ` Richard Guenther
2011-08-23 15:04                                                       ` Michael Matz
2011-07-26 17:28                                             ` Merge alignments from coalesced SSA pointers Ulrich Weigand
2011-07-27  9:13                                               ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).