OSDN Git Service

* tree.h (contains_packed_reference): Mention ARRAY_RANGE_REF in
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 11 Oct 2008 19:48:47 +0000 (19:48 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 11 Oct 2008 19:48:47 +0000 (19:48 +0000)
head comment.
(array_ref_element_size): Likewise.
(array_ref_low_bound): Likewise.
(array_ref_up_bound): Likewise.
* expr.c (contains_packed_reference): Likewise.
(array_ref_element_size): Likewise.
(array_ref_low_bound): Likewise.
(array_ref_up_bound): Likewise.
* tree-ssa-loop-ivopts.c (idx_contains_abnormal_ssa_name_p): Deal
with ARRAY_RANGE_REF.
(idx_find_step): Likewise.
(idx_record_use): Likewise.
(strip_offset_1): Likewise.
(idx_remove_ssa_names): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141065 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/loop_optimization5.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/loop_optimization5_pkg.ads [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c
gcc/tree.h

index a16fb6a..741c556 100644 (file)
@@ -1,3 +1,21 @@
+2008-10-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * tree.h (contains_packed_reference): Mention ARRAY_RANGE_REF in
+       head comment.
+       (array_ref_element_size): Likewise.
+       (array_ref_low_bound): Likewise.
+       (array_ref_up_bound): Likewise.
+       * expr.c (contains_packed_reference): Likewise.
+       (array_ref_element_size): Likewise.
+       (array_ref_low_bound): Likewise.
+       (array_ref_up_bound): Likewise.
+       * tree-ssa-loop-ivopts.c (idx_contains_abnormal_ssa_name_p): Deal
+       with ARRAY_RANGE_REF.
+       (idx_find_step): Likewise.
+       (idx_record_use): Likewise.
+       (strip_offset_1): Likewise.
+       (idx_remove_ssa_names): Likewise.
+
 2008-10-11  Uros Bizjak  <ubizjak@gmail.com>
            Andi Kleen  <ak@linux.intel.com>
 
index 277a6e1..11902b8 100644 (file)
@@ -6079,9 +6079,9 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
   return exp;
 }
 
-/* Given an expression EXP that may be a COMPONENT_REF or an ARRAY_REF,
-   look for whether EXP or any nested component-refs within EXP is marked
-   as PACKED.  */
+/* Given an expression EXP that may be a COMPONENT_REF, an ARRAY_REF or an
+   ARRAY_RANGE_REF, look for whether EXP or any nested component-refs within
+   EXP is marked as PACKED.  */
 
 bool
 contains_packed_reference (const_tree exp)
@@ -6121,7 +6121,7 @@ contains_packed_reference (const_tree exp)
 }
 
 /* Return a tree of sizetype representing the size, in bytes, of the element
-   of EXP, an ARRAY_REF.  */
+   of EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 
 tree
 array_ref_element_size (tree exp)
@@ -6148,7 +6148,7 @@ array_ref_element_size (tree exp)
 }
 
 /* Return a tree representing the lower bound of the array mentioned in
-   EXP, an ARRAY_REF.  */
+   EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 
 tree
 array_ref_low_bound (tree exp)
@@ -6169,7 +6169,7 @@ array_ref_low_bound (tree exp)
 }
 
 /* Return a tree representing the upper bound of the array mentioned in
-   EXP, an ARRAY_REF.  */
+   EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 
 tree
 array_ref_up_bound (tree exp)
index 5a31ae3..33940f7 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/loop_optimization5.adb: New test.
+       * gnat.dg/loop_optimization5_pkg.adb: New helper.
+
 2008-10-11  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/37794
