From patchwork Sat Nov 20 23:36:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 47970 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 07DD53858034 for ; Sat, 20 Nov 2021 23:36:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07DD53858034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637451410; bh=6gxHozWU+AIVKluQVyUaTP/Rq7XOKZROTn4V01O1yKQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LdddMonPFbCL3LV7G5YsBX5+NxxTn4a8h7276JDyeWZJHFfoEDowD4+rzmr3wRzX5 LpKwi19F/T+yEBDbM9dj93oY/bI84XV5DLsrZ8XazDBRhNRaIMx27NO+0jE13gX1ji TbOo9PMwRcyi8J6naLR2SW3EhXW782ukgYHy47Zc= 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 25088385840D for ; Sat, 20 Nov 2021 23:36:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 25088385840D Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id BD4FD28094C; Sun, 21 Nov 2021 00:36:18 +0100 (CET) Date: Sun, 21 Nov 2021 00:36:18 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix looping flag discovery in ipa-pure-const Message-ID: <20211120233618.GA54340@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.6 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, The testcase shows situation where there is non-trivial cycle in the callgraph involving a noreturn call. This cycle is important for const function discovery but not important for pure. IPA pure const uses same strongly connected components for both propagations which makes it to get suboptimal result (does not detect the pure flag). However local pure const gets the situation right becaue it processes functions in right order. This hits rarely executed code in propagate_pure_const that merge results with previously known state that has long standing bug in it that makes it to throw away the looping flag. Bootstrapped/regtested x86_64-linux. Comitted. gcc/ChangeLog: 2021-11-21 Jan Hubicka PR ipa/103052 * ipa-pure-const.c (propagate_pure_const): Fix merging of loping flag. gcc/testsuite/ChangeLog: 2021-11-21 Jan Hubicka PR ipa/103052 * gcc.c-torture/execute/pr103052.c: New test. diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index a332940b55d..fea8b08c4eb 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -1782,9 +1782,9 @@ propagate_pure_const (void) if (w_l->state_previously_known != IPA_NEITHER && this_state > w_l->state_previously_known) { - this_state = w_l->state_previously_known; if (this_state == IPA_NEITHER) - this_looping = w_l->looping_previously_known; + this_looping = w_l->looping_previously_known; + this_state = w_l->state_previously_known; } if (!this_looping && self_recursive_p (w)) this_looping = true; diff --git a/gcc/testsuite/gcc.c-torture/execute/pr103052.c b/gcc/testsuite/gcc.c-torture/execute/pr103052.c new file mode 100644 index 00000000000..bef8674a43c --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr103052.c @@ -0,0 +1,35 @@ +static void js_error(void); +static int top; +static void js_throw(void) +{ + __builtin_exit(0); +} + +// LOCATION A -- if js_pop is here, the bug is present +static void js_pop(void) +{ + if (++top > 100) + js_error(); +} + +static void jsC_error(const char *v) +{ + if (v[0] == 0) + js_error(); + js_throw(); +} +static void checkfutureword(const char *exp) +{ + if (!__builtin_strcmp(exp, "const")) + jsC_error("boom"); +} +static void js_error(void) { + checkfutureword("foo"); + checkfutureword("bar"); + js_pop(); +} +int main(void) +{ + checkfutureword("const"); + __builtin_abort (); +}