diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 187b81c08c6af9976443cc3e6278bd04d466447f..3bb9763337c287789f1e190f8bb4cb33f0a9e04e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,42 @@
+2012-07-20  Steven Bosscher  <steven@gcc.gnu.org>
+
+	* basic-block.h (BB_FLAGS_TO_PRESERVE): New define.
+	(brief_dump_cfg): Update prototype to take flags argument.
+	(check_bb_profile): Remove prototype.
+	* tracer.c (tracer): Update brief_dump_cfg calls.
+	* cfghooks.c (dump_bb): Do not pass TDF_COMMENT to dump_bb_info.
+	Call dump_bb_info before and after the cfghook dump_bb.  Terminate
+	the dump with a newline.
+	(dump_flow_info): Do not call check_bb_profile.
+	* cfg.c (clear_bb_flags): Update using BB_FLAGS_TO_PRESERVE.
+	(check_bb_profile): Make static.  Take indent and flags arguments.
+	(dump_bb_info): Always dump loop depth.  With TDF_DETAILS, call
+	check_bb_profile.  Print one edge per line.
+	(brief_dump_cfg): Take a flags argument, and filter out
+	TDF_COMMENT and TDF_DETAILS.
+	* pretty-print.c (pp_base_newline): Set pp_needs_newline to false.
+	* gimple-pretty-print.c (dump_gimple_bb_header): Do not use dump_bb_info
+	here, it is already called from dump_bb.  Idem for check_bb_profile.
+	(dump_gimple_bb_footer): Likewise.
+	(gimple_dump_bb_buff): Call pp_flush after dump_gimple_stmt to
+	avoid broken dumps for statement histograms.
+	(gimple_dump_bb): Handle ENTRY_BLOCK and EXIT_BLOCK.  Do
+	not call pp_flush here, the buffer should be empty.
+	* sched-rgn.c (debug_region): Pass TDF_BLOCKS to dump_bb.
+	* sched-vis.c (debug_bb_slim): Likewise.
+	* tree-cfg.c (remove_bb): Pass dump_flags to dump_bb.
+	(gimple_debug_bb): Pass TDF_BLOCKS to dump_bb.
+	(gimple_dump_cfg): Do brief_dump_cfg with TDF_COMMENT.
+	(dump_function_to_file): Do not call check_bb_profile on
+	ENTRY_BLOCK and EXIT_BLOCK, check_bb_profile doesn't handle them.
+	Use dump_bb instead of gimple_dump_bb.
+	(print_loops_bb): Use dump_bb instead of gimple_dump_bb.
+	* passes.c (execute_function_dump): Always call print_rtl_with_bb
+	for RTL dumps.
+	* cfgrtl.c (print_rtl_with_bb): Handle printing without an up-to-date
+	CFG.  With TDF_BLOCKS and TDF_DETAILS, do DF dumps at the top and bottom
+	of each basic block.
+
 2012-07-20  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/54031
@@ -1398,7 +1437,7 @@
 	(flow_nodes_print): Remove.
 	(flow_edge_list_print): Remove.
 	(inverted_post_order_compute): Use FOR_ALL_BB.
-	*cfgrtl.c (dump_flow_info): Moved from cfg.c.
+	* cfgrtl.c (dump_flow_info): Moved from cfg.c.
 	Do not call dump_reg_info.
 	(debug_flow_info): Moved from cfg.c
 	(dump_bb_info): Moved from cfg.c.  Take 'verbose' argument
diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index bf18baef139c99fbd502f5844778b56cd83c56e0..24f178f3e75234c4d78346e642a772f72284e5ef 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -203,9 +203,15 @@ enum cfg_bb_flags
 };
 #undef DEF_BASIC_BLOCK_FLAG
 
-/* Bit mask for all edge flags.  */
+/* Bit mask for all basic block flags.  */
 #define BB_ALL_FLAGS		((LAST_CFG_BB_FLAG - 1) * 2 - 1)
 
+/* Bit mask for all basic block flags that must be preserved.  These are
+   the bit masks that are *not* cleared by clear_bb_flags.  */
+#define BB_FLAGS_TO_PRESERVE					\
+  (BB_DISABLE_SCHEDULE | BB_RTL | BB_NON_LOCAL_GOTO_TARGET	\
+   | BB_HOT_PARTITION | BB_COLD_PARTITION)
+
 /* Dummy bitmask for convenience in the hot/cold partitioning code.  */
 #define BB_UNPARTITIONED	0
 
