OSDN Git Service

[CodeGenPrepare] use branch weight metadata to decide if a select should be turned...
authorSanjay Patel <spatel@rotateright.com>
Tue, 26 Apr 2016 17:11:17 +0000 (17:11 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 26 Apr 2016 17:11:17 +0000 (17:11 +0000)
commit6f5aa79cda95f448cc577cd521e20730a0cf55ce
treeab89143334fa2b78ffcc7e72226662d6224ff43f
parentc81ec9b2de27d79ab248c5ebd84d4b3d8296166d
[CodeGenPrepare] use branch weight metadata to decide if a select should be turned into a branch

This is part of solving PR27344:
https://llvm.org/bugs/show_bug.cgi?id=27344

CGP should undo the SimplifyCFG transform for the same reason that earlier patches have used this
same mechanism: it's possible that passes between SimplifyCFG and CGP may be able to optimize the
IR further with a select in place.

For the TLI hook default, >99% taken or not taken is chosen as the default threshold for a highly
predictable branch. Even the most limited HW branch predictors will be correct on this branch almost
all the time, so even a massive mispredict penalty perf loss would be overcome by the win from all
the times the branch was predicted correctly.

As a follow-up, we could make the default target hook less conservative by using the SchedMachineModel's
MispredictPenalty. Or we could just let targets override the default by implementing the hook with that
and other target-specific options. Note that trying to statically determine mispredict rates for
close-to-balanced profile weight data is generally impossible if the HW is sufficiently advanced. Ie,
50/50 taken/not-taken might still be 100% predictable.

Finally, note that this patch as-is will not solve PR27344 because the current __builtin_unpredictable()
branch weight default values are 4 and 64. A proposal to change that is in D19435.

Differential Revision: http://reviews.llvm.org/D19488

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267572 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/Instruction.h
include/llvm/IR/Instructions.h
include/llvm/Target/TargetLowering.h
lib/CodeGen/CodeGenPrepare.cpp
lib/CodeGen/TargetLoweringBase.cpp
lib/IR/Instructions.cpp
lib/IR/Metadata.cpp
test/CodeGen/X86/cmov-into-branch.ll