[patch] cfgloopmanip.c: Don't use FALLTHRU_EDGE and BRANCH_EDGE on trees.

Kazu Hirata kazu@cs.umass.edu
Mon Oct 25 15:06:00 GMT 2004


Hi,

Attached is a patch to teach cfgloopmanip.c:loopify not to use
FALLTHRU_EDGE and BRANCH_EDGE on trees.

FALLTHRU_EDGE and BRANCH_EDGE do not make sense on trees because they
use EDGE_FALLTHRU_EDGE, which we do not use in trees.

The patch fixes this problem by passing the two edges of switch_bb as
additional arguments.

This problem came up when I was trying to use VEC_safe_push instead of
VEC_safe_insert to insert an edge to an edge vector.  I'll post the
VEC_safe_push patch shortly.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-10-25  Kazu Hirata  <kazu@cs.umass.edu>

	* cfgloopmanip.c (loopify): Take two more arguments true_edge
	and false_edge.
	* cfgloop.h: Adjust the corresponding prototype.
	* loop-unswitch.c (unswitch_loop): Adjust a call to loopify.
	* tree-ssa-loop-manip.c (tree_ssa_loop_version): Likewise.

Index: cfgloop.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgloop.h,v
retrieving revision 1.33
diff -u -p -r1.33 cfgloop.h
--- cfgloop.h	13 Oct 2004 03:48:03 -0000	1.33
+++ cfgloop.h	25 Oct 2004 04:01:40 -0000
@@ -339,7 +339,8 @@ extern struct loop * duplicate_loop (str
 extern int duplicate_loop_to_header_edge (struct loop *, edge, struct loops *,
 					  unsigned, sbitmap, edge, edge *,
 					  unsigned *, int);
-extern struct loop *loopify (struct loops *, edge, edge, basic_block, bool);
+extern struct loop *loopify (struct loops *, edge, edge,
+			     basic_block, edge, edge, bool);
 extern void unloop (struct loops *, struct loop *);
 extern bool remove_path (struct loops *, edge);
 extern edge split_loop_bb (basic_block, void *);
Index: cfgloopmanip.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgloopmanip.c,v
retrieving revision 1.34
diff -u -p -r1.34 cfgloopmanip.c
--- cfgloopmanip.c	7 Oct 2004 06:14:15 -0000	1.34
+++ cfgloopmanip.c	25 Oct 2004 04:01:40 -0000
@@ -482,13 +482,14 @@ scale_loop_frequencies (struct loop *loo
    accordingly. Everything between them plus LATCH_EDGE destination must
    be dominated by HEADER_EDGE destination, and back-reachable from
    LATCH_EDGE source.  HEADER_EDGE is redirected to basic block SWITCH_BB,
-   FALLTHRU_EDGE (SWITCH_BB) to original destination of HEADER_EDGE and
-   BRANCH_EDGE (SWITCH_BB) to original destination of LATCH_EDGE.
+   FALSE_EDGE of SWITCH_BB to original destination of HEADER_EDGE and
+   TRUE_EDGE of SWITCH_BB to original destination of LATCH_EDGE.
    Returns newly created loop.  */
 
 struct loop *
 loopify (struct loops *loops, edge latch_edge, edge header_edge, 
-	 basic_block switch_bb, bool redirect_all_edges)
+	 basic_block switch_bb, edge true_edge, edge false_edge,
+	 bool redirect_all_edges)
 {
   basic_block succ_bb = latch_edge->dest;
   basic_block pred_bb = header_edge->src;
@@ -514,14 +515,14 @@ loopify (struct loops *loops, edge latch
 
   /* Redirect edges.  */
   loop_redirect_edge (latch_edge, loop->header);
-  loop_redirect_edge (BRANCH_EDGE (switch_bb), succ_bb);
+  loop_redirect_edge (true_edge, succ_bb);
 
   /* During loop versioning, one of the switch_bb edge is already properly
      set. Do not redirect it again unless redirect_all_edges is true.  */
   if (redirect_all_edges)
     {
       loop_redirect_edge (header_edge, switch_bb);
-      loop_redirect_edge (FALLTHRU_EDGE (switch_bb), loop->header); 
+      loop_redirect_edge (false_edge, loop->header); 
      
       /* Update dominators.  */
       set_immediate_dominator (CDI_DOMINATORS, switch_bb, pred_bb);
Index: loop-unswitch.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop-unswitch.c,v
retrieving revision 1.23
diff -u -p -r1.23 loop-unswitch.c
--- loop-unswitch.c	28 Sep 2004 07:59:48 -0000	1.23
+++ loop-unswitch.c	25 Oct 2004 04:01:40 -0000
@@ -474,7 +474,8 @@ unswitch_loop (struct loops *loops, stru
 
   /* Loopify from the copy of LOOP body, constructing the new loop.  */
   nloop = loopify (loops, latch_edge,
-		   EDGE_PRED (loop->header->rbi->copy, 0), switch_bb, true);
+		   EDGE_PRED (loop->header->rbi->copy, 0), switch_bb,
+		   BRANCH_EDGE (switch_bb), FALLTHRU_EDGE (switch_bb), true);
 
   /* Remove branches that are now unreachable in new loops.  */
   remove_path (loops, true_edge);
Index: tree-ssa-loop-manip.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-manip.c,v
retrieving revision 2.10
diff -u -p -r2.10 tree-ssa-loop-manip.c
--- tree-ssa-loop-manip.c	22 Oct 2004 17:05:08 -0000	2.10
+++ tree-ssa-loop-manip.c	25 Oct 2004 04:01:40 -0000
@@ -785,7 +785,7 @@ struct loop *
 tree_ssa_loop_version (struct loops *loops, struct loop * loop, 
 		       tree cond_expr, basic_block *condition_bb)
 {
-  edge entry, latch_edge, exit;
+  edge entry, latch_edge, exit, true_edge, false_edge;
   basic_block first_head, second_head;
   int irred_flag;
   struct loop *nloop;
@@ -819,10 +819,12 @@ tree_ssa_loop_version (struct loops *loo
 					    cond_expr); 
 
   latch_edge = EDGE_SUCC (loop->latch->rbi->copy, 0);
+  
+  extract_true_false_edges_from_block (*condition_bb, &true_edge, &false_edge);
   nloop = loopify (loops, 
 		   latch_edge,
 		   EDGE_PRED (loop->header->rbi->copy, 0),
-		   *condition_bb,
+		   *condition_bb, true_edge, false_edge,
 		   false /* Do not redirect all edges.  */);
 
   exit = loop->single_exit;
@@ -833,7 +835,8 @@ tree_ssa_loop_version (struct loops *loo
   lv_update_pending_stmts (latch_edge);
 
   /* loopify redirected condition_bb's succ edge. Update its PENDING_STMTS.  */ 
-  lv_update_pending_stmts (FALLTHRU_EDGE (*condition_bb));
+  extract_true_false_edges_from_block (*condition_bb, &true_edge, &false_edge);
+  lv_update_pending_stmts (false_edge);
 
   /* Adjust irreducible flag.  */
   if (irred_flag)



More information about the Gcc-patches mailing list