From patchwork Thu Nov 9 20:03:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 836489 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-466451-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="F/zB3Ph+"; 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 3yXvHS0mJ6z9s7m for ; Fri, 10 Nov 2017 07:03:31 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=A99rQ6C41zhEqCBXaaBa/1ZN3QQjU bFhO9DM9cTOQ9BVC9fFv1U96S8yX8bcfgwSA+ozlZbjkiCteJbBrbUimYYkJ+Qrz 1w7y9wNO88H00MmMx33X1VCvZ8RBnAA5FW8Npm3stEqdR+O6HhOnf56zYkSJK2i3 bQBFmkPCbYPPXs= 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=aDOkq78nMuZ7sFCnx6rA1QCXF58=; b=F/z B3Ph+3UNVNhNBtRmAypQBTF0dSdCdTWlXBtWAX2e9FBqPftqUyXmSd2BwkwkhN5p b6z9DTsRLsPw34wiX5lPKxeczUievBxin7NionLTEHdes9s3wTmoqFjsO+XixSVH glbbCOY3ZkUvjXftpoOLCAUY0IHwOHGh7Lp+gAf0= Received: (qmail 48241 invoked by alias); 9 Nov 2017 20:03:22 -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 48230 invoked by uid 89); 9 Nov 2017 20:03:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Nov 2017 20:03:20 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87D03368E6; Thu, 9 Nov 2017 20:03:19 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30A2C6BF8D; Thu, 9 Nov 2017 20:03:19 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vA9K3GLM019094; Thu, 9 Nov 2017 21:03:17 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vA9K3FVK019093; Thu, 9 Nov 2017 21:03:15 +0100 Date: Thu, 9 Nov 2017 21:03:15 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix profiledbootstrap - store-merging aliasing issue (PR bootstrap/82916) Message-ID: <20171109200315.GF14653@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! We want to terminate a chain if a chain with different base (or insn outside of any chain) has a store that the current stmt might use, or overwrite. The functions it used didn't cover the store after store case which in the middle-end aliasing model needs to avoid tbaa, because the latter store might be after a placement new or might otherwise change the dynamic object type of the object. The following patch does that. Bootstrapped/regtested on x86_64-linux and i686-linux, additionally profiledbootstrapped with the configure options Markus mentioned in the PR. Ok for trunk? 2017-11-09 Jakub Jelinek PR bootstrap/82916 * gimple-ssa-store-merging.c (pass_store_merging::terminate_all_aliasing_chains): For gimple_store_p stmts also call refs_output_dependent_p. * gcc.dg/store_merging_2.c: Only expect 2 successful mergings instead of 3. * gcc.dg/pr82916.c: New test. Jakub --- gcc/gimple-ssa-store-merging.c.jj 2017-11-09 15:51:08.000000000 +0100 +++ gcc/gimple-ssa-store-merging.c 2017-11-09 18:01:20.789236951 +0100 @@ -945,6 +945,7 @@ pass_store_merging::terminate_all_aliasi if (!gimple_vuse (stmt)) return false; + tree store_lhs = gimple_store_p (stmt) ? gimple_get_lhs (stmt) : NULL_TREE; for (imm_store_chain_info *next = m_stores_head, *cur = next; cur; cur = next) { next = cur->next; @@ -958,8 +959,10 @@ pass_store_merging::terminate_all_aliasi unsigned int i; FOR_EACH_VEC_ELT (cur->m_store_info, i, info) { - if (ref_maybe_used_by_stmt_p (stmt, gimple_assign_lhs (info->stmt)) - || stmt_may_clobber_ref_p (stmt, gimple_assign_lhs (info->stmt))) + tree lhs = gimple_assign_lhs (info->stmt); + if (ref_maybe_used_by_stmt_p (stmt, lhs) + || stmt_may_clobber_ref_p (stmt, lhs) + || (store_lhs && refs_output_dependent_p (store_lhs, lhs))) { if (dump_file && (dump_flags & TDF_DETAILS)) { --- gcc/testsuite/gcc.dg/store_merging_2.c.jj 2017-11-08 16:46:19.000000000 +0100 +++ gcc/testsuite/gcc.dg/store_merging_2.c 2017-11-09 18:16:33.482344795 +0100 @@ -77,4 +77,4 @@ main (void) return 0; } -/* { dg-final { scan-tree-dump-times "Merging successful" 3 "store-merging" } } */ +/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } } */ --- gcc/testsuite/gcc.dg/pr82916.c.jj 2017-11-09 18:12:40.707128841 +0100 +++ gcc/testsuite/gcc.dg/pr82916.c 2017-11-09 18:12:19.000000000 +0100 @@ -0,0 +1,47 @@ +/* PR bootstrap/82916 */ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-tree-dse" } */ + +struct A { struct A *next; }; +struct C +{ + int *of; + struct C *parent, *prev, *next; + int depth; + int min; + struct C *min_occ; +}; + +__attribute__((noipa)) struct C * +foo (int *node) +{ + struct A *p = __builtin_malloc (sizeof (struct C)); + if (!p) + return 0; + p->next = 0; + /* Originally placement new. */ + struct C *nw = (struct C *)(void *)p; + nw->of = node; + nw->parent = 0; + nw->prev = 0; + nw->next = 0; + nw->depth = 0; + nw->min_occ = nw; + nw->min = 0; + return nw; +} + +int +main () +{ + int o; + struct C *p = foo (&o); + if (p) + { + if (p->of != &o || p->parent || p->prev || p->next || p->depth + || p->min || p->min_occ != p) + __builtin_abort (); + } + __builtin_free (p); + return 0; +}