public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Richard Biener <rguenther@suse.de>, Richard Henderson <rth@redhat.com>
Subject: Re: [PATCH] Convert manual unsigned +/- overflow checking into {ADD,SUB}_OVERFLOW (PR target/67089)
Date: Wed, 25 Nov 2015 08:40:00 -0000	[thread overview]
Message-ID: <20151125083627.GU5675@tucnak.redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1511250817160.9949@laptop-mg.saclay.inria.fr>

On Wed, Nov 25, 2015 at 08:56:45AM +0100, Marc Glisse wrote:
> >This is the GIMPLE side of Richard's i?86 uadd/usub overflow
> >testing improvements.  If unsigned addition or subtraction
> >result is used both normally and in a GIMPLE_COND/COND_EXPR/tcc_comparison
> >that tests if unsigned overflow happened, the patch replaces it shortly
> >before expansion with {ADD,SUB}_OVERFLOW, so that RTL expansion can generate
> >better code on it.
> 
> If I test a+b<a and don't use a+b anywhere else, don't we also want to use
> the OVERFLOW things so we can expand to test the carry flag? That is, I am
> not convinced we want to punt on has_single_use for add_overflow. For
> sub_overflow with a single use of y-z, I guess y-z>y should become z>y, and
> going through a rewrite with sub_overflow neither helps nor hinders that.
> Actually, writing z>y is something the user is not unlikely to have done
> himself, and walking through the uses of y or z should not be hard, so I
> guess it could make sense to rewrite y-z>y to z>y always in match.pd and
> only look for the second form in math-opts.

Incremental diff for also handling the single use case if it is overflow
check is below.  But we already generate good code without it for the
x+y<x or x+y<y cases (and they aren't really problematic, as they are single
use), and while it is true that for x-y>x case the incremental patch below
improves the generated code right now, as you said it is better to rewrite
those as y>x and as it is a single use, it is easier to do it in match.pd.
So, I'd prefer to add that transformation and not use {ADD,SUB}_OVERFLOW
for those cases, because we get good enough code without increasing the IL
size, eating more memory etc.

> I was thinking more match.pd to transform a+b<a and sccvn to somehow CSE a+b
> with add_overflow(a,b), but your patch seems to work well with simpler code,
> that's cool :-)
> 
> And it shouldn't be too hard to add a few more later, to detect widening
> operations that are only used for overflow testing, although the form of
> such tests is much less universal among users.

--- gcc/tree-ssa-math-opts.c.jj	2015-11-24 17:00:10.000000000 +0100
+++ gcc/tree-ssa-math-opts.c	2015-11-25 09:25:31.781087597 +0100
@@ -3586,7 +3586,6 @@ match_uaddsub_overflow (gimple_stmt_iter
   tree type = TREE_TYPE (lhs);
   use_operand_p use_p;
   imm_use_iterator iter;
-  bool use_seen = false;
   bool ovf_use_seen = false;
   gimple *use_stmt;
 
@@ -3594,7 +3593,6 @@ match_uaddsub_overflow (gimple_stmt_iter
   if (!INTEGRAL_TYPE_P (type)
       || !TYPE_UNSIGNED (type)
       || has_zero_uses (lhs)
-      || has_single_use (lhs)
       || optab_handler (code == PLUS_EXPR ? uaddv4_optab : usubv4_optab,
 			TYPE_MODE (type)) == CODE_FOR_nothing)
     return false;
@@ -3606,14 +3604,13 @@ match_uaddsub_overflow (gimple_stmt_iter
 	continue;
 
       if (uaddsub_overflow_check_p (stmt, use_stmt))
-	ovf_use_seen = true;
-      else
-	use_seen = true;
-      if (ovf_use_seen && use_seen)
-	break;
+	{
+	  ovf_use_seen = true;
+	  break;
+	}
     }
 
-  if (!ovf_use_seen || !use_seen)
+  if (!ovf_use_seen)
     return false;
 
   tree ctype = build_complex_type (type);


	Jakub

  reply	other threads:[~2015-11-25  8:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 20:55 Jakub Jelinek
2015-11-25  8:11 ` Marc Glisse
2015-11-25  8:40   ` Jakub Jelinek [this message]
2015-11-25  8:48     ` Richard Biener
2015-11-25  8:59     ` Marc Glisse
2015-11-25  9:08       ` Jakub Jelinek
2015-11-25  9:12         ` Richard Biener
2015-11-25 11:23         ` Marc Glisse
2015-11-25 11:29           ` Jakub Jelinek
2015-11-25 21:27             ` Marc Glisse
2015-11-26  9:14               ` Richard Biener
2015-12-04 21:45           ` Marc Glisse
2015-11-25  8:45 ` 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=20151125083627.GU5675@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    --cc=rth@redhat.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).