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
Subject: Re: [PATCH] Fix up go regressions caused by my recent switchconv changes (PR go/91617)
Date: Sat, 31 Aug 2019 19:17:00 -0000	[thread overview]
Message-ID: <20190831174117.GG2120@tucnak> (raw)
In-Reply-To: <E2E51816-8914-4806-B37B-31C010907DAC@suse.de>

On Sat, Aug 31, 2019 at 07:23:35PM +0200, Richard Biener wrote:
> Hmm, couldn't we make range_check_type_for take an argument whether signed
> or unsigned type is required?  That is, what do we do if the caller wants
> a signed type?  Leaving it unspecified what the function returns is odd.

I think we never want specially signed type, either we don't care whether it
is signed or not, in that case we want just some type that wraps around, or we
do want an unsigned type.

So something like below, with using range_check_type (x, true) in some
places.

Note it will be more compile time expensive than just calling
unsigned_type_for after the range_check_type call, due to all the
wrap-around verification it does.

--- gcc/fold-const.h.jj	2019-08-08 08:34:28.010306157 +0200
+++ gcc/fold-const.h	2019-08-31 19:39:13.436366420 +0200
@@ -182,7 +182,7 @@ extern bool tree_expr_nonnegative_warnv_
 extern tree make_range (tree, int *, tree *, tree *, bool *);
 extern tree make_range_step (location_t, enum tree_code, tree, tree, tree,
 			     tree *, tree *, int *, bool *);
-extern tree range_check_type (tree);
+extern tree range_check_type (tree, bool = false);
 extern tree build_range_check (location_t, tree, tree, int, tree, tree);
 extern bool merge_ranges (int *, tree *, tree *, int, tree, tree, int,
 			  tree, tree);
--- gcc/fold-const.c.jj	2019-08-27 12:26:39.303884758 +0200
+++ gcc/fold-const.c	2019-08-31 19:39:06.235470312 +0200
@@ -4930,10 +4930,12 @@ maskable_range_p (const_tree low, const_
 }
 \f
 /* Helper routine for build_range_check and match.pd.  Return the type to
-   perform the check or NULL if it shouldn't be optimized.  */
+   perform the check or NULL if it shouldn't be optimized.
+   If UNSIGNEDP is true, the returned type must be unsigned, otherwise
+   it can be some INTEGER_TYPE that wraps around.  */
 
 tree
-range_check_type (tree etype)
+range_check_type (tree etype, bool unsignedp)
 {
   /* First make sure that arithmetics in this type is valid, then make sure
      that it wraps around.  */
@@ -4941,7 +4943,8 @@ range_check_type (tree etype)
     etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype),
 					    TYPE_UNSIGNED (etype));
 
-  if (TREE_CODE (etype) == INTEGER_TYPE && !TYPE_OVERFLOW_WRAPS (etype))
+  if (unsignedp
+      || (TREE_CODE (etype) == INTEGER_TYPE && !TYPE_OVERFLOW_WRAPS (etype)))
     {
       tree utype, minv, maxv;
 


	Jakub

  reply	other threads:[~2019-08-31 17:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-31 15:59 Jakub Jelinek
2019-08-31 17:12 ` Ian Lance Taylor via gcc-patches
2019-08-31 17:41 ` Richard Biener
2019-08-31 19:17   ` Jakub Jelinek [this message]
2019-08-31 20:15     ` Richard Biener
2019-09-01 16:34       ` Jakub Jelinek
2019-09-01 16:44         ` Richard Biener
2019-09-02  8:14           ` Jakub Jelinek
2019-09-02  8:29             ` Andrew Pinski
2019-09-02 13:37               ` Jakub Jelinek
2019-09-02  8:31             ` 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=20190831174117.GG2120@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /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).