[PATCH] D12341: add llvm.unpredictable intrinsic and lower it to metadata

Kevin B. Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 14:02:35 PDT 2015


kbsmith1 added a subscriber: kbsmith1.
kbsmith1 added a comment.

I don't think you want to do the number of times that the branch changed directions.  Hal made the comment that even 50% either way branches can have perfect prediction.  The example he gave was of long runs of one direction, and then long runs of another direction.

But branch predictors are usually much smarter than that.  Often they can also perfectly predict
ABABABABAB, branches which change direction with every other time.  How good and what patterns a predictor is able to do well
is a function both of how many bits the HW devotes to maintaining various pieces of prediction state, as well as the sophistication of
the branch prediction algorithms themselves.

I don't think you want to attempt to embed anything that needs to have deep knowledge of the predictor itself.  I think a simple
percentage of instances the "condition" is unpredictable would get the granularity (compared to bool) that you are thinking about,
without having any dependence on any specific prediction algorithm or implementation.

Feeding that information back into the IR from the HW can be interesting though.  Changes to the number and direction of branches
can indirectly impact other branch's prediction rates. :-).  Also, after various optimizations have happened, the relationship between
the predicitability of the final branch can, and that of the IR that it started out as can be hard to track, and thus feed back well.

Kevin Smith


http://reviews.llvm.org/D12341





More information about the llvm-commits mailing list