From patchwork Fri Nov 18 01:38:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 82817 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1094590qge; Thu, 17 Nov 2016 17:38:48 -0800 (PST) X-Received: by 10.13.247.65 with SMTP id h62mr5592133ywf.56.1479433128800; Thu, 17 Nov 2016 17:38:48 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id u45si1093690ybi.277.2016.11.17.17.38.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 17:38:48 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441892-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-441892-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441892-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=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:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=XEi+Wn8ZfLKC1tJ417oGTtyGcaXHiASwLyM54bVsE2wlYvMV6a sbia+oV4KImAUG8yB4uEJ9VBN0QlAybwXTpqd4eSsDX4lIWb6lw3l5X+p3WG9JFM pvMt3cfAFtu/W9EzN4skWq8DNqwxVulgElMiZRiP3/zaYEmRVay901qvA= 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:cc:message-id:date:mime-version:content-type; s= default; bh=To9vm76tCje59AhW7yyEBJxtibw=; b=UqyqBuaInCsnCN2UfuSP iaoyit1hk5b0kp59tEj8Vv3ptjJ2GzaeYgoncBjsMS4d2/t+wzP/iBXVPCeq0wGb rML9XnOT6yL/Ynt8iA38dHh3hbkqnrg4lTaRgnrIuNtQ+MW6T9HHD19XXD7MY+s6 WJI8on5gbmh1CT9bYkMLQlY= Received: (qmail 49205 invoked by alias); 18 Nov 2016 01:38:35 -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 49196 invoked by uid 89); 18 Nov 2016 01:38:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=TYPE_SIGN, type_sign, 8186, HX-Received:10.99.218.85 X-HELO: mail-pg0-f50.google.com Received: from mail-pg0-f50.google.com (HELO mail-pg0-f50.google.com) (74.125.83.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Nov 2016 01:38:25 +0000 Received: by mail-pg0-f50.google.com with SMTP id p66so97166758pga.2 for ; Thu, 17 Nov 2016 17:38:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version; bh=vC5o3W4wEwaIlw7I27IQi2i24RrM9n361gedeNuaQQE=; b=kWaCaj6EtlZB4+2EO1ZSS0HGj/NVynA9SV6gjoxsAdFebZgkpDpjermHtzEHqwv1RM xrM/yQsRqDnk47XeLMXYGZ5lvLWhrpUwqbf+nrjDhca5M4ISUn0Fy5ijn4nMYcEMksVW +zAlOpHLgcj2crZabp4db5vkFWJ+u8Md+6+8iOjLUozc2UEbpS92t/4Mtt/4ZexIPmn5 158rZXOZFwWUq11VXFJ/kNN1qjuylOWlfFKL7HjhkdbLBLwOwJZrn0vKbHvBtys8O5jX uEAWK+B+rE3snRHt4AYWp8Ha3gBKT7OHMTuH0xhs6l4ZO4MD1F0i5ReLrq9HV3LurCu1 xPtg== X-Gm-Message-State: ABUngve7G1OTA0PvQ4fNNt97IHGWJq2BplbYYmbq2VDHtUqH0U531Z8SL1UdEc96XBFzJwLK X-Received: by 10.99.218.85 with SMTP id l21mr13441680pgj.102.1479433103292; Thu, 17 Nov 2016 17:38:23 -0800 (PST) Received: from [10.1.1.7] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id s8sm11357444pfj.45.2016.11.17.17.38.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 17:38:22 -0800 (PST) From: kugan Subject: [PR78365] ICE in determine_value_range, at tree-ssa-loo p-niter.c:413 To: Jan Hubicka , Richard Biener Cc: "gcc-patches@gcc.gnu.org" Message-ID: <68396c67-fdcc-33ed-5463-a07502959865@linaro.org> Date: Fri, 18 Nov 2016 12:38:18 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, I was relying on ipa_get_callee_param_type to get type of parameter and then convert arguments to this type while computing jump functions. However, in cases like shown in PR78365, ipa_get_callee_param_type, instead of giving up, would return the wrong type. I think the current uses of ipa_get_callee_param_type are fine with this. Attached patch now uses callee's DECL_ARGUMENTS to get the type. If it cannot be found, then I would give up and set the jump function to varying. Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Is this OK for trunk? Thanks, Kugan gcc/testsuite/ChangeLog: 2016-11-18 Kugan Vivekanandarajah PR IPA/78365 * gcc.dg/torture/pr78365.c: New test. gcc/ChangeLog: 2016-11-18 Kugan Vivekanandarajah PR IPA/78365 * ipa-cp.c (propagate_constants_accross_call): get param type from callees DECL_ARGUMENTS if available. * ipa-prop.c (ipa_compute_jump_functions_for_edge): Likewise. (ipcp_update_vr): Remove now redundant conversion of precision for VR. * ipa-prop.h: Make ipa_get_callee_param_type local again. diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 2ec671f..924c846 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -2200,6 +2200,9 @@ propagate_constants_accross_call (struct cgraph_edge *cs) struct ipa_edge_args *args; bool ret = false; int i, args_count, parms_count; + struct cgraph_node *calee = cs->callee; + tree fndecl = calee ? calee->decl : NULL_TREE; + tree parm = fndecl ? DECL_ARGUMENTS (fndecl) : NULL_TREE; callee = cs->callee->function_symbol (&availability); if (!callee->definition) @@ -2247,7 +2250,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) @@ -2265,10 +2267,12 @@ propagate_constants_accross_call (struct cgraph_edge *cs) if (opt_for_fn (callee->decl, flag_ipa_vrp)) ret |= propagate_vr_accross_jump_function (cs, jump_func, dest_plats, - param_type); + parm ? + TREE_TYPE (parm) : NULL_TREE); else ret |= dest_plats->m_value_range.set_to_bottom (); } + parm = parm ? DECL_CHAIN (parm) : NULL_TREE; } for (; i < parms_count; i++) ret |= set_all_contains_variable (ipa_get_parm_lattices (callee_info, i)); diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 6321fdd..0f102c6c 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1651,7 +1651,7 @@ 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; @@ -1695,6 +1695,9 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, gcall *call = cs->call_stmt; int n, arg_num = gimple_call_num_args (call); bool useful_context = false; + struct cgraph_node *calee = cs->callee; + tree fndecl = calee ? calee->decl : NULL_TREE; + tree parm = fndecl ? DECL_ARGUMENTS (fndecl) : NULL_TREE; if (arg_num == 0 || args->jump_functions) return; @@ -1751,8 +1754,8 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, { wide_int min, max; value_range_type type; - if (TREE_CODE (arg) == SSA_NAME - && param_type + if (parm + && TREE_CODE (arg) == SSA_NAME && (type = get_range_info (arg, &min, &max)) && (type == VR_RANGE || type == VR_ANTI_RANGE)) { @@ -1764,7 +1767,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, vr.equiv = NULL; extract_range_from_unary_expr (&jfunc->m_vr, NOP_EXPR, - param_type, + TREE_TYPE (parm), &vr, TREE_TYPE (arg)); if (jfunc->m_vr.type == VR_RANGE || jfunc->m_vr.type == VR_ANTI_RANGE) @@ -1775,6 +1778,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, else gcc_assert (!jfunc->vr_known); } + parm = parm ? DECL_CHAIN (parm) : NULL_TREE; if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST)) @@ -5699,8 +5703,6 @@ ipcp_update_vr (struct cgraph_node *node) 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); if (INTEGRAL_TYPE_P (TREE_TYPE (ddef))) { if (dump_file) @@ -5713,11 +5715,7 @@ ipcp_update_vr (struct cgraph_node *node) print_decs (vr[i].max, dump_file); fprintf (dump_file, "]\n"); } - set_range_info (ddef, vr[i].type, - wide_int_storage::from (vr[i].min, prec, - TYPE_SIGN (type)), - wide_int_storage::from (vr[i].max, prec, - TYPE_SIGN (type))); + set_range_info (ddef, vr[i].type, vr[i].min, vr[i].max); } else if (POINTER_TYPE_P (TREE_TYPE (ddef)) && vr[i].type == VR_ANTI_RANGE diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 0e75cf4..4eeae88 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -818,7 +818,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); +}