This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR rtl-optimization/20017 - Take 2
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 22 Feb 2005 08:58:25 -0500 (EST)
- Subject: [patch] Fix PR rtl-optimization/20017 - Take 2
Hi,
Attached is a revised patch to fix PR rtl-optimization/20017, a
fall-out from one of my speed-up patches.
The original version was posted at:
http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01131.html
The patch calls delete_dead_jumptables if CSE, GCSE, or COMBINE folds
a conditional jump into an unconditonal one. We do so immediately
before cleanup_cfg. This solution should be a lot cheaper than
calling delete_dead_jumptables from cleanup_cfg as cleanup_cfg is run
many times.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2005-02-22 Kazu Hirata <kazu@cs.umass.edu>
PR rtl-optimization/20017.
* passes.c (rest_of_handle_combine, rest_of_handle_cse,
rest_of_handle_cse2, rest_of_handle_gcse): Call
delete_dead_jumptables immediately before calling cleanup_cfg.
2005-02-22 Kazu Hirata <kazu@cs.umass.edu>
PR rtl-optimization/20017.
* gcc.dg/pr20017.c: New.
Index: passes.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/passes.c,v
retrieving revision 2.71
diff -u -d -p -r2.71 passes.c
--- passes.c 15 Feb 2005 18:56:44 -0000 2.71
+++ passes.c 21 Feb 2005 19:52:41 -0000
@@ -895,6 +895,7 @@ rest_of_handle_combine (void)
rebuild_jump_labels (get_insns ());
timevar_pop (TV_JUMP);
+ delete_dead_jumptables ();
cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
}
@@ -971,6 +972,9 @@ rest_of_handle_cse (void)
expecting CSE to be run. But always rerun it in a cheap mode. */
cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
+ if (tem)
+ delete_dead_jumptables ();
+
if (tem || optimize > 1)
cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
@@ -1006,6 +1010,7 @@ rest_of_handle_cse2 (void)
{
timevar_push (TV_JUMP);
rebuild_jump_labels (get_insns ());
+ delete_dead_jumptables ();
cleanup_cfg (CLEANUP_EXPENSIVE);
timevar_pop (TV_JUMP);
}
@@ -1053,7 +1058,8 @@ rest_of_handle_gcse (void)
{
timevar_push (TV_JUMP);
rebuild_jump_labels (get_insns ());
+ delete_dead_jumptables ();
cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
timevar_pop (TV_JUMP);
}
--- /dev/null 2005-02-18 20:13:08.537291064 -0500
+++ pr20017.c 2005-02-19 10:28:17.000000000 -0500
@@ -0,0 +1,40 @@
+/* PR rtl-optimization/20017
+
+ After CSE/GCSE folds a switch statement to an unconditonal jump,
+ cfg_cleanup did not remove a dead jump table, confusing the CFG
+ layout code later on. */
+
+/* { dg-do compile } */
+/* { dg-options "-O1 -march=i386" } */
+
+int
+foo (int *buf, int *p)
+{
+ int result;
+ const int *tmp;
+
+ if (*buf)
+ return 1;
+
+ result = 2;
+ *buf = 2;
+ tmp = buf;
+ switch (*tmp)
+ {
+ case 3:
+ case 4:
+ case 6:
+ case 14:
+ return 1;
+
+ case 0:
+ result = *p;
+
+ /* Fall through. */
+ default:
+ if (result)
+ return 1;
+ }
+
+ return 0;
+}