tree-if-conv.c (memrefs_read_or_written_unconditionally): Strip all non-variable...
authorRichard Guenther <rguenther@suse.de>
Sun, 3 Apr 2011 08:30:53 +0000 (08:30 +0000)
committerIra Rosen <irar@gcc.gnu.org>
Sun, 3 Apr 2011 08:30:53 +0000 (08:30 +0000)
* tree-if-conv.c (memrefs_read_or_written_unconditionally): Strip all
non-variable offsets and compare the remaining bases of the two
accesses instead of looking for exact same data-ref.

Co-Authored-By: Ira Rosen <ira.rosen@linaro.org>
From-SVN: r171900

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/if-cvt-stores-vect-ifcvt-18.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect.exp
gcc/tree-if-conv.c

index d29b879e08819b54bd7a4c07715c8bd03a16cb58..faa7dab8da3a04581b149b31e0ecb7abc260b391 100644 (file)
@@ -1,3 +1,10 @@
+2011-04-03  Richard Guenther  <rguenther@suse.de>
+            Ira Rosen  <ira.rosen@linaro.org>
+
+       * tree-if-conv.c (memrefs_read_or_written_unconditionally): Strip all
+       non-variable offsets and compare the remaining bases of the two
+       accesses instead of looking for exact same data-ref.
+
 2011-04-02  Kai Tietz  <ktietz@redhat.com>
 
        PR target/48416
index dff95d8fdd3ea06d8f53d5660ce5d3344c0cd93c..5a39746b1a3551d70b8147f6cab32bf2f03b0ccf 100644 (file)
@@ -1,3 +1,10 @@
+2011-04-03  Richard Guenther  <rguenther@suse.de>
+           Ira Rosen  <ira.rosen@linaro.org>
+
+       * gcc.dg/vect/if-cvt-stores-vect-ifcvt-18.c: New test.
+       * gcc.dg/vect/vect.exp: Run if-cvt-stores-vect* tests with
+       -ftree-loop-if-convert-stores.
+
 2011-04-02  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/specs/aggr2.ads: New test.
diff --git a/gcc/testsuite/gcc.dg/vect/if-cvt-stores-vect-ifcvt-18.c b/gcc/testsuite/gcc.dg/vect/if-cvt-stores-vect-ifcvt-18.c
new file mode 100644 (file)
index 0000000..dc01e44
--- /dev/null
@@ -0,0 +1,69 @@
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+#define N 50
+
+typedef struct {
+  short a;
+  short b;
+} data;
+
+data in1[N], in2[N], out[N];
+short result[N*2] = {10,-7,11,-6,12,-5,13,-4,14,-3,15,-2,16,-1,17,0,18,1,19,2,20,3,21,4,22,5,23,6,24,7,25,8,26,9,27,10,28,11,29,12,30,13,31,14,32,15,33,16,34,17,35,18,36,19,37,20,38,21,39,22,40,23,41,24,42,25,43,26,44,27,45,28,46,29,47,30,48,31,49,32,50,33,51,34,52,35,53,36,54,37,55,38,56,39,57,40,58,41,59,42};
+short out1[N], out2[N];
+
+__attribute__ ((noinline)) void
+foo ()
+{
+  int i;
+  short c, d;
+
+  for (i = 0; i < N; i++)
+    {
+      c = in1[i].b;
+      d = in2[i].b;
+
+      if (c >= d)
+        {
+          out[i].b = in1[i].a;
+          out[i].a = d + 5;
+        }
+      else
+        {
+          out[i].b = d - 12;
+          out[i].a = in2[i].a + d;
+        }
+    }
+}
+
+int
+main (void)
+{
+  int i;
+
+  check_vect ();
+
+  for (i = 0; i < N; i++)
+    {
+      in1[i].a = i;
+      in1[i].b = i + 2;
+      in2[i].a = 5;
+      in2[i].b = i + 5;
+      __asm__ volatile ("");
+    }
+
+  foo ();
+
+  for (i = 0; i < N; i++)
+    {
+      if (out[i].a != result[2*i] || out[i].b != result[2*i+1])
+        abort ();
+    }
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect"  { xfail { vect_no_align || {! vect_strided } } } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
index 170c33db2a526d8edaa70709786df1db0b3959da..4e939591b97bf4e85a354a317ace413196feba9b 100644 (file)
@@ -210,6 +210,12 @@ lappend DEFAULT_VECTCFLAGS "--param" "ggc-min-expand=0" "--param" "ggc-min-heaps
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/ggc-*.\[cS\]]]  \
         "" $DEFAULT_VECTCFLAGS
 
