diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2008-10-11 19:48:47 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2008-10-11 19:48:47 +0000 |
commit | 9f7ccf694409ec79ed2ab4cbdf43f024c70960be (patch) | |
tree | 40f5d3aac1fccc02915a3d77bf03532479d573bc | |
parent | cb0dee885cb30b4e9beeef070cf000baa7d09abe (diff) | |
download | gcc-9f7ccf694409ec79ed2ab4cbdf43f024c70960be.zip gcc-9f7ccf694409ec79ed2ab4cbdf43f024c70960be.tar.gz gcc-9f7ccf694409ec79ed2ab4cbdf43f024c70960be.tar.bz2 |
tree.h (contains_packed_reference): Mention ARRAY_RANGE_REF in head comment.
* 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.
From-SVN: r141065
-rw-r--r-- | gcc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/expr.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/loop_optimization5.adb | 21 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/loop_optimization5_pkg.ads | 7 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-ivopts.c | 16 | ||||
-rw-r--r-- | gcc/tree.h | 12 |
7 files changed, 74 insertions, 17 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a16fb6a..741c556 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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> @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5a31ae3..33940f7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..09bf3e2 --- /dev/null +++ b/gcc/testsuite/gnat.dg/loop_optimization5.adb @@ -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 index 0000000..4af6c1c --- /dev/null +++ b/gcc/testsuite/gnat.dg/loop_optimization5_pkg.ads @@ -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; diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index c924a76..628d426 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -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 @@ -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); |