tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound in...
authorJan Hubicka <jh@suse.cz>
Tue, 7 Sep 2010 15:50:22 +0000 (17:50 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Tue, 7 Sep 2010 15:50:22 +0000 (15:50 +0000)
* tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound
in string access folding.

From-SVN: r163956

gcc/ChangeLog
gcc/tree-ssa-ccp.c

index 97f24154b5d2569cbf37077899ea18a6ba6173a4..7d75459163edeb8a9454d9e9b5ab2196d6b1a872 100644 (file)
@@ -1,3 +1,8 @@
+2010-09-07  Jan Hubicka  <jh@suse.cz>
+
+       * tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound
+       in string access folding.
+
 2010-09-07  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/45206
@@ -6,7 +11,7 @@
 
 2010-09-07  Jan Hubicka  <jh@suse.cz>
 
-       * gimple.c (maybe_fold_reference): Verify that operand is
+       * gimple-fold.c (maybe_fold_reference): Verify that operand is
        gimple_min_invariant.
 
 2010-09-07  Richard Guenther  <rguenther@suse.de>
index fc3f1586b167ef93395db09524ce6f53f5f4cb59..734147794a6b4baa3f0f82829c8f6cc7b79921f9 100644 (file)
@@ -1398,17 +1398,30 @@ fold_const_aggregate_ref (tree t)
        }
 
       /* Fold read from constant string.  */
-      if (TREE_CODE (ctor) == STRING_CST)
+      if (TREE_CODE (ctor) == STRING_CST
+         && TREE_CODE (idx) == INTEGER_CST)
        {
+         tree low_bound = array_ref_low_bound (t);
+         double_int low_bound_cst;
+         double_int index_cst;
+         double_int length_cst;
+         bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx));
+
+         if (TREE_CODE (low_bound) != INTEGER_CST)
+           return NULL_TREE;
+         low_bound_cst = tree_to_double_int (low_bound);
+         index_cst = tree_to_double_int (idx);
+         length_cst = uhwi_to_double_int (TREE_STRING_LENGTH (ctor));
+         index_cst = double_int_sub (index_cst, low_bound_cst);
          if ((TYPE_MODE (TREE_TYPE (t))
               == TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
              && (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor))))
                  == MODE_INT)
              && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) == 1
-             && compare_tree_int (idx, TREE_STRING_LENGTH (ctor)) < 0)
+             && double_int_cmp (index_cst, length_cst, signed_p) < 0)
            return build_int_cst_type (TREE_TYPE (t),
                                       (TREE_STRING_POINTER (ctor)
-                                       [TREE_INT_CST_LOW (idx)]));
+                                       [double_int_to_uhwi (index_cst)]));
          return NULL_TREE;
        }