+# -ftree-loop-if-convert-stores
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-ftree-loop-if-convert-stores"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/if-cvt-stores-vect-*.\[cS\]]]  \
+        "" $DEFAULT_VECTCFLAGS
+
 # With -O3.
 # Don't allow IPA cloning, because it throws our counts out of whack.
 set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
index d70e2321c1546eefaac1da53a1462cbba32a6b76..7ca6deec123634583c92b44adcdfdc8c9ffcdae8 100644 (file)
@@ -464,8 +464,8 @@ struct ifc_dr {
 /* Returns true when the memory references of STMT are read or written
    unconditionally.  In other words, this function returns true when
    for every data reference A in STMT there exist other accesses to
-   the same data reference with predicates that add up (OR-up) to the
-   true predicate: this ensures that the data reference A is touched
+   a data reference with the same base with predicates that add up (OR-up) to
+   the true predicate: this ensures that the data reference A is touched
    (read or written) on every iteration of the if-converted loop.  */
 
 static bool
@@ -489,21 +489,38 @@ memrefs_read_or_written_unconditionally (gimple stmt,
          continue;
 
        for (j = 0; VEC_iterate (data_reference_p, drs, j, b); j++)
-         if (DR_STMT (b) != stmt
-             && same_data_refs (a, b))
-           {
-             tree cb = bb_predicate (gimple_bb (DR_STMT (b)));
+          {
+            tree ref_base_a = DR_REF (a);
+            tree ref_base_b = DR_REF (b);
 
-             if (DR_RW_UNCONDITIONALLY (b) == 1
-                 || is_true_predicate (cb)
-                 || is_true_predicate (ca = fold_or_predicates (EXPR_LOCATION (cb),
-                                                                ca, cb)))
-               {
-                 DR_RW_UNCONDITIONALLY (a) = 1;
-                 DR_RW_UNCONDITIONALLY (b) = 1;
-                 found = true;
-                 break;
-               }
+            if (DR_STMT (b) == stmt)
+              continue;
+
+            while (TREE_CODE (ref_base_a) == COMPONENT_REF
+                   || TREE_CODE (ref_base_a) == IMAGPART_EXPR
+                   || TREE_CODE (ref_base_a) == REALPART_EXPR)
+              ref_base_a = TREE_OPERAND (ref_base_a, 0);
+
+            while (TREE_CODE (ref_base_b) == COMPONENT_REF
+                   || TREE_CODE (ref_base_b) == IMAGPART_EXPR
+                   || TREE_CODE (ref_base_b) == REALPART_EXPR)
+              ref_base_b = TREE_OPERAND (ref_base_b, 0);
+
+           if (!operand_equal_p (ref_base_a, ref_base_b, 0))
+             {
+               tree cb = bb_predicate (gimple_bb (DR_STMT (b)));
+
+               if (DR_RW_UNCONDITIONALLY (b) == 1
+                   || is_true_predicate (cb)
+                   || is_true_predicate (ca
+                        = fold_or_predicates (EXPR_LOCATION (cb), ca, cb)))
+                 {
+                   DR_RW_UNCONDITIONALLY (a) = 1;
+                   DR_RW_UNCONDITIONALLY (b) = 1;
+                   found = true;
+                   break;
+                 }
+               }
            }
 
        if (!found)