From patchwork Thu Mar 14 13:29:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1056519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-497900-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="He9q7RXP"; dkim-atps=neutral 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 44KqM02wBGz9s4Y for ; Fri, 15 Mar 2019 00:29:46 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=qakMhcD3Xi0EWuF2bE1ciMx0HLOIiPFes2x1K+Ctd6uv4XYl/g eMZuBu23iIbdEeXmRXldhLchXnqFu5/d9IWIvsxTXFS3w7+ytI6LyTdkSOQ8dIdV ABzbVzFH8WnjZQmod2RcmZWTWhPEU6GhSNIKO/pMvGDDcURtzvhZpZtcc= 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 :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=n/WURDsp8UsK50amb4RyJgiBGhk=; b=He9q7RXP7WTK1jy0OhjO NzL9raHBmCMYQdFgrQd4fcDJ8jATk9QuhFsvLSwdZV6nn411OtMv18AuzXjiAnrw gbd2B/pfAch4rok01e8aL2qm0p57qRdHdKOFOuMwT6OrdYYQ7f3elllpjwF5UFuV YJ/yiI5v8Da0Kiv3QPB3t4w= Received: (qmail 80821 invoked by alias); 14 Mar 2019 13:29:39 -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 80804 invoked by uid 89); 14 Mar 2019 13:29:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=ii, cb X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Mar 2019 13:29:37 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 365B0AFC7 for ; Thu, 14 Mar 2019 13:29:35 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Richard Biener Subject: [PR 89546] Add forgotten requeing in propagate_subaccesses_across_link User-Agent: Notmuch/0.28.2 (https://notmuchmail.org) Emacs/26.1 (x86_64-suse-linux-gnu) Date: Thu, 14 Mar 2019 14:29:34 +0100 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, PR 89546 is a nasty miscompilation bug that is in the compiler since r247604 (May 2017) but is surprisingly hard to trigger. Since that revision, SRA does not consider all aggregates that are assigned a value in a gimple assignment statement from another aggregate as automatically containing data. Instead, it records existence of such assignments and then propagates this information from RHSs to LHSs in a simple queue driven algorithm. That of course relies on the fact that whenever a part of a LHSs is marked as containing data, all relevant parts of that aggregate which are on the RHS of some other assignment are re-queued. Well, it turns out I forgot to add that to one spot where that has to be done. Fixed with the patch below. Bootstrapped and tested on x86_64-linux. OK for trunk and gcc 8? Thanks, Martin 2019-03-14 Martin Jambor PR tree-optimization/89546 * tree-sra.c (propagate_subaccesses_across_link): Requeue new_acc if any propagation to its children took place. testsuite/ * gcc.dg/tree-ssa/pr89546.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr89546.c | 100 ++++++++++++++++++++++++ gcc/tree-sra.c | 8 +- 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr89546.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89546.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89546.c new file mode 100644 index 00000000000..c4645ae1858 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr89546.c @@ -0,0 +1,100 @@ +/* { dg-do run } */ +/* { dg-options "-O" } */ + +struct I +{ + int i; +}; + +struct A +{ + struct I i1; + struct I i2; + struct I i3; +}; + +struct B +{ + struct I i0; + struct A a; +}; + +struct C +{ + struct I i00; + struct B b; +}; + +volatile int v; + +void __attribute__((noipa)) +consume_i (struct I i) +{ + v = i.i; +} + +void __attribute__((noipa)) +consume_a (struct A a) +{ + v = a.i1.i; +} + +void __attribute__((noipa)) +consume_b (struct B b) +{ + v = b.a.i1.i; +} + +void __attribute__((noipa)) +consume_c (struct C c) +{ + v = c.b.a.i1.i; +} + + + + +int __attribute__((noipa)) +foo (struct I input) +{ + struct I i1, i2, i3; + struct A a1, a2, a3; + struct B b1; + struct C c; + + i1 = input; + a1.i1 = i1; + b1.a = a1; + + i2.i = 1; + b1.i0 = i2; + + c.b = b1; + + a2 = c.b.a; + a3 = a2; + i3 = a3.i1; + + int t = c.b.i0.i; + a2.i3.i = 4; + consume_i (i1); + consume_i (i2); + consume_b (b1); + consume_a (a1); + consume_a (a2); + consume_a (a3); + consume_c (c); + + return i3.i + t; +} + +int +main (int argc, char *argv[]) +{ + struct I s; + s.i = 1234; + int i = foo (s); + if (i != 1235) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index ca3858d5fc7..fd51a3d0323 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -2752,8 +2752,12 @@ propagate_subaccesses_across_link (struct access *lacc, struct access *racc) rchild->grp_hint = 1; new_acc->grp_hint |= new_acc->grp_read; - if (rchild->first_child) - ret |= propagate_subaccesses_across_link (new_acc, rchild); + if (rchild->first_child + && propagate_subaccesses_across_link (new_acc, rchild)) + { + ret = 1; + add_access_to_work_queue (new_acc); + } } else {