This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] More improvements for the code generation of the if-conversion


On Fri, Jun 25, 2010 at 09:48, Richard Guenther <rguenther@suse.de> wrote:
>> 0001 adds a debug counter, useful to reduce code generation problems
>> due to the tree-if-conversion pass.
>
> Ok.
>

Committed r161395.

>> 0002 calls the cleanup_tree_cfg after if-conversion to ensure that the
>> CFG representation passed to the vectorizer is in good shape.
>
> Instead of
>
> + ?if (changed)
> + ? ?cleanup_tree_cfg ();
>
> ? return 0;
> ?}
>
> do
>
> ? return changed ? TODO_cleanup_cfg : 0;
>
> ok with that change.
>

Committed r161396.

>> 0006 uses a single function reset_bb_predicate to reset the predicate
>> of a BB to true. ?This function has to release all the SSA_NAMEs used
>> in the gimplification of a predicate.
>
> Ok.
>

Committed r161397.

>> 0007 avoids the generation of code computing the true predicate, that
>> occurs for all the BBs merging disjunct predicates leading to the true
>> predicate.
>
> Ok.
>

Committed r161398.

The attached patches are the ones that I committed to trunk.  These
patches passed regstrap on amd64-linux.

Sebastian Pop
--
AMD / Open Source Compiler Engineering / GNU Tools
From 617150e6953864cbdde00795f787822184950529 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Thu, 22 Apr 2010 11:40:18 -0500
Subject: [PATCH 1/4] Add a debug counter for the tree-ssa level if-conversion.

2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>

	* Makefile.in (tree-if-conv.o): Depends on DBGCNT_H.
	* dbgcnt.def (if_conversion_tree): New DEBUG_COUNTER.
	* tree-if-conv.c: Include dbgcnt.h.
	(tree_if_conversion): Use if_conversion_tree to count the number of
	if-convertible loops.
---
 gcc/ChangeLog      |   14 +++++++++++---
 gcc/Makefile.in    |    2 +-
 gcc/dbgcnt.def     |    1 +
 gcc/tree-if-conv.c |    4 +++-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 23818d9..7eb7808 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
+
+	* Makefile.in (tree-if-conv.o): Depends on DBGCNT_H.
+	* dbgcnt.def (if_conversion_tree): New DEBUG_COUNTER.
+	* tree-if-conv.c: Include dbgcnt.h.
+	(tree_if_conversion): Use if_conversion_tree to count the number of
+	if-convertible loops.
+
 2010-06-25  Changpeng Fang  <changpeng.fang@amd.com>
 
 	* common.opt (fprefetch-loop-arrays): Re-define
@@ -62,11 +70,11 @@
 	with only a call to ipa_analyze_node.
 	* ipa-inline.c (inline_indirect_intraprocedural_analysis): Analyze the
 	node with only a call to ipa_analyze_node.
-	
+
 2010-06-25  Manuel LÃpez-IbÃÃez  <manu@gcc.gnu.org>
 
 	* doc/invoke.texi (-Wsuggest-attribute): Add item for noreturn.
-	
+
 2010-06-25  Jan Hubicka  <jh@suse.cz>
 
 	* tree-pass.h (pass_split_functions): Declare.
@@ -85,7 +93,7 @@
 	* tree-inline.c (gimple_expand_calls_inline): Fix typo in comment.
 	* gimplify.c (is_gimple_reg_rhs_or_call): Likewise.
 	(gimplify_expr): Likewise.
-	
+
 2010-06-25  Martin Jambor  <mjambor@suse.cz>
 
 	* ipa-prop.c (determine_cst_member_ptr): Ignore non-clobbering
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 8b27fa2..2075cf3 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2501,7 +2501,7 @@ tree-nested.o: tree-nested.c $(CONFIG_H) $(SYSTEM_H) $(TM_H) $(TREE_H) \
 tree-if-conv.o: tree-if-conv.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(TREE_H) $(FLAGS_H) $(TIMEVAR_H) $(BASIC_BLOCK_H) $(TREE_FLOW_H) \
    $(CFGLOOP_H) $(TREE_DATA_REF_H) $(TREE_PASS_H) $(DIAGNOSTIC_H) \
-   $(TREE_DUMP_H) tree-pretty-print.h gimple-pretty-print.h
+   $(TREE_DUMP_H) $(DBGCNT_H) tree-pretty-print.h gimple-pretty-print.h
 tree-iterator.o : tree-iterator.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) \
    coretypes.h $(GGC_H) tree-iterator.h $(GIMPLE_H) gt-tree-iterator.h
 tree-dfa.o : tree-dfa.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def
