From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27983 invoked by alias); 3 Nov 2008 14:32:21 -0000 Received: (qmail 27847 invoked by uid 22791); 3 Nov 2008 14:32:20 -0000 X-Spam-Check-By: sourceware.org Received: from mailout07.t-online.de (HELO mailout07.t-online.de) (194.25.134.83) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 03 Nov 2008 14:31:38 +0000 Received: from fwd10.aul.t-online.de by mailout07.sul.t-online.de with smtp id 1Kx0Sr-0007x2-02; Mon, 03 Nov 2008 15:31:33 +0100 Received: from [84.152.215.159] (EG5fKaZAZhBF2WbWV49Gmd-Lrhix-QAK5B9gpDR4t-2hCbzRnNoBYnVjOKue-tggJ-@[84.152.215.159]) by fwd10.aul.t-online.de with esmtp id 1Kx0SX-0QK1GS0; Mon, 3 Nov 2008 15:31:13 +0100 Message-ID: <490F0A69.4020205@t-online.de> Date: Mon, 03 Nov 2008 14:32:00 -0000 From: Bernd Schmidt User-Agent: Thunderbird 2.0.0.17 (X11/20080929) MIME-Version: 1.0 To: GCC Patches Subject: Blackfin: Doloop optimization fix Content-Type: multipart/mixed; boundary="------------060009090409050802080304" X-ID: EG5fKaZAZhBF2WbWV49Gmd-Lrhix-QAK5B9gpDR4t-2hCbzRnNoBYnVjOKue-tggJ- X-TOI-MSGID: 3b0881d0-df3e-4d61-9514-4ebff07f0a37 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-11/txt/msg00065.txt.bz2 This is a multi-part message in MIME format. --------------060009090409050802080304 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-length: 799 This is a problem introduced by some earlier changes I made to generate more hardware loops on the Blackfin. In one case, with the following structure: ... jump point_inside_loop; head: do_stuff; point_inside_loop: do_some_more_stuff; if condition jump head; we would lose the initial jump into the loop; it was replaced by the LSETUP instruction. This patch fixes it. If do_some_more_stuff is simple enough, we emit it after the LSETUP, otherwise we use a jump to the point inside the loop. Committed as 141548. Bernd -- This footer brought to you by insane German lawmakers. Analog Devices GmbH Wilhelm-Wagenfeld-Str. 6 80807 Muenchen Sitz der Gesellschaft Muenchen, Registergericht Muenchen HRB 40368 Geschaeftsfuehrer Thomas Wessel, William A. Martin, Margaret Seif --------------060009090409050802080304 Content-Type: text/plain; name="loopfix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="loopfix.diff" Content-length: 2751 Index: ChangeLog =================================================================== --- ChangeLog (revision 141547) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2008-11-03 Bernd Schmidt + + * config/bfin/bfin.c (bfin_optimize_loop): Properly handle case + where we have one entry point in the loop which isn't the head. + 2008-11-03 Richard Guenther PR middle-end/37573 Index: config/bfin/bfin.c =================================================================== --- config/bfin/bfin.c (revision 141547) +++ config/bfin/bfin.c (working copy) @@ -4059,12 +4059,33 @@ bfin_optimize_loop (loop_info loop) print_rtl_single (dump_file, loop->loop_end); } + /* Create a sequence containing the loop setup. */ start_sequence (); if (loop->init != NULL_RTX) emit_insn (loop->init); seq_end = emit_insn (loop->loop_init); + /* If the loop isn't entered at the top, also create a jump to the entry + point. */ + if (!loop->incoming_src && loop->head != loop->incoming_dest) + { + rtx label = BB_HEAD (loop->incoming_dest); + /* If we're jumping to the final basic block in the loop, and there's + only one cheap instruction before the end (typically an increment of + an induction variable), we can just emit a copy here instead of a + jump. */ + if (loop->incoming_dest == loop->tail + && next_real_insn (label) == last_insn + && asm_noperands (last_insn) < 0 + && GET_CODE (PATTERN (last_insn)) == SET) + { + seq_end = emit_insn (copy_rtx (PATTERN (last_insn))); + } + else + seq_end = emit_insn (gen_jump (label)); + } + seq = get_insns (); end_sequence (); @@ -4084,21 +4105,19 @@ bfin_optimize_loop (loop_info loop) basic_block new_bb; edge e; edge_iterator ei; - + +#ifdef ENABLE_CHECKING if (loop->head != loop->incoming_dest) { + /* We aren't entering the loop at the top. Since we've established + that the loop is entered only at one point, this means there + can't be fallthru edges into the head. Any such fallthru edges + would become invalid when we insert the new block, so verify + that this does not in fact happen. */ FOR_EACH_EDGE (e, ei, loop->head->preds) - { - if (e->flags & EDGE_FALLTHRU) - { - rtx newjump = gen_jump (loop->start_label); - emit_insn_before (newjump, BB_HEAD (loop->head)); - new_bb = create_basic_block (newjump, newjump, loop->head->prev_bb); - gcc_assert (new_bb = loop->head->prev_bb); - break; - } - } + gcc_assert (!(e->flags & EDGE_FALLTHRU)); } +#endif emit_insn_before (seq, BB_HEAD (loop->head)); seq = emit_label_before (gen_label_rtx (), seq); --------------060009090409050802080304--