From patchwork Fri Jun 10 13:06:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 55009 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B8473829BF2 for ; Fri, 10 Jun 2022 13:07:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B8473829BF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654866449; bh=3CClDI7teQyO0mA1gN6tbY/hFnTxhDv+qDIHhd5fFC8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=iwKZDOftPTvw/MqQXefjCVCFJMetDSQYCJiNrZ98oPvojJ1cCcaB3nmbLBUuqU8ii vypC7Rwr068VCKuGn00pUCg+tg1z0m5Hs4jBdyXiKYDq1cTYltb6lDY9ijpYlOCWts XeUnIMxYnzCJQQoX53aed+vmiYf0wwAjIDql2KM4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 To: gcc-patches@gcc.gnu.org, mjambor@suse.cz Subject: Fix ipa-prop wrt volatile memory accesses Message-ID: MIME-Version: 1.0 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-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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" } } */