Nat! via llvm-dev
2015-Oct-27 17:55 UTC
[llvm-dev] How can I tell llvm, that a branch is preferred ?
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!
Chen Li via llvm-dev
2015-Oct-27 18:02 UTC
[llvm-dev] How can I tell llvm, that a branch is preferred ?
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>
Hans Wennborg via llvm-dev
2015-Oct-27 18:02 UTC
[llvm-dev] How can I tell llvm, that a branch is preferred ?
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
Diego Novillo via llvm-dev
2015-Oct-27 18:03 UTC
[llvm-dev] How can I tell llvm, that a branch is preferred ?
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. > >Well, you could generate a !prof annotation to specify branch weights that are then used when computing branch probability and block frequencies ( http://llvm.org/docs/BranchWeightMetadata.html) Diego. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151027/244ee946/attachment.html>