From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 81C8E385828B for ; Sun, 12 Jun 2022 18:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81C8E385828B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 908C61F94A; Sun, 12 Jun 2022 18:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1655057497; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J647xYFKTRnO/Yy58GKkzFSExQGjXVFO9Bct0W1mdx4=; b=rupNyUOsbWnShmmAu3hBo65C2qW7+0B9PFsWZiOItRhxei+xs9+IdEww+m6+avB3SnLlV6 c+B7g0Wc/C9HPSQOYuzUksBKXXIRnNxQBQuAqVVTA8iedfNfdNx8zFYXytcF7BH6+VQarF +uR/C19RL6Feqx9ZRewt+A3cnCDGoVw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1655057497; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J647xYFKTRnO/Yy58GKkzFSExQGjXVFO9Bct0W1mdx4=; b=HlSYJz3HRgw1kmtTx3QtfZSujA1T11GaU3qK+fEPC55sQ7fmQsfysXl4FlWqWDwMK0/tUP V+kwMAfAInDRXcDg== Received: from suse.cz (unknown [10.100.200.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 5DAAF2C141; Sun, 12 Jun 2022 18:11:37 +0000 (UTC) From: Martin Jambor To: Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: Fix ipa-prop wrt volatile memory accesses In-Reply-To: References: User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Sun, 12 Jun 2022 20:11:37 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , X-List-Received-Date: Sun, 12 Jun 2022 18:11:39 -0000 Hi, On Fri, Jun 10 2022, Jan Hubicka wrote: > Hi, > this patch prevents ipa-prop from propagating aggregates when load is > volatile. Martin, does this look OK? It seem to me that ipa-prop may > need some additional volatile flag checks. load_from_unmodified_param_or_agg checks for it, although at a bit weird place (quite late and it looks like volatile reads from an aggregate parameter passed by value might still be considered OK). Building of IPA_JF_LOAD_AGG jump functions also checks for it. compute_complex_assign_jump_func and get_ancestor_addr_info look at mem_refs in addr_exprs, so that should be safe. >From a quick scan of ipa-prop, it seems that only ipa_load_from_parm_agg missed it (modulo the parenthesis above). > > Bootstrapped/regtested x86_64-linux, OK? Sure, OK, thanks! Martin > gcc/ChangeLog: > > 2022-06-10 Jan Hubicka > > PR ipa/105739 > * ipa-prop.cc (ipa_load_from_parm_agg): Disqualify volatile memory > accesses. > > gcc/testsuite/ChangeLog: > > 2022-06-10 Jan Hubicka > > * gcc.dg/ipa/pr105739.c: New test. > > diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc > index afd9222b5a2..c037668e7d8 100644 > --- a/gcc/ipa-prop.cc > +++ b/gcc/ipa-prop.cc > @@ -1112,6 +1112,10 @@ ipa_load_from_parm_agg (struct ipa_func_body_info *fbi, > if (!base) > return false; > > + /* We can not propagate across volatile loads. */ > + if (TREE_THIS_VOLATILE (op)) > + return false; > + > if (DECL_P (base)) > { > int index = ipa_get_param_decl_index_1 (descriptors, base); > diff --git a/gcc/testsuite/gcc.dg/ipa/pr105739.c b/gcc/testsuite/gcc.dg/ipa/pr105739.c > new file mode 100644 > index 00000000000..8dbe8fc2494 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/ipa/pr105739.c > @@ -0,0 +1,30 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > + > + > +__attribute__((noinline)) > +static int > +test2(int a) > +{ > + if (__builtin_constant_p (a)) > + __builtin_abort (); > + return a; > +} > +static int > +test(int *a) > +{ > + int val = *(volatile int *)a; > + if (__builtin_constant_p (val)) > + __builtin_abort (); > + if (val) > + return test2(val); > + return 0; > +} > +int a; > +int > +main() > +{ > + a = 0; > + return test (&a); > +} > +/* { dg-final { scan-tree-dump "test2" "optimized" } } */