index 33afb0b..0d73d94 100644
--- a/gcc/dbgcnt.def
+++ b/gcc/dbgcnt.def
@@ -160,6 +160,7 @@ DEBUG_COUNTER (global_alloc_at_reg)
 DEBUG_COUNTER (hoist)
 DEBUG_COUNTER (ia64_sched2)
 DEBUG_COUNTER (if_conversion)
+DEBUG_COUNTER (if_conversion_tree)
 DEBUG_COUNTER (if_after_combine)
 DEBUG_COUNTER (if_after_reload)
 DEBUG_COUNTER (local_alloc_for_sched)
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 1686473..b7fe749 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -98,6 +98,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-data-ref.h"
 #include "tree-scalar-evolution.h"
 #include "tree-pass.h"
+#include "dbgcnt.h"
 
 /* List of basic blocks in if-conversion-suitable order.  */
 static basic_block *ifc_bbs;
@@ -1178,7 +1179,8 @@ tree_if_conversion (struct loop *loop)
 {
   ifc_bbs = NULL;
 
-  if (!if_convertible_loop_p (loop))
+  if (!if_convertible_loop_p (loop)
+      || !dbg_cnt (if_conversion_tree))
     goto cleanup;
 
   /* Now all statements are if-convertible.  Combine all the basic
-- 
1.7.0.4

From db7a76b0dc5d01ab456c7626a28382e6fbc1e747 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Wed, 16 Jun 2010 14:57:01 -0500
Subject: [PATCH 2/4] Call cleanup_tree_cfg after if-conversion.

2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>

	* tree-if-conv.c (combine_blocks): Remove FIXME comment.
	(tree_if_conversion): Returns true when something has been changed.
	(main_tree_if_conversion): Return TODO_cleanup_cfg when if-conversion
	changed something.
---
 gcc/ChangeLog      |    7 +++++++
 gcc/tree-if-conv.c |   17 ++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7eb7808..b7fbcb9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
 2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* tree-if-conv.c (combine_blocks): Remove FIXME comment.
+	(tree_if_conversion): Returns true when something has been changed.
+	(main_tree_if_conversion): Return TODO_cleanup_cfg when if-conversion
+	changed something.
+
+2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* Makefile.in (tree-if-conv.o): Depends on DBGCNT_H.
 	* dbgcnt.def (if_conversion_tree): New DEBUG_COUNTER.
 	* tree-if-conv.c: Include dbgcnt.h.
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index b7fe749..f200d48 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -1162,9 +1162,7 @@ combine_blocks (struct loop *loop)
 
   /* If possible, merge loop header to the block with the exit edge.
      This reduces the number of basic blocks to two, to please the
-     vectorizer that handles only loops with two nodes.
-
-     FIXME: Call cleanup_tree_cfg.  */
+     vectorizer that handles only loops with two nodes.  */
   if (exit_bb
       && exit_bb != loop->header
       && can_merge_blocks_p (loop->header, exit_bb))
@@ -1172,11 +1170,12 @@ combine_blocks (struct loop *loop)
 }
 
 /* If-convert LOOP when it is legal.  For the moment this pass has no
-   profitability analysis.  */
+   profitability analysis.  Returns true when something changed.  */
 
-static void
+static bool
 tree_if_conversion (struct loop *loop)
 {
+  bool changed = false;
   ifc_bbs = NULL;
 
   if (!if_convertible_loop_p (loop)
@@ -1187,6 +1186,7 @@ tree_if_conversion (struct loop *loop)
      blocks into one huge basic block doing the if-conversion
      on-the-fly.  */
   combine_blocks (loop);
+  changed = true;
 
  cleanup:
   if (ifc_bbs)
@@ -1199,6 +1199,8 @@ tree_if_conversion (struct loop *loop)
       free (ifc_bbs);
       ifc_bbs = NULL;
     }
+
+  return changed;
 }
 
 /* Tree if-conversion pass management.  */
@@ -1208,14 +1210,15 @@ main_tree_if_conversion (void)
 {
   loop_iterator li;
   struct loop *loop;
+  bool changed = false;
 
   if (number_of_loops () <= 1)
     return 0;
 
   FOR_EACH_LOOP (li, loop, 0)
-    tree_if_conversion (loop);
+    changed |= tree_if_conversion (loop);
 
-  return 0;
+  return changed ? TODO_cleanup_cfg : 0;
 }
 
 static bool
