From patchwork Mon Dec 6 18:38:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 74440 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 16083B70EB for ; Tue, 7 Dec 2010 05:38:18 +1100 (EST) Received: (qmail 1410 invoked by alias); 6 Dec 2010 18:38:16 -0000 Received: (qmail 1400 invoked by uid 22791); 6 Dec 2010 18:38:16 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CF, 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, 06 Dec 2010 18:38:12 +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 oB6IcAEb015449 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 Dec 2010 13:38:10 -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 oB6Ic9ii009495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 6 Dec 2010 13:38:10 -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 oB6Ic9dU017031 for ; Mon, 6 Dec 2010 19:38:09 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oB6Ic9Yc017030 for gcc-patches@gcc.gnu.org; Mon, 6 Dec 2010 19:38:09 +0100 Date: Mon, 6 Dec 2010 19:38:09 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't duplicate BARRIER after tablejump in cfglayout bb header or footer (PR rtl-optimization/46777) Message-ID: <20101206183809.GV29412@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! The following testcase ICEs, because a BB has a tablejump followed by BARRIER in its il.rtl->header, and during unrolling duplicate_insn_chain doesn't (intentionally) duplicate the tablejump, but does duplicate the BARRIER into a header of many bbs, which breaks out of cfglayout pass. Fixed by not duplicating the corresponding BARRIER either. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-12-06 Jakub Jelinek PR rtl-optimization/46777 * cfglayout.c (duplicate_insn_chain): Avoid duplicating also barrier after tablejump. * gcc.dg/pr46777.c: New test. Jakub --- gcc/cfglayout.c.jj 2010-11-19 20:56:55.000000000 +0100 +++ gcc/cfglayout.c 2010-12-06 14:51:01.000000000 +0100 @@ -1177,7 +1177,20 @@ duplicate_insn_chain (rtx from, rtx to) moved far from original jump. */ if (GET_CODE (PATTERN (insn)) == ADDR_VEC || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC) - break; + { + /* Avoid copying following barrier as well if any + (and debug insns in between). */ + rtx next; + + for (next = NEXT_INSN (insn); + next != NEXT_INSN (to); + next = NEXT_INSN (next)) + if (!DEBUG_INSN_P (next)) + break; + if (next != NEXT_INSN (to) && BARRIER_P (next)) + insn = next; + break; + } copy = emit_copy_of_insn_after (insn, get_last_insn ()); maybe_copy_prologue_epilogue_insn (insn, copy); break; --- gcc/testsuite/gcc.dg/pr46777.c.jj 2010-12-06 15:12:33.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr46777.c 2010-12-06 15:10:21.000000000 +0100 @@ -0,0 +1,49 @@ +/* PR rtl-optimization/46777 */ +/* { dg-do compile } */ +/* { dg-options "-fgcse -O -fno-tree-dominator-opts -funroll-loops" } */ + +struct S { char s[256]; }; + +static inline int +foo (int x, int y) +{ + switch (x) + { + case 1: + case 2: + return 3; + case 3: + case 4: + return 2; + case 5: + switch (y) + { + case 4: + return 1; + } + } + return 0; +} + +void +bar (struct S *x, int *y, int *z, int **w) +{ + switch (*y ? x->s[*y] : foo (y[1], y[0])) + { + case 3: + if (y + 2 == z) + for (;;) + { + y += 2; + switch (*y ? x->s[*y] : foo (y[1], y[0])) + { + case 6: + break; + default: + *w = y; + } + if (y == z) + break; + } + } +}