[Bug c++/85799] __builin_expect doesn't propagate through inlined functions

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 27 11:59:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85799

--- Comment #8 from Martin Liška <marxin at gcc dot gnu.org> ---
So what happens, pass_strip_predict_hints is called as last
pass_all_early_optimizations pass. That's called for first function. Then the
second one goes through einline pass, but in this time the first one is already
stripped. So solution would be to make pass_strip_predict_hints a simple IPA
pass and put it right after that. I have patch for that.

That would mean that following will not be striped before einline:

1) __builtin_expect (plus corresponding IFN) - it's fine
2) predict_exprs (and gimple_predict_exprs) - PRED_GOTO, PRED_CONTINUE,
PRED_FORTRAN_FAIL_IO, PRED_NORETURN, PRED_FORTRAN_WARN_ONCE,
PRED_TREE_EARLY_RETURN

Hope all are fine, maybe PRED_TREE_EARLY_RETURN is bit unreliable?
Honza what do you think? If you agree, I can make it IPA pass.
Having that, we'll have:
Predictions for bb 2
  call heuristics of edge 2->4 (edge pair duplicate): 33.00%
  call heuristics of edge 2->3 (edge pair duplicate): 33.00%
  first match heuristics: 10.00%
  combined heuristics: 10.00%
  __builtin_expect heuristics of edge 2->3: 10.00%
Predictions for bb 3
1 edges in bb 3 predicted to even probabilities
Predictions for bb 4
1 edges in bb 4 predicted to even probabilities
Predictions for bb 5
1 edges in bb 5 predicted to even probabilities
inline_func_hint (bool b)
{
  bool D.2307;
  bool b;
  long int _9;
  long int _10;

  <bb 2> [local count: 1073741825]:
  _9 = (long int) b_3(D);
  _10 = __builtin_expect (_9, 0);
  if (_10 != 0)
    goto <bb 3>; [10.00%]
  else
    goto <bb 4>; [90.00%]

  <bb 3> [local count: 107374182]:
  unlikely ();
  goto <bb 5>; [100.00%]

  <bb 4> [local count: 966367642]:
  likely ();

  <bb 5> [local count: 1073741825]:
  return;

}


More information about the Gcc-bugs mailing list