From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41036 invoked by alias); 31 Aug 2019 17:41:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 41023 invoked by uid 89); 31 Aug 2019 17:41:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=verification, 35PM, 35pm, integer_type X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 31 Aug 2019 17:41:25 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 157CF308424E; Sat, 31 Aug 2019 17:41:24 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-139.ams2.redhat.com [10.36.116.139]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1BAF5D6A5; Sat, 31 Aug 2019 17:41:23 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x7VHfLXQ026003; Sat, 31 Aug 2019 19:41:21 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x7VHfH0x026002; Sat, 31 Aug 2019 19:41:17 +0200 Date: Sat, 31 Aug 2019 19:17:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix up go regressions caused by my recent switchconv changes (PR go/91617) Message-ID: <20190831174117.GG2120@tucnak> Reply-To: Jakub Jelinek References: <20190831131207.GF2120@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg02146.txt.bz2 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_ } /* 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