From patchwork Wed Aug 14 13:12:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Belevantsev X-Patchwork-Id: 267119 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 498052C00FA for ; Wed, 14 Aug 2013 23:12:38 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=BaFds/qEHyONISRlVIK2Am/r1w0cP+3qSf4X3uU3sDy8T1 c4IsIwyfBvlALy8wPw3LFvuiP+wIthpmuKGxVUPWiwkqeRKllra96hDbK8Q5B0Wk 9kOKZcxwXbi+XFnFG0/LcxADac7UbZ+N4TTPSot2/Pndji8uryph6+QO+UH3Y= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=oP8hvvnkm66ZiiKazCAUtudrE4Q=; b=XBesVhc6e+ugXilVmdTC 1saclwkgpfOzatJ8stdXu6E9mgBJxcmIMq+4vxKFhh78PB+ooo6telmw+0jMrOq6 31LzfEys7hnad2rJOd5o+8+RWDAOA0dRiU/Gvz8YyfbuyRrPsJ1q0UWbM4O4lCJD nEWOB+jDf4XRsJHq91145qg= Received: (qmail 24123 invoked by alias); 14 Aug 2013 13:12:31 -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 24109 invoked by uid 89); 14 Aug 2013 13:12:31 -0000 X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 Received: from mail.ispras.ru (HELO mail.ispras.ru) (83.149.199.45) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 14 Aug 2013 13:12:29 +0000 Received: from [10.10.3.52] (pluton2.ispras.ru [83.149.199.44]) by mail.ispras.ru (Postfix) with ESMTPSA id 71EE1540151; Wed, 14 Aug 2013 17:12:26 +0400 (MSK) Message-ID: <520B823A.7070406@ispras.ru> Date: Wed, 14 Aug 2013 17:12:26 +0400 From: Andrey Belevantsev User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Thunderbird/23.0 MIME-Version: 1.0 To: GCC Patches , Alexander Monakov Subject: [PATCH] Fix PR 57662 X-Virus-Found: No Hello, As noted in Bugzilla, the problem is this PR is the rare case of removing the unconditional jump that is used for traversing CFG when simplifying control flow. We rescan the remaining successors when we know the flow below the current point has changed, and when we have removed the jump we are currently on, we segfault. The fix is just to break out of successor iterator loop as in the unconditional jump case we have already visited the only successor. Bootstrapped and tested on x86-64, ok for trunk? If yes, Alexander, could you please commit this for me? Andrey 2013-08-14 Andrey Belevantsev PR rtl-optimization/57662 gcc/ * sel-sched.c (code_motion_process_successors): When the current insn is removed after the recursive traversal, break from the loop. Add comments and debug printouts. testsuite/ * gcc.dg/pr57662.c: New test. diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c index fb9386f..a7b8897 100644 --- a/gcc/sel-sched.c +++ b/gcc/sel-sched.c @@ -6424,10 +6424,23 @@ code_motion_process_successors (insn_t insn, av_set_t orig_ops, res = b; /* We have simplified the control flow below this point. In this case, - the iterator becomes invalid. We need to try again. */ + the iterator becomes invalid. We need to try again. + If we have removed the insn itself, it could be only an + unconditional jump. Thus, do not rescan but break immediately -- + we have already visited the only successor block. */ + if (!BLOCK_FOR_INSN (insn)) + { + if (sched_verbose >= 6) + sel_print ("Not doing rescan: already visited the only successor" + " of block %d\n", old_index); + break; + } if (BLOCK_FOR_INSN (insn)->index != old_index || EDGE_COUNT (bb->succs) != old_succs) { + if (sched_verbose >= 6) + sel_print ("Rescan: control flow simplified below insn %d, block %d\n", + INSN_UID (insn), BLOCK_FOR_INSN (insn)->index); insn = sel_bb_end (BLOCK_FOR_INSN (insn)); goto rescan; } diff --git a/gcc/testsuite/gcc.dg/pr57662.c b/gcc/testsuite/gcc.dg/pr57662.c new file mode 100644 index 0000000..7af8455 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr57662.c @@ -0,0 +1,47 @@ +/* { dg-do compile { target powerpc*-*-* ia64-*-* x86_64-*-* } } */ +/* { dg-options " -O -fno-guess-branch-probability -fpeel-loops -freorder-blocks-and-partition -fschedule-insns2 -fsel-sched-pipelining -fselective-scheduling2 -ftree-pre" } */ + +struct intC +{ + short x; + short y; +}; + +void Get(void); + +int size_x; + +struct +{ + int *depot_table; + struct intC *ti; + int size; +} dummy; + +static inline int +GetRotatedTileFromOffset (int *a, struct intC tidc) +{ + if (!*a) + Get (); + switch (*a) + { + case 0: + return (tidc.y << size_x) + tidc.x; + case 1: + return tidc.y + (dummy.size - tidc.x) * size_x; + case 2: + return tidc.x + (dummy.size - tidc.y) * size_x; + case 3: + return (dummy.size - tidc.x); + } + return 0; +} + +int +GetHangarNum (int *a, int i) +{ + while (dummy.size) + if (GetRotatedTileFromOffset (a, dummy.ti[i])) + return *dummy.depot_table; + return 0; +}