-- 
1.7.0.4

From 68612f9244803f079bb1979052f1936425eddb0d Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Wed, 16 Jun 2010 16:01:27 -0500
Subject: [PATCH 3/4] Use reset_bb_predicate whenever the predicate of a BB should be reset to true.

2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>

	* tree-if-conv.c (init_bb_predicate): Initialize the predicate
	to boolean_true_node.
	(reset_bb_predicate): New.
	(predicate_bbs): Call reset_bb_predicate.
---
 gcc/ChangeLog      |    7 +++++++
 gcc/tree-if-conv.c |   17 +++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b7fbcb9..0e9bd83 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
 2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* tree-if-conv.c (init_bb_predicate): Initialize the predicate
+	to boolean_true_node.
+	(reset_bb_predicate): New.
+	(predicate_bbs): Call reset_bb_predicate.
+
+2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* tree-if-conv.c (combine_blocks): Remove FIXME comment.
 	(tree_if_conversion): Returns true when something has been changed.
 	(main_tree_if_conversion): Return TODO_cleanup_cfg when if-conversion
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index f200d48..80a53a8 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -175,7 +175,7 @@ init_bb_predicate (basic_block bb)
 {
   bb->aux = XNEW (struct bb_predicate_s);
   set_bb_predicate_gimplified_stmts (bb, NULL);
-  set_bb_predicate (bb, NULL_TREE);
+  set_bb_predicate (bb, boolean_true_node);
 }
 
 /* Free the predicate of basic block BB.  */
@@ -203,6 +203,16 @@ free_bb_predicate (basic_block bb)
   bb->aux = NULL;
 }
 
+/* Free the predicate of BB and reinitialize it with the true
+   predicate.  */
+
+static inline void
+reset_bb_predicate (basic_block bb)
+{
+  free_bb_predicate (bb);
+  init_bb_predicate (bb);
+}
+
 /* Create a new temp variable of type TYPE.  Add GIMPLE_ASSIGN to assign EXP
    to the new variable.  */
 
@@ -605,8 +615,7 @@ predicate_bbs (loop_p loop)
 	 to be processed: skip it.  */
       if (bb == loop->latch)
 	{
-	  set_bb_predicate (loop->latch, boolean_true_node);
-	  set_bb_predicate_gimplified_stmts (loop->latch, NULL);
+	  reset_bb_predicate (loop->latch);
 	  continue;
 	}
 
@@ -680,7 +689,7 @@ predicate_bbs (loop_p loop)
     }
 
   /* The loop header is always executed.  */
-  set_bb_predicate (loop->header, boolean_true_node);
+  reset_bb_predicate (loop->header);
   gcc_assert (bb_predicate_gimplified_stmts (loop->header) == NULL
 	      && bb_predicate_gimplified_stmts (loop->latch) == NULL);
 
-- 
1.7.0.4

From ef28ff91f71fc5c62cc08d74cf93188aeec9ec08 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Fri, 25 Jun 2010 11:09:00 -0500
Subject: [PATCH 4/4] Do not insert statements computing the true predicate.

2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>

	* tree-if-conv.c (insert_gimplified_predicates): Do not insert
	statements computing the true predicate.
---
 gcc/ChangeLog      |    5 +++++
 gcc/tree-if-conv.c |    9 +++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0e9bd83..34afcc1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
 2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* tree-if-conv.c (insert_gimplified_predicates): Do not insert
+	statements computing the true predicate.
+
+2010-06-25  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* tree-if-conv.c (init_bb_predicate): Initialize the predicate
 	to boolean_true_node.
 	(reset_bb_predicate): New.
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 80a53a8..8d5d226 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -1021,6 +1021,15 @@ insert_gimplified_predicates (loop_p loop)
       basic_block bb = ifc_bbs[i];
       gimple_seq stmts = bb_predicate_gimplified_stmts (bb);
 
+      if (!is_predicated (bb))
+	{
+	  /* Do not insert statements for a basic block that is not
+	     predicated.  Also make sure that the predicate of the
+	     basic block is set to true.  */
+	  reset_bb_predicate (bb);
+	  continue;
+	}
+
       if (stmts)
 	{
 	  gimple_stmt_iterator gsi = gsi_last_bb (bb);
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]