From c1ee2e626ea59d8ba14a1d2f36621a2fe525320a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 13 May 2015 10:07:58 +0200 Subject: [PATCH] re PR target/66112 (__builtin_mul_overflow for int16_t emits poor code) 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 | 6 ++++++ gcc/internal-fn.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/i386/pr66112-1.c | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr66112-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 35f8197d22b..1199ad7dc2c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-05-13 Jakub Jelinek + + 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 PR target/66048 diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 0053ed95749..4eeb68133a7 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2f83f4e4fca..4600fe1f8a4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-05-13 Jakub Jelinek + + PR target/66112 + * gcc.target/i386/pr66112-1.c: New test. + 2015-05-13 Ilya Enkovich 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 index 00000000000..268990ccf85 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr66112-1.c @@ -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\]" } } */ -- 2.30.2