@@ -395,7 +401,7 @@ extern basic_block create_basic_block_structure (rtx, rtx, rtx, basic_block);
 extern void clear_bb_flags (void);
 extern void dump_bb_info (FILE *, basic_block, int, int, bool, bool);
 extern void dump_edge_info (FILE *, edge, int, int);
-extern void brief_dump_cfg (FILE *);
+extern void brief_dump_cfg (FILE *, int);
 extern void clear_edges (void);
 extern void scale_bbs_frequencies_int (basic_block *, int, int, int);
 extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,
@@ -816,7 +822,6 @@ unsigned bb_dom_dfs_out (enum cdi_direction, basic_block);
 extern edge try_redirect_by_replacing_jump (edge, basic_block, bool);
 extern void break_superblocks (void);
 extern void relink_block_chain (bool);
-extern void check_bb_profile (basic_block, FILE *);
 extern void update_bb_profile_for_threading (basic_block, int, gcov_type, edge);
 extern void init_rtl_bb_info (basic_block);
 
diff --git a/gcc/cfg-flags.def b/gcc/cfg-flags.def
index a9aaf186ec1343d99da470e3b763fbe20262b521..839b9b358cf4cfc077e16fd42926b3218ab6988e 100644
--- a/gcc/cfg-flags.def
+++ b/gcc/cfg-flags.def
@@ -90,8 +90,7 @@ DEF_BASIC_BLOCK_FLAG(MODIFIED, 12)
 DEF_BASIC_BLOCK_FLAG(VISITED, 13)
 
 /* Set on blocks that are in a transaction.  This is calculated on
-   demand, and is available after calling
-   compute_transaction_bits().  */
+   demand, and is available after calling compute_transaction_bits().  */
 DEF_BASIC_BLOCK_FLAG(IN_TRANSACTION, 14)
 
 #endif
diff --git a/gcc/cfg.c b/gcc/cfg.c
index 66458e337dee4322dd738c265a80f8fd8c41705b..f8614074ff64a0c76740937882d52b3e53e9445b 100644
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -382,16 +382,14 @@ redirect_edge_pred (edge e, basic_block new_pred)
   connect_src (e);
 }
 
-/* Clear all basic block flags, with the exception of partitioning and
-   setjmp_target.  */
+/* Clear all basic block flags that do not have to be preserved.  */
 void
 clear_bb_flags (void)
 {
   basic_block bb;
 
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
-    bb->flags = (BB_PARTITION (bb)
-		 | (bb->flags & (BB_DISABLE_SCHEDULE + BB_RTL + BB_NON_LOCAL_GOTO_TARGET)));
+    bb->flags &= BB_FLAGS_TO_PRESERVE;
 }
 
 /* Check the consistency of profile information.  We can't do that
@@ -399,13 +397,16 @@ clear_bb_flags (void)
    solved graphs, later eliminating of conditionals or roundoff errors.
    It is still practical to have them reported for debugging of simple
    testcases.  */
-void
-check_bb_profile (basic_block bb, FILE * file)
+static void
+check_bb_profile (basic_block bb, FILE * file, int indent, int flags)
 {
   edge e;
   int sum = 0;
   gcov_type lsum;
   edge_iterator ei;
+  char *s_indent = (char *) alloca ((size_t) indent + 1);
+  memset ((void *) s_indent, ' ', (size_t) indent);
+  s_indent[indent] = '\0';
 
   if (profile_status == PROFILE_ABSENT)
     return;
@@ -415,14 +416,16 @@ check_bb_profile (basic_block bb, FILE * file)
       FOR_EACH_EDGE (e, ei, bb->succs)
 	sum += e->probability;
       if (EDGE_COUNT (bb->succs) && abs (sum - REG_BR_PROB_BASE) > 100)
-	fprintf (file, "Invalid sum of outgoing probabilities %.1f%%\n",
+	fprintf (file, "%s%sInvalid sum of outgoing probabilities %.1f%%\n",
+		 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
 		 sum * 100.0 / REG_BR_PROB_BASE);
       lsum = 0;
       FOR_EACH_EDGE (e, ei, bb->succs)
 	lsum += e->count;
       if (EDGE_COUNT (bb->succs)
 	  && (lsum - bb->count > 100 || lsum - bb->count < -100))
-	fprintf (file, "Invalid sum of outgoing counts %i, should be %i\n",
+	fprintf (file, "%s%sInvalid sum of outgoing counts %i, should be %i\n",
+		 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
 		 (int) lsum, (int) bb->count);
     }
   if (bb != ENTRY_BLOCK_PTR)
@@ -432,13 +435,15 @@ check_bb_profile (basic_block bb, FILE * file)
 	sum += EDGE_FREQUENCY (e);
       if (abs (sum - bb->frequency) > 100)
 	fprintf (file,
-		 "Invalid sum of incoming frequencies %i, should be %i\n",
+		 "%s%sInvalid sum of incoming frequencies %i, should be %i\n",
+		 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
 		 sum, bb->frequency);
       lsum = 0;
       FOR_EACH_EDGE (e, ei, bb->preds)
 	lsum += e->count;
       if (lsum - bb->count > 100 || lsum - bb->count < -100)
-	fprintf (file, "Invalid sum of incoming counts %i, should be %i\n",
+	fprintf (file, "%s%sInvalid sum of incoming counts %i, should be %i\n",
+		 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
 		 (int) lsum, (int) bb->count);
     }
 }
@@ -679,6 +684,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
 #undef DEF_BASIC_BLOCK_FLAG
     };
   const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+  bool first;
   char *s_indent = (char *) alloca ((size_t) indent + 1);
   memset ((void *) s_indent, ' ', (size_t) indent);
   s_indent[indent] = '\0';
