From patchwork Mon Nov 12 19:48:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 198447 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 B77732C007D for ; Tue, 13 Nov 2012 06:49:11 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1353354552; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=YkqHnWY0m7plHJcler1o zhGC7hc=; b=bauefSC4MooZaKXqnD3bwf8aSqDREzwuJuudbBOzBgPXZBoTLTS6 J/LvIdpTFv3Al2TVYNim528As0Hn88g7rSw3VOxp0syvW7PXDvZxgT7VRTSg4Vnz ppIuPGNq11bV1wH5Cdob6rNhK020GKXcuWAwywo6J56vvuGHIlOEFwc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=dsK4K9DQ7Z0H5L5JnUv041QkquKDfn1GFsfIfKdrrnnajuT0B3N+cNbYb2Rymw lo7V1G8QwJXWmWIpo+R/GJXakgIhPedIhvV8awgeBXxKhlqNxPkR9/Xra/B9r3g2 /oMenYQTsSDbqmPF9udOqfi6Rxrq1k4/PVLSXCcxaEX7E=; Received: (qmail 9152 invoked by alias); 12 Nov 2012 19:48:55 -0000 Received: (qmail 9132 invoked by uid 22791); 12 Nov 2012 19:48:54 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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, 12 Nov 2012 19:48:48 +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.14.4/8.14.4) with ESMTP id qACJmmIM032679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 12 Nov 2012 14:48:48 -0500 Received: from zalov.redhat.com (vpn1-4-50.ams2.redhat.com [10.36.4.50]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qACJmk1h010837 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 12 Nov 2012 14:48:48 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qACJmk5g013081 for ; Mon, 12 Nov 2012 20:48:46 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qACJmkfe013080 for gcc-patches@gcc.gnu.org; Mon, 12 Nov 2012 20:48:46 +0100 Date: Mon, 12 Nov 2012 20:48:45 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix force_nonfallthru_and_redirect with asm goto (PR rtl-optimization/54127) Message-ID: <20121112194845.GT1886@tucnak.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! The following testcase was ICEing on powerpc64-linux. While force_nonfallthru_and_redirect properly adjusted the LABEL_REFs in asm goto from the old fallthru block to a new one, it didn't adjust LABEL_NUSES and didn't adjust JUMP_LABEL resp. REG_LABEL_TARGET. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk (and 4.7 after say a week)? 2012-11-12 Jakub Jelinek PR rtl-optimization/54127 * cfgrtl.c (force_nonfallthru_and_redirect): When redirecting asm goto labels from BB_HEAD (e->dest) to target bb, decrement LABEL_NUSES of BB_HEAD (e->dest) and increment LABEL_NUSES of BB_HEAD (target) appropriately and adjust JUMP_LABEL and/or REG_LABEL_TARGET and REG_LABEL_OPERAND. * gcc.dg/torture/pr54127.c: New test. Jakub --- gcc/cfgrtl.c.jj 2012-11-05 08:55:21.000000000 +0100 +++ gcc/cfgrtl.c 2012-11-12 11:06:32.254919581 +0100 @@ -1424,14 +1424,46 @@ force_nonfallthru_and_redirect (edge e, && (note = extract_asm_operands (PATTERN (BB_END (e->src))))) { int i, n = ASM_OPERANDS_LABEL_LENGTH (note); + bool adjust_jump_target = false; for (i = 0; i < n; ++i) { if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (e->dest)) - XEXP (ASM_OPERANDS_LABEL (note, i), 0) = block_label (target); + { + LABEL_NUSES (XEXP (ASM_OPERANDS_LABEL (note, i), 0))--; + XEXP (ASM_OPERANDS_LABEL (note, i), 0) = block_label (target); + LABEL_NUSES (XEXP (ASM_OPERANDS_LABEL (note, i), 0))++; + adjust_jump_target = true; + } if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (target)) asm_goto_edge = true; } + if (adjust_jump_target) + { + rtx insn = BB_END (e->src), note; + rtx old_label = BB_HEAD (e->dest); + rtx new_label = BB_HEAD (target); + + if (JUMP_LABEL (insn) == old_label) + { + JUMP_LABEL (insn) = new_label; + note = find_reg_note (insn, REG_LABEL_TARGET, new_label); + if (note) + remove_note (insn, note); + } + else + { + note = find_reg_note (insn, REG_LABEL_TARGET, old_label); + if (note) + remove_note (insn, note); + if (JUMP_LABEL (insn) != new_label + && !find_reg_note (insn, REG_LABEL_TARGET, new_label)) + add_reg_note (insn, REG_LABEL_TARGET, new_label); + } + while ((note = find_reg_note (insn, REG_LABEL_OPERAND, old_label)) + != NULL_RTX) + XEXP (note, 0) = new_label; + } } if (EDGE_COUNT (e->src->succs) >= 2 || abnormal_edge_flags || asm_goto_edge) --- gcc/testsuite/gcc.dg/torture/pr54127.c.jj 2012-11-12 11:13:45.422433593 +0100 +++ gcc/testsuite/gcc.dg/torture/pr54127.c 2012-11-12 11:09:07.000000000 +0100 @@ -0,0 +1,16 @@ +/* PR rtl-optimization/54127 */ +/* { dg-do compile } */ + +extern void foo (void) __attribute__ ((__noreturn__)); + +void +bar (int x) +{ + if (x < 0) + foo (); + if (x == 0) + return; + __asm goto ("# %l[lab] %l[lab2]" : : : : lab, lab2); +lab:; +lab2:; +}