diff --git a/gcc/testsuite/gnat.dg/loop_optimization5.adb b/gcc/testsuite/gnat.dg/loop_optimization5.adb
new file mode 100644 (file)
index 0000000..09bf3e2
--- /dev/null
@@ -0,0 +1,21 @@
+-- { dg-do compile }
+-- { dg-options "-O -gnatp" }
+
+with Loop_Optimization5_Pkg; use Loop_Optimization5_Pkg;
+
+procedure Loop_Optimization5 is
+   Str : constant String := "12345678";
+   Cmd : constant String := Init;
+   StartP : Positive := Cmd'First;
+   StartS : Positive := Cmd'Last + 1;
+   EndP   : Natural := StartP - 1;
+   Full_Cmd : String_Access;
+begin
+   for J in StartP .. Cmd'Last - Str'Length + 1 loop
+      if Cmd (J .. J + Str'Length - 1) = Str then
+         EndP := J - 1;
+         exit;
+      end if;
+   end loop;
+   Full_Cmd := Locate (Cmd (StartP .. EndP));
+end;
diff --git a/gcc/testsuite/gnat.dg/loop_optimization5_pkg.ads b/gcc/testsuite/gnat.dg/loop_optimization5_pkg.ads
new file mode 100644 (file)
index 0000000..4af6c1c
--- /dev/null
@@ -0,0 +1,7 @@
+package Loop_Optimization5_Pkg is
+
+  type String_Access is access all String;
+  function Init return String;
+  function Locate (S : String) return String_Access;
+
+end Loop_Optimization5_Pkg;
index c924a76..628d426 100644 (file)
@@ -632,7 +632,7 @@ static bool
 idx_contains_abnormal_ssa_name_p (tree base, tree *index,
                                  void *data ATTRIBUTE_UNUSED)
 {
-  if (TREE_CODE (base) == ARRAY_REF)
+  if (TREE_CODE (base) == ARRAY_REF || TREE_CODE (base) == ARRAY_RANGE_REF)
     {
       if (abnormal_ssa_name_p (TREE_OPERAND (base, 2)))
        return false;
@@ -1356,8 +1356,13 @@ idx_find_step (tree base, tree *idx, void *data)
      reference out of the loop (in order to take its address in strength
      reduction).  In order for this to work we need both lower bound
      and step to be loop invariants.  */
-  if (TREE_CODE (base) == ARRAY_REF)
+  if (TREE_CODE (base) == ARRAY_REF || TREE_CODE (base) == ARRAY_RANGE_REF)
     {
+      /* Moreover, for a range, the size needs to be invariant as well.  */
+      if (TREE_CODE (base) == ARRAY_RANGE_REF
+         && !expr_invariant_in_loop_p (loop, TYPE_SIZE (TREE_TYPE (base))))
+       return false;
+
       step = array_ref_element_size (base);
       lbound = array_ref_low_bound (base);
 
@@ -1381,7 +1386,7 @@ idx_find_step (tree base, tree *idx, void *data)
   if (integer_zerop (iv->step))
     return true;
 
-  if (TREE_CODE (base) == ARRAY_REF)
+  if (TREE_CODE (base) == ARRAY_REF || TREE_CODE (base) == ARRAY_RANGE_REF)
     {
       step = array_ref_element_size (base);
 
@@ -1418,7 +1423,7 @@ idx_record_use (tree base, tree *idx,
 {
   struct ivopts_data *data = (struct ivopts_data *) vdata;
   find_interesting_uses_op (data, *idx);
-  if (TREE_CODE (base) == ARRAY_REF)
+  if (TREE_CODE (base) == ARRAY_REF || TREE_CODE (base) == ARRAY_RANGE_REF)
     {
       find_interesting_uses_op (data, array_ref_element_size (base));
       find_interesting_uses_op (data, array_ref_low_bound (base));
@@ -1918,6 +1923,7 @@ strip_offset_1 (tree expr, bool inside_addr, bool top_compref,
       return fold_convert (orig_type, expr);
 
     case ARRAY_REF:
+    case ARRAY_RANGE_REF:
       if (!inside_addr)
        return orig_expr;
 
@@ -5180,7 +5186,7 @@ idx_remove_ssa_names (tree base, tree *idx,
   if (TREE_CODE (*idx) == SSA_NAME)
     *idx = SSA_NAME_VAR (*idx);
 
-  if (TREE_CODE (base) == ARRAY_REF)
+  if (TREE_CODE (base) == ARRAY_REF || TREE_CODE (base) == ARRAY_RANGE_REF)
     {
       op = &TREE_OPERAND (base, 2);
       if (*op
index 034be6a..a8edda7 100644 (file)
@@ -4552,24 +4552,24 @@ extern tree get_inner_reference (tree, HOST_WIDE_INT *, HOST_WIDE_INT *,
                                 tree *, enum machine_mode *, int *, int *,
                                 bool);
 
-/* Given an expression EXP that may be a COMPONENT_REF or an ARRAY_REF,
-   look for whether EXP or any nested component-refs within EXP is marked
-   as PACKED.  */
+/* Given an expression EXP that may be a COMPONENT_REF, an ARRAY_REF or an
+   ARRAY_RANGE_REF, look for whether EXP or any nested component-refs within
+   EXP is marked as PACKED.  */
 
 extern bool contains_packed_reference (const_tree exp);
 
 /* Return a tree of sizetype representing the size, in bytes, of the element
-   of EXP, an ARRAY_REF.  */
+   of EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 
 extern tree array_ref_element_size (tree);
 
 /* Return a tree representing the lower bound of the array mentioned in
-   EXP, an ARRAY_REF.  */
+   EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 
 extern tree array_ref_low_bound (tree);
 
 /* Return a tree representing the upper bound of the array mentioned in
-   EXP, an ARRAY_REF.  */
+   EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 
 extern tree array_ref_up_bound (tree);