Generate signed types whenever possible.
authorSebastian Pop <sebastian.pop@amd.com>
Thu, 21 Jul 2011 22:57:49 +0000 (22:57 +0000)
committerSebastian Pop <spop@gcc.gnu.org>
Thu, 21 Jul 2011 22:57:49 +0000 (22:57 +0000)
2011-07-21  Sebastian Pop  <sebastian.pop@amd.com>

* graphite-clast-to-gimple.c (type_for_interval): Generate signed
types whenever possible.

From-SVN: r176604

gcc/ChangeLog
gcc/graphite-clast-to-gimple.c

index d3921eda98f88ebbc972cac4a021595fcd1a700b..ea4db8c36c2cdb493bbbdc51e9038fb35e4eea88 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-21  Sebastian Pop  <sebastian.pop@amd.com>
+
+       * graphite-clast-to-gimple.c (type_for_interval): Generate signed
+       types whenever possible.
+
 2011-07-21  Sebastian Pop  <sebastian.pop@amd.com>
 
        * graphite-clast-to-gimple.c (struct clast_name_index): Add lb
index 6bc84d2a4b236333723a46da3395e8e705607330..9cd27372bb65a3cef727388c6edf0155259fb2a8 100644 (file)
@@ -443,6 +443,7 @@ type_for_interval (mpz_t v1, mpz_t v2)
   bool unsigned_p;
   tree type;
   enum machine_mode mode;
+  int wider_precision;
   int precision = MAX (mpz_sizeinbase (v1, 2),
                       mpz_sizeinbase (v2, 2));
 
@@ -458,8 +459,16 @@ type_for_interval (mpz_t v1, mpz_t v2)
     unsigned_p = (mpz_sgn (v2) >= 0);
 
   mode = smallest_mode_for_size (precision, MODE_INT);
-  precision = GET_MODE_PRECISION (mode);
-  type = build_nonstandard_integer_type (precision, unsigned_p);
+  wider_precision = GET_MODE_PRECISION (mode);
+
+  /* As we want to generate signed types as much as possible, try to
+     fit the interval [v1, v2] in a signed type.  For example,
+     supposing that we have the interval [0, 100], instead of
+     generating unsigned char, we want to generate a signed char.  */
+  if (unsigned_p && precision < wider_precision)
+    unsigned_p = false;
+
+  type = build_nonstandard_integer_type (wider_precision, unsigned_p);
 
   if (!type)
     {