@@ -691,11 +697,12 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
 
       if (flags & TDF_COMMENT)
 	fputs (";; ", outf);
-      fprintf (outf, "%sbasic block %d", s_indent, bb->index);
+      fprintf (outf, "%sbasic block %d, loop depth %d",
+	       s_indent, bb->index, bb->loop_depth);
       if (flags & TDF_DETAILS)
 	{
-	  fprintf (outf, ", loop depth %d, count " HOST_WIDEST_INT_PRINT_DEC,
-		   bb->loop_depth, (HOST_WIDEST_INT) bb->count);
+	  fprintf (outf, ", count " HOST_WIDEST_INT_PRINT_DEC,
+		   (HOST_WIDEST_INT) bb->count);
 	  fprintf (outf, ", freq %i", bb->frequency);
 	  if (maybe_hot_bb_p (bb))
 	    fputs (", maybe hot", outf);
@@ -703,11 +710,11 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
 	    fputs (", probably never executed", outf);
 	}
       fputc ('\n', outf);
+      if (TDF_DETAILS)
+	check_bb_profile (bb, outf, indent, flags);
 
       if (flags & TDF_DETAILS)
 	{
-	  bool first = true;
-
 	  if (flags & TDF_COMMENT)
 	    fputs (";; ", outf);
 	  fprintf (outf, "%s prev block ", s_indent);
@@ -722,6 +729,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
 	    fprintf (outf, "(nil)");
 
 	  fputs (", flags:", outf);
+	  first = true;
 	  for (i = 0; i < n_bitnames; i++)
 	    if (bb->flags & (1 << i))
 	      {
@@ -734,15 +742,25 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
 	      }
 	  if (!first)
 	    fputc (')', outf);
+	  fputc ('\n', outf);
 	}
-      fputc ('\n', outf);
 
       if (flags & TDF_COMMENT)
 	fputs (";; ", outf);
       fprintf (outf, "%s pred:      ", s_indent);
+      first = true;
       FOR_EACH_EDGE (e, ei, bb->preds)
-	dump_edge_info (outf, e, flags, 0);
-      fputc ('\n', outf);
+	{
+	  if (! first)
+	    {
+	      if (flags & TDF_COMMENT)
+		fputs (";; ", outf);
+	      fprintf (outf, "%s            ", s_indent);
+	    }
+	  first = false;
+	  dump_edge_info (outf, e, flags, 0);
+	  fputc ('\n', outf);
+	}
     }
 
   if (do_footer)
@@ -750,22 +768,34 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
       if (flags & TDF_COMMENT)
 	fputs (";; ", outf);
       fprintf (outf, "%s succ:      ", s_indent);
+      first = true;
       FOR_EACH_EDGE (e, ei, bb->succs)
-	dump_edge_info (outf, e, flags, 1);
-      fputs ("\n\n", outf);
+        {
+	  if (! first)
+	    {
+	      if (flags & TDF_COMMENT)
+		fputs (";; ", outf);
+	      fprintf (outf, "%s            ", s_indent);
+	    }
+	  first = false;
+	  dump_edge_info (outf, e, flags, 1);
+	  fputc ('\n', outf);
+	}
     }
 }
 
 /* Dumps a brief description of cfg to FILE.  */
 
 void
