From patchwork Sun Jan 29 23:23:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 92787 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1200497qgi; Sun, 29 Jan 2017 15:24:12 -0800 (PST) X-Received: by 10.99.178.89 with SMTP id t25mr20559325pgo.183.1485732252073; Sun, 29 Jan 2017 15:24:12 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g29si10847587plj.102.2017.01.29.15.24.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Jan 2017 15:24:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-447409-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-447409-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-447409-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=TAOti73M1Ztr08Hr0mQtF9U+aX0WmhezGMHAP8djdNV5BfuJiDY/q isBlrAL7FgV91I0YnpcC2jv3XXWWXfFV1TRzxl3kUmes9uELO2OOoqCQ4mmJhdZY k8eRaK+BjUTev3OUiwwIxsCE4iU61sxCGrCapeezemea/iXq7l7hd4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=tu94oEUOvwguW3VEqU+JvieHKMU=; b=opf6dodakFpnixEGDu2x dfMcX8eoics1Lhm37zjdvC4KXpE4QNC1uBk41fMf3jTo7jCJr0m8hGXDzOZ+nNJO Bf8lhmITGPP+TkkairE+lHrG6NMRjjvVeSEsom3UL5UV4S7rv44Ny0VcIUuU5SBv QIQ41I2zzxzgGaozQHujEss= Received: (qmail 16985 invoked by alias); 29 Jan 2017 23:23:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 16961 invoked by uid 89); 29 Jan 2017 23:23:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=5277, 522 X-HELO: mail-pf0-f171.google.com Received: from mail-pf0-f171.google.com (HELO mail-pf0-f171.google.com) (209.85.192.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 29 Jan 2017 23:23:45 +0000 Received: by mail-pf0-f171.google.com with SMTP id e4so85450577pfg.1 for ; Sun, 29 Jan 2017 15:23:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version; bh=V7+AuGnVWPKuR8DUZCfYOFn9JKua+M9DljicMZLQHCk=; b=EWa9X/HY+cccS2TyW0Vkvm7NThEnbWvUs4xOIZLDFNE3aoITDjSdBtVuJU1ENUvmTg aMINiS4dmLtsDU0YKZgQ8shqT82BCvZVJm8ag2d6n509Uj7oeMRwzRv4dPbZPToqUoJS 7sHF9fMHhkgvofkGiHiJkt00hwYyp/XLxuWj29qSlvm+f6xSKuDE7nKAEVNEv7byhLXA rG3kZqj/xlW2MsjjiW7Q8j+gbitL0syXsfLjMrsKhvghPjH2vmWkJg/ln8OePMLhemVz cZd/0VrCMtmNlP9Rw9u/uJJb198d46Hp5Nh9ShOB0hee+q8DVIkRhr+96Ta0X11LJKS+ 48jQ== X-Gm-Message-State: AIkVDXJ8dIDe/r/s4QYDJQOxH8V/S4yM5jugsQbdbQVZ/DN/vxLlybdVEg9Z+3yVDHiOk4Jv X-Received: by 10.98.16.14 with SMTP id y14mr20191397pfi.63.1485732223329; Sun, 29 Jan 2017 15:23:43 -0800 (PST) Received: from [192.168.1.101] ([61.68.87.228]) by smtp.gmail.com with ESMTPSA id 134sm26934948pgh.13.2017.01.29.15.23.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Jan 2017 15:23:42 -0800 (PST) From: kugan Subject: [RFC] Bug lto/78140 To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jan Hubicka , Martin Jambor Message-ID: Date: Mon, 30 Jan 2017 10:23:38 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi All, As suggested by Richard in the PR, I tried to implement variable size structures for VR as shown in attached patch. That is, I changed ipa-prop.h to: variable structure. Thanks, Kugan diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index aa3c997..bc6670f 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -4945,21 +4945,29 @@ ipcp_store_vr_results (void) for (unsigned i = 0; i < count; i++) { ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i); - ipa_vr vr; + ipa_vr *vr; if (!plats->m_value_range.bottom_p () && !plats->m_value_range.top_p ()) { - vr.known = true; - vr.type = plats->m_value_range.m_vr.type; - vr.min = plats->m_value_range.m_vr.min; - vr.max = plats->m_value_range.m_vr.max; + wide_int min = plats->m_value_range.m_vr.min; + wide_int max = plats->m_value_range.m_vr.max; + unsigned int precision = min.get_precision (); + size_t size = (sizeof (ipa_vr) + + trailing_wide_ints <2>::extra_size (precision)); + vr = static_cast (ggc_internal_alloc (size)); + vr->ints.set_precision (precision); + vr->known = true; + vr->type = plats->m_value_range.m_vr.type; + vr->set_min (min); + vr->set_max (max); } else { - vr.known = false; - vr.type = VR_VARYING; - vr.min = vr.max = wi::zero (INT_TYPE_SIZE); + size_t size = (sizeof (ipa_vr)); + vr = static_cast (ggc_internal_alloc (size)); + vr->known = false; + vr->type = VR_VARYING; } ts->m_vr->quick_push (vr); } diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 834c27d..98e8a1b 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -3810,14 +3810,37 @@ ipa_node_params_t::duplicate(cgraph_node *src, cgraph_node *dst, { ipcp_grow_transformations_if_necessary (); src_trans = ipcp_get_transformation_summary (src); - const vec *src_vr = src_trans->m_vr; - vec *&dst_vr + vec *src_vr = src_trans->m_vr; + vec *dst_vr = ipcp_get_transformation_summary (dst)->m_vr; if (vec_safe_length (src_trans->m_vr) > 0) { vec_safe_reserve_exact (dst_vr, src_vr->length ()); for (unsigned i = 0; i < src_vr->length (); ++i) - dst_vr->quick_push ((*src_vr)[i]); + { + ipa_vr *dst1, *src1 = (*src_vr)[i]; + if (src1->known) + { + size_t size; + unsigned int precision = src1->get_min ().get_precision (); + size = (sizeof (ipa_vr) + + trailing_wide_ints <2>::extra_size (precision)); + dst1 = static_cast (ggc_internal_alloc (size)); + dst1->ints.set_precision (precision); + dst1->known = true; + dst1->type = src1->type; + dst1->set_min (src1->get_min ()); + dst1->set_max (src1->get_max ()); + } + else + { + size_t size = (sizeof (ipa_vr)); + dst1 = static_cast (ggc_internal_alloc (size)); + dst1->known = false; + dst1->type = src1->type; + } + dst_vr->quick_push (dst1); + } } } @@ -5213,7 +5236,7 @@ write_ipcp_transformation_info (output_block *ob, cgraph_node *node) for (unsigned i = 0; i < count; ++i) { struct bitpack_d bp; - ipa_vr *parm_vr = &(*ts->m_vr)[i]; + ipa_vr *parm_vr = (*ts->m_vr)[i]; bp = bitpack_create (ob->main_stream); bp_pack_value (&bp, parm_vr->known, 1); streamer_write_bitpack (&bp); @@ -5221,8 +5244,8 @@ write_ipcp_transformation_info (output_block *ob, cgraph_node *node) { streamer_write_enum (ob->main_stream, value_rang_type, VR_LAST, parm_vr->type); - streamer_write_wide_int (ob, parm_vr->min); - streamer_write_wide_int (ob, parm_vr->max); + streamer_write_wide_int (ob, parm_vr->get_min ()); + streamer_write_wide_int (ob, parm_vr->get_max ()); } } } @@ -5283,21 +5306,38 @@ read_ipcp_transformation_info (lto_input_block *ib, cgraph_node *node, ipcp_grow_transformations_if_necessary (); ipcp_transformation_summary *ts = ipcp_get_transformation_summary (node); - vec_safe_grow_cleared (ts->m_vr, count); + vec_safe_reserve_exact (ts->m_vr, count); for (i = 0; i < count; i++) { ipa_vr *parm_vr; - parm_vr = &(*ts->m_vr)[i]; struct bitpack_d bp; bp = streamer_read_bitpack (ib); - parm_vr->known = bp_unpack_value (&bp, 1); - if (parm_vr->known) + bool known = bp_unpack_value (&bp, 1); + if (known) + { + enum value_range_type type = streamer_read_enum (ib, + value_range_type, + VR_LAST); + wide_int min = streamer_read_wide_int (ib); + wide_int max = streamer_read_wide_int (ib); + unsigned int precision = min.get_precision (); + size_t size = (sizeof (ipa_vr) + + trailing_wide_ints <2>::extra_size (precision)); + parm_vr = static_cast (ggc_internal_alloc (size)); + (parm_vr)->ints.set_precision (precision); + (parm_vr)->known = known; + (parm_vr)->type = type; + (parm_vr)->set_min (min); + (parm_vr)->set_max (max); + } + else { - parm_vr->type = streamer_read_enum (ib, value_range_type, - VR_LAST); - parm_vr->min = streamer_read_wide_int (ib); - parm_vr->max = streamer_read_wide_int (ib); + size_t size = (sizeof (ipa_vr)); + parm_vr = static_cast (ggc_internal_alloc (size)); + (parm_vr)->known = known; + (parm_vr)->type = VR_VARYING; } + ts->m_vr->quick_push (parm_vr); } } count = streamer_read_uhwi (ib); @@ -5673,7 +5713,7 @@ ipcp_update_vr (struct cgraph_node *node) ipcp_transformation_summary *ts = ipcp_get_transformation_summary (node); if (!ts || vec_safe_length (ts->m_vr) == 0) return; - const vec &vr = *ts->m_vr; + const vec &vr = *ts->m_vr; unsigned count = vr.length (); for (unsigned i = 0; i < count; ++i, parm = next_parm) @@ -5688,8 +5728,8 @@ ipcp_update_vr (struct cgraph_node *node) if (!ddef || !is_gimple_reg (parm)) continue; - if (vr[i].known - && (vr[i].type == VR_RANGE || vr[i].type == VR_ANTI_RANGE)) + if (vr[i]->known + && (vr[i]->type == VR_RANGE || vr[i]->type == VR_ANTI_RANGE)) { tree type = TREE_TYPE (ddef); unsigned prec = TYPE_PRECISION (type); @@ -5699,22 +5739,22 @@ ipcp_update_vr (struct cgraph_node *node) { fprintf (dump_file, "Setting value range of param %u ", i); fprintf (dump_file, "%s[", - (vr[i].type == VR_ANTI_RANGE) ? "~" : ""); - print_decs (vr[i].min, dump_file); + (vr[i]->type == VR_ANTI_RANGE) ? "~" : ""); + print_decs (vr[i]->get_min (), dump_file); fprintf (dump_file, ", "); - print_decs (vr[i].max, dump_file); + print_decs (vr[i]->get_max (), dump_file); fprintf (dump_file, "]\n"); } - set_range_info (ddef, vr[i].type, - wide_int_storage::from (vr[i].min, prec, + set_range_info (ddef, vr[i]->type, + wide_int_storage::from (vr[i]->get_min (), prec, TYPE_SIGN (type)), - wide_int_storage::from (vr[i].max, prec, + wide_int_storage::from (vr[i]->get_max (), prec, TYPE_SIGN (type))); } else if (POINTER_TYPE_P (TREE_TYPE (ddef)) - && vr[i].type == VR_ANTI_RANGE - && wi::eq_p (vr[i].min, 0) - && wi::eq_p (vr[i].max, 0)) + && vr[i]->type == VR_ANTI_RANGE + && wi::eq_p (vr[i]->get_min (), 0) + && wi::eq_p (vr[i]->get_max (), 0)) { if (dump_file) fprintf (dump_file, "Setting nonnull for %u\n", i); diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 93a2390c..acab2aa 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -157,13 +157,15 @@ struct GTY(()) ipa_bits }; /* Info about value ranges. */ -struct GTY(()) ipa_vr +struct GTY ((variable_size)) ipa_vr { /* The data fields below are valid only if known is true. */ bool known; enum value_range_type type; - wide_int min; - wide_int max; + /* Minimum and maximum. */ + TRAILING_WIDE_INT_ACCESSOR (min, ints, 0) + TRAILING_WIDE_INT_ACCESSOR (max, ints, 1) + trailing_wide_ints <2> ints; }; /* A jump function for a callsite represents the values passed as actual @@ -525,7 +527,7 @@ struct GTY(()) ipcp_transformation_summary /* Known bits information. */ vec *bits; /* Value range information. */ - vec *m_vr; + vec *m_vr; }; void ipa_set_node_agg_value_chain (struct cgraph_node *node, diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 93a2390c..acab2aa 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -157,13 +157,15 @@ struct GTY(()) ipa_bits }; /* Info about value ranges. */ -struct GTY(()) ipa_vr +struct GTY ((variable_size)) ipa_vr { /* The data fields below are valid only if known is true. */ bool known; enum value_range_type type; - wide_int min; - wide_int max; + /* Minimum and maximum. */ + TRAILING_WIDE_INT_ACCESSOR (min, ints, 0) + TRAILING_WIDE_INT_ACCESSOR (max, ints, 1) + trailing_wide_ints <2> ints; }; /* A jump function for a callsite represents the values passed as actual @@ -525,7 +527,7 @@ struct GTY(()) ipcp_transformation_summary /* Known bits information. */ vec *bits; /* Value range information. */ - vec *m_vr; + vec *m_vr; }; void ipa_set_node_agg_value_chain (struct cgraph_node *node, However, I am running into error when I do LTO bootstrap that memory seems to have deallocated by the garbage collector. Since we have the reference to the memory allocated by ggc_internal_alloc in the vector (m_vr), I thought it will not be deallocated. But during the bootstrap, when in ipa_node_params_t::duplicate, it seems to have been deallocated as shown in the back trace. I dont understand internals of gc in gcc so any help is appreciated. lto1: internal compiler error: Segmentation fault 0xdedc4b crash_signal ../../gcc/gcc/toplev.c:333 0xb46680 ipa_node_params_t::duplicate(cgraph_node*, cgraph_node*, ipa_node_params*, ipa_node_params*) ../../gcc/gcc/ipa-prop.c:3819 0xb306a3 function_summary::symtab_duplication(cgraph_node*, cgraph_node*, void*) ../../gcc/gcc/symbol-summary.h:187 0x85aba7 symbol_table::call_cgraph_duplication_hooks(cgraph_node*, cgraph_node*) ../../gcc/gcc/cgraph.c:488 0x8765bf cgraph_node::create_clone(tree_node*, long, int, bool, vec, bool, cgraph_node*, bitmap_head*, char const*) ../../gcc/gcc/cgraphclones.c:522 0x166fb3b clone_inlined_nodes(cgraph_edge*, bool, bool, int*, int) ../../gcc/gcc/ipa-inline-transform.c:227 0x166fbd7 clone_inlined_nodes(cgraph_edge*, bool, bool, int*, int) ../../gcc/gcc/ipa-inline-transform.c:242 0x1670893 inline_call(cgraph_edge*, bool, vec*, int*, bool, bool*) ../../gcc/gcc/ipa-inline-transform.c:449 0x1665bd3 inline_small_functions ../../gcc/gcc/ipa-inline.c:2024 0x1667157 ipa_inline ../../gcc/gcc/ipa-inline.c:2434 0x1667fa7 execute ../../gcc/gcc/ipa-inline.c:2845 I tried similar think without variable structure like: diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 93a2390c..b0cc832 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -525,7 +525,7 @@ struct GTY(()) ipcp_transformation_summary /* Known bits information. */ vec *bits; /* Value range information. */ - vec *m_vr; + vec *m_vr; }; This also has the same issue so I don't think it has anything to do with