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: 33235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp284311wrn; Wed, 14 Dec 2022 07:18:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4urclt/sC8g/3sWOKmFWfSFfGr8RAqiixXwMqsKGOeZxh1L+6/mSEKiHPeqIJ4QwGim5Ge X-Received: by 2002:a17:906:c088:b0:7c4:a773:4d72 with SMTP id f8-20020a170906c08800b007c4a7734d72mr3681009ejz.64.1671031139649; Wed, 14 Dec 2022 07:18:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671031139; cv=none; d=google.com; s=arc-20160816; b=p4/E61VnTbmJ2vEA6Sny2aX7mZTIxec4xiwuMmKXdwmi6d7ybddpcKxIfifveFQlKf fthngCATe0Z2mJLNnoxw+vETfpt63ig2CQqjOM/7XmIOEs3B0dKBXPo6yYkdA+X7Jg0R 1wY+PIL0gscZxa7RoyqeO8wugmWr49dsVbsffuU6bPRK2bd1HaWy5WijKo47JjEcb3uy x6W7i4USUh/xhjNcQvGEjPPDQ3eU6O8AmAQ8VqIUksHVmmCQr8gpPwf7/SIRsC7tKLoc FTRZ2TtpZk5X4K0mJ7RRC/7XywIdYOPTS0SwzgT9u7ksIESy5ABiCqb0VRJc2KAVk+Q/ T82w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=IQmGBT47HNxmx4x0ZYBuw9IQe4F66jKA/W7/g7R2hS0=; b=s7iJGs6WQRRPrT0hMCx+ZyxIFN9EnHjat68fVxi8POMtpxFqXESEviriih9QE3HMw1 H9oRkfAs5aN7L7n89C+E1fZZBXz+3y31EjX3i+nG/h3RirfusdS/3YvqEP+4QkC7EhOz MrbLsSHrvjTik5/V8mJihvlAxAC+cVwpDWPDJHRA1U7v4M9jJcg2yrAGzpvV1XceW3B3 egi0mUcriJQtEc+CU8Cfwe+xQKB1UVdTknYrBmiLoUJ81ZaGneJUgS+kClIiNIfewdfl NLcGRVUAebLj2enYgfnqxiS3xXu6TXI0RKV7pKZkC7FPDpiGk+zRidz2WAs7u/RC61f3 65gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=zTJP5XKI; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=kynWMx+e; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id nb18-20020a1709071c9200b007c082259effsi10469414ejc.101.2022.12.14.07.18.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 07:18:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=zTJP5XKI; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=kynWMx+e; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C2F90382CBA4 for ; Wed, 14 Dec 2022 15:18:48 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752203148370117124?= X-GMAIL-MSGID: =?utf-8?q?1752203148370117124?= 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" } } */