From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 88446 invoked by alias); 31 Aug 2019 13:12:15 -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 88436 invoked by uid 89); 31 Aug 2019 13:12:15 -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,SPF_PASS autolearn=ham version=3.3.1 spammy=sk:switch_, build_one_array, sk:range_c 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 13:12:13 +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 1E2A23082A8B; Sat, 31 Aug 2019 13:12:12 +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 A3E005D6A5; Sat, 31 Aug 2019 13:12:11 +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 x7VDC9SA024752; Sat, 31 Aug 2019 15:12:09 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x7VDC7Ti024751; Sat, 31 Aug 2019 15:12:07 +0200 Date: Sat, 31 Aug 2019 15:59:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up go regressions caused by my recent switchconv changes (PR go/91617) Message-ID: <20190831131207.GF2120@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes X-SW-Source: 2019-08/txt/msg02132.txt.bz2 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; Jakub