[PATCH] D34769: [X86] X86::CMOV to Branch heuristic based optimization

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 12:20:16 PDT 2017


hfinkel added a comment.

In https://reviews.llvm.org/D34769#794220, @aaboud wrote:

> In https://reviews.llvm.org/D34769#794214, @hfinkel wrote:
>
> > Interestingly, we just recently introduced a pass into the PowerPC backend that does essentially the same thing; lib/Target/PowerPC/PPCExpandISEL.cpp. Could you please take a look at that and see how it compares to this implementation? I'm obviously curious as to whether we could add some target callbacks and unify the underlying logic in a target-independent pass. FWIW, both implementations are around 500 lines.
>
>
> Thanks for the information, I will take a look.
>
> > One thing that's not clear to me: how are you determining whether or not the branch is predictable?
>
> I did not determine if it is predictable, however, I did the transformation only when I can assure gain of more than 25% of the mis-prediction penalty.
>  On the other hand, I considered during development of this pass to try determine one case where branch is not predicted, which is tree-search like algorithms.
>  I did that roughly by looking for how the CMOV result value was used, and if it was used for another "pointer-like" load, I considered it a possible case for tree-search.
>  Notice, that this is not part of this patch, but we might consider adding it if found reasonable.


Thanks. That heuristic sounds like an interesting idea. Hopefully, we can investigate that in the future.

> 
> 
>> One outstanding TODO item we have from the PPC functionality is to support __builtin_unpredictable (which turns in to metadata at the IR level). Have you looked at that?
> 
> I know about this built-in, but as you said, it is not lowered into the machine IR. I did not try to figure out how to preserve it though.

One way of doing this might be to have the branch instructions get the metadata from the IR (there are MI metadata operands, although I think they're only currently used for debug-info pseudo instructions).


https://reviews.llvm.org/D34769





More information about the llvm-commits mailing list