tree-affine.c (add_elt_to_tree): Avoid converting all pointer arithmetic to sizetype.
authorRichard Biener <rguenther@suse.de>
Mon, 2 Sep 2013 11:37:13 +0000 (11:37 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 2 Sep 2013 11:37:13 +0000 (11:37 +0000)
2013-09-02  Richard Biener  <rguenther@suse.de>

* tree-affine.c (add_elt_to_tree): Avoid converting all pointer
arithmetic to sizetype.

* gcc.dg/tree-ssa/loop-4.c: Adjust scan looking for one memory
reference.

From-SVN: r202165

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/loop-4.c
gcc/tree-affine.c

index 5b3126636d9a67bac44a4b4630efce732a0be47b..2ffa49e1750a374b3158ac46c4cc602f8dc3e9a3 100644 (file)
@@ -1,3 +1,8 @@
+2013-09-02  Richard Biener  <rguenther@suse.de>
+
+       * tree-affine.c (add_elt_to_tree): Avoid converting all pointer
+       arithmetic to sizetype.
+
 2013-09-02  Bin Cheng  <bin.cheng@arm.com>
 
        * tree-ssa-loop-ivopts.c (set_autoinc_for_original_candidates):
index b74effc240aaea5761abad27dae605721f8e1503..4cb359c3ca1082f3e36c637e8877b4a927dad820 100644 (file)
@@ -1,3 +1,8 @@
+2013-09-02  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/tree-ssa/loop-4.c: Adjust scan looking for one memory
+       reference.
+
 2013-09-02  Bin Cheng  <bin.cheng@arm.com>
 
        * gcc.target/arm/ivopts-orig_biv-inc.c: New testcase.
index a6c8c8fd34a1ac4beaf1d931945311f7ace72d5d..4313fca50e7d90cd661611119fed2c5e862baed6 100644 (file)
@@ -37,7 +37,7 @@ void xxx(void)
 
 /* { dg-final { scan-tree-dump-times " \\* \[^\\n\\r\]*=" 0 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "\[^\\n\\r\]*= \\* " 0 "optimized" } } */
-/* { dg-final { scan-tree-dump-times "MEM" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " MEM" 1 "optimized" } } */
 
 /* And the original induction variable should be eliminated.  */
 
index 46a183a07b4ddd10e0bb1bb3b1807e37ac0b6fcc..914b3d77051973e7bb1395c32da6e998e064cb8c 100644 (file)
@@ -377,35 +377,46 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
     type1 = sizetype;
 
   scale = double_int_ext_for_comb (scale, comb);
-  elt = fold_convert (type1, elt);
+
+  if (scale.is_minus_one ()
+      && POINTER_TYPE_P (TREE_TYPE (elt)))
+    {
+      elt = fold_build1 (NEGATE_EXPR, sizetype, convert_to_ptrofftype (elt));
+      scale = double_int_one;
+    }
 
   if (scale.is_one ())
     {
       if (!expr)
-       return fold_convert (type, elt);
-
-      if (POINTER_TYPE_P (type))
-        return fold_build_pointer_plus (expr, elt);
-      return fold_build2 (PLUS_EXPR, type, expr, elt);
+       return elt;
+
+      if (POINTER_TYPE_P (TREE_TYPE (expr)))
+       return fold_build_pointer_plus (expr, convert_to_ptrofftype (elt));
+      if (POINTER_TYPE_P (TREE_TYPE (elt)))
+       return fold_build_pointer_plus (elt, convert_to_ptrofftype (expr));
+      return fold_build2 (PLUS_EXPR, type1,
+                         fold_convert (type1, expr),
+                         fold_convert (type1, elt));
     }
 
   if (scale.is_minus_one ())
     {
       if (!expr)
-       return fold_convert (type, fold_build1 (NEGATE_EXPR, type1, elt));
-
-      if (POINTER_TYPE_P (type))
-       {
-         elt = fold_build1 (NEGATE_EXPR, type1, elt);
-         return fold_build_pointer_plus (expr, elt);
-       }
-      return fold_build2 (MINUS_EXPR, type, expr, elt);
+       return fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
+
+      if (POINTER_TYPE_P (TREE_TYPE (expr)))
+       return fold_build_pointer_plus
+           (expr, convert_to_ptrofftype
+            (fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt)));
+      return fold_build2 (MINUS_EXPR, type1,
+                         fold_convert (type1, expr),
+                         fold_convert (type1, elt));
     }
 
+  elt = fold_convert (type1, elt);
   if (!expr)
-    return fold_convert (type,
-                        fold_build2 (MULT_EXPR, type1, elt,
-                                     double_int_to_tree (type1, scale)));
+    return fold_build2 (MULT_EXPR, type1, elt,
+                       double_int_to_tree (type1, scale));
 
   if (scale.is_negative ())
     {
@@ -417,13 +428,14 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
 
   elt = fold_build2 (MULT_EXPR, type1, elt,
                     double_int_to_tree (type1, scale));
-  if (POINTER_TYPE_P (type))
+  if (POINTER_TYPE_P (TREE_TYPE (expr)))
     {
       if (code == MINUS_EXPR)
         elt = fold_build1 (NEGATE_EXPR, type1, elt);
       return fold_build_pointer_plus (expr, elt);
     }
-  return fold_build2 (code, type, expr, elt);
+  return fold_build2 (code, type1,
+                     fold_convert (type1, expr), elt);
 }
 
 /* Makes tree from the affine combination COMB.  */