]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
convert.c (convert_to_integer): Do not introduce useless conversions between integral...
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 3 Oct 2014 10:28:50 +0000 (10:28 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 3 Oct 2014 10:28:50 +0000 (10:28 +0000)
* convert.c (convert_to_integer): Do not introduce useless conversions
between integral types.

From-SVN: r215843

gcc/ChangeLog
gcc/convert.c

index 62903f447627cc17b78a4ec40b2c767ddaf901bf..56add5bffc1b9f81a8c1452b1ab80ac1cac19397 100644 (file)
@@ -1,3 +1,8 @@
+2014-10-03  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * convert.c (convert_to_integer): Do not introduce useless conversions
+       between integral types.
+
 2014-10-03  David Sherwood  <david.sherwood@arm.com>
 
        * ira-int.h (ira_allocno): Mark hard_regno as signed.
index 3834351aad52811f5c63ae1dd074e2c12de2f1a9..9ef27f6347f8257e6bc6c24a1f484e02ebe51b3e 100644 (file)
@@ -746,8 +746,9 @@ convert_to_integer (tree type, tree expr)
                /* Can't do arithmetic in enumeral types
                   so use an integer type that will hold the values.  */
                if (TREE_CODE (typex) == ENUMERAL_TYPE)
-                 typex = lang_hooks.types.type_for_size
-                   (TYPE_PRECISION (typex), TYPE_UNSIGNED (typex));
+                 typex
+                   = lang_hooks.types.type_for_size (TYPE_PRECISION (typex),
+                                                     TYPE_UNSIGNED (typex));
 
                /* But now perhaps TYPEX is as wide as INPREC.
                   In that case, do nothing special here.
@@ -788,9 +789,15 @@ convert_to_integer (tree type, tree expr)
                            && (ex_form == PLUS_EXPR
                                || ex_form == MINUS_EXPR
                                || ex_form == MULT_EXPR)))
-                     typex = unsigned_type_for (typex);
+                     {
+                       if (!TYPE_UNSIGNED (typex))
+                         typex = unsigned_type_for (typex);
+                     }
                    else
-                     typex = signed_type_for (typex);
+                     {
+                       if (TYPE_UNSIGNED (typex))
+                         typex = signed_type_for (typex);
+                     }
                    return convert (type,
                                    fold_build2 (ex_form, typex,
                                                 convert (typex, arg0),
@@ -805,7 +812,19 @@ convert_to_integer (tree type, tree expr)
          /* This is not correct for ABS_EXPR,
             since we must test the sign before truncation.  */
          {
-           tree typex = unsigned_type_for (type);
+           /* Do the arithmetic in type TYPEX,
+              then convert result to TYPE.  */
+           tree typex = type;
+
+           /* Can't do arithmetic in enumeral types
+              so use an integer type that will hold the values.  */
+           if (TREE_CODE (typex) == ENUMERAL_TYPE)
+             typex
+               = lang_hooks.types.type_for_size (TYPE_PRECISION (typex),
+                                                 TYPE_UNSIGNED (typex));
+
+           if (!TYPE_UNSIGNED (typex))
+             typex = unsigned_type_for (typex);
            return convert (type,
                            fold_build1 (ex_form, typex,
                                         convert (typex,