diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index fec772921c2daf9580d98d08b6d544f63a93cc72..12ad1e27d45679ff3f5453dd9714e9af04776373 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,30 @@
+2005-01-19  Kenneth Zadeck <zadeck@naturalbridge.com>
+
+	* df-scan.c (df_scan_free_bb_info): Added basic block parameter to
+	be able to clean out basic block when not necessary.
+	(df_scan_free): Fixed to properly delete information if df is
+	unused before calling df_finish.
+	(df_scan_alloc, df_rescan_blocks, df_reg_chain_unlink,
+	df_insn_create_insn_record, df_bb_refs_record): Fixed formatting
+	or comment typos.
+	(df_bb_refs_delete): New function.
+	(df_refs_delete): Moved per block code to df_bb_refs_delete.
+	* df-core.c (df_set_blocks): Added code to properly clean out
+	unused blocks if they are not part of the blocks to consider.
+	Added additional null check.
+	(df_compact_blocks): Added basic block parameter to free_bb_fun to
+	be able to clean out basic block when not necessary
+	* df.h (df_free_bb_function): Ditto.
+	(df_bb_refs_delete): New function.
+	* df-problems.c (df_ru_free_bb_info, df_rd_set_bb_info,
+	df_lr_set_bb_info, df_ur_free_bb_info, df_urec_free_bb_info):Added
+	basic block parameter to be able to clean out basic block when not
+	necessary.
+	(df_ru_alloc, df_rd_alloc): Fixed dyslexic overflow test.
+	(df_ru_free, df_rd_free, df_lr_free, df_ur_free, df_urec_free):
+	Fixed to properly delete information if df is unused before
+	calling df_finish.
+
 2005-01-19  Kenneth Zadeck <zadeck@naturalbridge.com>
 
 	PR rtl-optimization/25799 
diff --git a/gcc/df-core.c b/gcc/df-core.c
index 59602dea2917265e8a5733aa3d411daab0883fbb..87d9324d80f3c9a83da4e6b742bf4de127d7404c 100644
--- a/gcc/df-core.c
+++ b/gcc/df-core.c
@@ -354,7 +354,30 @@ df_set_blocks (struct df *df, bitmap blocks)
 {
   if (blocks)
     {
-      if (!df->blocks_to_analyze)
+      if (df->blocks_to_analyze)
+	{
+	  int p;
+	  bitmap diff = BITMAP_ALLOC (NULL);
+	  bitmap_and_compl (diff, df->blocks_to_analyze, blocks);
+	  for (p = 0; p < df->num_problems_defined; p++)
+	    {
+	      struct dataflow *dflow = df->problems_in_order[p];
+	      if (*dflow->problem->free_bb_fun)
+		{
+		  bitmap_iterator bi;
+		  unsigned int bb_index;
+		  
+		  EXECUTE_IF_SET_IN_BITMAP (diff, 0, bb_index, bi)
+		    {
+		      basic_block bb = BASIC_BLOCK (bb_index);
+		      (*dflow->problem->free_bb_fun) (dflow, bb, diff);
+		    }
+		}
+	    }
+
+	  BITMAP_FREE (diff);
+	}
+      else
 	df->blocks_to_analyze = BITMAP_ALLOC (NULL);
       bitmap_copy (df->blocks_to_analyze, blocks);
     }
@@ -781,8 +804,10 @@ df_compact_blocks (struct df *df)
 	     These are from orphaned blocks.  */
 	  for (i = NUM_FIXED_BLOCKS; i < last_basic_block; i++)
 	    {
-	      if (problem_temps[i])
-		(*dflow->problem->free_bb_fun) (dflow, problem_temps[i]);
+	      basic_block bb = BASIC_BLOCK (i); 
+	      if (problem_temps[i] && bb)
+		(*dflow->problem->free_bb_fun) 
+		  (dflow, bb, problem_temps[i]);
 	    }
 	}
     }
