re PR target/66112 (__builtin_mul_overflow for int16_t emits poor code)
authorJakub Jelinek <jakub@redhat.com>
Wed, 13 May 2015 08:07:58 +0000 (10:07 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 13 May 2015 08:07:58 +0000 (10:07 +0200)
PR target/66112
* internal-fn.c (get_min_precision): Use UNSIGNED instead of
SIGNED to get precision of non-negative value.

* gcc.target/i386/pr66112-1.c: New test.

From-SVN: r223115

gcc/ChangeLog
gcc/internal-fn.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr66112-1.c [new file with mode: 0644]

index 35f8197d22bf156ca09a35dcf9ce93fee72297e7..1199ad7dc2c40a471d52dab11839ce32cab5335d 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/66112
+       * internal-fn.c (get_min_precision): Use UNSIGNED instead of
+       SIGNED to get precision of non-negative value.
+
 2015-05-13  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        PR target/66048
index 0053ed9574910991f21d217b1f2087822b44d64e..4eeb68133a798b909781df22297cefecff6f15f2 100644 (file)
@@ -399,7 +399,7 @@ get_min_precision (tree arg, signop sign)
     }
   else if (sign == UNSIGNED && !wi::neg_p (arg_min, SIGNED))
     {
-      int p = wi::min_precision (arg_max, SIGNED);
+      int p = wi::min_precision (arg_max, UNSIGNED);
       prec = MIN (prec, p);
     }
   return prec + (orig_sign != sign);
index 2f83f4e4fca78f0c907e0bd5e1b2625f97a45c37..4600fe1f8a46ed3e550219f48f9d87decd019ac9 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/66112
+       * gcc.target/i386/pr66112-1.c: New test.
+
 2015-05-13  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        PR target/66048
diff --git a/gcc/testsuite/gcc.target/i386/pr66112-1.c b/gcc/testsuite/gcc.target/i386/pr66112-1.c
new file mode 100644 (file)
index 0000000..268990c
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR target/66112 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+unsigned int
+foo (long long a, long long b)
+{
+  unsigned int res;
+  a &= ~0U;
+  b &= ~0U;
+  if (__builtin_mul_overflow (a, b, &res))
+    res = 0x123U;
+  return res;
+}
+
+/* { dg-final { scan-assembler "jn?o\[ \t\]" } } */