From patchwork Mon Dec 12 07:57:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 704947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tcZvg2Nhhz9t0w for ; Mon, 12 Dec 2016 18:58:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CGRysmq2"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=ZCQgYSevM1YFdqVNS zS89mRzw1NwKeg/OzGqGdKRT6vqWbPKFRtMVJ1B26byZMQoCNfXXlE5dpLIuIEwW fS3/4MGXkfAo5lQ04f+KnJHgh0/1j8LVSGmGLlG/JK6kGJAai/i6jMg1tsFNRzt/ +UNB4PeFGVXbbnatR7edqsLiJM= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=uWSYpLjlzss01CyxRHqyEOT c6P4=; b=CGRysmq28Ds0NkCTadjWUuNyFCekeR9Cny368nv77/NnP+hJg0Z5pIc OkYPkKGkJalTzZnMXJrjPTtFNMbCxqXMkVwTiYFaaahLYvA2/O37eHBJNPU87x/s yAcf7OpI5R6P95OfuRzcm8i6ms2Oe/rg2KHRbSeb2mClJjVF84Cc= Received: (qmail 6279 invoked by alias); 12 Dec 2016 07:57:43 -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 6149 invoked by uid 89); 12 Dec 2016 07:57:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:10.1.1, VR_ANTI_RANGE, vr_anti_range, honza X-HELO: mail-pg0-f54.google.com Received: from mail-pg0-f54.google.com (HELO mail-pg0-f54.google.com) (74.125.83.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Dec 2016 07:57:31 +0000 Received: by mail-pg0-f54.google.com with SMTP id 3so32858283pgd.0 for ; Sun, 11 Dec 2016 23:57:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=bC3cCoVXQPThJdQAgM4J+pvIsdYF/SbfJVaNcwTVIsg=; b=VOYv41FIK7C3dPPLuS8JVWfQGVmW4WSJoAfJRtPCEkB5W67ksWMMEo9kyMBYQZKXh+ bkiIWlJAPLVU7TQPwBVpbRZ7gtU9fJH2371GiFKrHh+wnpjHx71PT9vpsSf/oh3+MMoA TUKImwCTHxXv+ejEbtQAj8H7/Ghrn6kXjuXYn5G0vdZ5YoYC4jbiDeCmwZuIIoB4vewC RkokyhNh5ApgGW/CmllzAeBE5YR2vLe4OHwb4h5ln304hMjcMoxkzBeblwXt7hHsayQi Qe0TmU9cBhFe+ZhoNy63JeJVdKjSii0ouWGUrTkjHy0JvPKEOvLbUlYObVvOW/84kvfT gzzQ== X-Gm-Message-State: AKaTC03MEuDWVZrnB3aB5wKMvodeCNUBe0rl32pyYhVA7GOYKTo0J2pEoZP6+UTIIM06aKOu X-Received: by 10.99.54.140 with SMTP id d134mr164560262pga.132.1481529450059; Sun, 11 Dec 2016 23:57:30 -0800 (PST) Received: from [10.1.1.4] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id w24sm74244167pfa.9.2016.12.11.23.57.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Dec 2016 23:57:29 -0800 (PST) Subject: Re: [PR78365] ICE in determine_value_range, at tree-ssa-loo p-niter.c:413 To: Richard Biener , Jan Hubicka , "gcc-patches@gcc.gnu.org" References: <68396c67-fdcc-33ed-5463-a07502959865@linaro.org> <20161123153317.wjyjxgp6ltg5cp6t@virgil.suse.cz> <4f03c618-081b-e5b8-5ef6-6abdfddd9d9b@linaro.org> <20161207100853.ae3qcpo5ycblqxau@virgil.suse.cz> <20161209105127.mb3xasvrcipt2kqg@virgil.suse.cz> From: kugan Message-ID: <3a8d994c-ad91-d940-eb95-8f8664ca6e36@linaro.org> Date: Mon, 12 Dec 2016 18:57:25 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes Hi Richard, >> I am fine with the new patch but you'll need an approval from Honza >> or Richi. >> >> I find it a bit saddening that we cannot really rely on >> gimple_call_fntype but at least I do not see any other way. > > The patch looks somewhat backward. It populates the param type from > the callee but the only thing we really know is the _originating_ type > from the callers DECL_ARGUMENTS (if the JF is based on a parameter I am not sure I understood this. I think we get param_type from callees DECL_ARGUMENTS. > which is the only case where we do not know the type of the actual > value statically -- we only know the type we expect). > > So the type would be present only on IPA_JF_PASS_THROUGH JFs > (? does that also cover modified params?). > > At propagation time when applying the jump-function we have to make > sure to first convert the actual parameter value to that expected type > (or drop to BOTTOM if we can't do that conversion due to excess mismatches). From ipa vrp point of view, that is what is being done with the patch (In this version, I also changed the POINTER_TYPE_P to use param_type). At the point we create ipa_compute_jump_functions_for_edge, we are covering the VR for arguments to param_type. In propagate_vr_accross_jump_function also, we are doing the conversion. Thanks, Kugan diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 2ec671f..9853467 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -1846,11 +1846,11 @@ propagate_bits_accross_jump_function (cgraph_edge *cs, int idx, ipa_jump_func *j static bool propagate_vr_accross_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc, - struct ipcp_param_lattices *dest_plats, - tree param_type) + struct ipcp_param_lattices *dest_plats) { struct ipcp_param_lattices *src_lats; ipcp_vr_lattice *dest_lat = &dest_plats->m_value_range; + tree param_type = jfunc->param_type; if (dest_lat->bottom_p ()) return false; @@ -2247,7 +2247,6 @@ propagate_constants_accross_call (struct cgraph_edge *cs) { struct ipa_jump_func *jump_func = ipa_get_ith_jump_func (args, i); struct ipcp_param_lattices *dest_plats; - tree param_type = ipa_get_callee_param_type (cs, i); dest_plats = ipa_get_parm_lattices (callee_info, i); if (availability == AVAIL_INTERPOSABLE) @@ -2264,8 +2263,7 @@ propagate_constants_accross_call (struct cgraph_edge *cs) dest_plats); if (opt_for_fn (callee->decl, flag_ipa_vrp)) ret |= propagate_vr_accross_jump_function (cs, - jump_func, dest_plats, - param_type); + jump_func, dest_plats); else ret |= dest_plats->m_value_range.set_to_bottom (); } diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 642111d..d9a817a 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1659,26 +1659,13 @@ determine_locally_known_aggregate_parts (gcall *call, tree arg, /* Return the Ith param type of callee associated with call graph edge E. */ -tree +static tree ipa_get_callee_param_type (struct cgraph_edge *e, int i) { int n; - tree type = (e->callee - ? TREE_TYPE (e->callee->decl) - : gimple_call_fntype (e->call_stmt)); - tree t = TYPE_ARG_TYPES (type); - - for (n = 0; n < i; n++) - { - if (!t) - break; - t = TREE_CHAIN (t); - } - if (t) - return TREE_VALUE (t); if (!e->callee) - return NULL; - t = DECL_ARGUMENTS (e->callee->decl); + return NULL; + tree t = DECL_ARGUMENTS (e->callee->decl); for (n = 0; n < i; n++) { if (!t) @@ -1732,6 +1719,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, useful_context = true; } + jfunc->param_type = param_type; if (POINTER_TYPE_P (TREE_TYPE (arg))) { bool addr_nonzero = false; @@ -1748,8 +1736,8 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, { jfunc->vr_known = true; jfunc->m_vr.type = VR_ANTI_RANGE; - jfunc->m_vr.min = build_int_cst (TREE_TYPE (arg), 0); - jfunc->m_vr.max = build_int_cst (TREE_TYPE (arg), 0); + jfunc->m_vr.min = build_int_cst (param_type, 0); + jfunc->m_vr.max = build_int_cst (param_type, 0); jfunc->m_vr.equiv = NULL; } else @@ -4717,6 +4705,7 @@ ipa_write_jump_function (struct output_block *ob, int i, count; streamer_write_uhwi (ob, jump_func->type); + stream_write_tree (ob, jump_func->param_type, true); switch (jump_func->type) { case IPA_JF_UNKNOWN: @@ -4800,6 +4789,7 @@ ipa_read_jump_function (struct lto_input_block *ib, int i, count; jftype = (enum jump_func_type) streamer_read_uhwi (ib); + jump_func->param_type = stream_read_tree (ib, data_in); switch (jftype) { case IPA_JF_UNKNOWN: diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 0e75cf4..eeb0f6b 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -182,6 +182,9 @@ struct GTY (()) ipa_jump_func bool vr_known; value_range m_vr; + /* Type of callee param corresponding to this jump_func. */ + tree param_type; + enum jump_func_type type; /* Represents a value of a jump function. pass_through is used only in jump function context. constant represents the actual constant in constant jump @@ -818,7 +821,6 @@ ipa_parm_adjustment *ipa_get_adjustment_candidate (tree **, bool *, ipa_parm_adjustment_vec, bool); void ipa_release_body_info (struct ipa_func_body_info *); -tree ipa_get_callee_param_type (struct cgraph_edge *e, int i); /* From tree-sra.c: */ tree build_ref_for_offset (location_t, tree, HOST_WIDE_INT, bool, tree, diff --git a/gcc/testsuite/gcc.dg/torture/pr78365.c b/gcc/testsuite/gcc.dg/torture/pr78365.c index e69de29..5180a01 100644 --- a/gcc/testsuite/gcc.dg/torture/pr78365.c +++ b/gcc/testsuite/gcc.dg/torture/pr78365.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +int a, b, c; +char d; +static void fn1 (void *, int); +int fn2 (int); + +void fn1 (cc, yh) void *cc; +char yh; +{ + char y; + a = fn2(c - b + 1); + for (; y <= yh; y++) + ; +} + +void fn3() +{ + fn1((void *)fn3, 1); + fn1((void *)fn3, d - 1); +}