[llvm-dev] How can I tell llvm, that a branch is preferred ?
Chen Li via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 27 11:02:01 PDT 2015
Hi Nat!,
I think you can try to attach branch weight metadata to the branch or switch, and give a higher weight to the likely taken path. In that way, LLVM should be able to order the code correctly.
For branch weight metadata, you can refer to the following document:
http://llvm.org/docs/BranchWeightMetadata.html <http://llvm.org/docs/BranchWeightMetadata.html>
thanks,
chen
> On Oct 27, 2015, at 10:55 AM, Nat! via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>
> If I read the llvm language correctly, it doesn't have a way to specify the preferred branch, correct ? I see nothing in the specs for "branch" or "switch". And __buildin_expect does nothing, that I am sure of.
>
> Unfortunately llvm has this knack for ordering my one most crucial part of code exactly the opposite I want to, it does: (x86_64)
>
> cmpq %r15, (%rax,%rdx)
> jne LBB0_3
> Ltmp18:
> leaq 8(%rax,%rdx), %rcx
> jmp LBB0_4
> LBB0_3:
> addq $8, %rcx
> LBB0_4:
>
>
>
> when I want,
>
> cmpq %r15, (%rax,%rdx)
> jeq LBB0_3
>
> addq $8, %rcx
> jmp LBB0_4
> LBB0_3:
> leaq 8(%rax,%rdx), %rcx
> LBB0_4:
>
> since that saves me executing a jump 99.9% of the time. Is there anything I can do ?
>
> Ciao
> Nat!
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151027/316913c7/attachment.html>
More information about the llvm-dev
mailing list