summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/predict-18.c
blob: 0c93638a9712f00b7e1f49244220eb36f10fd131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-profile_estimate" } */

extern int global;

int x;

short v = 0;
short expected = 0;
short max = ~0;
#define STRONG 0

void foo (int a, int b)
{
  if (__builtin_expect_with_probability (a < b, 1, 0.6f) > __builtin_expect (b, 0))
    global++;

  if (__builtin_expect_with_probability (a < b, 1, 0.777f) > 0)
    global++;

  if (__builtin_expect_with_probability (a < b, 1, 0.99) == __atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED))
    global++;

  if (__builtin_expect_with_probability (a < 10, 1, 0.9f) > __builtin_expect_with_probability (b, 0, 0.8f))
    global++;
}

/* { dg-final { scan-tree-dump "__builtin_expect_with_probability heuristics of edge .*->.*: 54.00%" "profile_estimate"} } */
/* { dg-final { scan-tree-dump "__builtin_expect_with_probability heuristics of edge .*->.*: 77.70%" "profile_estimate"} } */
/* { dg-final { scan-tree-dump "__builtin_expect_with_probability heuristics of edge .*->.*: 98.96%" "profile_estimate"} } */
/* { dg-final { scan-tree-dump "__builtin_expect_with_probability heuristics of edge .*->.*: 71.99%" "profile_estimate"} } */