On 12/01/2016 02:48 AM, Martin Liška wrote:
On 11/30/2016 11:46 PM, Martin Sebor wrote:
On 11/24/2016 05:59 AM, Martin Liška wrote:
On 11/24/2016 09:29 AM, Richard Biener wrote:
Please guard with ! TDF_GIMPLE, otherwise the output will not be
with the GIMPLE FE.


Done and verified that and it provides equal dumps for -fdump*-gimple.
Installed as r242837.

Hi Martin,

I'm trying to understand how to interpret the probabilities (to
make sure one of my tests, builtin-sprintf-2.c, is testing what
it's supposed to be testing).

With this example:

  char d2[2];

  void f (void)
    if (2 != __builtin_sprintf (d2, "%i", 12))
      __builtin_abort ();

the probability of the branch to abort is 0%:

  f1 ()
    int _1;

    <bb 2> [100.0%]:
    _1 = __builtin_sprintf (&d, "%i", 12);
    if (_1 != 2)
      goto <bb 3>; [0.0%]
      goto <bb 4>; [100.0%]

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

    <bb 4> [100.0%]:

Hello Martin.

Looks I did a small error. I use only only one digit after decimal
point, which is unable to
display noreturn predictor (defined as PROB_VERY_UNLIKELY):

#define PROB_VERY_UNLIKELY    (REG_BR_PROB_BASE / 2000 - 1) // this is 4

I would suggest to use following patch to display at least 2 digits,
that would distinguish
between real zero and PROB_VERY_UNLIKELY:


f ()
  int _1;

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

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

  <bb 4> [99.96%]:


Yet the call to abort is in the assembly so I would expect its
probability to be more than zero.  So my question is: it it safe
to be testing for calls to abort in the optimized dump as a way
of verifying that the call has not been eliminated from the program
regardless of their probabilities?

I think so, otherwise the call would be removed.

Okay, thanks for the clarification.  One other question though.
Why would the probability be near zero?  In the absence of any
hints the expression 2 != sprintf(d, "%i", 12) should have
a very high probability of being true, near 100% in fact.

I ask because the test I referenced tries to verify the absence
of the sprintf return value optimization.  Without it the
likelihood of each of the calls to abort should in the EQL kind
of test cases like the one above should be nearly 100% (but not
quite).  When it's the opposite it suggests that the sprintf
optimization is providing some hint (in the form of a range of
return values) that changes the odds.  I have verified that
the optimization is not performed so something else must be
setting the probability or the value isn't correct.


I'm going to test the patch (and eventually update scanned patterns).


Patch candidate:

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);
-        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);

For reference, the directive the test uses since this change was
committed looks like this:

{ dg-final { scan-tree-dump-times "> \\\[\[0-9.\]+%\\\]:\n
*__builtin_abort" 114 "optimized" }

If I'm reading the heavily escaped regex right it matches any
percentage, even 0.0% (and the test passes).


Reply via email to