diff --git a/gcc/df-problems.c b/gcc/df-problems.c
index 790b3e244a1bafe1e12ad9cec4761224e1e4408f..ecc8eab6627f35365e42076dfd15259497feb4b2 100644
--- a/gcc/df-problems.c
+++ b/gcc/df-problems.c
@@ -324,7 +324,9 @@ df_ru_set_bb_info (struct dataflow *dflow, unsigned int index,
 /* Free basic block info.  */
 
 static void
-df_ru_free_bb_info (struct dataflow *dflow, void *vbb_info)
+df_ru_free_bb_info (struct dataflow *dflow, 
+		    basic_block bb ATTRIBUTE_UNUSED, 
+		    void *vbb_info)
 {
   struct df_ru_bb_info *bb_info = (struct df_ru_bb_info *) vbb_info;
   if (bb_info)
@@ -687,35 +689,38 @@ df_ru_free (struct dataflow *dflow)
   struct df_ru_problem_data *problem_data =
     (struct df_ru_problem_data *) dflow->problem_data;
 
-  for (i = 0; i < dflow->block_info_size; i++)
+  if (problem_data)
     {
-      struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, i);
-      if (bb_info)
+      for (i = 0; i < dflow->block_info_size; i++)
 	{
-	  BITMAP_FREE (bb_info->kill);
-	  BITMAP_FREE (bb_info->sparse_kill);
-	  BITMAP_FREE (bb_info->gen);
-	  BITMAP_FREE (bb_info->in);
-	  BITMAP_FREE (bb_info->out);
+	  struct df_ru_bb_info *bb_info = df_ru_get_bb_info (dflow, i);
+	  if (bb_info)
+	    {
+	      BITMAP_FREE (bb_info->kill);
+	      BITMAP_FREE (bb_info->sparse_kill);
+	      BITMAP_FREE (bb_info->gen);
+	      BITMAP_FREE (bb_info->in);
+	      BITMAP_FREE (bb_info->out);
+	    }
 	}
+      
+      free_alloc_pool (dflow->block_pool);
+      
+      for (i = 0; i < problem_data->use_sites_size; i++)
+	{
+	  bitmap bm = problem_data->use_sites[i];
+	  if (bm)
+	    BITMAP_FREE (bm);
+	}
+      
+      free (problem_data->use_sites);
+      BITMAP_FREE (problem_data->sparse_invalidated_by_call);
+      BITMAP_FREE (problem_data->dense_invalidated_by_call);
+      
+      dflow->block_info_size = 0;
+      free (dflow->block_info);
+      free (dflow->problem_data);
     }
-
-  free_alloc_pool (dflow->block_pool);
-
-  for (i = 0; i < problem_data->use_sites_size; i++)
-    {
-      bitmap bm = problem_data->use_sites[i];
-      if (bm)
-	BITMAP_FREE (bm);
-    }
-
-  free (problem_data->use_sites);
-  BITMAP_FREE (problem_data->sparse_invalidated_by_call);
-  BITMAP_FREE (problem_data->dense_invalidated_by_call);
-
-  dflow->block_info_size = 0;
-  free (dflow->block_info);
-  free (dflow->problem_data);
   free (dflow);
 }
 
