From patchwork Tue Jan 26 17:21:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 573366 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 065341401DA for ; Wed, 27 Jan 2016 04:21:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dNnzse0c; 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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=AcTBXVmLZFK8VtpIIm1gt1REOBrhACnUj8xcadXKg1z7VR4yn6 sIIEp+8XqIxdJYNKqyBF3pmYccxwpFS1l6J2neKuqHlYiGJ+28bCHXzk0kNgjgID KVUYo19u8t0I7JNwsZH+II5JzMG6nJ+cmBHZVW4YIL6cTEhmm8+s2aG50= 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:mime-version:content-type; s= default; bh=G0GuOdHSd2ooIIHNijI2MFqEG+I=; b=dNnzse0cJkg7mSjDXlk0 wHyJ3oTpfPyv2Oh6ZFXitOlzuyzJxyakcjRiG4429V4HMixoONqQXaVcwPycAZsu sYI8+baRqv+kJk3ThmmROwGLNrZiOeCY8S6un48tcchwiUEMWeK1gp2rAM2AD+u6 t3MyoiKU9IF5PFcaWlgfL4k= Received: (qmail 25777 invoked by alias); 26 Jan 2016 17:21:37 -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 25767 invoked by uid 89); 26 Jan 2016 17:21:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=sra, Hx-languages-length:2413 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 26 Jan 2016 17:21:35 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B9696ABB0 for ; Tue, 26 Jan 2016 17:21:30 +0000 (UTC) Date: Tue, 26 Jan 2016 18:21:31 +0100 From: Martin Jambor To: GCC Patches Cc: Richard Biener Subject: [PR 69355] Correct hole detection when total_scalarization fails Message-ID: <20160126172131.GJ32511@virgil.suse.cz> Mail-Followup-To: GCC Patches , Richard Biener MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi, PR 69355 has revealed that when SRA attempts total scalarization of an aggregate but this fails because the user type-casts a scalar field and stores into a it a smaller aggregate (and the scalar field is not written to, whether directly or as a part of an aggregate store), the pass can loose track of unscalarized data there. I think that this can happen only when violating strict aliasing rules but with -fno-strict-aliasing it should work. Fixed thusly with the patch below (the condition is there to avoid detecting padding after aggregate-fields in totally-scalarized aggregates as unscalarized data). Bootstrapped and tested on x86_64-linux. OK for trunk? And the gcc-5 branch? Thanks, Martin 2016-01-26 Martin Jambor PR tree-optimization/69355 * tree-sra.c (analyze_access_subtree): Correct hole detection when total_scalarization fails. testsuite/ * gcc.dg/tree-ssa/pr69355.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr69355.c | 44 +++++++++++++++++++++++++++++++++ gcc/tree-sra.c | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr69355.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c new file mode 100644 index 0000000..f515c21 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c @@ -0,0 +1,44 @@ +/* { dg-do run } */ +/* { dg-options "-O -fno-strict-aliasing" } */ + +struct S +{ + void *a; + long double b; +}; + +struct Z +{ + long long l; + short s; +} __attribute__((packed)); + +struct S __attribute__((noclone, noinline)) +foo (void *v, struct Z *z) +{ + struct S t; + t.a = v; + *(struct Z *) &t.b = *z; + return t; +} + +struct Z gz; + +int +main (int argc, char **argv) +{ + struct S s; + + if (sizeof (long double) < sizeof (struct Z)) + return 0; + + gz.l = 0xbeef; + gz.s = 0xab; + + s = foo ((void *) 0, &gz); + + if ((((struct Z *) &s.b)->l != gz.l) + || (((struct Z *) &s.b)->s != gz.s)) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 740542f..b0e737a 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -2421,7 +2421,7 @@ analyze_access_subtree (struct access *root, struct access *parent, if (covered_to < limit) hole = true; - if (scalar) + if (scalar || !allow_replacements) root->grp_total_scalarization = 0; }