tree-ssa-loop-ivopts.c (set_autoinc_for_original_candidates): Find auto-increment...
authorBin Cheng <bin.cheng@arm.com>
Mon, 2 Sep 2013 09:58:41 +0000 (09:58 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Mon, 2 Sep 2013 09:58:41 +0000 (09:58 +0000)
* tree-ssa-loop-ivopts.c (set_autoinc_for_original_candidates):
Find auto-increment use both before and after candidate.

* gcc.target/arm/ivopts-orig_biv-inc.c: New testcase.

From-SVN: r202164

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/arm/ivopts-orig_biv-inc.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c

index f24b24a202094fb2eac52e382b25717db82386e2..5b3126636d9a67bac44a4b4630efce732a0be47b 100644 (file)
@@ -1,3 +1,8 @@
+2013-09-02  Bin Cheng  <bin.cheng@arm.com>
+
+       * tree-ssa-loop-ivopts.c (set_autoinc_for_original_candidates):
+       Find auto-increment use both before and after candidate.
+
 2013-09-02  Marek Polacek  <polacek@redhat.com>
 
        * Makefile.in (ubsan.o): Add $(TM_P_H) dependency.
index c87b30ac4b0c5dff28060618e8ba9e40a9383c66..b74effc240aaea5761abad27dae605721f8e1503 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-02  Bin Cheng  <bin.cheng@arm.com>
+
+       * gcc.target/arm/ivopts-orig_biv-inc.c: New testcase.
+
 2013-09-02  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/21682, implement DR 565
diff --git a/gcc/testsuite/gcc.target/arm/ivopts-orig_biv-inc.c b/gcc/testsuite/gcc.target/arm/ivopts-orig_biv-inc.c
new file mode 100644 (file)
index 0000000..f466ff3
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
+/* { dg-skip-if "" { arm_thumb1 } } */
+
+extern char *__ctype_ptr__;
+
+unsigned char * foo(unsigned char *ReadPtr)
+{
+
+ unsigned char c;
+
+ while (!(((__ctype_ptr__+sizeof(""[*ReadPtr]))[(int)(*ReadPtr)])&04) == (!(0)))
+  ReadPtr++;
+
+ return ReadPtr;
+}
+
+/* { dg-final { scan-tree-dump-times "original biv" 2 "ivopts"} } */
+/* { dg-final { cleanup-tree-dump "ivopts" } } */
index 7cfe80d921355f034d9a9347be4663a62ac66fdd..c45f3167f2f4e3b295effc98f5a110fa40c14bc7 100644 (file)
@@ -4876,22 +4876,36 @@ set_autoinc_for_original_candidates (struct ivopts_data *data)
   for (i = 0; i < n_iv_cands (data); i++)
     {
       struct iv_cand *cand = iv_cand (data, i);
-      struct iv_use *closest = NULL;
+      struct iv_use *closest_before = NULL;
+      struct iv_use *closest_after = NULL;
       if (cand->pos != IP_ORIGINAL)
        continue;
+
       for (j = 0; j < n_iv_uses (data); j++)
        {
          struct iv_use *use = iv_use (data, j);
          unsigned uid = gimple_uid (use->stmt);
-         if (gimple_bb (use->stmt) != gimple_bb (cand->incremented_at)
-             || uid > gimple_uid (cand->incremented_at))
+
+         if (gimple_bb (use->stmt) != gimple_bb (cand->incremented_at))
            continue;
-         if (closest == NULL || uid > gimple_uid (closest->stmt))
-           closest = use;
+
+         if (uid < gimple_uid (cand->incremented_at)
+             && (closest_before == NULL
+                 || uid > gimple_uid (closest_before->stmt)))
+           closest_before = use;
+
+         if (uid > gimple_uid (cand->incremented_at)
+             && (closest_after == NULL
+                 || uid < gimple_uid (closest_after->stmt)))
+           closest_after = use;
        }
-      if (closest == NULL || !autoinc_possible_for_pair (data, closest, cand))
-       continue;
-      cand->ainc_use = closest;
+
+      if (closest_before != NULL
+         && autoinc_possible_for_pair (data, closest_before, cand))
+       cand->ainc_use = closest_before;
+      else if (closest_after != NULL
+              && autoinc_possible_for_pair (data, closest_after, cand))
+       cand->ainc_use = closest_after;
     }
 }