@@ -837,7 +842,9 @@ df_rd_set_bb_info (struct dataflow *dflow, unsigned int index,
 /* Free basic block info.  */
 
 static void
-df_rd_free_bb_info (struct dataflow *dflow, void *vbb_info)
+df_rd_free_bb_info (struct dataflow *dflow, 
+		    basic_block bb ATTRIBUTE_UNUSED, 
+		    void *vbb_info)
 {
   struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
   if (bb_info)
@@ -1174,35 +1181,38 @@ df_rd_free (struct dataflow *dflow)
   struct df_rd_problem_data *problem_data =
     (struct df_rd_problem_data *) dflow->problem_data;
 
-  for (i = 0; i < dflow->block_info_size; i++)
+  if (problem_data)
     {
-      struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, i);
-      if (bb_info)
+      for (i = 0; i < dflow->block_info_size; i++)
 	{
-	  BITMAP_FREE (bb_info->kill);
-	  BITMAP_FREE (bb_info->sparse_kill);
-	  BITMAP_FREE (bb_info->gen);
-	  BITMAP_FREE (bb_info->in);
-	  BITMAP_FREE (bb_info->out);
+	  struct df_rd_bb_info *bb_info = df_rd_get_bb_info (dflow, i);
+	  if (bb_info)
+	    {
+	      BITMAP_FREE (bb_info->kill);
+	      BITMAP_FREE (bb_info->sparse_kill);
+	      BITMAP_FREE (bb_info->gen);
+	      BITMAP_FREE (bb_info->in);
+	      BITMAP_FREE (bb_info->out);
+	    }
 	}
+      
+      free_alloc_pool (dflow->block_pool);
+      
+      for (i = 0; i < problem_data->def_sites_size; i++)
+	{
+	  bitmap bm = problem_data->def_sites[i];
+	  if (bm)
+	    BITMAP_FREE (bm);
+	}
+      
+      free (problem_data->def_sites);
+      BITMAP_FREE (problem_data->sparse_invalidated_by_call);
+      BITMAP_FREE (problem_data->dense_invalidated_by_call);
+      
+      dflow->block_info_size = 0;
+      free (dflow->block_info);
+      free (dflow->problem_data);
     }
-
-  free_alloc_pool (dflow->block_pool);
-
-  for (i = 0; i < problem_data->def_sites_size; i++)
-    {
-      bitmap bm = problem_data->def_sites[i];
-      if (bm)
-	BITMAP_FREE (bm);
-    }
-
-  free (problem_data->def_sites);
-  BITMAP_FREE (problem_data->sparse_invalidated_by_call);
-  BITMAP_FREE (problem_data->dense_invalidated_by_call);
-
-  dflow->block_info_size = 0;
-  free (dflow->block_info);
-  free (dflow->problem_data);
   free (dflow);
 }
 
