diff options
author | Juergen Ributzka <juergen@apple.com> | 2014-08-19 19:05:24 +0000 |
---|---|---|
committer | Juergen Ributzka <juergen@apple.com> | 2014-08-19 19:05:24 +0000 |
commit | 4bf6c01cdb9c246b84d291763cd94e2b8cbd0b63 (patch) | |
tree | 0a3068ba1e72c7faef1a1d45700ca479d3ded6d1 /llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | |
parent | 113ba3e6c091402e2fa7895f04247a97924756ba (diff) | |
download | bcm5719-llvm-4bf6c01cdb9c246b84d291763cd94e2b8cbd0b63.tar.gz bcm5719-llvm-4bf6c01cdb9c246b84d291763cd94e2b8cbd0b63.zip |
Reapply [FastISel] Let the target decide first if it wants to materialize a constant (215588).
Note: This was originally reverted to track down a buildbot error. This commit
exposed a latent bug that was fixed in r215753. Therefore it is reapplied
without any modifications.
I run it through SPEC2k and SPEC2k6 for AArch64 and it didn't introduce any new
regeressions.
Original commit message:
This changes the order in which FastISel tries to materialize a constant.
Originally it would try to use a simple target-independent approach, which
can lead to the generation of inefficient code.
On X86 this would result in the use of movabsq to materialize any 64bit
integer constant - even for simple and small values such as 0 and 1. Also
some very funny floating-point materialization could be observed too.
On AArch64 it would materialize the constant 0 in a register even the
architecture has an actual "zero" register.
On ARM it would generate unnecessary mov instructions or not use mvn.
This change simply changes the order and always asks the target first if it
likes to materialize the constant. This doesn't fix all the issues
mentioned above, but it enables the targets to implement such
optimizations.
Related to <rdar://problem/17420988>.
llvm-svn: 216006
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/FastISel.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index 6be5f8a57e2..ec0531e04d4 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -198,29 +198,24 @@ unsigned FastISel::getRegForValue(const Value *V) { return Reg; } -/// materializeRegForValue - Helper for getRegForValue. This function is -/// called when the value isn't already available in a register and must -/// be materialized with new instructions. -unsigned FastISel::materializeRegForValue(const Value *V, MVT VT) { +unsigned FastISel::MaterializeConstant(const Value *V, MVT VT) { unsigned Reg = 0; - if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) { if (CI->getValue().getActiveBits() <= 64) Reg = FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue()); - } else if (isa<AllocaInst>(V)) { + } else if (isa<AllocaInst>(V)) Reg = TargetMaterializeAlloca(cast<AllocaInst>(V)); - } else if (isa<ConstantPointerNull>(V)) { + else if (isa<ConstantPointerNull>(V)) // Translate this as an integer zero so that it can be // local-CSE'd with actual integer zeros. Reg = getRegForValue(Constant::getNullValue(DL.getIntPtrType(V->getContext()))); - } else if (const ConstantFP *CF = dyn_cast<ConstantFP>(V)) { - if (CF->isNullValue()) { + else if (const ConstantFP *CF = dyn_cast<ConstantFP>(V)) { + if (CF->isNullValue()) Reg = TargetMaterializeFloatZero(CF); - } else { + else // Try to emit the constant directly. Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF); - } if (!Reg) { // Try to emit the constant by using an integer constant with a cast. @@ -253,15 +248,26 @@ unsigned FastISel::materializeRegForValue(const Value *V, MVT VT) { BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TargetOpcode::IMPLICIT_DEF), Reg); } + return Reg; +} - // If target-independent code couldn't handle the value, give target-specific - // code a try. - if (!Reg && isa<Constant>(V)) +/// materializeRegForValue - Helper for getRegForValue. This function is +/// called when the value isn't already available in a register and must +/// be materialized with new instructions. +unsigned FastISel::materializeRegForValue(const Value *V, MVT VT) { + unsigned Reg = 0; + // Give the target-specific code a try first. + if (isa<Constant>(V)) Reg = TargetMaterializeConstant(cast<Constant>(V)); + // If target-specific code couldn't or didn't want to handle the value, then + // give target-independent code a try. + if (!Reg) + Reg = MaterializeConstant(V, VT); + // Don't cache constant materializations in the general ValueMap. // To do so would require tracking what uses they dominate. - if (Reg != 0) { + if (Reg) { LocalValueMap[V] = Reg; LastLocalValue = MRI.getVRegDef(Reg); } |