[llvm-dev] How can I tell llvm, that a branch is preferred ?
Hans Wennborg via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 27 11:02:02 PDT 2015
On Tue, 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 ?
I haven't tried myself, but the documentation claims that
__builtin_expect should work:
http://llvm.org/docs/BranchWeightMetadata.html#builtin-expect
Can you turn your code into an example we can try?
- Hans
More information about the llvm-dev
mailing list