public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: "Thomas Preud'homme" <thomas.preudhomme@arm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix PR61375: cancel bswap optimization when value doesn't fit in a HOST_WIDE_INT
Date: Mon, 23 Jun 2014 08:18:00 -0000	[thread overview]
Message-ID: <CAFiYyc0Y6do+ahNngtoE=RzVutBw3=5MXcNr0fXpM6xaOo+YUw@mail.gmail.com> (raw)
In-Reply-To: <002301cf8c74$3a934a20$afb9de60$@arm.com>

On Fri, Jun 20, 2014 at 12:41 PM, Thomas Preud'homme
<thomas.preudhomme@arm.com> wrote:
>> From: Richard Biener [mailto:richard.guenther@gmail.com]
>> Sent: Tuesday, June 10, 2014 5:05 PM
>>
>> Backports are welcome - please post a patch.
>>
>
> Sorry for the delay. Here you are:
>
> diff --git a/gcc/testsuite/gcc.c-torture/execute/pr61375.c b/gcc/testsuite/gcc.c-torture/execute/pr61375.c
> new file mode 100644
> index 0000000..d3b54a8
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/execute/pr61375.c
> @@ -0,0 +1,35 @@
> +#ifdef __UINT64_TYPE__
> +typedef __UINT64_TYPE__ uint64_t;
> +#else
> +typedef unsigned long long uint64_t;
> +#endif
> +
> +#ifndef __SIZEOF_INT128__
> +#define __int128 long long
> +#endif
> +
> +/* Some version of bswap optimization would ICE when analyzing a mask constant
> +   too big for an HOST_WIDE_INT (PR61375).  */
> +
> +__attribute__ ((noinline, noclone)) uint64_t
> +uint128_central_bitsi_ior (unsigned __int128 in1, uint64_t in2)
> +{
> +  __int128 mask = (__int128)0xffff << 56;
> +  return ((in1 & mask) >> 56) | in2;
> +}
> +
> +int
> +main (int argc)
> +{
> +  __int128 in = 1;
> +#ifdef __SIZEOF_INT128__
> +  in <<= 64;
> +#endif
> +  if (sizeof (uint64_t) * __CHAR_BIT__ != 64)
> +    return 0;
> +  if (sizeof (unsigned __int128) * __CHAR_BIT__ != 128)
> +    return 0;
> +  if (uint128_central_bitsi_ior (in, 2) != 0x102)
> +    __builtin_abort ();
> +  return 0;
> +}
> diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
> index 9ff857c..9d64205 100644
> --- a/gcc/tree-ssa-math-opts.c
> +++ b/gcc/tree-ssa-math-opts.c
> @@ -1741,6 +1741,8 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit)
>           if (n->size % BITS_PER_UNIT != 0)
>             return NULL_TREE;
>           n->size /= BITS_PER_UNIT;
> +         if (n->size > (int)sizeof (unsigned HOST_WIDEST_INT))
> +           return NULL_TREE;
>           n->n = (sizeof (HOST_WIDEST_INT) < 8 ? 0 :
>                   (unsigned HOST_WIDEST_INT)0x08070605 << 32 | 0x04030201);
>
> @@ -1781,6 +1783,8 @@ find_bswap_1 (gimple stmt, struct symbolic_number *n, int limit)
>             type_size = TYPE_PRECISION (gimple_expr_type (stmt));
>             if (type_size % BITS_PER_UNIT != 0)
>               return NULL_TREE;
> +           if (type_size > (int)HOST_BITS_PER_WIDEST_INT)
> +             return NULL_TREE;
>
>             if (type_size / BITS_PER_UNIT < (int)(sizeof (HOST_WIDEST_INT)))
>               {
>
> Ok for GCC 4.8 and GCC 4.9 branches?

Ok.

Thanks,
Richard.

> Best regards,
>
> Thomas
>
>

  reply	other threads:[~2014-06-23  8:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-10  2:30 Thomas Preud'homme
2014-06-10  9:04 ` Richard Biener
2014-06-20 10:41   ` Thomas Preud'homme
2014-06-23  8:18     ` Richard Biener [this message]
2014-06-23  8:36       ` Jakub Jelinek
2014-06-23  8:51         ` Thomas Preud'homme
2014-06-23  8:59           ` Jakub Jelinek
2014-06-23  9:29             ` Thomas Preud'homme
2014-06-23  9:32               ` Thomas Preud'homme
2014-06-26  1:11             ` Thomas Preud'homme
2014-07-02  5:46               ` Thomas Preud'homme
2014-07-31  7:39               ` Thomas Preud'homme
2014-08-01  6:59                 ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFiYyc0Y6do+ahNngtoE=RzVutBw3=5MXcNr0fXpM6xaOo+YUw@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=thomas.preudhomme@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).