-brief_dump_cfg (FILE *file)
+brief_dump_cfg (FILE *file, int flags)
 {
   basic_block bb;
 
   FOR_EACH_BB (bb)
     {
-      dump_bb_info (file, bb, 0, 0, true, true);
+      dump_bb_info (file, bb, 0,
+		    flags & (TDF_COMMENT | TDF_DETAILS),
+		    true, true);
     }
 }
 
diff --git a/gcc/cfghooks.c b/gcc/cfghooks.c
index 69655390102f74220b5ac444dcdcd4908ef2acc1..be117cfbacf7833517f9962b1d2323200a9e3343 100644
--- a/gcc/cfghooks.c
+++ b/gcc/cfghooks.c
@@ -271,9 +271,11 @@ verify_flow_info (void)
 void
 dump_bb (FILE *outf, basic_block bb, int indent, int flags)
 {
-  dump_bb_info (outf, bb, indent, flags | TDF_COMMENT, true, true);
+  dump_bb_info (outf, bb, indent, flags, true, false);
   if (cfg_hooks->dump_bb)
     cfg_hooks->dump_bb (outf, bb, indent, flags);
+  dump_bb_info (outf, bb, indent, flags, false, true);
+  fputc ('\n', outf);
 }
 
 /* Dump the complete CFG to FILE.  FLAGS are the TDF_* flags in dumpfile.h.  */
@@ -284,10 +286,7 @@ dump_flow_info (FILE *file, int flags)
 
   fprintf (file, "\n%d basic blocks, %d edges.\n", n_basic_blocks, n_edges);
   FOR_ALL_BB (bb)
-    {
-      dump_bb (file, bb, 0, flags);
-      check_bb_profile (bb, file);
-    }
+    dump_bb (file, bb, 0, flags);
 
   putc ('\n', file);
 }
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index e87f06db3a0cb6459b9976897f1e26cba5caf4bf..2bf22d86880a8bb8d5736731f9ef388f0d13cde3 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -1875,8 +1875,9 @@ rtl_dump_bb (FILE *outf, basic_block bb, int indent, int flags)
 
 }
 
-/* Like print_rtl, but also print out live information for the start of each
-   basic block.  FLAGS are the flags documented in dumpfile.h.  */
+/* Like dump_function_to_file, but for RTL.  Print out dataflow information
+   for the start of each basic block.  FLAGS are the TDF_* masks documented
+   in dumpfile.h.  */
 
 void
 print_rtl_with_bb (FILE *outf, const_rtx rtx_first, int flags)
@@ -1891,52 +1892,74 @@ print_rtl_with_bb (FILE *outf, const_rtx rtx_first, int flags)
       basic_block *start = XCNEWVEC (basic_block, max_uid);
       basic_block *end = XCNEWVEC (basic_block, max_uid);
       enum bb_state *in_bb_p = XCNEWVEC (enum bb_state, max_uid);
-
       basic_block bb;
 
+      /* After freeing the CFG, we still have BLOCK_FOR_INSN set on most
+	 insns, but the CFG is not maintained so the basic block info
+	 is not reliable.  Therefore it's omitted from the dumps.  */
+      if (! (cfun->curr_properties & PROP_cfg))
+        flags &= ~TDF_BLOCKS;
+
       if (df)
 	df_dump_start (outf);
 
