From patchwork Thu Oct 14 19:30:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 67855 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 264CAB70EE for ; Fri, 15 Oct 2010 06:30:45 +1100 (EST) Received: (qmail 31109 invoked by alias); 14 Oct 2010 19:30:42 -0000 Received: (qmail 31095 invoked by uid 22791); 14 Oct 2010 19:30:39 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_EV, TW_FC, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Oct 2010 19:30:32 +0000 Received: (qmail 29563 invoked from network); 14 Oct 2010 19:30:31 -0000 Received: from unknown (HELO ?59.104.57.187?) (cltang@127.0.0.2) by mail.codesourcery.com with ESMTPA; 14 Oct 2010 19:30:31 -0000 Message-ID: <4CB75A6F.5030002@codesourcery.com> Date: Fri, 15 Oct 2010 03:30:55 +0800 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: Eric Botcazou CC: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix ifcvt ICE References: <4CB34E16.3020804@codesourcery.com> <201010130951.20037.ebotcazou@adacore.com> In-Reply-To: <201010130951.20037.ebotcazou@adacore.com> 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 Eric Botcazou wrote: >> So this patch is quite simple: implement two replacement functions >> find_active_insn_before/after() that correct the above mentioned >> behavior, and use them in ifcvt. > > OK on principle, but the implementation isn't fully correct because it uses > BLOCK_FOR_INSN and this isn't defined for BARRIERs. > > Please add a BB parameter to both functions and test against BB_HEAD or BB_END > to stop the iteration, like in first_active_insn/last_active_insn. > Here's the updated patch, tests were ran again to verify same results. Ok for trunk now? Thanks, Chung-Lin Index: ifcvt.c =================================================================== --- ifcvt.c (revision 165474) +++ ifcvt.c (working copy) @@ -88,6 +88,8 @@ static bool cheap_bb_rtx_cost_p (const_basic_block, int); static rtx first_active_insn (basic_block); static rtx last_active_insn (basic_block, int); +static rtx find_active_insn_before (basic_block, rtx); +static rtx find_active_insn_after (basic_block, rtx); static basic_block block_fallthru (basic_block); static int cond_exec_process_insns (ce_if_block_t *, rtx, rtx, rtx, rtx, int); static rtx cond_exec_get_condition (rtx); @@ -229,6 +231,44 @@ return insn; } +static rtx +find_active_insn_before (basic_block curr_bb, rtx insn) +{ + if (!insn || insn == BB_HEAD (curr_bb)) + return NULL_RTX; + + while ((insn = PREV_INSN (insn)) != NULL_RTX) + { + if (NONJUMP_INSN_P (insn) || JUMP_P (insn) || CALL_P (insn)) + break; + + /* No other active insn all the way to the start of the basic block. */ + if (insn == BB_HEAD (curr_bb)) + return NULL_RTX; + } + + return insn; +} + +static rtx +find_active_insn_after (basic_block curr_bb, rtx insn) +{ + if (!insn || insn == BB_END (curr_bb)) + return NULL_RTX; + + while ((insn = NEXT_INSN (insn)) != NULL_RTX) + { + if (NONJUMP_INSN_P (insn) || JUMP_P (insn) || CALL_P (insn)) + break; + + /* No other active insn all the way to the end of the basic block. */ + if (insn == BB_END (curr_bb)) + return NULL_RTX; + } + + return insn; +} + /* Return the basic block reached by falling though the basic block BB. */ static basic_block @@ -447,9 +487,9 @@ if (n_matching > 0) { if (then_end) - then_end = prev_active_insn (then_first_tail); + then_end = find_active_insn_before (then_bb, then_first_tail); if (else_end) - else_end = prev_active_insn (else_first_tail); + else_end = find_active_insn_before (else_bb, else_first_tail); n_insns -= 2 * n_matching; } @@ -487,9 +527,9 @@ if (n_matching > 0) { if (then_start) - then_start = next_active_insn (then_last_head); + then_start = find_active_insn_after (then_bb, then_last_head); if (else_start) - else_start = next_active_insn (else_last_head); + else_start = find_active_insn_after (else_bb, else_last_head); n_insns -= 2 * n_matching; } } @@ -645,7 +685,7 @@ { rtx from = then_first_tail; if (!INSN_P (from)) - from = next_active_insn (from); + from = find_active_insn_after (then_bb, from); delete_insn_chain (from, BB_END (then_bb), false); } if (else_last_head) Index: testsuite/gcc.dg/20101010-1.c =================================================================== --- testsuite/gcc.dg/20101010-1.c (revision 0) +++ testsuite/gcc.dg/20101010-1.c (revision 0) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-crossjumping" } */ + +int foo (void) +{ + int len; + if (bar1 (&len)) + { + char devpath [len]; + if (bar2 (devpath) == len) + return len; + } + return -1; +}