Question Details

No question body available.

Tags

c++ clang compiler-explorer

Answers (1)

October 21, 2025 Score: 3 Rep: 38,048 Quality: Medium Completeness: 60%

Aside from Profile-Guided Optimization (PGO), branch probabilities can be estimated from control flow analysis or set explicitly with builtinexpectwith_probability directive. I'm not aware of any existing fancy tool to nicely report these estimated probabilities but stock llvm tooling is sufficient to take a peek.

Example program calculating Fibonacci sequence:

// test.cpp int fib(int n) { if (n %6 probability is 0x40000000 / 0x80000000 = 50.00% edge %1 -> %8 probability is 0x40000000 / 0x80000000 = 50.00% edge %6 -> %16 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge] edge %8 -> %16 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]