From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 05C8D3858D35 for ; Sun, 22 Aug 2021 17:32:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 05C8D3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id B2CE52809AE; Sun, 22 Aug 2021 19:32:14 +0200 (CEST) Date: Sun, 22 Aug 2021 19:32:14 +0200 From: Jan Hubicka To: Martin =?iso-8859-2?Q?Li=B9ka?= Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] IPA: MODREF should skip EAF_* flags for indirect calls Message-ID: <20210822173214.GF68480@kam.mff.cuni.cz> References: <7d70a502-f714-77d1-f790-995e245b9ab2@suse.cz> <20210822123806.GF81418@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210822123806.GF81418@kam.mff.cuni.cz> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Sun, 22 Aug 2021 17:32:18 -0000 > Thanks for looking into this bug - it is interesting that ipa-pta > requires !EAF_NOCLOBBER when function is called... > > I have some work done on teaching ipa-modref (and other propagation > passes) to use ipa-devirt info when the full set of callees is known. > This goes oposite way. > > You can drop flags only when callee == NAME and you can just frop > EAF_NOCLOBBER. For example in testcase > > struct a { > void (*foo)(); > void *bar; > } > > void wrap (struct a *a) > { > a->foo (); > } > > will prevent us from figuring out that bar can not be modified when you > pass non-ecaping instance of struct a to wrap. > I am testing this updated patch which implements that. I am not very happy about this (it punishes -fno-ipa-pta path for not very good reason), but we need bugfix for release branch. It is very easy now to add now EAF flags at modref side so we can track EAF_NOT_CALLED. tree-ssa-structalias side is always bit anoying wrt new EAF flags because it has three copies of the code building constraints for call (for normal, pure and const). Modref is already tracking if function can read/modify global memory. I plan to add flags for NRC and link chain and then we can represent effect of ECF_CONST and PURE by simply adding flags. I would thus would like to merge that code. We do various optimizations to reduce amount of constriants produced, but hopefully this is not very important (or can be implemented by special casing in unified code). Honza gcc/ChangeLog: 2021-08-22 Jan Hubicka Martin Liska * ipa-modref.c (analyze_ssa_name_flags): Indirect call implies ~EAF_NOCLOBBER. gcc/testsuite/ChangeLog: 2021-08-22 Jan Hubicka Martin Liska * gcc.dg/lto/pr101949_0.c: New test. * gcc.dg/lto/pr101949_1.c: New test. diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index fafd804d4ba..549153865b8 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -1700,6 +1700,15 @@ analyze_ssa_name_flags (tree name, vec &lattice, int depth, else if (gcall *call = dyn_cast (use_stmt)) { tree callee = gimple_call_fndecl (call); + + /* IPA PTA internally it treats calling a function as "writing" to + the argument space of all functions the function pointer points to + (PR101949). We can not drop EAF_NOCLOBBER only when ipa-pta + is on since that would allow propagation of this from -fno-ipa-pta + to -fipa-pta functions. */ + if (gimple_call_fn (use_stmt) == name) + lattice[index].merge (~EAF_NOCLOBBER); + /* Return slot optimization would require bit of propagation; give up for now. */ if (gimple_call_return_slot_opt_p (call) diff --git a/gcc/testsuite/gcc.dg/lto/pr101949_0.c b/gcc/testsuite/gcc.dg/lto/pr101949_0.c new file mode 100644 index 00000000000..142dffe8780 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr101949_0.c @@ -0,0 +1,20 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O2 -fipa-pta -flto -flto-partition=1to1" } } */ + +extern int bar (int (*)(int *), int *); + +static int x; + +static int __attribute__ ((noinline)) foo (int *p) +{ + *p = 1; + x = 0; + return *p; +} + +int main () +{ + if (bar (foo, &x) != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/lto/pr101949_1.c b/gcc/testsuite/gcc.dg/lto/pr101949_1.c new file mode 100644 index 00000000000..871d15c9bfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr101949_1.c @@ -0,0 +1,4 @@ +int __attribute__((noinline,noclone)) bar (int (*fn)(int *), int *p) +{ + return fn (p); +}