llvm-6502/include/llvm
Quentin Colombet 9b6ca9304c [CodeGenPrepare] Move extractelement close to store if they can be combined.
This patch adds an optimization in CodeGenPrepare to move an extractelement
right before a store when the target can combine them.
The optimization may promote any scalar operations to vector operations in the
way to make that possible.


** Context **

Some targets use different register files for both vector and scalar operations.
This means that transitioning from one domain to another may incur copy from one
register file to another. These copies are not coalescable and may be expensive.
For example, according to the scheduling model, on cortex-A8 a vector to GPR
move is 20 cycles.


** Motivating Example **

Let us consider an example:
define void @foo(<2 x i32>* %addr1, i32* %dest) {
 %in1 = load <2 x i32>* %addr1, align 8
 %extract = extractelement <2 x i32> %in1, i32 1
 %out = or i32 %extract, 1
 store i32 %out, i32* %dest, align 4
 ret void
}

As it is, this IR generates the following assembly on armv7:
  vldr  d16, [r0]            @vector load  
  vmov.32 r0, d16[1]  @ cross-register-file copy: 20 cycles
  orr r0, r0, #1           @ scalar bitwise or
  str r0, [r1]               @ scalar store
  bx  lr

Whereas we could generate much faster code:
  vldr  d16, [r0]               @ vector load
  vorr.i32  d16, #0x1     @ vector bitwise or
  vst1.32 {d16[1]}, [r1:32] @ vector extract + store
  bx  lr

Half of the computation made in the vector is useless, but this allows to get
rid of the expensive cross-register-file copy.


** Proposed Solution **

To avoid this cross-register-copy penalty, we promote the scalar operations to
vector operations. The penalty will be removed if we manage to promote the whole
chain of computation in the vector domain.
Currently, we do that only when the chain of computation ends by a store and the
target is able to combine an extract with a store.

Stores are the most likely candidates, because other instructions produce values
that would need to be promoted and so, extracted as some point[1]. Moreover,
this is customary that targets feature stores that perform a vector extract (see
AArch64 and X86 for instance).

The proposed implementation relies on the TargetTransformInfo to decide whether
or not it is beneficial to promote a chain of computation in the vector domain.
Unfortunately, this interface is rather inaccurate for this level of details and
although this optimization may be beneficial for X86 and AArch64, the inaccuracy
will lead to the optimization being too aggressive.
Basically in TargetTransformInfo, everything that is legal has a cost of 1,
whereas, even if a vector type is legal, usually a vector operation is slightly
more expensive than its scalar counterpart. That will lead to too many
promotions that may not be counter balanced by the saving of the
cross-register-file copy. For instance, on AArch64 this penalty is just 4
cycles.

For now, the optimization is just enabled for ARM prior than v8, since those
processors have a larger penalty on cross-register-file copies, and the scope is
limited to basic blocks. Because of these two factors, we limit the effects of
the inaccuracy. Indeed, I did not want to build up a fancy cost model with block
frequency and everything on top of that.

[1] We can imagine targets that can combine an extractelement with  other
instructions than just stores. If we want to go into that direction, the current
interfaces must be augmented and, moreover, I think this becomes a global isel
problem.

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

<rdar://problem/14170854>


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220978 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-31 17:52:53 +00:00
..
ADT Add MapVector::rbegin(), MapVector::rend() to completment MapVector::begin(), MapVector::end(). 2014-10-27 17:20:53 +00:00
Analysis [ScalarEvolution] Guard dump() with #if 2014-10-27 21:14:41 +00:00
AsmParser Pass a MemoryBufferRef when we can avoid taking ownership. 2014-08-26 21:49:01 +00:00
Bitcode Spell out the template args for compilers having issues with the injected class 2014-09-15 16:13:33 +00:00
CodeGen [PBQP] Remove a spurious 'typename' keyword. This was causing an error on MSVC. 2014-10-27 17:59:51 +00:00
Config Re-land r219354: Use llvm-symbolizer to symbolize LLVM/Clang crash dumps. 2014-10-10 22:06:59 +00:00
DebugInfo Constify input argument of RelocVisitor and DWARFContext constructors. NFC. 2014-10-20 20:28:51 +00:00
ExecutionEngine [MCJIT] Turn the getSymbolAddress free function created in r218626 into a static 2014-10-01 04:11:13 +00:00
IR X86: Implement the vectorcall calling convention 2014-10-28 01:29:26 +00:00
IRReader Pass a MemoryBufferRef when we can avoid taking ownership. 2014-08-26 21:49:01 +00:00
LineEditor [C++11] Replace OwningPtr with std::unique_ptr in places where it doesn't break the API. 2014-04-21 09:34:48 +00:00
Linker Remove the PreserveSource linker mode. 2014-10-28 00:24:16 +00:00
LTO Add an option to the LTO code generator to disable vectorization during LTO 2014-10-26 21:50:58 +00:00
MC [MC] Attach labels to existing fragments instead of using a separate fragment 2014-10-22 22:38:06 +00:00
Object Object, COFF: Cleanup symbol type code, improve binutils compatibility 2014-10-31 05:07:00 +00:00
Option Add an overload of getLastArgNoClaim taking two OptSpecifiers. 2014-09-12 19:42:53 +00:00
ProfileData Fix comment spelling and tidy diagnostic call in profile reader. 2014-10-30 20:19:19 +00:00
Support Threading.h: Give named parameters to llvm::call_once(flag,UserFn). [-Wdocumentation] 2014-10-31 00:54:20 +00:00
TableGen [TableGen] Fully resolve class-instance values before defs in multiclasses 2014-09-16 17:14:13 +00:00
Target [CodeGenPrepare] Move extractelement close to store if they can be combined. 2014-10-31 17:52:53 +00:00
Transforms Shrinkify libcalls: use float versions of double libm functions with fast-math (bug 17850) 2014-10-22 15:29:23 +00:00
CMakeLists.txt Remove llvm_headers_do_not_build for the benefit of XCode and Visual Studio users. 2014-08-14 00:51:47 +00:00
InitializePasses.h Add a new pass FunctionTargetTransformInfo. This pass serves as a 2014-09-18 00:34:14 +00:00
LinkAllIR.h [cleanup] Move the Dominators.h and Verifier.h headers into the IR 2014-01-13 09:26:24 +00:00
LinkAllPasses.h Make AAMDNodes ctor and operator bool (!!!) explicit, mop up bugs and weirdness exposed by it. 2014-10-04 22:44:29 +00:00
module.modulemap [modules] Stop excluding Support/Debug.h from the Support module. This header 2014-10-13 00:41:03 +00:00
module.modulemap.build [modules] Add module maps for LLVM. These are not quite ready for prime-time 2014-05-21 02:46:14 +00:00
Pass.h Revert "[PM] Add pass run listeners to the pass manager." 2014-05-15 17:49:20 +00:00
PassAnalysisSupport.h [C++11] More 'nullptr' conversion. In some cases just using a boolean check instead of comparing to nullptr. 2014-04-14 00:51:57 +00:00
PassInfo.h Remove pimpl class from PassRegistry. 2014-06-12 16:06:51 +00:00
PassManager.h Move the old pass manager infrastructure into a legacy namespace and 2013-11-09 12:26:54 +00:00
PassRegistry.h [PM] Remove an unused and rather expensive mapping from an analysis 2014-10-06 00:30:59 +00:00
PassSupport.h Defining a new API for debug options that doesn't rely on static global cl::opts. 2014-10-15 21:54:35 +00:00