From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8979 invoked by alias); 16 Jan 2019 22:43:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 8965 invoked by uid 89); 16 Jan 2019 22:43:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Never, HTo:U*ebotcazou, altered, alter X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Jan 2019 22:43:18 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 888272C7CD; Wed, 16 Jan 2019 22:43:17 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-69.ams2.redhat.com [10.36.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F25A608E7; Wed, 16 Jan 2019 22:43:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x0GMhEau031001; Wed, 16 Jan 2019 23:43:14 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x0GMhBBm031000; Wed, 16 Jan 2019 23:43:11 +0100 Date: Wed, 16 Jan 2019 22:43:00 -0000 From: Jakub Jelinek To: Richard Biener , Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't DCE const/pure calls that can throw if cfg can't be altered (PR rtl-optimization/88870) Message-ID: <20190116224311.GA30353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00956.txt.bz2 Hi! For normal instructions, deletable_insn_p has: /* Don't delete insns that may throw if we cannot do so. */ if (!(cfun->can_delete_dead_exceptions && can_alter_cfg) && !insn_nothrow_p (insn)) return false; The following patch adds that for the const/pure non-looping calls that are handled earlier in the function as well (I haven't moved this test earlier so we don't check insn_nothrow_p on jump insns etc.). The other change is just to handle those calls the same as non-const/pure, if we never consider them to be deletable, there is no point in find_call_stack_args for them, like we don't do that for normal calls. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-01-16 Jakub Jelinek PR rtl-optimization/88870 * dce.c (deletable_insn_p): Never delete const/pure calls that can throw if we can't alter the cfg or delete dead exceptions. (mark_insn): Don't call find_call_stack_args for such calls. * gcc.dg/pr88870.c: New test. --- gcc/dce.c.jj 2019-01-01 12:37:21.308906844 +0100 +++ gcc/dce.c 2019-01-16 11:39:13.432604633 +0100 @@ -108,7 +108,10 @@ deletable_insn_p (rtx_insn *insn, bool f /* We can delete dead const or pure calls as long as they do not infinite loop. */ && (RTL_CONST_OR_PURE_CALL_P (insn) - && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))) + && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)) + /* Don't delete calls that may throw if we cannot do so. */ + && ((cfun->can_delete_dead_exceptions && can_alter_cfg) + || insn_nothrow_p (insn))) return find_call_stack_args (as_a (insn), false, fast, arg_stores); @@ -201,7 +204,9 @@ mark_insn (rtx_insn *insn, bool fast) && !df_in_progress && !SIBLING_CALL_P (insn) && (RTL_CONST_OR_PURE_CALL_P (insn) - && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))) + && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn)) + && ((cfun->can_delete_dead_exceptions && can_alter_cfg) + || insn_nothrow_p (insn))) find_call_stack_args (as_a (insn), true, fast, NULL); } } --- gcc/testsuite/gcc.dg/pr88870.c.jj 2019-01-16 11:25:01.434552788 +0100 +++ gcc/testsuite/gcc.dg/pr88870.c 2019-01-16 11:24:48.172769383 +0100 @@ -0,0 +1,23 @@ +/* PR rtl-optimization/88870 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fexceptions -fnon-call-exceptions -ftrapv -fno-tree-dominator-opts" } */ + +int a, b; + +void +foo (int *x) +{ + int c = 0; + { + int d; + x = &c; + for (;;) + { + x = &d; + b = 0; + d = c + 1; + b = c = 1; + ++a; + } + } +} Jakub