From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 76728 invoked by alias); 31 Aug 2019 15:42:08 -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 76719 invoked by uid 89); 31 Aug 2019 15:42:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.8 required=5.0 tests=AWL,BAYES_00,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS,USER_IN_DEF_SPF_WL autolearn=ham version=3.3.1 spammy= X-HELO: mail-vk1-f193.google.com Received: from mail-vk1-f193.google.com (HELO mail-vk1-f193.google.com) (209.85.221.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 31 Aug 2019 15:42:06 +0000 Received: by mail-vk1-f193.google.com with SMTP id d66so105969vka.2 for ; Sat, 31 Aug 2019 08:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bTIHMXDCza08NXO3X1zqE4Kspf2N6AYA9PgWB5hbs60=; b=NCDYNDrDH9jGKsf96Bm8mTCdeNr+qGH935tXn7gs0WuI9FoSca/ful2WTY2l82azaS Fq2eltufCoaRNc/6zM8WGDLylEj3bxYZxe7BJZDpAvRMp8PvtYZXJq/UVKYsKOjFtdt5 OE4zRQJ2XOW3WF0jBqDeC+IhviWbrb7i/NbXqhMhpgXQv6Kr/8sx1zkD9a2s3szxu9oo rx4JHprWscojY8k0ZhpgFWzE770pgsUNR+u6YQS+E6F9CZqUowYqiYxGryuf7060RgSq IiBXBAMCn+ksQ+5FeIQRc0Pn5ehdW5S6jwYD9V+iL9et+kZRJE6H+Fqqk4oUEj4yeEGo z6tg== MIME-Version: 1.0 References: <20190831131207.GF2120@tucnak> In-Reply-To: <20190831131207.GF2120@tucnak> From: "Ian Lance Taylor via gcc-patches" Reply-To: Ian Lance Taylor Date: Sat, 31 Aug 2019 17:12:00 -0000 Message-ID: Subject: Re: [PATCH] Fix up go regressions caused by my recent switchconv changes (PR go/91617) To: Jakub Jelinek Cc: Richard Biener , gcc-patches Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg02135.txt.bz2 On Sat, Aug 31, 2019 at 6:12 AM Jakub Jelinek wrote: > > Hi! > > Apparently my recent tree-{cfg,switch-conversion}.c changes broke a bunch of > go tests. > The problem is that range_check_type actually doesn't guarantee an unsigned > type; it forces integer type for enum/bool (that was what was really needed > to fix the PR), and for integer types that don't wrap forces unsigned type > (and then verifies the wrap-around). Seems go uses -fwrapv by default > and we got thus signed types from it. That is fine if we emit the > x >= low && x < high range tests as x - low >= 0 && x - low < high - low, > but we actually don't emit the >= 0 check and so we do need an unsigned > type. The other uses of range_check_type also eventually also call > unsigned_type_for, e.g. > etype = range_check_type (etype); > if (etype == NULL_TREE) > return NULL_TREE; > > if (POINTER_TYPE_P (etype)) > etype = unsigned_type_for (etype); > and in the recursion then because low is 0: > if (! TYPE_UNSIGNED (etype)) > { > etype = unsigned_type_for (etype); > high = fold_convert_loc (loc, etype, high); > exp = fold_convert_loc (loc, etype, exp); > } > Similarly match.pd: > tree etype = range_check_type (TREE_TYPE (@0)); > if (etype) > { > if (! TYPE_UNSIGNED (etype)) > etype = unsigned_type_for (etype); > ... > So, the following patch calls unsigned_type_for on the range_check_type > result. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2019-08-31 Jakub Jelinek > > PR go/91617 > * tree-cfg.c (generate_range_test): Call unsigned_type_for on > the range_check_type result. > * tree-switch-conversion.c (switch_conversion::build_one_array, > bit_test_cluster::emit): Likewise. > > --- gcc/tree-cfg.c.jj 2019-08-31 12:09:09.135153318 +0200 > +++ gcc/tree-cfg.c 2019-08-31 12:48:06.259939680 +0200 > @@ -9222,6 +9222,7 @@ generate_range_test (basic_block bb, tre > { > tree type = TREE_TYPE (index); > tree utype = range_check_type (type); > + utype = unsigned_type_for (utype); > > low = fold_convert (utype, low); > high = fold_convert (utype, high); > --- gcc/tree-switch-conversion.c.jj 2019-08-31 12:09:09.129153406 +0200 > +++ gcc/tree-switch-conversion.c 2019-08-31 12:48:28.340617487 +0200 > @@ -616,6 +616,7 @@ switch_conversion::build_one_array (int > > /* We must use type of constructor values. */ > gimple_seq seq = NULL; > + type = unsigned_type_for (type); > tree tmp = gimple_convert (&seq, type, m_index_expr); > tree tmp2 = gimple_build (&seq, MULT_EXPR, type, > wide_int_to_tree (type, coeff_a), tmp); > @@ -1486,6 +1487,7 @@ bit_test_cluster::emit (tree index_expr, > unsigned int count; > > tree unsigned_index_type = range_check_type (index_type); > + unsigned_index_type = unsigned_type_for (unsigned_index_type); > > gimple_stmt_iterator gsi; > gassign *shift_stmt; Thanks for looking into this. Ian