From patchwork Fri Nov 12 13:03:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1554371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=c0gRSd6E; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HrJgg4dP0z9s1l for ; Sat, 13 Nov 2021 00:03:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A83B3858036 for ; Fri, 12 Nov 2021 13:03:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A83B3858036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636722237; bh=98ICopF+r9GajustqbKU7Bl4ZDztcxC8YanJHJ/C6tQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=c0gRSd6ER4IiL/ycyIv52cxDQQhqKxZpslMTNWPmYjbehieTbspgLfbeoLxaPqFi5 BlKdImkbb2xCSwKFOnJQZyiEmfsAP8lbl6W208LuIpwblNc8iMl7938YWPWBQktWWQ OtGzKcQ7rmjj7H57TCrEPEEc9GOBfUKWMP3gUZA0= 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 74B613858402 for ; Fri, 12 Nov 2021 13:03:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74B613858402 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 6BC452809A9; Fri, 12 Nov 2021 14:03:15 +0100 (CET) Date: Fri, 12 Nov 2021 14:03:15 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix ipa-modref pure/const discovery Message-ID: <20211112130315.GO17431@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.8 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 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-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch fixes bug I introduced while breaking up the bigger change. We currently can not use pure/const to discover looping pures&const since lack of global memory writes/stores does not imply we can CSE on the function. THis is witnessed by testsuite doing volatile asm or also can happen if i.e. function returns result of malloc. I have followup patch to add the analysis, but will first look into current ICE of ltobootstrap. Bootstrapped/regtested x86_64-linux, comitted. PR ipa/103200 * ipa-modref.c (analyze_function, modref_propagate_in_scc): Do not mark pure/const function if there are side-effects. diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 72006251f29..44b3427a202 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -2790,7 +2790,8 @@ analyze_function (function *f, bool ipa) if (!ipa && flag_ipa_pure_const) { - if (!summary->stores->every_base && !summary->stores->bases) + if (!summary->stores->every_base && !summary->stores->bases + && !summary->side_effects) { if (!summary->loads->every_base && !summary->loads->bases) fixup_cfg = ipa_make_function_const @@ -4380,7 +4381,8 @@ modref_propagate_in_scc (cgraph_node *component_node) modref_summary_lto *summary_lto = summaries_lto ? summaries_lto->get (cur) : NULL; - if (summary && !summary->stores->every_base && !summary->stores->bases) + if (summary && !summary->stores->every_base && !summary->stores->bases + && !summary->side_effects) { if (!summary->loads->every_base && !summary->loads->bases) pureconst |= ipa_make_function_const @@ -4390,7 +4392,7 @@ modref_propagate_in_scc (cgraph_node *component_node) (cur, summary->side_effects, false); } if (summary_lto && !summary_lto->stores->every_base - && !summary_lto->stores->bases) + && !summary_lto->stores->bases && !summary_lto->side_effects) { if (!summary_lto->loads->every_base && !summary_lto->loads->bases) pureconst |= ipa_make_function_const