2013-09-03 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Sep 2013 10:02:56 +0000 (10:02 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Sep 2013 10:02:56 +0000 (10:02 +0000)
* tree-affine.c (add_elt_to_tree): Fix association issue,
avoid useless converts and make sure to always return a
properly typed result.

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

gcc/ChangeLog
gcc/tree-affine.c

index 11b95c7..e107860 100644 (file)
@@ -1,5 +1,11 @@
 2013-09-03  Richard Biener  <rguenther@suse.de>
 
+       * tree-affine.c (add_elt_to_tree): Fix association issue,
+       avoid useless converts and make sure to always return a
+       properly typed result.
+
+2013-09-03  Richard Biener  <rguenther@suse.de>
+
        PR middle-end/57656
        * fold-const.c (negate_expr_p): Fix division case.
        (negate_expr): Likewise.
index 914b3d7..81da521 100644 (file)
@@ -381,36 +381,43 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
   if (scale.is_minus_one ()
       && POINTER_TYPE_P (TREE_TYPE (elt)))
     {
-      elt = fold_build1 (NEGATE_EXPR, sizetype, convert_to_ptrofftype (elt));
+      elt = convert_to_ptrofftype (elt);
+      elt = fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
       scale = double_int_one;
     }
 
   if (scale.is_one ())
     {
       if (!expr)
-       return elt;
+       {
+         if (POINTER_TYPE_P (TREE_TYPE (elt)))
+           return elt;
+         else
+           return fold_convert (type1, elt);
+       }
 
       if (POINTER_TYPE_P (TREE_TYPE (expr)))
-       return fold_build_pointer_plus (expr, convert_to_ptrofftype (elt));
+       return fold_build_pointer_plus (expr, elt);
       if (POINTER_TYPE_P (TREE_TYPE (elt)))
-       return fold_build_pointer_plus (elt, convert_to_ptrofftype (expr));
+       return fold_build_pointer_plus (elt, expr);
       return fold_build2 (PLUS_EXPR, type1,
-                         fold_convert (type1, expr),
-                         fold_convert (type1, elt));
+                         expr, fold_convert (type1, elt));
     }
 
   if (scale.is_minus_one ())
     {
       if (!expr)
-       return fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
+       return fold_build1 (NEGATE_EXPR, type1,
+                           fold_convert (type1, 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)));
+       {
+         elt = convert_to_ptrofftype (elt);
+         elt = fold_build1 (NEGATE_EXPR, TREE_TYPE (elt), elt);
+         return fold_build_pointer_plus (expr, elt);
+       }
       return fold_build2 (MINUS_EXPR, type1,
-                         fold_convert (type1, expr),
-                         fold_convert (type1, elt));
+                         expr, fold_convert (type1, elt));
     }
 
   elt = fold_convert (type1, elt);
@@ -434,8 +441,7 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale,
         elt = fold_build1 (NEGATE_EXPR, type1, elt);
       return fold_build_pointer_plus (expr, elt);
     }
-  return fold_build2 (code, type1,
-                     fold_convert (type1, expr), elt);
+  return fold_build2 (code, type1, expr, elt);
 }
 
 /* Makes tree from the affine combination COMB.  */