llvm-6502/lib
Benjamin Kramer 59957500f9 CodeGenPrepare: Add a transform to turn selects into branches in some cases.
This came up when a change in block placement formed a cmov and slowed down a
hot loop by 50%:

	ucomisd	(%rdi), %xmm0
	cmovbel	%edx, %esi

cmov is a really bad choice in this context because it doesn't get branch
prediction. If we emit it as a branch, an out-of-order CPU can do a better job
(if the branch is predicted right) and avoid waiting for the slow load+compare
instruction to finish. Of course it won't help if the branch is unpredictable,
but those are really rare in practice.

This patch uses a dumb conservative heuristic, it turns all cmovs that have one
use and a direct memory operand into branches. cmovs usually save some code
size, so we disable the transform in -Os mode. In-Order architectures are
unlikely to benefit as well, those are included in the
"predictableSelectIsExpensive" flag.

It would be better to reuse branch probability info here, but BPI doesn't
support select instructions currently. It would make sense to use the same
heuristics as the if-converter pass, which does the opposite direction of this
transform.


Test suite shows a small improvement here and there on corei7-level machines,
but the actual results depend a lot on the used microarchitecture. The
transformation is currently disabled by default and available by passing the
-enable-cgp-select2branch flag to the code generator.

Thanks to Chandler for the initial test case to him and Evan Cheng for providing
me with comments and test-suite numbers that were more stable than mine :)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156234 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-05 12:49:22 +00:00
..
Analysis Rename the Region::block_iterator to Region::block_node_iterator, and 2012-05-04 20:55:23 +00:00
Archive Include cstdio in a few place that depended on getting it transitively through StringExtras.h 2012-03-23 11:35:30 +00:00
AsmParser
Bitcode llvm::SwitchInst 2012-03-11 06:09:17 +00:00
CodeGen Add a new target hook "predictableSelectIsExpensive". 2012-05-05 12:49:14 +00:00
DebugInfo Fix a C++11 UDL conflict. 2012-04-04 20:33:56 +00:00
ExecutionEngine RuntimeDyld cleanup: 2012-05-01 10:41:12 +00:00
Linker Add a flag to the struct type finder to collect only those types which have 2012-04-21 23:59:16 +00:00
MC MC: Unknown assembler directives are now hard errors. 2012-05-01 18:38:27 +00:00
Object Fix the implementation of MachOObjectFile::isSectionZeroInit so it follows the MachO spec. 2012-05-02 02:31:28 +00:00
Support This patch adds a new NVPTX back-end to LLVM which supports code generation for NVIDIA PTX 3.0. This back-end will (eventually) replace the current PTX back-end, while maintaining compatibility with it. 2012-05-04 20:18:50 +00:00
TableGen Move llvm-tblgen's StringMatcher into the TableGen library so it can 2012-05-02 17:32:48 +00:00
Target Add a new target hook "predictableSelectIsExpensive". 2012-05-05 12:49:14 +00:00
Transforms CodeGenPrepare: Add a transform to turn selects into branches in some cases. 2012-05-05 12:49:22 +00:00
VMCore Reapply r155682, making constant folding more consistent, with a fix to work 2012-04-27 17:50:22 +00:00
CMakeLists.txt
LLVMBuild.txt
Makefile