From patchwork Tue May 10 07:55:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 620508 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 3r3s5V2QCfz9t3p for ; Tue, 10 May 2016 17:56:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=f28XD7hB; 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:from :to:cc:subject:date:message-id; q=dns; s=default; b=MIIjEaOG35v3 sRo6vVKJtLQlZyQqPGeIwcfK+zAsXwtFc7/ZYJNqHExrQvOcKKupXfw5uLHDL2ig upNLFqHltUr2uwTnMHMUPZuSrwY9owEp5WFbNqqNMDyS6OWIPMDd9ww20hl+9eIa Zc+zFA/i3Ny/hzUFfKmaroQxdMIV8Gg= 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:from :to:cc:subject:date:message-id; s=default; bh=TKm/nWpxHQTGrjwR8D F5zrpwLBM=; b=f28XD7hBwm+c564MvZTR4On/chPi8TyJy3C0qzOaC5Pze/785T iPilc6OxnsF4U2PzVA6JdMnUt+wdYvkDwNQya98HHGeGiv95LhsDzDDCnGKhRvUM aQhSAEzr05g0g8DrotRip0cXXs9lJ14C6oE3fTybRCvVR80LTM6V7yvq0= Received: (qmail 58572 invoked by alias); 10 May 2016 07:56:04 -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 58522 invoked by uid 89); 10 May 2016 07:56:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=arms, Hx-languages-length:1793, 2016-05-10 X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 May 2016 07:55:53 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 1FCEC1C0441; Tue, 10 May 2016 07:55:49 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: bschmidt@redhat.com, Segher Boessenkool Subject: [PATCH] cfgcleanup: Handle a branch with just a return in both arms (PR71028) Date: Tue, 10 May 2016 07:55:44 +0000 Message-Id: <0aaffa29eefa48e435814390bdeea56107ab2404.1462866472.git.segher@kernel.crashing.org> X-IsSubscribed: yes If we have a conditional jump that has only a return in both the branch path and the fallthrough path, and the return on the branch path can not be made a conditional return, we will try to make a conditional return from the fallthrough path, and that does not work because we then try to redirect the (new) jump in the fallthrough block to the original dest in the branch path, which is the exit block. For the testcase on ARM we end up in this situation because before the jump2 pass there are some other insns in the return blocks as well, but the same insns in both, so those are moved above the conditional jump. Only later (in the ce3 pass) are the conditional jump and two returns melded into one return, so we need to handle this strange case here. Bootstrapped and regression checked on powerpc64-linux; the testcase (already in the testsuite) also tried on an arm-linux-gnueabi cross-compiler. Is this okay for trunk? Segher 2016-05-10 Segher Boessenkool PR rtl-optimization/71028 * cfgcleanup.c (try_optimize_cfg): Do not flip a conditional jump with just a return in the fallthrough block if the branch block contains just a returns as well. --- gcc/cfgcleanup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c index 2463f7c..b3a3989 100644 --- a/gcc/cfgcleanup.c +++ b/gcc/cfgcleanup.c @@ -2875,6 +2875,7 @@ try_optimize_cfg (int mode) a return so that it becomes a conditional return and a new jump to the original branch target. */ if (EDGE_COUNT (b->succs) == 2 + && BRANCH_EDGE (b)->dest != EXIT_BLOCK_PTR_FOR_FN (cfun) && any_condjump_p (BB_END (b)) && bb_is_just_return (FALLTHRU_EDGE (b)->dest, &ret, &use)) {