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]

[PATCH] Small cleanups to cse.c


Hi,

This patch contains four small cleanups:
* Makes us update the CFG incrementally in cse.c.  I can now run
  verify_flow_info at the end of cse and assert that purge_dead_edges
  is a NOP.  This is a required change to make CSE work on extended
  basic blocks instead of an insns list.
* Removes cse_altered.  Once upon a time, CSE could produce tons of
  garbage.  But not anymore.
* Changes the TAKEN argument of record_jump_equiv to a bool.  Just
  because true/false arguments shouldn't be int IMHO ;-)
* Removes the code guarded with USE_C_ALLOCA.  We don't use that in
  any other place in GCC.  Looks like more relics from the Old Days.

This patch mostly helps reducing the size of another cse.c patch I will
submit soon, that will make CSE path following work on the CFG.  That
patch is a ~2000 lines unidiff right now, but I'm trying to cut it into
manageable pieces.

Bootstrapped (c,c++,objc,fortran,java) and tested on x86_64-linux.
I'm going to commit this patch in a few days unless I hear objections.

Gr.
Steven


	* cse.c (cse_altered): Remove.
	(record_jump_equiv): Make true/false argument a bool instead
	of an int.
	(cse_insn): Don't set cse_altered.  Use delete_insn_and_edges
	where appropriate.  Emit a new jump before the existing one
	instead of after so that delete_insn_and_edges removes the
	dead edges properly.  Check any_condjump_p before calling
	record_jump_equiv.
	(cse_basic_block): Check any_condjump_p before calling
	record_jump_equiv.
	(cse_main): Don't set/check cse_altered.  Remove USE_C_ALLOCA.

Index: cse.c
===================================================================
--- cse.c	(revision 119190)
+++ cse.c	(working copy)
@@ -371,11 +371,6 @@ static int max_uid;
 
 #define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
 
-/* Nonzero if this pass has made changes, and therefore it's
-   worthwhile to run the garbage collector.  */
-
-static int cse_altered;
-
 /* Nonzero if cse has altered conditional jump insns
    in such a way that jump optimization should be redone.  */
 
@@ -603,7 +598,7 @@ static enum rtx_code find_comparison_arg
 					   enum machine_mode *);
 static rtx fold_rtx (rtx, rtx);
 static rtx equiv_constant (rtx);
-static void record_jump_equiv (rtx, int);
+static void record_jump_equiv (rtx, bool);
 static void record_jump_cond (enum rtx_code, enum machine_mode, rtx, rtx,
 			      int);
 static void cse_insn (rtx, rtx);
@@ -3694,8 +3689,8 @@ equiv_constant (rtx x)
   return 0;
 }
 
-/* Given INSN, a jump insn, PATH_TAKEN indicates if we are following the "taken"
-   branch.  It will be zero if not.
+/* Given INSN, a jump insn, TAKEN indicates if we are following the
+   "taken" branch.
 
    In certain cases, this can cause us to add an equivalence.  For example,
    if we are following the taken case of
@@ -3706,7 +3701,7 @@ equiv_constant (rtx x)
    comparison is seen later, we will know its value.  */
 
 static void
-record_jump_equiv (rtx insn, int taken)
+record_jump_equiv (rtx insn, bool taken)
 {
   int cond_known_true;
   rtx op0, op1;
@@ -3715,9 +3710,11 @@ record_jump_equiv (rtx insn, int taken)
   int reversed_nonequality = 0;
   enum rtx_code code;
 
+#ifdef ENABLE_CHECKING
   /* Ensure this is the right kind of insn.  */
-  if (! any_condjump_p (insn))
-    return;
+  gcc_assert (any_condjump_p (insn));
+#endif
+
   set = pc_set (insn);
 
   /* See if this jump condition is known true or false.  */
@@ -4942,7 +4939,6 @@ cse_insn (rtx insn, rtx libcall_insn)
       /* If we made a change, recompute SRC values.  */
       if (src != sets[i].src)
 	{
-	  cse_altered = 1;
 	  do_not_record = 0;
 	  hash_arg_in_memory = 0;
 	  sets[i].src = src;
@@ -5044,7 +5040,7 @@ cse_insn (rtx insn, rtx libcall_insn)
       else if (n_sets == 1 && dest == pc_rtx && src == pc_rtx)
 	{
 	  /* One less use of the label this insn used to jump to.  */
-	  delete_insn (insn);
+	  delete_insn_and_edges (insn);
 	  cse_jumps_altered = 1;
 	  /* No more processing for this set.  */
 	  sets[i].rtl = 0;
@@ -5071,7 +5067,7 @@ cse_insn (rtx insn, rtx libcall_insn)
 	    {
 	      rtx new, note;
 
-	      new = emit_jump_insn_after (gen_jump (XEXP (src, 0)), insn);
+	      new = emit_jump_insn_before (gen_jump (XEXP (src, 0)), insn);
 	      JUMP_LABEL (new) = XEXP (src, 0);
 	      LABEL_NUSES (XEXP (src, 0))++;
 
@@ -5083,7 +5079,7 @@ cse_insn (rtx insn, rtx libcall_insn)
 		  REG_NOTES (new) = note;
 		}
 
-	      delete_insn (insn);
+	      delete_insn_and_edges (insn);
 	      insn = new;
 
 	      /* Now emit a BARRIER after the unconditional jump.  */
@@ -5636,10 +5632,8 @@ cse_insn (rtx insn, rtx libcall_insn)
   /* If this is a conditional jump insn, record any known equivalences due to
      the condition being tested.  */
 
-  if (JUMP_P (insn)
-      && n_sets == 1 && GET_CODE (x) == SET
-      && GET_CODE (SET_SRC (x)) == IF_THEN_ELSE)
-    record_jump_equiv (insn, 0);
+  if (n_sets == 1 && any_condjump_p (insn))
+    record_jump_equiv (insn, false);
 
 #ifdef HAVE_cc0
   /* If the previous insn set CC0 and this insn no longer references CC0,
@@ -5649,7 +5643,7 @@ cse_insn (rtx insn, rtx libcall_insn)
       && (tem = single_set (prev_insn)) != 0
       && SET_DEST (tem) == cc0_rtx
       && ! reg_mentioned_p (cc0_rtx, x))
-    delete_insn (prev_insn);
+    delete_insn_and_edges (prev_insn);
 
   prev_insn_cc0 = this_insn_cc0;
   prev_insn_cc0_mode = this_insn_cc0_mode;
@@ -6016,7 +6010,6 @@ cse_main (rtx f, int nregs)
   insn = f;
   while (insn)
     {
-      cse_altered = 0;
       cse_end_of_basic_block (insn, &val, flag_cse_follow_jumps);
 
       /* If this basic block was already processed or has no sets, skip it.  */
@@ -6062,13 +6055,6 @@ cse_main (rtx f, int nregs)
 
 	  cse_jumps_altered |= old_cse_jumps_altered;
 	}
-
-      if (cse_altered)
-	ggc_collect ();
-
-#ifdef USE_C_ALLOCA
-      alloca (0);
-#endif
     }
 
   /* Clean up.  */
@@ -6130,7 +6116,8 @@ cse_basic_block (rtx from, rtx to, struc
 	  if (status != PATH_NOT_TAKEN)
 	    {
 	      gcc_assert (status == PATH_TAKEN);
-	      record_jump_equiv (insn, 1);
+	      if (any_condjump_p (insn))
+		record_jump_equiv (insn, true);
 
 	      /* Set the last insn as the jump insn; it doesn't affect cc0.
 		 Then follow this branch.  */


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