From patchwork Mon Nov 22 22:00:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 72601 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]) by ozlabs.org (Postfix) with SMTP id D04A2B70F4 for ; Tue, 23 Nov 2010 09:00:43 +1100 (EST) Received: (qmail 21321 invoked by alias); 22 Nov 2010 22:00:40 -0000 Received: (qmail 21309 invoked by uid 22791); 22 Nov 2010 22:00:38 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 22 Nov 2010 22:00:31 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAMM0TeB005321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 22 Nov 2010 17:00:29 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAMM0S4i015413 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 22 Nov 2010 17:00:28 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oAMM0Sfe030021 for ; Mon, 22 Nov 2010 23:00:28 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oAMM0R9H030019 for gcc-patches@gcc.gnu.org; Mon, 22 Nov 2010 23:00:27 +0100 Date: Mon, 22 Nov 2010 23:00:27 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up maybe_cleanup_end_of_block (PR middle-end/46499) Message-ID: <20101122220027.GR29412@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! On the attached testcases jumpif* emits: (jump_insn 8 7 9 (set (pc) (label_ref 0)) pr46499-1.c:26 -1 (nil)) (barrier 9 8 10) (jump_insn 10 9 11 (set (pc) (label_ref 0)) pr46499-1.c:26 -1 (nil)) (barrier 11 10 0) where the label_ref in both cases is the non-fallthru label. This is because ssa_name & ssa_name is the condition and both ssa_name's are found using TER to be 0 (and the -fno-* options ensure it is not optimized earlier). maybe_cleanup_end_of_block is called to find out when the sequence ends with an unconditional jump to the non-fallthru label, with no fallthru code_label afterwards, which means all the sequence does (assuming no side-effects in it but GIMPLE should ensure that) is that unconditional jump and attempts to remove any other jumps from the sequence. Apparently it was expecting just conditional jumps to the non-fallthru label, for unconditional ones as in this example the following barrier needs to be removed too, otherwise we end up with a barrier in a middle of a bb and we either ICE on it, or miscompile it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-11-22 Jakub Jelinek PR middle-end/46499 * cfgexpand.c (maybe_cleanup_end_of_block): Remove also BARRIERs following unconditional jumps. * gcc.dg/pr46499-1.c: New test. * gcc.dg/pr46499-2.c: New test. Jakub --- gcc/cfgexpand.c.jj 2010-11-10 13:14:53.000000000 +0100 +++ gcc/cfgexpand.c 2010-11-22 14:45:49.000000000 +0100 @@ -1694,7 +1694,14 @@ maybe_cleanup_end_of_block (edge e, rtx { insn = PREV_INSN (insn); if (JUMP_P (NEXT_INSN (insn))) - delete_insn (NEXT_INSN (insn)); + { + if (!any_condjump_p (insn)) + { + gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn)))); + delete_insn (NEXT_INSN (NEXT_INSN (insn))); + } + delete_insn (NEXT_INSN (insn)); + } } } } --- gcc/testsuite/gcc.dg/pr46499-1.c.jj 2010-11-22 14:59:48.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr46499-1.c 2010-11-22 14:59:11.000000000 +0100 @@ -0,0 +1,31 @@ +/* PR middle-end/46499 */ +/* { dg-do run } */ +/* { dg-options "-O -fno-omit-frame-pointer -fno-tree-ccp -fno-tree-dominator-opts -finline-small-functions" } */ + +extern void abort (void); + +int count = 0; + +int +foo (void) +{ + count++; + return 0; +} + +int +bar (void) +{ + count++; + return 0; +} + +int +main () +{ + if ((foo () == 1) & (bar () == 1)) + abort (); + if (count != 2) + abort (); + return 0; +} --- gcc/testsuite/gcc.dg/pr46499-2.c.jj 2010-11-22 14:59:53.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr46499-2.c 2010-11-22 14:55:37.000000000 +0100 @@ -0,0 +1,19 @@ +/* PR middle-end/46499 */ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ccp -fno-tree-dominator-opts" } */ + +extern void abort (void); + +static inline int +foo (void) +{ + return 0; +} + +int +main () +{ + if ((foo () == 1) & (foo () == 1)) + abort (); + return 0; +}