-      FOR_EACH_BB_REVERSE (bb)
+      if (flags & TDF_BLOCKS)
 	{
-	  rtx x;
-
-	  start[INSN_UID (BB_HEAD (bb))] = bb;
-	  end[INSN_UID (BB_END (bb))] = bb;
-	  for (x = BB_HEAD (bb); x != NULL_RTX; x = NEXT_INSN (x))
+	  FOR_EACH_BB_REVERSE (bb)
 	    {
-	      enum bb_state state = IN_MULTIPLE_BB;
+	      rtx x;
+
+	      start[INSN_UID (BB_HEAD (bb))] = bb;
+	      end[INSN_UID (BB_END (bb))] = bb;
+	      for (x = BB_HEAD (bb); x != NULL_RTX; x = NEXT_INSN (x))
+		{
+		  enum bb_state state = IN_MULTIPLE_BB;
 
-	      if (in_bb_p[INSN_UID (x)] == NOT_IN_BB)
-		state = IN_ONE_BB;
-	      in_bb_p[INSN_UID (x)] = state;
+		  if (in_bb_p[INSN_UID (x)] == NOT_IN_BB)
+		    state = IN_ONE_BB;
+		  in_bb_p[INSN_UID (x)] = state;
 
-	      if (x == BB_END (bb))
-		break;
+		  if (x == BB_END (bb))
+		    break;
+		}
 	    }
 	}
 
       for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
 	{
-	  bb = start[INSN_UID (tmp_rtx)];
-	  if (bb != NULL)
-	    dump_bb_info (outf, bb, 0, dump_flags | TDF_COMMENT, true, false);
+	  if (flags & TDF_BLOCKS)
+	    {
+	      bb = start[INSN_UID (tmp_rtx)];
+	      if (bb != NULL)
+		{
+		  dump_bb_info (outf, bb, 0, dump_flags | TDF_COMMENT, true, false);
+		  if (df && (flags & TDF_DETAILS))
+		    df_dump_top (bb, outf);
+		}
 
-	  if (in_bb_p[INSN_UID (tmp_rtx)] == NOT_IN_BB
-	      && !NOTE_P (tmp_rtx)
-	      && !BARRIER_P (tmp_rtx))
-	    fprintf (outf, ";; Insn is not within a basic block\n");
-	  else if (in_bb_p[INSN_UID (tmp_rtx)] == IN_MULTIPLE_BB)
-	    fprintf (outf, ";; Insn is in multiple basic blocks\n");
+	      if (in_bb_p[INSN_UID (tmp_rtx)] == NOT_IN_BB
+		  && !NOTE_P (tmp_rtx)
+		  && !BARRIER_P (tmp_rtx))
+		fprintf (outf, ";; Insn is not within a basic block\n");
+	      else if (in_bb_p[INSN_UID (tmp_rtx)] == IN_MULTIPLE_BB)
+		fprintf (outf, ";; Insn is in multiple basic blocks\n");
+	    }
 
 	  if (! (flags & TDF_SLIM))
 	    print_rtl_single (outf, tmp_rtx);
 	  else
 	    dump_insn_slim (outf, tmp_rtx);
 
-	  bb = end[INSN_UID (tmp_rtx)];
-	  if (bb != NULL)
-	    dump_bb_info (outf, bb, 0, dump_flags | TDF_COMMENT, false, true);
+	  if (flags & TDF_BLOCKS)
+	    {
+	      bb = end[INSN_UID (tmp_rtx)];
+	      if (bb != NULL)
+		{
+		  dump_bb_info (outf, bb, 0, dump_flags | TDF_COMMENT, false, true);
+		  if (df && (flags & TDF_DETAILS))
+		    df_dump_bottom (bb, outf);
+		}
+	    }
 
 	  putc ('\n', outf);
 	}
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index febf1d98dbc16f93bfa6b0f584a1cb7ae9caa963..ce9a3ac880d8b5d9eb9a81e3663614aa06f25fc1 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -115,7 +115,9 @@ print_gimple_expr (FILE *file, gimple g, int spc, int flags)
 
 
 /* Print the GIMPLE sequence SEQ on BUFFER using SPC indentantion
-   spaces and FLAGS as in dump_gimple_stmt.  */
+   spaces and FLAGS as in dump_gimple_stmt.
+   The caller is responsible for calling pp_flush on BUFFER to finalize
+   the pretty printer.  */
 
 static void
 dump_gimple_seq (pretty_printer *buffer, gimple_seq seq, int spc, int flags)
@@ -1578,8 +1580,9 @@ dump_gimple_asm (pretty_printer *buffer, gimple gs, int spc, int flags)
 }
 
 
-/* Dump a PHI node PHI.  BUFFER, SPC and FLAGS are as in
-   dump_gimple_stmt.  */
+/* Dump a PHI node PHI.  BUFFER, SPC and FLAGS are as in dump_gimple_stmt.
+   The caller is responsible for calling pp_flush on BUFFER to finalize
+   pretty printer.  */
 
 static void
 dump_gimple_phi (pretty_printer *buffer, gimple phi, int spc, int flags)
