From patchwork Tue Mar 5 14:42:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1051756 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-497368-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="voVZIYbD"; 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 44DKPC4ckHz9s47 for ; Wed, 6 Mar 2019 01:42:37 +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=btaLS9DUALvD7y83us+QPHgJay3CtL7rRv5kbV7Hx13tP79ist 9B+TQUd41eyyz8WURPYSCJdRlrX8MEOLmvBr+JkNgnqCVzbINyxqccTmdvwWOILL iAU0pLOL45Ug1RoZKwGEifr26OwVBQk+X6Ld280s5XS5S2VEeZkCVEgLE= 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=5pNvET2auiS8u6OffhEGVCiQcZM=; b=voVZIYbDDThkGm8M+XDK Qjc/jD3ZFQD/tUzhCafxjHaIVy1rmlyMQAQtm2Cq9lCyC01qwsCrSI9FyTNQOzGd 2WJnKHwecBSjnX59NZcxZRX92dAU/kGdv4PX8Tfz/S0vrpRBWKsr67FnfhdCTr8/ 62EX5ALO9Zgdjpcq7DGe9Ps= Received: (qmail 6445 invoked by alias); 5 Mar 2019 14:42:28 -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 6355 invoked by uid 89); 5 Mar 2019 14:42:28 -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.2 spammy=at, REF, za, yx 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; Tue, 05 Mar 2019 14:42:26 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 24CF1AB7D for ; Tue, 5 Mar 2019 14:42:24 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Richard Biener Subject: [PR 85762, 87008, 85459] Relax MEM_REF check in contains_vce_or_bfcref_p User-Agent: Notmuch/0.28.2 (https://notmuchmail.org) Emacs/26.1 (x86_64-suse-linux-gnu) Date: Tue, 05 Mar 2019 15:42:23 +0100 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, after looking into the three PRs I found that the problem is the same in all of them, introduced in revision 255510, with SRA treating completely non type-punning MEM_REFs to a filed of a structure as a V_C_E (these are typically introduced by inlining tiny C++ getters/setters and other methods), sending it to a paranoid mode and leaving many unnecessary memory accesses behind. I believe the right fix is to relax the condition to what it was intended to do in r255510 to fix PR 83141. This particular behavior was chosen because we were afraid floating-point accesses might be introduced to load non-FP data, but as https://pastebin.com/Jk7ZPsVH shows, that can still happen and so if it really must be avoided at all costs, we have to deal with it differently. The regressions this fixes are potentially severe, therefore I'd like to backport this also to the gcc-8-branch. The patch has passed bootstrap and testing on x86_64-linux and aarch64-linux, testing and bootstrap on i686-linux and ppc64le-linux are in progress. OK for trunk and then later on for the branch? Thanks, Martin 2019-03-01 Martin Jambor PR tree-optimization/85762 PR tree-optimization/87008 PR tree-optimization/85459 * tree-sra.c (contains_vce_or_bfcref_p): Relax MEM_REF type-conversion check. testsuite/ * g++.dg/tree-ssa/pr87008.C: New test. --- gcc/testsuite/g++.dg/tree-ssa/pr87008.C | 17 +++++++++++++++++ gcc/tree-sra.c | 13 ++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/pr87008.C diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr87008.C b/gcc/testsuite/g++.dg/tree-ssa/pr87008.C new file mode 100644 index 00000000000..eef521f9ad5 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/pr87008.C @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +extern void dontcallthis(); + +struct A { long a, b; }; +struct B : A {}; +templatevoid cp(T&a,T const&b){a=b;} +long f(B x){ + B y; cp(y,x); + B z; cp(z,x); + if (y.a - z.a) + dontcallthis (); + return 0; +} + +/* { dg-final { scan-tree-dump-not "dontcallthis" "optimized" } } */ diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index eeef31ba496..bd30af5c6e0 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -1151,7 +1151,7 @@ contains_view_convert_expr_p (const_tree ref) } /* Return true if REF contains a VIEW_CONVERT_EXPR or a MEM_REF that performs - type conversion or a COMPONENT_REF with a bit-field field declaration. */ + memcpy or a COMPONENT_REF with a bit-field field declaration. */ static bool contains_vce_or_bfcref_p (const_tree ref) @@ -1165,14 +1165,9 @@ contains_vce_or_bfcref_p (const_tree ref) ref = TREE_OPERAND (ref, 0); } - if (TREE_CODE (ref) != MEM_REF - || TREE_CODE (TREE_OPERAND (ref, 0)) != ADDR_EXPR) - return false; - - tree mem = TREE_OPERAND (TREE_OPERAND (ref, 0), 0); - if (TYPE_MAIN_VARIANT (TREE_TYPE (ref)) - != TYPE_MAIN_VARIANT (TREE_TYPE (mem))) - return true; + if (TREE_CODE (ref) == MEM_REF + && TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (ref, 1)))) + return true; return false; }