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 D303A384859E for ; Fri, 10 Jun 2022 13:06:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D303A384859E Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 648A0289A0F; Fri, 10 Jun 2022 15:06:52 +0200 (CEST) Date: Fri, 10 Jun 2022 15:06:52 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, mjambor@suse.cz Subject: Fix ipa-prop wrt volatile memory accesses Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Fri, 10 Jun 2022 13:07:02 -0000 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. Bootstrapped/regtested x86_64-linux, OK? Honza 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" } } */