@@ -1843,7 +1846,8 @@ dump_gimple_mem_ops (pretty_printer *buffer, gimple gs, int spc, int flags)
 
 /* Dump the gimple statement GS on the pretty printer BUFFER, SPC
    spaces of indent.  FLAGS specifies details to show in the dump (see
-   TDF_* in dumpfile.h).  */
+   TDF_* in dumpfile.h).  The caller is responsible for calling
+   pp_flush on BUFFER to finalize the pretty printer.  */
 
 void
 dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags)
@@ -2067,8 +2071,6 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
 {
   if (flags & TDF_BLOCKS)
     {
-      dump_bb_info (outf, bb, indent, flags, true, false);
-
       if (flags & TDF_LINENO)
 	{
 	  gimple_stmt_iterator gsi;
@@ -2103,8 +2105,6 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
 	  fprintf (outf, "%s<bb %d>:\n", s_indent, bb->index);
 	}
     }
-  if (cfun)
-    check_bb_profile (bb, outf);
 }
 
 
@@ -2112,9 +2112,13 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
    spaces.  */
 
 static void
-dump_gimple_bb_footer (FILE *outf, basic_block bb, int indent, int flags)
+dump_gimple_bb_footer (FILE *outf ATTRIBUTE_UNUSED,
+		       basic_block bb ATTRIBUTE_UNUSED,
+		       int indent ATTRIBUTE_UNUSED,
+		       int flags ATTRIBUTE_UNUSED)
 {
-  dump_bb_info (outf, bb, indent, flags, false, true);
+  /* There is currently no GIMPLE-specific basic block info to dump.  */
+  return;
 }
 
 
@@ -2256,7 +2260,7 @@ gimple_dump_bb_buff (pretty_printer *buffer, basic_block bb, int indent,
 
       INDENT (curr_indent);
       dump_gimple_stmt (buffer, stmt, curr_indent, flags);
-      pp_newline (buffer);
+      pp_flush (buffer);
       dump_histograms_for_stmt (cfun, buffer->buffer->stream, stmt);
     }
 
@@ -2271,8 +2275,10 @@ void
 gimple_dump_bb (FILE *file, basic_block bb, int indent, int flags)
 {
   dump_gimple_bb_header (file, bb, indent, flags);
-  maybe_init_pretty_print (file);
-  gimple_dump_bb_buff (&buffer, bb, indent, flags);
-  pp_flush (&buffer);
+  if (bb->index >= NUM_FIXED_BLOCKS)
+    {
+      maybe_init_pretty_print (file);
+      gimple_dump_bb_buff (&buffer, bb, indent, flags);
+    }
   dump_gimple_bb_footer (file, bb, indent, flags);
 }
