From patchwork Mon May 23 15:44:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 625292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3rD2sk5WkBz9t4c for ; Tue, 24 May 2016 01:44:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dQUlrKpy; dkim-atps=neutral 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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=IHLcRSyhy2mllNLIb SDGx79g0UQIR/XzsqFkmwa+K/Of6sbpQAlZc3bwDNpKZiHz1WSeNC5s6tkKjs5vW bn+mVzYrS8YTDQy8p+7QGGgeAxJe28VZaIXf4Iuy9Gd3m8idu15z7p5M4CMf4NdC je5PiueVfqOGu2A4BtVJOoc9f8= 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:references:mime-version :content-type:in-reply-to; s=default; bh=ISLreklH2rndfvH9XitTGib AEGE=; b=dQUlrKpy9RoeGIA9x9yvtf2MwQvPkKtOAYvbUXMeYjm/BTKVaTASs/g gfS7U05ZfoHc1QVwYaHf0QtIRxKuvWMApdEn7RUvW39yhPyiNuE60Z4IzUat2JEb 6vOpTBe64l1e2TMcEeCjgJOlOkRpOmfAVcUaxXxPX2trTrTEeWD8= Received: (qmail 120910 invoked by alias); 23 May 2016 15:44:34 -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 120888 invoked by uid 89); 23 May 2016 15:44:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 23 May 2016 15:44:21 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CEAB15556; Mon, 23 May 2016 15:44:20 +0000 (UTC) Received: from redhat.com (ovpn-204-17.brq.redhat.com [10.40.204.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4NFiHmP006629 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 23 May 2016 11:44:19 -0400 Date: Mon, 23 May 2016 17:44:16 +0200 From: Marek Polacek To: Jakub Jelinek Cc: GCC Patches , Richard Biener Subject: Re: [PATCH] Introduce can_remove_lhs_p Message-ID: <20160523154416.GT1611@redhat.com> References: <20160523142833.GS1611@redhat.com> <20160523143630.GT28550@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160523143630.GT28550@tucnak.redhat.com> User-Agent: Mutt/1.6.1 (2016-04-27) On Mon, May 23, 2016 at 04:36:30PM +0200, Jakub Jelinek wrote: > On Mon, May 23, 2016 at 04:28:33PM +0200, Marek Polacek wrote: > > As promised in , > > this is a simple clean-up which makes use of a new predicate. Richi suggested > > adding maybe_drop_lhs_from_noreturn_call which would be nicer, but I didn't > > know how to do that, given the handling if lhs is an SSA_NAME. > > Shouldn't it be should_remove_lhs_p instead? > I mean, it is not just an optimization, but part of how we define the IL. Aha, ok. Renamed. > Shouldn't it be also used in tree-cfg.c (verify_gimple_call)? I left that spot on purpose but now I don't quite see why, fixed. Thanks, Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-05-23 Marek Polacek * tree.h (should_remove_lhs_p): New predicate. * cgraph.c (cgraph_edge::redirect_call_stmt_to_callee): Use it. * gimple-fold.c (gimple_fold_call): Likewise. * gimplify.c (gimplify_modify_expr): Likewise. * tree-cfg.c (verify_gimple_call): Likewise. * tree-cfgcleanup.c (fixup_noreturn_call): Likewise. Marek diff --git gcc/cgraph.c gcc/cgraph.c index cf9192f..1a4f665 100644 --- gcc/cgraph.c +++ gcc/cgraph.c @@ -1513,10 +1513,7 @@ cgraph_edge::redirect_call_stmt_to_callee (void) } /* If the call becomes noreturn, remove the LHS if possible. */ - if (lhs - && (gimple_call_flags (new_stmt) & ECF_NORETURN) - && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST - && !TREE_ADDRESSABLE (TREE_TYPE (lhs))) + if (gimple_call_noreturn_p (new_stmt) && should_remove_lhs_p (lhs)) { if (TREE_CODE (lhs) == SSA_NAME) { diff --git gcc/gimple-fold.c gcc/gimple-fold.c index 858f484..6b50d43 100644 --- gcc/gimple-fold.c +++ gcc/gimple-fold.c @@ -3052,12 +3052,9 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace) == void_type_node)) gimple_call_set_fntype (stmt, TREE_TYPE (fndecl)); /* If the call becomes noreturn, remove the lhs. */ - if (lhs - && (gimple_call_flags (stmt) & ECF_NORETURN) + if (gimple_call_noreturn_p (stmt) && (VOID_TYPE_P (TREE_TYPE (gimple_call_fntype (stmt))) - || ((TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) - == INTEGER_CST) - && !TREE_ADDRESSABLE (TREE_TYPE (lhs))))) + || should_remove_lhs_p (lhs))) { if (TREE_CODE (lhs) == SSA_NAME) { diff --git gcc/gimplify.c gcc/gimplify.c index 4a544e3..c77eb51 100644 --- gcc/gimplify.c +++ gcc/gimplify.c @@ -4847,9 +4847,7 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } } notice_special_calls (call_stmt); - if (!gimple_call_noreturn_p (call_stmt) - || TREE_ADDRESSABLE (TREE_TYPE (*to_p)) - || TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (*to_p))) != INTEGER_CST) + if (!gimple_call_noreturn_p (call_stmt) || !should_remove_lhs_p (*to_p)) gimple_call_set_lhs (call_stmt, *to_p); else if (TREE_CODE (*to_p) == SSA_NAME) /* The above is somewhat premature, avoid ICEing later for a diff --git gcc/tree-cfg.c gcc/tree-cfg.c index 7c2ee78..82f0da6c 100644 --- gcc/tree-cfg.c +++ gcc/tree-cfg.c @@ -3385,11 +3385,9 @@ verify_gimple_call (gcall *stmt) return true; } - if (lhs - && gimple_call_ctrl_altering_p (stmt) + if (gimple_call_ctrl_altering_p (stmt) && gimple_call_noreturn_p (stmt) - && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST - && !TREE_ADDRESSABLE (TREE_TYPE (lhs))) + && should_remove_lhs_p (lhs)) { error ("LHS in noreturn call"); return true; diff --git gcc/tree-cfgcleanup.c gcc/tree-cfgcleanup.c index 46d0fa3..4134c38 100644 --- gcc/tree-cfgcleanup.c +++ gcc/tree-cfgcleanup.c @@ -604,8 +604,7 @@ fixup_noreturn_call (gimple *stmt) temporaries of variable-sized types is not supported. Also don't do this with TREE_ADDRESSABLE types, as assign_temp will abort. */ tree lhs = gimple_call_lhs (stmt); - if (lhs && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST - && !TREE_ADDRESSABLE (TREE_TYPE (lhs))) + if (should_remove_lhs_p (lhs)) { gimple_call_set_lhs (stmt, NULL_TREE); diff --git gcc/tree.h gcc/tree.h index 2510d16..1d72437 100644 --- gcc/tree.h +++ gcc/tree.h @@ -5471,4 +5471,14 @@ desired_pro_or_demotion_p (const_tree to_type, const_tree from_type) return to_type_precision <= TYPE_PRECISION (from_type); } +/* Return true if the LHS of a call should be removed. */ + +inline bool +should_remove_lhs_p (tree lhs) +{ + return (lhs + && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST + && !TREE_ADDRESSABLE (TREE_TYPE (lhs))); +} + #endif /* GCC_TREE_H */