This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [cfg-branch]: Print reasons for unrolling/unswitching/peelingto dump file
- From: Daniel Berlin <dan at dberlin dot org>
- To: Daniel Berlin <dan at dberlin dot org>
- Cc: gcc-patches at gcc dot gnu dot org, jh at suse dot cz
- Date: 22 Mar 2002 21:20:05 -0500
- Subject: Re: [cfg-branch]: Print reasons for unrolling/unswitching/peelingto dump file
- Organization:
- References: <1016845908.31083.167.camel@localhost.localdomain>
Here's a slightly better version, same changelog (so i omitted it).
Made it print the number of peelings/unrollings, and caught a few places
i either shouldn't be printing, or printed the reverse of what it should
be.
Index: unroll-new.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/unroll-new.c,v
retrieving revision 1.1.2.1
diff -c -3 -p -r1.1.2.1 unroll-new.c
*** unroll-new.c 2002/03/18 20:44:14 1.1.2.1
--- unroll-new.c 2002/03/23 02:17:38
*************** Software Foundation, 59 Temple Place - S
*** 40,45 ****
--- 40,46 ----
#include "cfglayout.h"
#include "loop.h"
#include "params.h"
+ #include "output.h"
static basic_block simple_exit PARAMS ((struct loops *, struct loop *, basic_block *, int *));
static bool simple_condition_p PARAMS ((struct loop *, basic_block *, rtx, struct loop_desc *));
*************** simple_increment (loops, loop, body, des
*** 246,251 ****
--- 247,254 ----
/* mod_insn must be a simple increment/decrement. */
set = single_set (mod_insn);
+ if (!set)
+ return NULL;
if (!rtx_equal_p (SET_DEST (set), desc->var))
return NULL;
*************** unroll_loop_constant_iterations (loops,
*** 452,458 ****
/* Normalization. */
if (!count_loop_iterations (desc, &niter, NULL))
! return 0;
if (niter < 0)
{
--- 455,465 ----
/* Normalization. */
if (!count_loop_iterations (desc, &niter, NULL))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unrolling loop, can't count loop iterations\n");
! return 0;
! }
if (niter < 0)
{
*************** unroll_loop_constant_iterations (loops,
*** 477,482 ****
--- 484,491 ----
loop, e, loops, niter + 1, 0xfe - (1 << (niter + 1)),
DLTHE_FLAG_ALL))
abort ();
+ if (rtl_dump_file)
+ fprintf (rtl_dump_file, ";; Unrolled loop %d times\n",niter);
return 1;
}
*************** unroll_loop_constant_iterations (loops,
*** 488,493 ****
--- 497,505 ----
DLTHE_FLAG_ALL))
abort ();
+ if (rtl_dump_file)
+ fprintf (rtl_dump_file, ";; Unrolled loop %d times\n",max_unroll);
+
return 1;
}
*************** unroll_loop_runtime_iterations (loops, l
*** 514,519 ****
--- 526,533 ----
start_sequence ();
if (!count_loop_iterations (desc, NULL, &niter))
{
+ if (rtl_dump_file)
+ fprintf (rtl_dump_file, ";; Not unrolling loop, can't count loop iterations\n");
end_sequence ();
return 0;
}
*************** unroll_loop_runtime_iterations (loops, l
*** 613,618 ****
--- 627,635 ----
DLTHE_FLAG_ALL))
abort ();
+ if (rtl_dump_file)
+ fprintf (rtl_dump_file, ";; Unrolled loop %d times\n", max_unroll);
+
return 1;
}
*************** unroll_simple_loop (loops, loop, max_unr
*** 626,632 ****
struct loop_desc *desc;
{
if (!can_duplicate_loop_p (loop))
! return 0;
switch (desc->cond)
{
--- 643,653 ----
struct loop_desc *desc;
{
if (!can_duplicate_loop_p (loop))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unrolling loop, can't duplicate\n");
! return 0;
! }
switch (desc->cond)
{
*************** unroll_simple_loop (loops, loop, max_unr
*** 634,639 ****
--- 655,662 ----
case GTU:
case LEU:
case LTU:
+ if (rtl_dump_file)
+ fprintf (rtl_dump_file, ";; Not unrolling loop, GEU/GTU/LEU/LTU condition\n");
/* I'm not brave enough to cope with this. */
return 0;
default:
*************** peel_loop (loops, loop, will_unroll)
*** 666,681 ****
/* Do not peel cold areas. */
if (!maybe_hot_bb_p (loop->header))
! return 1;
/* Only peel innermost loops. */
if (loop->inner)
! return 1;
!
/* Do not peel loops that roll too much. */
niter = expected_loop_iterations (loop);
if (niter > 2 * PARAM_VALUE (MAX_PEEL_TIMES))
! return 1;
ninsns = num_loop_insns (loop);
--- 689,717 ----
/* Do not peel cold areas. */
if (!maybe_hot_bb_p (loop->header))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not peeling loop, header is cold area\n");
! return 1;
! }
/* Only peel innermost loops. */
if (loop->inner)
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not peeling loop, not innermost loop\n");
! return 1;
! }
!
/* Do not peel loops that roll too much. */
niter = expected_loop_iterations (loop);
if (niter > 2 * PARAM_VALUE (MAX_PEEL_TIMES))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not peeling loop, rolls too much (%d iterations > %d [2 * maximum peelings])\n", niter, 2 * PARAM_VALUE (MAX_PEEL_TIMES));
! return 1;
! }
!
ninsns = num_loop_insns (loop);
*************** peel_loop (loops, loop, will_unroll)
*** 690,702 ****
/* Do not peel simple loops if also unrolling will be done, not to
interfere with it. */
if (will_unroll && simple_loop_p (loops, loop, &desc))
! return 1;
!
for (e = loop->header->pred; e->src == loop->latch; e = e->pred_next);
if (!duplicate_loop_to_header_edge (loop, e, loops, npeel, 0,
DLTHE_FLAG_ALL))
! return 0;
}
return 1;
}
--- 726,748 ----
/* Do not peel simple loops if also unrolling will be done, not to
interfere with it. */
if (will_unroll && simple_loop_p (loops, loop, &desc))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not peeling loop, loop will be unrolled\n");
! return 1;
! }
!
for (e = loop->header->pred; e->src == loop->latch; e = e->pred_next);
if (!duplicate_loop_to_header_edge (loop, e, loops, npeel, 0,
DLTHE_FLAG_ALL))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Peeling unsuccessful\n");
! return 0;
! }
}
+ if (rtl_dump_file && npeel > 0)
+ fprintf (rtl_dump_file, ";; Peeling loop %d times\n", npeel);
return 1;
}
*************** unroll_loop_new (loops, loop, unroll_all
*** 712,718 ****
/* Do not unroll cold areas. */
if (!maybe_hot_bb_p (loop->header))
! return 1;
ninsns = num_loop_insns (loop);
--- 758,768 ----
/* Do not unroll cold areas. */
if (!maybe_hot_bb_p (loop->header))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unrolling loop, cold area\n");
! return 1;
! }
ninsns = num_loop_insns (loop);
*************** unroll_loop_new (loops, loop, unroll_all
*** 736,749 ****
/* Do not unroll loops that do not roll. */
niter = expected_loop_iterations (loop);
if (niter < 2 * PARAM_VALUE (MAX_UNROLL_TIMES))
! return 1;
/* Some hard case; try stupid unrolling anyway. */
for (e = loop->header->pred; e->src != loop->latch; e = e->pred_next);
if (!duplicate_loop_to_header_edge (loop, e, loops, nunroll, 0,
DLTHE_FLAG_ALL))
! return 0;
}
! }
return 1;
}
--- 786,810 ----
/* Do not unroll loops that do not roll. */
niter = expected_loop_iterations (loop);
if (niter < 2 * PARAM_VALUE (MAX_UNROLL_TIMES))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unrolling loop, doesn't roll\n");
! return 1;
! }
/* Some hard case; try stupid unrolling anyway. */
for (e = loop->header->pred; e->src != loop->latch; e = e->pred_next);
if (!duplicate_loop_to_header_edge (loop, e, loops, nunroll, 0,
DLTHE_FLAG_ALL))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unrolling loop, can't duplicate\n");
! return 0;
! }
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Unrolled loop %d times\n", nunroll);
!
}
! }
return 1;
}
Index: loop-new.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/loop-new.c,v
retrieving revision 1.1.2.8
diff -c -3 -p -r1.1.2.8 loop-new.c
*** loop-new.c 2002/03/18 20:44:12 1.1.2.8
--- loop-new.c 2002/03/23 02:17:38
*************** Software Foundation, 59 Temple Place - S
*** 41,47 ****
#include "cfglayout.h"
#include "loop.h"
#include "params.h"
!
/* Stupid definitions of dominator manipulation. */
basic_block
--- 41,47 ----
#include "cfglayout.h"
#include "loop.h"
#include "params.h"
! #include "output.h"
/* Stupid definitions of dominator manipulation. */
basic_block
*************** unswitch_single_loop (loops, loop, cond_
*** 459,485 ****
/* Do not unswitch too much. */
if (num > PARAM_VALUE (MAX_UNSWITCH_LEVEL))
! return;
/* We only unswitch innermost loops (at least for now). */
if (loop->inner)
! return;
/* And we must be able to duplicate loop body. */
if (!can_duplicate_loop_p (loop))
! return;
/* Check the size of loop. */
if (num_loop_insns (loop) > PARAM_VALUE (MAX_UNSWITCH_INSNS))
! return;
!
/* Do not unswitch in cold areas. */
if (!maybe_hot_bb_p (loop->header))
! return;
!
/* Nor if it usually do not pass. */
if (expected_loop_iterations (loop) < 1)
! return;
do
{
--- 459,509 ----
/* Do not unswitch too much. */
if (num > PARAM_VALUE (MAX_UNSWITCH_LEVEL))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unswitching anymore, hit max level\n");
! return;
! }
/* We only unswitch innermost loops (at least for now). */
if (loop->inner)
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unswitching, not innermost loop\n");
! return;
! }
/* And we must be able to duplicate loop body. */
if (!can_duplicate_loop_p (loop))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unswitching, can't duplicate loop\n");
! return;
! }
/* Check the size of loop. */
if (num_loop_insns (loop) > PARAM_VALUE (MAX_UNSWITCH_INSNS))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unswitching, loop too big\n");
! return;
! }
!
/* Do not unswitch in cold areas. */
if (!maybe_hot_bb_p (loop->header))
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unswitching, not hot area\n");
! return;
! }
!
/* Nor if it usually do not pass. */
if (expected_loop_iterations (loop) < 1)
! {
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Not unswitching, loop iterations < 1\n");
! return;
! }
do
{
*************** unswitch_single_loop (loops, loop, cond_
*** 557,563 ****
bb = split_loop_bb (loops, bbs[i], PREV_INSN (bbs[i]->end))->dest;
free (bbs);
true_first = !(bb->succ->flags & EDGE_FALLTHRU);
!
/* Unswitch the loop. */
nloop = unswitch_loop (loops, loop, bb);
if (!nloop)
--- 581,588 ----
bb = split_loop_bb (loops, bbs[i], PREV_INSN (bbs[i]->end))->dest;
free (bbs);
true_first = !(bb->succ->flags & EDGE_FALLTHRU);
! if (rtl_dump_file)
! fprintf (rtl_dump_file, ";; Unswitching loop\n");
/* Unswitch the loop. */
nloop = unswitch_loop (loops, loop, bb);
if (!nloop)
On Fri, 2002-03-22 at 20:11, Daniel Berlin wrote:
> It's always nice to know *why* something happened or didn't, without
> having to try to discern it from RTL.
> 0 functional changes.
>