diff --git a/gcc/passes.c b/gcc/passes.c
index 5612a35a867de7b7c4d2625eaee050490ec5af82..7709671a052feac38af2dc434fafee7e4c033af1 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -1725,11 +1725,7 @@ execute_function_dump (void *data ATTRIBUTE_UNUSED)
         dump_function_to_file (current_function_decl, dump_file, dump_flags);
       else
 	{
-	  if ((cfun->curr_properties & PROP_cfg)
-	      && (dump_flags & TDF_BLOCKS))
-	    print_rtl_with_bb (dump_file, get_insns (), dump_flags);
-          else
-	    print_rtl (dump_file, get_insns ());
+	  print_rtl_with_bb (dump_file, get_insns (), dump_flags);
 
 	  if ((cfun->curr_properties & PROP_cfg)
 	      && graph_dump_format != no_graph
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 8aa99787c59ab5fe5fa77d34f5498f74ca6a0a10..4033ba38715d5d09c13caa1dbd4b3cb3312771be 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -759,6 +759,7 @@ void
 pp_base_newline (pretty_printer *pp)
 {
   obstack_1grow (pp->buffer->obstack, '\n');
+  pp_needs_newline (pp) = false;
   pp->buffer->line_length = 0;
 }
 
diff --git a/gcc/sched-rgn.c b/gcc/sched-rgn.c
index 69645b4ff49eeffa2643f0a63397e044eddc2d9b..1dd0d814a452082894131eea4858541a77ccc291 100644
--- a/gcc/sched-rgn.c
+++ b/gcc/sched-rgn.c
@@ -397,7 +397,7 @@ debug_region (int rgn)
   for (bb = 0; bb < rgn_table[rgn].rgn_nr_blocks; bb++)
     {
       dump_bb (stderr, BASIC_BLOCK (rgn_bb_table[current_blocks + bb]),
-	       0, TDF_SLIM);
+	       0, TDF_SLIM | TDF_BLOCKS);
       fprintf (stderr, "\n");
     }
 
diff --git a/gcc/sched-vis.c b/gcc/sched-vis.c
index 768aa133522483b39b92b26fed9d7573d2d76013..d5a8747169a4526319c3e8d3d5ec7fc5703955eb 100644
--- a/gcc/sched-vis.c
+++ b/gcc/sched-vis.c
@@ -810,7 +810,7 @@ extern void debug_bb_slim (basic_block);
 DEBUG_FUNCTION void
 debug_bb_slim (basic_block bb)
 {
-  dump_bb (stderr, bb, 0, TDF_SLIM);
+  dump_bb (stderr, bb, 0, TDF_SLIM | TDF_BLOCKS);
 }
 
 extern void debug_bb_n_slim (int);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f02f16ededfb95f7b829e4a270f7f64d26b4fb64..56aace37ff451b4d90bc8e93162022b4ca1dc3be 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2012-07-20  Steven Bosscher  <steven@gcc.gnu.org>
+
+	* gcc.dg/tree-prof/update-loopch.c: Look for counts on the dumps of
+	the basic block and check loop depth.
+	* gcc.dg/tree-ssa/pr18133-1.c: Dump details, not blocks.  Update
+	matching patterns and comments.
+	* gcc.dg/tree-ssa/20031021-1.c: Fix check patterns.
+	* gcc.dg/tree-ssa/vector-2.c: Likewise.
+
 2012-07-20  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/28656
diff --git a/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c b/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
index 2bce8a2e5ffaca4dd4c080a5d5c08af35febb781..3388996a8c9d33e26773dd91dc022394c4e0f70b 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/update-loopch.c
@@ -1,4 +1,4 @@
-/* { dg-options "-O2 -fdump-ipa-profile-blocks -fdump-tree-optimized-blocks" } */
+/* { dg-options "-O2 -fdump-ipa-profile-details -fdump-tree-optimized-details" } */
 int max = 33333;
 int a[8];
 int
@@ -14,8 +14,8 @@ main ()
 /* Loop header copying will peel away the initial conditional, so the loop body
    is once reached directly from entry point of function, rest via loopback
    edge.  */
-/* { dg-final-use { scan-ipa-dump "count:33333" "profile"} } */
-/* { dg-final-use { scan-tree-dump "count:33332" "optimized"} } */
+/* { dg-final-use { scan-ipa-dump "loop depth 1, count 33334" "profile"} } */
+/* { dg-final-use { scan-tree-dump "loop depth 1, count 33332" "optimized"} } */
 /* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
 /* { dg-final-use { cleanup-ipa-dump "profile" } } */
 /* { dg-final-use { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20031021-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20031021-1.c
index 117cddf12a799d6a4126ad2fbb690cc34f4206cb..7c34ff4496ac295ef921afa6410f764091e8b9fb 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/20031021-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/20031021-1.c
@@ -17,5 +17,5 @@ int main()
 }
 
 /* We should only store to a.i, not load from it.  */
-/* { dg-final { scan-tree-dump-times "a.i" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "= a.i" "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr18133-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr18133-1.c
index f225f662da4379a08d15bfe68ab375fe48cbc261..8a26479e2944f67cbbefae2c0dd42a3b830afea9 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr18133-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr18133-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized-blocks" } */
+/* { dg-options "-O1 -fdump-tree-optimized-details" } */
 
 void foo (void)
 {
@@ -12,17 +12,17 @@ return;
 
 /* The goto &L0 should have been optimized away during CFG
    cleanups.  */
-/* { dg-final { scan-tree-dump-times "goto &L0" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "goto &L0" "optimized" } } */
 
 /* There should not be any abnormal edges as DOM removed the
    computed goto.  */
 
-/* { dg-final { scan-tree-dump-times "ab" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "ABNORMAL" "optimized" } } */
 
 /* And verify that we have fixed the fallthru flag as well. 
    After DOM we will have two fallthru edges (e->0, 0->1),
-   but in the dump files we mention the 0->1 two times.  So
-   scan for 3 instances of "fallthru".  */
+   but in the dump files we mention the 2->3 two times.  So
+   scan for 3 instances of "FALLTHRU".  */
 
-/* { dg-final { scan-tree-dump-times "fallthru" 3 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "FALLTHRU" 3 "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vector-2.c b/gcc/testsuite/gcc.dg/tree-ssa/vector-2.c
index e34532d3faa5422abce3d1f9ade4a5a99fc140b6..2d214df40952b8a742e1e6d9c77e3faef666254d 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vector-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vector-2.c
@@ -17,7 +17,7 @@ float f(vector float a, int b, vector float c)
 }
 
 /* We should be able to optimize this to just "return 0.0;" */
-/* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 0 "optimized"} } */
-/* { dg-final { scan-tree-dump-times "0.0" 1 "optimized"} } */
+/* { dg-final { scan-tree-dump-not "BIT_FIELD_REF" "optimized"} } */
+/* { dg-final { scan-tree-dump-times "return 0.0" 1 "optimized"} } */
 
 /* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/tracer.c b/gcc/tracer.c
index bbf973aa215cb78647795a8a6aeb9fe94d4bc337..f60f3486e124a419b5a763fc5359689073b16557 100644
--- a/gcc/tracer.c
+++ b/gcc/tracer.c
@@ -374,7 +374,7 @@ tracer (void)
 
   mark_dfs_back_edges ();
   if (dump_file)
-    brief_dump_cfg (dump_file);
+    brief_dump_cfg (dump_file, dump_flags);
 
   /* Trace formation is done on the fly inside tail_duplicate */
   changed = tail_duplicate ();
@@ -382,7 +382,7 @@ tracer (void)
     free_dominance_info (CDI_DOMINATORS);
 
   if (dump_file)
-    brief_dump_cfg (dump_file);
+    brief_dump_cfg (dump_file, dump_flags);
 
   return changed ? TODO_cleanup_cfg : 0;
 }
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e4cf076f28beb0fdacff55284099c9c2ce903659..c9187b924565fc0406d6ac2d610f9f7681a5605d 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -1844,7 +1844,7 @@ remove_bb (basic_block bb)
       fprintf (dump_file, "Removing basic block %d\n", bb->index);
       if (dump_flags & TDF_DETAILS)
 	{
-	  dump_bb (dump_file, bb, 0, 0);
+	  dump_bb (dump_file, bb, 0, dump_flags);
 	  fprintf (dump_file, "\n");
 	}
     }
