From patchwork Fri Oct 28 02:58:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 79833 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp959712qge; Thu, 27 Oct 2016 19:58:46 -0700 (PDT) X-Received: by 10.99.181.10 with SMTP id y10mr16951717pge.161.1477623526686; Thu, 27 Oct 2016 19:58:46 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a4si9238734paz.178.2016.10.27.19.58.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 19:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439790-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-439790-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439790-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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=TDOjMHj4kyhAGyG56 Qz+/5dVOsYhhEopfk1AK/P4APHQL9NHEQPi2xOVYIxKFW3cERq/PIPMJGZ7F+Mmv qe/CS/+H9OM5Potv2qRfubGhsmj7n34NYCGGwvnxQ4AvLK6nERFRpe5pDYfy0Wnk tZHadflp9cITLVol9bj/09J2wo= 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=VLNkA+6VLVgFUYQsasRMyb5 CgG0=; b=HhTTM6Mp7E1ts4jNf29VfbIubIc+TMdo4xWcKJlakLZZxo8iZGEWvEG SR+3cSm+IM1U5lLiQbQBUHduOjYCATtMxke/paXs60VQAcyIoWoL+9BRjyQ+KET8 18XjgEzI17lvNvQtgd5fv3FbsRKJpfbuQPAiBCevsIuvqxe0drOo= Received: (qmail 20484 invoked by alias); 28 Oct 2016 02:58:31 -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 20460 invoked by uid 89); 28 Oct 2016 02:58:30 -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=Setting, 2016-10-28, 20161028 X-HELO: mail-pf0-f173.google.com Received: from mail-pf0-f173.google.com (HELO mail-pf0-f173.google.com) (209.85.192.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Oct 2016 02:58:19 +0000 Received: by mail-pf0-f173.google.com with SMTP id 197so28792937pfu.0 for ; Thu, 27 Oct 2016 19:58:19 -0700 (PDT) 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=tjne+mntWiLu2opZ/KiMuLr5D9zBbfDBBLBwepv6noI=; b=cbZbRBZqeAWR8uIXSGLVOdYfT23Xo29OiryQVGWGpF/uidnXCJPeY3gsQwdLh46L3b HsIN6PUvhBOJj0ejzWmLa5nPNVYHwrUAOUXt0Z3+gAk0vmYyA6a/RMXp/vdzmVoMXNZW NOs/tuWgMXO7CPQv6G1dqLSJRbkn6cA6BjFzNfvavFVFLuMW1iGSKlXOipwchsnToLgs p19FkwuA3UrycEonOAffuQFx0PD44iVRDypSPGZBBcM8zq6EUdTit0x9ub+jRgjIJfEm 7H0Ao2JYRaJ0c+ZIYxiFZlh4czLCAvVXRVmmR2vf6QG6T9Qd9aoUrdEWKPrXby8pYKXt thdQ== X-Gm-Message-State: ABUngvcyK5CsMXxiZUcJfg8LbhE5Itwv3YcPF1gcGNfNL0omO4Nj1pB6ShvO/cSMuO4DtqRa X-Received: by 10.99.137.66 with SMTP id v63mr17058960pgd.117.1477623497942; Thu, 27 Oct 2016 19:58:17 -0700 (PDT) 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 g196sm14656834pfb.43.2016.10.27.19.58.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 19:58:17 -0700 (PDT) Subject: [ipa-vrp] ice in set_value_range To: "gcc-patches@gcc.gnu.org" , Jan Hubicka References: <1549ba52-153b-6bf1-28f6-5a1d2a2562fd@linaro.org> <20161027121127.qohmzldbovabbg7m@virgil.suse.cz> From: kugan Message-ID: Date: Fri, 28 Oct 2016 13:58:13 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20161027121127.qohmzldbovabbg7m@virgil.suse.cz> X-IsSubscribed: yes Hi, >> { >> tree val = ipa_get_jf_constant (jfunc); >> if (TREE_CODE (val) == INTEGER_CST) >> { >> + value_range vr; >> if (TREE_OVERFLOW_P (val)) >> val = drop_tree_overflow (val); >> - jfunc->vr_known = true; >> - jfunc->m_vr.type = VR_RANGE; >> - jfunc->m_vr.min = val; >> - jfunc->m_vr.max = val; >> + >> + vr.type = VR_RANGE; >> + vr.min = val; >> + vr.max = val; >> + vr.equiv = NULL; >> + extract_range_from_unary_expr (&jfunc->m_vr, >> + NOP_EXPR, >> + param_type, >> + &vr, TREE_TYPE (val)); > > Do I understand it correctly that extract_range_from_unary_expr deals > with any potential type conversions better (compared to what you did > before here)? Yes, this can be wrong at times too as reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78121. I have separated this part of the patch with a testcase. Please note that I am using fold_convert in the attached patch. Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Is this OK for trunk? Thanks, Kugan gcc/ChangeLog: 2016-10-28 Kugan Vivekanandarajah PR ipa/78121 * ipa-cp.c (propagate_vr_accross_jump_function): Pass param type. Also fold constant passed as argument while computing value range. (propagate_constants_accross_call): Pass param type. * ipa-prop.c: export ipa_get_callee_param_type. * ipa-prop.h: export ipa_get_callee_param_type. gcc/testsuite/ChangeLog: 2016-10-28 Kugan Vivekanandarajah PR ipa/78121 * gcc.dg/ipa/pr78121.c: New test. >From 64776c1b43c9fd68aee6c40624660d20e1c4e653 Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Fri, 28 Oct 2016 09:44:23 +1100 Subject: [PATCH 1/2] fix convertion --- gcc/ipa-cp.c | 16 +++++++++++++--- gcc/ipa-prop.c | 5 ++++- gcc/ipa-prop.h | 1 + gcc/testsuite/gcc.dg/ipa/pr78121.c | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr78121.c diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 1dc5cb6..9f28557 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -1840,12 +1840,14 @@ propagate_bits_accross_jump_function (cgraph_edge *cs, int idx, ipa_jump_func *j } /* Propagate value range across jump function JFUNC that is associated with - edge CS and update DEST_PLATS accordingly. */ + edge CS with param of callee of PARAM_TYPE and update DEST_PLATS + accordingly. */ static bool propagate_vr_accross_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc, - struct ipcp_param_lattices *dest_plats) + struct ipcp_param_lattices *dest_plats, + tree param_type) { struct ipcp_param_lattices *src_lats; ipcp_vr_lattice *dest_lat = &dest_plats->m_value_range; @@ -1853,6 +1855,11 @@ propagate_vr_accross_jump_function (cgraph_edge *cs, if (dest_lat->bottom_p ()) return false; + if (!param_type + || (!INTEGRAL_TYPE_P (param_type) + && !POINTER_TYPE_P (param_type))) + return dest_lat->set_to_bottom (); + if (jfunc->type == IPA_JF_PASS_THROUGH) { struct ipa_node_params *caller_info = IPA_NODE_REF (cs->caller); @@ -1871,6 +1878,7 @@ propagate_vr_accross_jump_function (cgraph_edge *cs, { if (TREE_OVERFLOW_P (val)) val = drop_tree_overflow (val); + val = fold_convert (param_type, val); jfunc->vr_known = true; jfunc->m_vr.type = VR_RANGE; jfunc->m_vr.min = val; @@ -2220,6 +2228,7 @@ 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) @@ -2236,7 +2245,8 @@ 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); + jump_func, dest_plats, + param_type); else ret |= dest_plats->m_value_range.set_to_bottom (); } diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 1629870..74fe199 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1595,7 +1595,10 @@ determine_locally_known_aggregate_parts (gcall *call, tree arg, } } -static tree +/* Return the Ith param type of callee associated with call graph + edge E. */ + +tree ipa_get_callee_param_type (struct cgraph_edge *e, int i) { int n; diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 4eeae88..0e75cf4 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -818,6 +818,7 @@ 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/ipa/pr78121.c b/gcc/testsuite/gcc.dg/ipa/pr78121.c new file mode 100644 index 0000000..4a0ae18 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr78121.c @@ -0,0 +1,16 @@ +/* PR ipa/78121 */ +/* { dg-do compile } */ +/* { dg-options "-ansi -O2 -fdump-ipa-cp-details" } */ + +void fn2 (unsigned char c); +int a; +static void fn1(c) unsigned char c; +{ + if (a) + fn2 (c); + fn1('#'); +} + +void fn3() { fn1 (267); } + +/* { dg-final { scan-ipa-dump-times "Setting value range of param 0 \\\[11, 35\\\]" 1 "cp" } } */ -- 2.7.4