From patchwork Wed Jan 16 22:43:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1026246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-494187-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RJyyBtux"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43g2L91xKTz9sBn for ; Thu, 17 Jan 2019 09:43:29 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=IFW/j3m6g28jUI8VsKXcSpCV/m9L2 jD1Kzt/3280op6Tio1USZ80WQRY4wPSqSrzW+vLRSljzSk6Kln/pxGqSnIab4AZs glBvyJF4/w0P3iXfxS2j4bR/D5BuQD8HBUIlzYWu/z9v7xU1m6zdPwPA+CK8+nEG fczfi/zZTBMrGQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=7DyHMkfRLoIW35KAC7IpkHkMpq8=; b=RJy yBtux611oDGLFZlyZLB/iOVqwOyE8dL2DPO6nmsnClLXg2zwUBtB6a8PlWJe9+sy kdyRaumEjfn6p6oP1zx5Feto0j1JciZAH3vrJRz+L0XJFRUviiuYFHBwB9TXqqG8 1oz0oL50pqZLLW2sUzGkoMK0ddjrl4I5oRzwABP4= 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@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 23:43:11 +0100 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-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes 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. Jakub --- 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; + } + } +}