@@ -2063,7 +2063,7 @@ find_case_label_for_value (gimple switch_stmt, tree val)
 void
 gimple_debug_bb (basic_block bb)
 {
-  dump_bb (stderr, bb, 0, TDF_VOPS|TDF_MEMSYMS);
+  dump_bb (stderr, bb, 0, TDF_VOPS|TDF_MEMSYMS|TDF_BLOCKS);
 }
 
 
@@ -2103,7 +2103,7 @@ gimple_dump_cfg (FILE *file, int flags)
       fprintf (file, ";; \n%d basic blocks, %d edges, last basic block %d.\n\n",
 	       n_basic_blocks, n_edges, last_basic_block);
 
-      brief_dump_cfg (file);
+      brief_dump_cfg (file, flags | TDF_COMMENT);
       fprintf (file, "\n");
     }
 
@@ -6687,7 +6687,6 @@ dump_function_to_file (tree fn, FILE *file, int flags)
   if (cfun && cfun->decl == fn && cfun->cfg && basic_block_info)
     {
       /* If the CFG has been built, emit a CFG-based dump.  */
-      check_bb_profile (ENTRY_BLOCK_PTR, file);
       if (!ignore_topmost_bind)
 	fprintf (file, "{\n");
 
@@ -6695,10 +6694,9 @@ dump_function_to_file (tree fn, FILE *file, int flags)
 	fprintf (file, "\n");
 
       FOR_EACH_BB (bb)
-	gimple_dump_bb (file, bb, 2, flags);
+	dump_bb (file, bb, 2, flags | TDF_COMMENT);
 
       fprintf (file, "}\n");
-      check_bb_profile (EXIT_BLOCK_PTR, file);
     }
   else if (DECL_SAVED_TREE (fn) == NULL)
     {
@@ -6821,7 +6819,7 @@ print_loops_bb (FILE *file, basic_block bb, int indent, int verbosity)
   if (verbosity >= 3)
     {
       fprintf (file, "%s  {\n", s_indent);
-      gimple_dump_bb (file, bb, indent + 4, TDF_VOPS|TDF_MEMSYMS);
+      dump_bb (file, bb, indent + 4, TDF_VOPS|TDF_MEMSYMS);
       fprintf (file, "%s  }\n", s_indent);
     }
 }