From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106150 invoked by alias); 8 Jan 2019 12:40:46 -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 106137 invoked by uid 89); 8 Jan 2019 12:40:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 Jan 2019 12:40:44 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9D2DBB04F; Tue, 8 Jan 2019 12:40:41 +0000 (UTC) From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Use proper type in linear transformation in tree-switch-conversion (PR tree-optimization/88753). To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek Message-ID: <1b7be4a1-525c-101d-d897-76b637fd14b1@suse.cz> Date: Tue, 08 Jan 2019 12:40:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BBE565E6414D6CB0752E9A4E" X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00389.txt.bz2 This is a multi-part message in MIME format. --------------BBE565E6414D6CB0752E9A4E Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 588 Hi. As seen in the PR, when doing switch convert linear transformation, one needs to first convert to unsigned type for constructor values. Patch survives regression tests and bootstrap on x86_64-linux-gnu. Ready for trunk? Thanks, Martin gcc/ChangeLog: 2019-01-08 Martin Liska PR tree-optimization/88753 * tree-switch-conversion.c (switch_conversion::build_one_array): Come up with local variable constructor. Convert first to type of constructor values. --- gcc/tree-switch-conversion.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --------------BBE565E6414D6CB0752E9A4E Content-Type: text/x-patch; name="0001-Use-proper-type-in-linear-transformation-in-tree-swi.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Use-proper-type-in-linear-transformation-in-tree-swi.pa"; filename*1="tch" Content-length: 1697 diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index 614c450dd4d..de41050f317 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -600,9 +600,9 @@ switch_conversion::build_one_array (int num, tree arr_index_type, name = copy_ssa_name (PHI_RESULT (phi)); m_target_inbound_names[num] = name; + vec *constructor = m_constructors[num]; wide_int coeff_a, coeff_b; - bool linear_p = contains_linear_function_p (m_constructors[num], &coeff_a, - &coeff_b); + bool linear_p = contains_linear_function_p (constructor, &coeff_a, &coeff_b); if (linear_p) { if (dump_file && coeff_a.to_uhwi () > 0) @@ -610,7 +610,8 @@ switch_conversion::build_one_array (int num, tree arr_index_type, " and B = %" PRId64 "\n", coeff_a.to_shwi (), coeff_b.to_shwi ()); - tree t = unsigned_type_for (TREE_TYPE (m_index_expr)); + /* We must use type of constructor values. */ + tree t = unsigned_type_for (TREE_TYPE ((*constructor)[0].value)); gimple_seq seq = NULL; tree tmp = gimple_convert (&seq, t, m_index_expr); tree tmp2 = gimple_build (&seq, MULT_EXPR, t, @@ -633,10 +634,10 @@ switch_conversion::build_one_array (int num, tree arr_index_type, unsigned int i; constructor_elt *elt; - FOR_EACH_VEC_SAFE_ELT (m_constructors[num], i, elt) + FOR_EACH_VEC_SAFE_ELT (constructor, i, elt) elt->value = fold_convert (value_type, elt->value); } - ctor = build_constructor (array_type, m_constructors[num]); + ctor = build_constructor (array_type, constructor); TREE_CONSTANT (ctor) = true; TREE_STATIC (ctor) = true; --------------BBE565E6414D6CB0752E9A4E--