From patchwork Mon Nov 4 20:13:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 288245 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EA4DB2C013B for ; Tue, 5 Nov 2013 07:14:12 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=PaogojWK8YAv+3LVIEyKdBp5zj6dt AnOpfZg9WhjY/4jM1mSV36Twt4Qcrw7qGfFwqBYtNVn2FYrPDe2gAKS3XaTXq8NP gN96gtmPrZO81iN/j3xOHWf/Kn/IwufhmWjVwtCzPoLq1HxJ91AWyQep8eNDh9BM a9QIdaIztwihgI= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=QzSDFquGPvTmmKEMN6O2n2aR7Ek=; b=ZbI 0mUO/ZXOXjecnOLwoKsHcRp6qWdGtoB5t0OfkUcMXafmJAhHLFLIteEC3FWKTY7E OeIn0qaI19SGPBmN7wP/Sv2osfvm4XODkfaT9nas5GX7qU4QN/l2u9lrXiHJ8RDD JRsBmxRUIk2gF9xF242zG8N+NHkB3ATq7Dq06wYU= Received: (qmail 3898 invoked by alias); 4 Nov 2013 20:13:59 -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 3889 invoked by uid 89); 4 Nov 2013 20:13:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_40, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Nov 2013 20:13:57 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA4KDnHG001085 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Nov 2013 15:13:50 -0500 Received: from tucnak.zalov.cz (vpn1-5-212.ams2.redhat.com [10.36.5.212]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA4KDmbl014877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 4 Nov 2013 15:13:49 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id rA4KDllM032763; Mon, 4 Nov 2013 21:13:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id rA4KDkvg032762; Mon, 4 Nov 2013 21:13:46 +0100 Date: Mon, 4 Nov 2013 21:13:46 +0100 From: Jakub Jelinek To: Richard Biener , Martin Jambor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ipcp_transform_function (PR tree-optimization/58984) Message-ID: <20131104201346.GX27813@tucnak.zalov.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! This patch fixes PR58984, where determine_known_aggregate_parts notices that o.f0 = 1 store (because of ESRA) and p.f0 = 1 store (because the field isn't a bitfield) are known constants at offset 0 of the first parameter, but doesn't record the access of that size (8 bits) and happily replaces BIT_FIELD_REF in the called function with 1 (which is wrong, because the f1 bitfield also contains 1). As the size isn't recorded explicitly, this patch looks at TYPE_SIZE of the constants we've recorded, if the IL was correct then the store to it should be a useless type conversion and thus have the same number of bits. Bootstrapped/regtested on x86_64-linux and i686-linux (together with a short hack to record how many times this has changed compiler's behavior and the only case during bootstrap/regtest was on this testcase on x86_64-linux 64-bit). Ok for trunk/4.8? 2013-11-04 Jakub Jelinek PR tree-optimization/58984 * ipa-prop.c (ipa_load_from_parm_agg_1): Add SIZE_P argument, set *SIZE_P if non-NULL on success. (ipa_load_from_parm_agg, ipa_analyze_indirect_call_uses): Adjust callers. (ipcp_transform_function): Likewise. Punt if size of access is different from TYPE_SIZE on v->value's type. * gcc.c-torture/execute/pr58984.c: New test. Jakub --- gcc/ipa-prop.c.jj 2013-11-01 12:41:34.000000000 +0100 +++ gcc/ipa-prop.c 2013-11-04 15:47:36.373955817 +0100 @@ -852,7 +852,7 @@ static bool ipa_load_from_parm_agg_1 (vec descriptors, struct param_analysis_info *parms_ainfo, gimple stmt, tree op, int *index_p, HOST_WIDE_INT *offset_p, - bool *by_ref_p) + HOST_WIDE_INT *size_p, bool *by_ref_p) { int index; HOST_WIDE_INT size, max_size; @@ -870,6 +870,8 @@ ipa_load_from_parm_agg_1 (vecdescriptors, NULL, stmt, op, index_p, - offset_p, by_ref_p); + offset_p, NULL, by_ref_p); } /* Given that an actual argument is an SSA_NAME (given in NAME) and is a result @@ -1826,7 +1830,7 @@ ipa_analyze_indirect_call_uses (struct c if (gimple_assign_single_p (def) && ipa_load_from_parm_agg_1 (info->descriptors, parms_ainfo, def, gimple_assign_rhs1 (def), &index, &offset, - &by_ref)) + NULL, &by_ref)) { struct cgraph_edge *cs = ipa_note_param_call (node, index, call); cs->indirect_info->offset = offset; @@ -4567,7 +4571,7 @@ ipcp_transform_function (struct cgraph_n struct ipa_agg_replacement_value *v; gimple stmt = gsi_stmt (gsi); tree rhs, val, t; - HOST_WIDE_INT offset; + HOST_WIDE_INT offset, size; int index; bool by_ref, vce; @@ -4594,13 +4598,15 @@ ipcp_transform_function (struct cgraph_n continue; if (!ipa_load_from_parm_agg_1 (descriptors, parms_ainfo, stmt, - rhs, &index, &offset, &by_ref)) + rhs, &index, &offset, &size, &by_ref)) continue; for (v = aggval; v; v = v->next) if (v->index == index && v->offset == offset) break; - if (!v || v->by_ref != by_ref) + if (!v + || v->by_ref != by_ref + || tree_low_cst (TYPE_SIZE (TREE_TYPE (v->value)), 0) != size) continue; gcc_checking_assert (is_gimple_ip_invariant (v->value)); --- gcc/testsuite/gcc.c-torture/execute/pr58984.c.jj 2013-11-04 15:49:48.657239937 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr58984.c 2013-11-04 16:00:44.876785998 +0100 @@ -0,0 +1,57 @@ +/* PR tree-optimization/58984 */ + +struct S { int f0 : 8; int : 6; int f1 : 5; }; +struct T { char f0; int : 6; int f1 : 5; }; + +int a, *c = &a, e, n, b, m; + +static int +foo (struct S p) +{ + const unsigned short *f[36]; + for (; e < 2; e++) + { + const unsigned short **i = &f[0]; + *c ^= 1; + if (p.f1) + { + *i = 0; + return b; + } + } + return 0; +} + +static int +bar (struct T p) +{ + const unsigned short *f[36]; + for (; e < 2; e++) + { + const unsigned short **i = &f[0]; + *c ^= 1; + if (p.f1) + { + *i = 0; + return b; + } + } + return 0; +} + +int +main () +{ + struct S o = { 1, 1 }; + foo (o); + m = n || o.f0; + if (a != 1) + __builtin_abort (); + e = 0; + struct T p = { 1, 1 }; + bar (p); + m |= n || p.f0; + if (a != 0) + __builtin_abort (); + return 0; +}