public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com
Subject: Re: [PATCH] Handle overflow in dependence analysis lambda ops gracefully
Date: Wed, 20 Jan 2021 12:33:58 +0100	[thread overview]
Message-ID: <20210120113358.GP4020736@tucnak> (raw)
In-Reply-To: <nycvar.YFH.7.76.2101201228390.24028@elmra.sevgm.obk>

On Wed, Jan 20, 2021 at 12:29:23PM +0100, Richard Biener wrote:
> +/* Compute the product of signed A and B and indicate in *OVERFLOW whether
> +   that operation overflowed.  */
> +
> +inline HOST_WIDE_INT
> +mul_hwi (HOST_WIDE_INT a, HOST_WIDE_INT b, bool *overflow)
> +{
> +  unsigned HOST_WIDE_INT result = a * (unsigned HOST_WIDE_INT)b;
> +  if (a != 0 && (HOST_WIDE_INT)result / a != b)
> +    *overflow = true;
> +  else
> +    *overflow = false;

This isn't sufficiently bulletproof.
It should be
  if ((a == -1 && b == HOST_WIDE_INT_MIN)
      || (a != 0 && (HOST_WIDE_INT)result / a != b))
    *overflow = true;
  else
    *overflow = false;
or so.

And except that a == -1 && b == min checks my recent widening_mul changes
should match that to __builtin_mul_overflow, so it will not be perfect code,
but at least will not be unnecessarily slow on x86.

	Jakub


  reply	other threads:[~2021-01-20 11:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 11:29 Richard Biener
2021-01-20 11:33 ` Jakub Jelinek [this message]
2021-01-20 12:15   ` Richard Biener
2021-01-20 12:19     ` Jakub Jelinek
2021-01-20 13:24       ` Richard Biener
2021-01-20 14:21         ` Richard Biener
2021-01-20 14:24           ` Richard Sandiford
2021-01-20 14:26             ` Richard Biener

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=20210120113358.GP4020736@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    --cc=richard.sandiford@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).