From patchwork Wed Dec 14 15:18:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1715830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=zTJP5XKI; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=kynWMx+e; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NXJsr18Tkz23yy for ; Thu, 15 Dec 2022 02:18:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9B303886A00 for ; Wed, 14 Dec 2022 15:18:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id DB74B382CB82 for ; Wed, 14 Dec 2022 15:18:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB74B382CB82 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BEEC81FFA0; Wed, 14 Dec 2022 15:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671031100; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=IQmGBT47HNxmx4x0ZYBuw9IQe4F66jKA/W7/g7R2hS0=; b=zTJP5XKIHNU41Dp7kcfiI6Ec9KZ5rAP/cxZMN61rbWgk7NNBOk7nJRn8qsZtq8q2RbXKi1 zhggoM1NRnxlhAoFLxRX91A32176OLib7K3EgsD7GvyCISErBEGm2vP1xwbaBRr0u4DoBZ dLUqcgoqxSxoi3bSu8XwZGhnbWraSQg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671031100; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=IQmGBT47HNxmx4x0ZYBuw9IQe4F66jKA/W7/g7R2hS0=; b=kynWMx+eutZAR/fdsYu8mh837Y88s9wtLA6Bg46X87RNU3z9UuUAtS/NI+C7lI5GJ/Vtrn CXjzm+SO7s1js2Cg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B1FBE1333E; Wed, 14 Dec 2022 15:18:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +r5uKzzpmWOzQwAAMHmgww (envelope-from ); Wed, 14 Dec 2022 15:18:20 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Jan Hubicka Subject: [PATCH] ipa-sra: Fix address escape case when detecting Fortran descriptors User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Wed, 14 Dec 2022 16:18:20 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, The discussion about scan_expr_access in ipa-sra.cc brought my attention to a missing case of handling an ADDR_EXPR. As the added testcase shows, the heuristics which looks for parameters which are local variables that are only written to and passed by reference in calls can miss a case where the address of the variable in question is stored elsewhere in an assignment. This patch adds that case to the function and also adds the optimization that Richi suggested, i.e. bailing out early on simple SSA_NAMEs and constant trees. The patch is undergoing bootstrap and testing on an x86_64-linux right now. OK if it passes? Thanks, Martin gcc/ChangeLog: 2022-12-14 Martin Jambor * ipa-sra.cc (loaded_decls): Adjust comment. (scan_expr_access): Also detect assignments of address of local variables to a variable. Bail out early on SSA_NAMEs and constants as an optimization. gcc/testsuite/ChangeLog: 2022-12-14 Martin Jambor * gcc.dg/ipa/ipa-sra-29.c: New test. --- gcc/ipa-sra.cc | 16 ++++++++++- gcc/testsuite/gcc.dg/ipa/ipa-sra-29.c | 38 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-sra-29.c diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index 93f5e34b15c..bcabdedfc6c 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -592,7 +592,8 @@ namespace { hash_map *decl2desc; -/* All local DECLs ever loaded from. */ +/* All local DECLs ever loaded from of and of those that have their address + assigned to a variable. */ hash_set *loaded_decls; @@ -1743,6 +1744,19 @@ scan_expr_access (tree expr, gimple *stmt, isra_scan_context ctx, bool deref = false; bool reverse; + if (TREE_CODE (expr) == ADDR_EXPR) + { + if (ctx == ISRA_CTX_ARG) + return; + tree t = get_base_address (TREE_OPERAND (expr, 0)); + if (TREE_CODE (t) == VAR_DECL && !TREE_STATIC (t)) + loaded_decls->add (t); + return; + } + if (TREE_CODE (expr) == SSA_NAME + || CONSTANT_CLASS_P (expr)) + return; + if (TREE_CODE (expr) == BIT_FIELD_REF || TREE_CODE (expr) == IMAGPART_EXPR || TREE_CODE (expr) == REALPART_EXPR) diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-sra-29.c b/gcc/testsuite/gcc.dg/ipa/ipa-sra-29.c new file mode 100644 index 00000000000..aee45ea0e8f --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-sra-29.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-sra-details" } */ + +struct S +{ + float f; + int i; + void *p; +}; + +extern struct S *gp; +int baz (float); + +static int +__attribute__((noinline)) +bar (struct S *p) +{ + if (p->i != 6) + __builtin_abort (); + + return baz(p->f); +} + +int +foo (void) +{ + struct S s; + + gp = &s; + s.f = 7.4; + s.i = 6; + s.p = &s; + + bar (&s); + return 0; +} + +/* { dg-final { scan-ipa-dump-not "Variable constructed just to be passed to calls" "sra" } } */