@@ -1315,7 +1325,9 @@ df_lr_set_bb_info (struct dataflow *dflow, unsigned int index,
 /* Free basic block info.  */
 
 static void
-df_lr_free_bb_info (struct dataflow *dflow, void *vbb_info)
+df_lr_free_bb_info (struct dataflow *dflow, 
+		    basic_block bb ATTRIBUTE_UNUSED, 
+		    void *vbb_info)
 {
   struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
   if (bb_info)
@@ -1586,22 +1598,25 @@ df_lr_transfer_function (struct dataflow *dflow, int bb_index)
 static void
 df_lr_free (struct dataflow *dflow)
 {
-  unsigned int i;
-  for (i = 0; i < dflow->block_info_size; i++)
+  if (dflow->block_info)
     {
-      struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, i);
-      if (bb_info)
+      unsigned int i;
+      for (i = 0; i < dflow->block_info_size; i++)
 	{
-	  BITMAP_FREE (bb_info->use);
-	  BITMAP_FREE (bb_info->def);
-	  BITMAP_FREE (bb_info->in);
-	  BITMAP_FREE (bb_info->out);
+	  struct df_lr_bb_info *bb_info = df_lr_get_bb_info (dflow, i);
+	  if (bb_info)
+	    {
+	      BITMAP_FREE (bb_info->use);
+	      BITMAP_FREE (bb_info->def);
+	      BITMAP_FREE (bb_info->in);
+	      BITMAP_FREE (bb_info->out);
+	    }
 	}
+      free_alloc_pool (dflow->block_pool);
+      
+      dflow->block_info_size = 0;
+      free (dflow->block_info);
     }
-  free_alloc_pool (dflow->block_pool);
-
-  dflow->block_info_size = 0;
-  free (dflow->block_info);
   free (dflow);
 }
 
@@ -1695,7 +1710,9 @@ df_ur_set_bb_info (struct dataflow *dflow, unsigned int index,
 /* Free basic block info.  */
 
 static void
-df_ur_free_bb_info (struct dataflow *dflow, void *vbb_info)
+df_ur_free_bb_info (struct dataflow *dflow, 
+		    basic_block bb ATTRIBUTE_UNUSED, 
+		    void *vbb_info)
 {
   struct df_ur_bb_info *bb_info = (struct df_ur_bb_info *) vbb_info;
   if (bb_info)
@@ -1915,23 +1932,26 @@ df_ur_transfer_function (struct dataflow *dflow, int bb_index)
 static void
 df_ur_free (struct dataflow *dflow)
 {
-  unsigned int i;
-
-  for (i = 0; i < dflow->block_info_size; i++)
+  if (dflow->block_info)
     {
-      struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, i);
-      if (bb_info)
+      unsigned int i;
+      
+      for (i = 0; i < dflow->block_info_size; i++)
 	{
-	  BITMAP_FREE (bb_info->gen);
-	  BITMAP_FREE (bb_info->kill);
-	  BITMAP_FREE (bb_info->in);
-	  BITMAP_FREE (bb_info->out);
+	  struct df_ur_bb_info *bb_info = df_ur_get_bb_info (dflow, i);
+	  if (bb_info)
+	    {
+	      BITMAP_FREE (bb_info->gen);
+	      BITMAP_FREE (bb_info->kill);
+	      BITMAP_FREE (bb_info->in);
+	      BITMAP_FREE (bb_info->out);
+	    }
 	}
+      
+      free_alloc_pool (dflow->block_pool);
+      dflow->block_info_size = 0;
+      free (dflow->block_info);
     }
-
-  free_alloc_pool (dflow->block_pool);
-  dflow->block_info_size = 0;
-  free (dflow->block_info);
   free (dflow);
 }
 
@@ -2039,7 +2059,9 @@ df_urec_set_bb_info (struct dataflow *dflow, unsigned int index,
 /* Free basic block info.  */
 
 static void
-df_urec_free_bb_info (struct dataflow *dflow, void *vbb_info)
+df_urec_free_bb_info (struct dataflow *dflow, 
+		      basic_block bb ATTRIBUTE_UNUSED, 
+		      void *vbb_info)
 {
   struct df_urec_bb_info *bb_info = (struct df_urec_bb_info *) vbb_info;
   if (bb_info)
@@ -2529,26 +2551,29 @@ df_urec_transfer_function (struct dataflow *dflow, int bb_index)
 static void
 df_urec_free (struct dataflow *dflow)
 {
-  unsigned int i;
-
-  for (i = 0; i < dflow->block_info_size; i++)
+  if (dflow->block_info)
     {
-      struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, i);
-      if (bb_info)
+      unsigned int i;
+      
+      for (i = 0; i < dflow->block_info_size; i++)
 	{
-	  BITMAP_FREE (bb_info->gen);
-	  BITMAP_FREE (bb_info->kill);
-	  BITMAP_FREE (bb_info->in);
-	  BITMAP_FREE (bb_info->out);
-	  BITMAP_FREE (bb_info->earlyclobber);
+	  struct df_urec_bb_info *bb_info = df_urec_get_bb_info (dflow, i);
+	  if (bb_info)
+	    {
+	      BITMAP_FREE (bb_info->gen);
+	      BITMAP_FREE (bb_info->kill);
+	      BITMAP_FREE (bb_info->in);
+	      BITMAP_FREE (bb_info->out);
+	      BITMAP_FREE (bb_info->earlyclobber);
+	    }
 	}
+      
+      free_alloc_pool (dflow->block_pool);
+      
+      dflow->block_info_size = 0;
+      free (dflow->block_info);
+      free (dflow->problem_data);
     }
-
-  free_alloc_pool (dflow->block_pool);
-  
-  dflow->block_info_size = 0;
-  free (dflow->block_info);
-  free (dflow->problem_data);
   free (dflow);
 }
 
diff --git a/gcc/df-scan.c b/gcc/df-scan.c
index 82de4a8b2a7a7133e064105d87391694c653babd..8f1995660a3c3d0e494dfdbf139c709f2e808571 100644
--- a/gcc/df-scan.c
+++ b/gcc/df-scan.c
@@ -181,11 +181,14 @@ df_scan_set_bb_info (struct dataflow *dflow, unsigned int index,
 /* Free basic block info.  */
 
 static void
-df_scan_free_bb_info (struct dataflow *dflow, void *vbb_info)
+df_scan_free_bb_info (struct dataflow *dflow, basic_block bb, void *vbb_info)
 {
   struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
   if (bb_info)
-    pool_free (dflow->block_pool, bb_info);
+    {
+      df_bb_refs_delete (dflow, bb->index);
+      pool_free (dflow->block_pool, bb_info);
+    }
 }
 
 
@@ -222,7 +225,6 @@ df_scan_alloc (struct dataflow *dflow, bitmap blocks_to_rescan)
   problem_data->insn_pool 
     = create_alloc_pool ("df_scan_insn pool", 
 			 sizeof (struct df_insn_info), block_size);
-
   problem_data->reg_pool 
     = create_alloc_pool ("df_scan_reg pool", 
 			 sizeof (struct df_reg_info), block_size);
@@ -261,14 +263,18 @@ df_scan_free (struct dataflow *dflow)
 {
   struct df *df = dflow->df;
   
-  df_scan_free_internal (dflow);
+  if (dflow->problem_data)
+    {
+      df_scan_free_internal (dflow);
+      free (dflow->problem_data);
+    }
+
   if (df->blocks_to_scan)
     BITMAP_FREE (df->blocks_to_scan);
   
   if (df->blocks_to_analyze)
     BITMAP_FREE (df->blocks_to_analyze);
 
-  free (dflow->problem_data);
   free (dflow);
 }
 
@@ -412,7 +418,7 @@ df_rescan_blocks (struct df *df, bitmap blocks)
 {
   bitmap local_blocks_to_scan = BITMAP_ALLOC (NULL);
 
-  struct dataflow *dflow = df->problems_by_index [DF_SCAN];
+  struct dataflow *dflow = df->problems_by_index[DF_SCAN];
   basic_block bb;
 
   df->def_info.refs_organized = false;
@@ -655,7 +661,7 @@ df_reg_chain_unlink (struct dataflow *dflow, struct df_ref *ref)
 void
 df_ref_remove (struct df *df, struct df_ref *ref)
 {
-  struct dataflow *dflow = df->problems_by_index [DF_SCAN];
+  struct dataflow *dflow = df->problems_by_index[DF_SCAN];
   if (DF_REF_REG_DEF_P (ref))
     {
       if (DF_REF_FLAGS (ref) & DF_REF_ARTIFICIAL)
@@ -713,7 +719,8 @@ df_insn_create_insn_record (struct dataflow *dflow, rtx insn)
   return insn_rec;
 }
 
-/* Delete all of the refs information from BLOCKS.  */
+
+/* Delete all of the refs information from INSN.  */
 
 void 
 df_insn_refs_delete (struct dataflow *dflow, rtx insn)
@@ -741,6 +748,42 @@ df_insn_refs_delete (struct dataflow *dflow, rtx insn)
 }
 
 
+/* Delete all of the refs information from basic_block with BB_INDEX.  */
+
+void
+df_bb_refs_delete (struct dataflow *dflow, int bb_index)
+{
+  struct df_ref *def;
+  struct df_ref *use;
+
+  struct df_scan_bb_info *bb_info 
+    = df_scan_get_bb_info (dflow, bb_index);
+  rtx insn;
+  basic_block bb = BASIC_BLOCK (bb_index);
+  FOR_BB_INSNS (bb, insn)
+    {
+      if (INSN_P (insn))
+	{
+	  /* Record defs within INSN.  */
+	  df_insn_refs_delete (dflow, insn);
+	}
+    }
+  
+  /* Get rid of any artifical uses.  */
+  if (bb_info)
+    {
+      def = bb_info->artificial_defs;
+      while (def)
+	def = df_reg_chain_unlink (dflow, def);
+      bb_info->artificial_defs = NULL;
+      use = bb_info->artificial_uses;
+      while (use)
+	use = df_reg_chain_unlink (dflow, use);
+      bb_info->artificial_uses = NULL;
+    }
+}
+
+
 /* Delete all of the refs information from BLOCKS.  */
 
 void 
@@ -748,36 +791,10 @@ df_refs_delete (struct dataflow *dflow, bitmap blocks)
 {
   bitmap_iterator bi;
   unsigned int bb_index;
-  struct df_ref *def;
-  struct df_ref *use;
 
   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, bb_index, bi)
     {
-      struct df_scan_bb_info *bb_info 
-	= df_scan_get_bb_info (dflow, bb_index);
-      rtx insn;
-      basic_block bb = BASIC_BLOCK (bb_index);
-      FOR_BB_INSNS (bb, insn)
-	{
-	  if (INSN_P (insn))
-	    {
-	      /* Record defs within INSN.  */
-	      df_insn_refs_delete (dflow, insn);
-	    }
-	}
-
-      /* Get rid of any artifical uses.  */
-      if (bb_info)
-	{
-	  def = bb_info->artificial_defs;
-	  while (def)
-	    def = df_reg_chain_unlink (dflow, def);
-	  bb_info->artificial_defs = NULL;
-	  use = bb_info->artificial_uses;
-	  while (use)
-	    use = df_reg_chain_unlink (dflow, use);
-	  bb_info->artificial_uses = NULL;
-	}
+      df_bb_refs_delete (dflow, bb_index);
     }
 }
 
@@ -1568,7 +1585,7 @@ df_bb_refs_record (struct dataflow *dflow, basic_block bb)
 	  
 	  /* Any reference to any pseudo before reload is a potential
 	     reference of the frame pointer.  */
-	  df_uses_record (dflow, &regno_reg_rtx [FRAME_POINTER_REGNUM],
+	  df_uses_record (dflow, &regno_reg_rtx[FRAME_POINTER_REGNUM],
 			  DF_REF_REG_USE, bb, NULL, DF_REF_ARTIFICIAL);
 	  
 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
diff --git a/gcc/df.h b/gcc/df.h
index 09a112762bf6abcd2780107afeb545fd9d2b5e17..a353d36ce11eac02d2d475d41e22d97d6ac238d0 100644
--- a/gcc/df.h
+++ b/gcc/df.h
@@ -69,7 +69,7 @@ typedef void (*df_alloc_function) (struct dataflow *, bitmap);
 
 /* Free the basic block info.  Called from the block reordering code
    to get rid of the blocks that have been squished down.   */
-typedef void (*df_free_bb_function) (struct dataflow *, void *);
+typedef void (*df_free_bb_function) (struct dataflow *, basic_block, void *);
 
 /* Local compute function.  */
 typedef void (*df_local_compute_function) (struct dataflow *, bitmap, bitmap);
@@ -569,6 +569,7 @@ extern void df_reg_chain_create (struct df_reg_info *, struct df_ref *);
 extern struct df_ref *df_reg_chain_unlink (struct dataflow *, struct df_ref *);
 extern void df_ref_remove (struct df *, struct df_ref *);
 extern void df_insn_refs_delete (struct dataflow *, rtx);
+extern void df_bb_refs_delete (struct dataflow *, int);
 extern void df_refs_delete (struct dataflow *, bitmap);
 extern void df_reorganize_refs (struct df_ref_info *);
 extern void df_set_state (int);