profile_probability op1_prob = profile_probability::uninitialized ();
if (prob.initialized_p ())
{
- profile_probability false_prob = prob.invert ();
- profile_probability op0_false_prob = false_prob.apply_scale (1, 2);
- profile_probability op1_false_prob = false_prob.apply_scale (1, 2)
- / op0_false_prob.invert ();
+ op1_prob = prob.invert ();
+ op0_prob = op1_prob.split (profile_probability::even ());
/* Get the probability that each jump below is true. */
- op0_prob = op0_false_prob.invert ();
- op1_prob = op1_false_prob.invert ();
+ op0_prob = op0_prob.invert ();
+ op1_prob = op1_prob.invert ();
}
if (if_false_label == NULL)
{
profile_probability op1_prob = profile_probability::uninitialized ();
if (prob.initialized_p ())
{
- op0_prob = prob.apply_scale (1, 2);
- op1_prob = prob.apply_scale (1, 2) / op0_prob.invert ();
+ op1_prob = prob;
+ op0_prob = op1_prob.split (profile_probability::even ());
}
if (if_true_label == NULL)
{
else
{
- profile_probability first_prob = prob;
+ profile_probability cprob
+ = profile_probability::guessed_always ();
if (first_code == UNORDERED)
- first_prob = profile_probability::guessed_always ().apply_scale
- (1, 100);
+ cprob = cprob.apply_scale (1, 100);
else if (first_code == ORDERED)
- first_prob = profile_probability::guessed_always ().apply_scale
- (99, 100);
+ cprob = cprob.apply_scale (99, 100);
+ else
+ cprob = profile_probability::even ();
+ /* We want to split:
+ if (x) goto t; // prob;
+ into
+ if (a) goto t; // first_prob;
+ if (b) goto t; // prob;
+ such that the overall probability of jumping to t
+ remains the same and first_prob is prob * cprob. */
if (and_them)
{
rtx_code_label *dest_label;
+ prob = prob.invert ();
+ profile_probability first_prob = prob.split (cprob).invert ();
+ prob = prob.invert ();
/* If we only jump if true, just bypass the second jump. */
if (! if_false_label)
{
size, dest_label, NULL, first_prob);
}
else
- do_compare_rtx_and_jump (op0, op1, first_code, unsignedp, mode,
- size, NULL, if_true_label, first_prob);
+ {
+ profile_probability first_prob = prob.split (cprob);
+ do_compare_rtx_and_jump (op0, op1, first_code, unsignedp, mode,
+ size, NULL, if_true_label, first_prob);
+ }
}
}
return *this;
}
+ /* Split *THIS (ORIG) probability into 2 probabilities, such that
+ the returned one (FIRST) is *THIS * CPROB and *THIS is
+ adjusted (SECOND) so that FIRST + FIRST.invert () * SECOND
+ == ORIG. This is useful e.g. when splitting a conditional
+ branch like:
+ if (cond)
+ goto lab; // ORIG probability
+ into
+ if (cond1)
+ goto lab; // FIRST = ORIG * CPROB probability
+ if (cond2)
+ goto lab; // SECOND probability
+ such that the overall probability of jumping to lab remains
+ the same. CPROB gives the relative probability between the
+ branches. */
+ profile_probability split (const profile_probability &cprob)
+ {
+ profile_probability ret = *this * cprob;
+ /* The following is equivalent to:
+ *this = cprob.invert () * *this / ret.invert (); */
+ *this = (*this - ret) / ret.invert ();
+ return ret;
+ }
+
gcov_type apply (gcov_type val) const
{
if (*this == profile_probability::uninitialized ())