This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] fix pr22550
- From: Diego Novillo <dnovillo at redhat dot com>
- To: "James A. Morrison" <ja2morri at csclub dot uwaterloo dot ca>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 25 Jul 2005 11:55:40 -0400
- Subject: Re: [patch] fix pr22550
- References: <kfh4qajymrj.fsf@csclub.uwaterloo.ca>
On Mon, Jul 25, 2005 at 10:37:52AM -0400, James A. Morrison wrote:
>
> Hi,
>
> This fixes PR22550 by simply returning COND in vrp_evaluate_condition if
> it is an INTEGER_CST. In PR22550 I believe the if (0) comes from
> merge_seq_blocks which is called after cleanup_control_flow in
> cleanup_tree_cfg. This patch has been bootstrapped and regtested on ia64-linux
> with no new regressions, ok for mainline?
>
> --
> Thanks,
> Jim
>
> http://www.csclub.uwaterloo.ca/~ja2morri/
> http://phython.blogspot.com
> http://open.nit.ca/wiki/?page=jim
>
> 2005-07-25 James A. Morrison <phython@gcc.gnu.org>
>
> PR tree-optimization/22550
> * tree-vrp.c (vrp_evaluate_condition): Return COND if it is an
> INTEGER_CST.
>
No. This just papers over the bug in CFG cleanup. VRP is not at
fault here. Merging blocks can actually leave superfluous condtional
predicates:
-----------------------------------------------------------------------------
# BLOCK 0
# PRED: ENTRY (fallthru,exec)
# VUSE <mf_arr_5>;
D.1771_4 = mf_arr[0].__pfn;
D.1772_6 = D.1771_4;
# VUSE <mf_arr_5>;
D.1773_11 = mf_arr[0].__delta;
D.1774_12 = D.1773_11;
# SUCC: 4 (fallthru)
# BLOCK 4
# PRED: 0 (fallthru)
# iftmp.0_1 = PHI <1(0)>;
<L4>:;
if (iftmp.0_1 == 0) goto <L5>; else goto <L7>;
# SUCC: 5 (true,exec) 6 (false,exec)
-----------------------------------------------------------------------------
When merging block 0 with block 4, we'll end up with 'if (0)' at
the end of block 0.
The fix is something along these lines (untested):
Index: tree-cfgcleanup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfgcleanup.c,v
retrieving revision 2.3
diff -d -u -p -r2.3 tree-cfgcleanup.c
--- tree-cfgcleanup.c 18 Jul 2005 23:20:09 -0000 2.3
+++ tree-cfgcleanup.c 25 Jul 2005 15:54:24 -0000
@@ -504,7 +504,6 @@ cleanup_tree_cfg (void)
/* Forwarder blocks can carry line number information which is
useful when debugging, so we only clean them up when
optimizing. */
-
if (optimize > 0)
{
/* cleanup_forwarder_blocks can redirect edges out of
@@ -516,6 +515,15 @@ cleanup_tree_cfg (void)
end_recording_case_labels ();
}
+ /* Merging the blocks may create new opportunities for folding
+ conditional branches (due to the elimination of single-valued PHI
+ nodes). */
+ retval |= merge_seq_blocks ();
+ if (retval && cleanup_control_flow ())
+ delete_unreachable_blocks ();
+
+ compact_blocks ();
+
#ifdef ENABLE_CHECKING
if (retval)
{
@@ -524,18 +532,12 @@ cleanup_tree_cfg (void)
if (optimize > 0)
gcc_assert (!cleanup_forwarder_blocks ());
}
-#endif
-
- /* Merging the blocks creates no new opportunities for the other
- optimizations, so do it here. */
- retval |= merge_seq_blocks ();
- compact_blocks ();
-
-#ifdef ENABLE_CHECKING
verify_flow_info ();
#endif
+
timevar_pop (TV_TREE_CLEANUP_CFG);
+
return retval;
}