This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Remove dead labels to increase superblock scope
On 11/18/2011 09:16 PM, Andrew Pinski wrote:
> On Fri, Nov 18, 2011 at 5:11 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>> Hi Eric,
>>
>> this patch fixes an inefficiency problem I observed while working on PR50764.
>>
>> For the test-case of PR50764, a dead label is introduced by fixup_reorder_chain
>> in cfg_layout_finalize, called from pass_reorder_blocks.
>> The dead label is removed by a cleanup_cfg in pass_duplicate_computed_gotos, but
>> is still present during pass_sched2.
>> When constructing ebbs in schedule_ebbs, the dead label ends an ebb. If we
>> remove the label before pass_sched2, the ebb is allowed to grow larger.
>>
>> The patch tries to get rid of the dead label immediately after it's introduced,
>> in cfg_layout_finalized.
>>
>> The new test gcc.dg/superblock.c uses -fno-asynchronous-unwind-tables to work
>> around PR50764.
>>
>> bootstrapped and reg-tested on x86_64.
>>
>> OK for next stage 1?
>
> ENOPATCH.
>
Thanks Andrew.
here it is.
Thanks,
- Tom
>>
>> 2011-11-18 Tom de Vries <tom@codesourcery.com>
>>
>> * rtl.h (delete_dead_labels): Declare.
>> * cfgcleanup.c (delete_dead_labels): New function.
>> * cfglayout.c (cfg_layout_finalize): Use delete_dead_labels.
>>
>> * gcc.dg/superblock.c: New test.
>>
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h (revision 181377)
+++ gcc/rtl.h (working copy)
@@ -2481,6 +2481,7 @@ extern void dump_combine_total_stats (FI
/* In cfgcleanup.c */
extern void delete_dead_jumptables (void);
+extern void delete_dead_labels (void);
/* In sched-vis.c. */
extern void debug_bb_n_slim (int);
Index: gcc/cfgcleanup.c
===================================================================
--- gcc/cfgcleanup.c (revision 181377)
+++ gcc/cfgcleanup.c (working copy)
@@ -2900,6 +2900,37 @@ delete_dead_jumptables (void)
}
}
+/* Delete labels which are dead and can be removed. */
+
+void
+delete_dead_labels (void)
+{
+ basic_block bb;
+
+ FOR_EACH_BB (bb)
+ {
+ rtx insn;
+
+ FOR_BB_INSNS (bb, insn)
+ {
+ if (NOTE_INSN_BASIC_BLOCK_P (insn))
+ continue;
+
+ if (!LABEL_P (insn)
+ || LABEL_NUSES (insn) != 0
+ || LABEL_PRESERVE_P (insn)
+ || LABEL_NAME (insn) != 0)
+ break;
+
+ if (dump_file)
+ fprintf (dump_file, "Dead label %i removed\n",
+ INSN_UID (insn));
+
+ delete_insn (insn);
+ break;
+ }
+ }
+}
/* Tidy the CFG by deleting unreachable code and whatnot. */
Index: gcc/cfglayout.c
===================================================================
--- gcc/cfglayout.c (revision 181377)
+++ gcc/cfglayout.c (working copy)
@@ -1369,6 +1369,7 @@ cfg_layout_finalize (void)
rebuild_jump_labels (get_insns ());
delete_dead_jumptables ();
+ delete_dead_labels ();
#ifdef ENABLE_CHECKING
verify_insn_chain ();
Index: gcc/testsuite/gcc.dg/superblock.c
===================================================================
--- /dev/null (new file)
+++ gcc/testsuite/gcc.dg/superblock.c (revision 0)
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-asynchronous-unwind-tables -fsched2-use-superblocks -fdump-rtl-sched2 -fdump-rtl-bbro" } */
+
+typedef int aligned __attribute__ ((aligned (64)));
+extern void abort (void);
+
+int bar (void *p);
+
+void
+foo (void)
+{
+ char *p = __builtin_alloca (13);
+ aligned i;
+
+ if (bar (p) || bar (&i))
+ abort ();
+}
+
+/* { dg-final { scan-rtl-dump-times "0 uses" 0 "bbro"} } */
+/* { dg-final { scan-rtl-dump-times "ADVANCING TO" 2 "sched2"} } */
+/* { dg-final { cleanup-rtl-dump "bbro" } } */
+/* { dg-final { cleanup-rtl-dump "sched2" } } */
+