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] Print 2 digits after decimal delimiter for BB frequencies


With the patch applied, one can distinguish between PROB_VERY_UNLIKELY and
real zero probability:

f ()
{
  int _1;

  <bb 2> [100.00%]:
  _1 = __builtin_sprintf (&d2, "%i", 12);
  if (_1 != 2)
    goto <bb 3>; [0.04%]
  else
    goto <bb 4>; [99.96%]

  <bb 3> [0.04%]:
  __builtin_abort ();

  <bb 4> [99.96%]:
  return;

} 

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin
>From 18f0fa35f91db675f5abf6a0aa8cf3582e79c772 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 1 Dec 2016 10:55:55 +0100
Subject: [PATCH] Print 2 digits after decimal delimiter for BB frequencies

gcc/ChangeLog:

2016-12-01  Martin Liska  <mliska@suse.cz>

	* gimple-pretty-print.c (dump_edge_probability): Use newly
	defined PROBABILITY_FORMAT.
	(dump_gimple_label): Likewise.
	(dump_gimple_bb_header): Likewise.

gcc/testsuite/ChangeLog:

2016-12-02  Martin Liska  <mliska@suse.cz>

	* gcc.dg/tree-ssa/20040703-1.c: Update scanned pattern.
	* gcc.dg/tree-ssa/dump-2.c: Likewise.
---
 gcc/gimple-pretty-print.c                  | 12 +++++++++---
 gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c |  2 +-
 gcc/testsuite/gcc.dg/tree-ssa/dump-2.c     |  2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index b5e866d..de57e89 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -72,12 +72,17 @@ debug_gimple_stmt (gimple *gs)
   print_gimple_stmt (stderr, gs, 0, TDF_VOPS|TDF_MEMSYMS);
 }
 
+/* Print format used for displaying probability of an edge or frequency
+   of a basic block.  */
+
+#define PROBABILITY_FORMAT "[%.2f%%]"
+
 /* Dump E probability to BUFFER.  */
 
 static void
 dump_edge_probability (pretty_printer *buffer, edge e)
 {
-  pp_scalar (buffer, " [%.1f%%]",
+  pp_scalar (buffer, " " PROBABILITY_FORMAT,
 	     e->probability * 100.0 / REG_BR_PROB_BASE);
 }
 
@@ -1023,7 +1028,7 @@ dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags)
       dump_generic_node (buffer, label, spc, flags, false);
       basic_block bb = gimple_bb (gs);
       if (bb && !(flags & TDF_GIMPLE))
-	pp_scalar (buffer, " [%.1f%%]",
+	pp_scalar (buffer, " " PROBABILITY_FORMAT,
 		   bb->frequency * 100.0 / REG_BR_PROB_BASE);
       pp_colon (buffer);
     }
@@ -2590,7 +2595,8 @@ dump_gimple_bb_header (FILE *outf, basic_block bb, int indent, int flags)
 	  if (flags & TDF_GIMPLE)
 	    fprintf (outf, "%*sbb_%d:\n", indent, "", bb->index);
 	  else
-	    fprintf (outf, "%*s<bb %d> [%.1f%%]:\n", indent, "", bb->index,
+	    fprintf (outf, "%*s<bb %d> " PROBABILITY_FORMAT ":\n",
+		     indent, "", bb->index,
 		     bb->frequency * 100.0 / REG_BR_PROB_BASE);
 	}
     }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c
index 2980047..eb9fb56 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c
@@ -9,4 +9,4 @@ float foo(float x)
 }
 
 /* We should *not* fold the arithmetic.  */
-/* { dg-final { scan-tree-dump-times "0\\.0\[^%\]" 0 "dom2"} } */
+/* { dg-final { scan-tree-dump-times "0\\.0\[^%0\]" 0 "dom2"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dump-2.c b/gcc/testsuite/gcc.dg/tree-ssa/dump-2.c
index 11cde92..8a63af4 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/dump-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/dump-2.c
@@ -6,4 +6,4 @@ int f(void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump "<bb \[0-9\]> \\\[100\\\.0%\\\]:" "optimized" } } */
+/* { dg-final { scan-tree-dump "<bb \[0-9\]> \\\[100\\\.00%\\\]:" "optimized" } } */
-- 
2.10.2


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