* [PATCH] sel-sched: Fix adding of preheader blocks from inner loops (PR48302)
@ 2011-04-07 17:34 Alexander Monakov
2011-04-07 20:16 ` Vladimir Makarov
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Monakov @ 2011-04-07 17:34 UTC (permalink / raw)
To: gcc-patches; +Cc: Vladimir N. Makarov
Hello,
(quoting myself from the PR audit trail)
We call sched_scan for preheader blocks from inner regions twice: first during
sel_add_loop_preheaders, and then during the subsequent call to sel_init_bbs
in setup_current_loop_nest. As a result, we also call remove_notes for those
blocks twice, and after the second call incorrectly record that the block has
no notes.
The solution is to call sel_add_loop_preheaders after sel_init_bbs. We need
to add new preheader blocks into 'bbs' vector in setup_current_loop_nest, so
we pass the pointer to the vector to sel_add_loop_preheaders.
PR rtl-optimization/48302
* sel-sched-ir.h (sel_add_loop_preheaders): Update prototype.
* sel-sched-ir.c (sel_add_loop_preheaders): Add 'bbs' argument. Use
it to record added preheader blocks.
(setup_current_loop_nest): Add 'bbs' argument. Pass it on to
sel_add_loop_preheaders.
(sel_region_init): Move call to setup_current_loop_nest after
sel_init_bbs.
testsuite:
g++.dg/opt/pr48302.C: New.
diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 95c1431..a6daa58 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -6094,11 +6094,11 @@ sel_find_rgns (void)
bbs_in_loop_rgns = NULL;
}
-/* Adds the preheader blocks from previous loop to current region taking
- it from LOOP_PREHEADER_BLOCKS (current_loop_nest).
+/* Add the preheader blocks from previous loop to current region taking
+ it from LOOP_PREHEADER_BLOCKS (current_loop_nest) and record them in *BBS.
This function is only used with -fsel-sched-pipelining-outer-loops. */
void
-sel_add_loop_preheaders (void)
+sel_add_loop_preheaders (bb_vec_t *bbs)
{
int i;
basic_block bb;
@@ -6109,6 +6109,7 @@ sel_add_loop_preheaders (void)
VEC_iterate (basic_block, preheader_blocks, i, bb);
i++)
{
+ VEC_safe_push (basic_block, heap, *bbs, bb);
VEC_safe_push (basic_block, heap, last_added_blocks, bb);
sel_add_bb (bb);
}
diff --git a/gcc/sel-sched-ir.h b/gcc/sel-sched-ir.h
index 5516da9..b0c52eb 100644
--- a/gcc/sel-sched-ir.h
+++ b/gcc/sel-sched-ir.h
@@ -1628,7 +1628,7 @@ extern void sel_sched_region (int);
extern loop_p get_loop_nest_for_rgn (unsigned int);
extern bool considered_for_pipelining_p (struct loop *);
extern void make_region_from_loop_preheader (VEC(basic_block, heap) **);
-extern void sel_add_loop_preheaders (void);
+extern void sel_add_loop_preheaders (bb_vec_t *);
extern bool sel_is_loop_preheader_p (basic_block);
extern void clear_outdated_rtx_info (basic_block);
extern void free_data_sets (basic_block);
diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c
index fb1a026..48fb2e0 100644
--- a/gcc/sel-sched.c
+++ b/gcc/sel-sched.c
@@ -6801,7 +6801,7 @@ current_region_empty_p (void)
/* Prepare and verify loop nest for pipelining. */
static void
-setup_current_loop_nest (int rgn)
+setup_current_loop_nest (int rgn, bb_vec_t *bbs)
{
current_loop_nest = get_loop_nest_for_rgn (rgn);
@@ -6810,7 +6810,7 @@ setup_current_loop_nest (int rgn)
/* If this loop has any saved loop preheaders from nested loops,
add these basic blocks to the current region. */
- sel_add_loop_preheaders ();
+ sel_add_loop_preheaders (bbs);
/* Check that we're starting with a valid information. */
gcc_assert (loop_latch_edge (current_loop_nest));
@@ -6849,9 +6849,6 @@ sel_region_init (int rgn)
if (current_region_empty_p ())
return true;
- if (flag_sel_sched_pipelining)
- setup_current_loop_nest (rgn);
-
sel_setup_region_sched_flags ();
bbs = VEC_alloc (basic_block, heap, current_nr_blocks);
@@ -6861,6 +6858,9 @@ sel_region_init (int rgn)
sel_init_bbs (bbs, NULL);
+ if (flag_sel_sched_pipelining)
+ setup_current_loop_nest (rgn, &bbs);
+
/* Initialize luids and dependence analysis which both sel-sched and haifa
need. */
sched_init_luids (bbs, NULL, NULL, NULL);
diff --git a/gcc/testsuite/g++.dg/opt/pr48302.C b/gcc/testsuite/g++.dg/opt/pr48302.C
new file mode 100644
index 0000000..fd51ba4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr48302.C
@@ -0,0 +1,21 @@
+// { dg-do compile { target powerpc*-*-* ia64-*-* x86_64-*-* } }
+// { dg-options "-O -fcrossjumping -fgcse -fschedule-insns2 -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops -fselective-scheduling2 --param lim-expensive=320 --param min-crossjump-insns=1" }
+
+struct S
+{
+ int i, j;
+ S *s;
+ ~S();
+};
+
+S *gs;
+
+void foo ()
+{
+restart:
+ for (S *s = gs; s; s = s->s)
+ if (s->j && s->j != (s->i & 1)) {
+ delete s;
+ goto restart;
+ }
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sel-sched: Fix adding of preheader blocks from inner loops (PR48302)
2011-04-07 17:34 [PATCH] sel-sched: Fix adding of preheader blocks from inner loops (PR48302) Alexander Monakov
@ 2011-04-07 20:16 ` Vladimir Makarov
2011-04-08 14:22 ` [committed] sel-sched: Fixup adding of preheader blocks from inner loops Alexander Monakov
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Makarov @ 2011-04-07 20:16 UTC (permalink / raw)
To: Alexander Monakov; +Cc: gcc-patches
On 04/07/2011 01:34 PM, Alexander Monakov wrote:
> Hello,
>
> (quoting myself from the PR audit trail)
> We call sched_scan for preheader blocks from inner regions twice: first during
> sel_add_loop_preheaders, and then during the subsequent call to sel_init_bbs
> in setup_current_loop_nest. As a result, we also call remove_notes for those
> blocks twice, and after the second call incorrectly record that the block has
> no notes.
>
> The solution is to call sel_add_loop_preheaders after sel_init_bbs. We need
> to add new preheader blocks into 'bbs' vector in setup_current_loop_nest, so
> we pass the pointer to the vector to sel_add_loop_preheaders.
>
>
> PR rtl-optimization/48302
> * sel-sched-ir.h (sel_add_loop_preheaders): Update prototype.
> * sel-sched-ir.c (sel_add_loop_preheaders): Add 'bbs' argument. Use
> it to record added preheader blocks.
> (setup_current_loop_nest): Add 'bbs' argument. Pass it on to
> sel_add_loop_preheaders.
> (sel_region_init): Move call to setup_current_loop_nest after
> sel_init_bbs.
>
> testsuite:
> g++.dg/opt/pr48302.C: New.
Ok, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [committed] sel-sched: Fixup adding of preheader blocks from inner loops
2011-04-07 20:16 ` Vladimir Makarov
@ 2011-04-08 14:22 ` Alexander Monakov
0 siblings, 0 replies; 3+ messages in thread
From: Alexander Monakov @ 2011-04-08 14:22 UTC (permalink / raw)
To: Vladimir Makarov; +Cc: gcc-patches
I failed to notice that current_loop_nest is modified in
setup_current_loop_nest and used in sel_setup_region_sched_flags. Therefore,
sel_setup_region_sched_flags should be moved with setup_current_loop_nest
after sel_init_bbs as well.
I've committed the following patch under the 'obvious' rule after noticing the
problem on ia64 bootstrap with selective scheduler enabled at -O2 (I normally
do this together with amd64 bootstraps before committing patches, but this
time I made a typo that completely disabled sel-sched for ia64 testing).
Sorry for the noise.
2011-04-08 Alexander Monakov <amonakov@ispras.ru>
* sel-sched.c (sel_region_init): Move call to
sel_setup_region_sched_flags after setup_current_loop_nest.
Index: gcc/sel-sched.c
===================================================================
--- gcc/sel-sched.c (revision 172177)
+++ gcc/sel-sched.c (working copy)
@@ -6868,8 +6868,6 @@ sel_region_init (int rgn)
if (current_region_empty_p ())
return true;
- sel_setup_region_sched_flags ();
-
bbs = VEC_alloc (basic_block, heap, current_nr_blocks);
for (i = 0; i < current_nr_blocks; i++)
@@ -6880,6 +6878,8 @@ sel_region_init (int rgn)
if (flag_sel_sched_pipelining)
setup_current_loop_nest (rgn, &bbs);
+ sel_setup_region_sched_flags ();
+
/* Initialize luids and dependence analysis which both sel-sched and haifa
need. */
sched_init_luids (bbs, NULL, NULL, NULL);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-04-08 14:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07 17:34 [PATCH] sel-sched: Fix adding of preheader blocks from inner loops (PR48302) Alexander Monakov
2011-04-07 20:16 ` Vladimir Makarov
2011-04-08 14:22 ` [committed] sel-sched: Fixup adding of preheader blocks from inner loops Alexander Monakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).