On 7/4/19 6:02 PM, Jan Hubicka wrote:
> perhaps we want to also document that builtin-expect can be used this way?
> It owuld be also nice to have a testcase.

Good idea! I'm going to install the following patch.

Martin
>From 6b59938eff83600ae237409de027040b7904f66d Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Tue, 9 Jul 2019 11:10:20 +0200
Subject: [PATCH] Document and test __builtin_expect_with_probability.

gcc/ChangeLog:

2019-07-09  Martin Liska  <mli...@suse.cz>

	* doc/extend.texi: Document influence on loop
	optimizers.

gcc/testsuite/ChangeLog:

2019-07-09  Martin Liska  <mli...@suse.cz>

	* gcc.dg/predict-17.c: Test loop optimizer assumption
	about loop iterations.
---
 gcc/doc/extend.texi               | 5 ++++-
 gcc/testsuite/gcc.dg/predict-17.c | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index f2619e12f93..061607411eb 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -13045,8 +13045,11 @@ when testing pointer or floating-point values.
 For the purposes of branch prediction optimizations, the probability that
 a @code{__builtin_expect} expression is @code{true} is controlled by GCC's
 @code{builtin-expect-probability} parameter, which defaults to 90%.  
+
 You can also use @code{__builtin_expect_with_probability} to explicitly 
-assign a probability value to individual expressions.
+assign a probability value to individual expressions.  If the built-in
+is used in a loop construct, the provided probability will influence
+the expected number of iterations made by loop optimizations.
 @end deftypefn
 
 @deftypefn {Built-in Function} long __builtin_expect_with_probability
diff --git a/gcc/testsuite/gcc.dg/predict-17.c b/gcc/testsuite/gcc.dg/predict-17.c
index 5069aa47c8c..45b618a942c 100644
--- a/gcc/testsuite/gcc.dg/predict-17.c
+++ b/gcc/testsuite/gcc.dg/predict-17.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate-details" } */
 
 extern int global;
 
@@ -11,3 +11,5 @@ void foo (int base)
 
 /* { dg-final { scan-tree-dump "first match heuristics: 5.00%" "profile_estimate"} } */
 /* { dg-final { scan-tree-dump "__builtin_expect_with_probability heuristics of edge .*->.*: 5.00%" "profile_estimate"} } */
+/* { dg-final { scan-tree-dump "is probably executed at most 19" "profile_estimate"} } */
+
-- 
2.22.0

Reply via email to