diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-01-31 21:14:40 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-01-31 21:14:40 +0000 |
commit | 093b0413fe827b48306ef459af7690ba9df14a8e (patch) | |
tree | b3005646888a6e670d1ff823548599d155c51c81 /lib | |
parent | d8324e6983d06c3d56debcbfdc9ead0e0d4a817d (diff) | |
download | llvm-093b0413fe827b48306ef459af7690ba9df14a8e.tar.gz llvm-093b0413fe827b48306ef459af7690ba9df14a8e.tar.bz2 llvm-093b0413fe827b48306ef459af7690ba9df14a8e.tar.xz |
[SLPV] Recognize vectorizable intrinsics during SLP vectorization and
transform accordingly. Based on similar code from Loop vectorization.
Subsequent commits will include vectorization of function calls to
vector intrinsics and form function calls to vector library calls.
Patch by Raul Silvera! (Much delayed due to my not running dcommit)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200576 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Vectorize/SLPVectorizer.cpp | 89 |
1 files changed, 86 insertions, 3 deletions
diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 80d9ffccaf..0dec4b05f9 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -947,6 +947,39 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth) { buildTree_rec(Operands, Depth + 1); return; } + case Instruction::Call: { + // Check if the calls are all to the same vectorizable intrinsic. + IntrinsicInst *II = dyn_cast<IntrinsicInst>(VL[0]); + if (II==NULL) { + newTreeEntry(VL, false); + DEBUG(dbgs() << "SLP: Non-vectorizable call.\n"); + return; + } + + Intrinsic::ID ID = II->getIntrinsicID(); + + for (unsigned i = 1, e = VL.size(); i != e; ++i) { + IntrinsicInst *II2 = dyn_cast<IntrinsicInst>(VL[i]); + if (!II2 || II2->getIntrinsicID() != ID) { + newTreeEntry(VL, false); + DEBUG(dbgs() << "SLP: mismatched calls:" << *II << "!=" << *VL[i] + << "\n"); + return; + } + } + + newTreeEntry(VL, true); + for (unsigned i = 0, e = II->getNumArgOperands(); i != e; ++i) { + ValueList Operands; + // Prepare the operand vector. + for (unsigned j = 0; j < VL.size(); ++j) { + IntrinsicInst *II2 = dyn_cast<IntrinsicInst>(VL[j]); + Operands.push_back(II2->getArgOperand(i)); + } + buildTree_rec(Operands, Depth + 1); + } + return; + } default: newTreeEntry(VL, false); DEBUG(dbgs() << "SLP: Gathering unknown instruction.\n"); @@ -1072,6 +1105,30 @@ int BoUpSLP::getEntryCost(TreeEntry *E) { int VecStCost = TTI->getMemoryOpCost(Instruction::Store, VecTy, 1, 0); return VecStCost - ScalarStCost; } + case Instruction::Call: { + CallInst *CI = cast<CallInst>(VL0); + IntrinsicInst *II = cast<IntrinsicInst>(CI); + Intrinsic::ID ID = II->getIntrinsicID(); + + // Calculate the cost of the scalar and vector calls. + SmallVector<Type*, 4> ScalarTys, VecTys; + for (unsigned op = 0, opc = II->getNumArgOperands(); op!= opc; ++op) { + ScalarTys.push_back(CI->getArgOperand(op)->getType()); + VecTys.push_back(VectorType::get(CI->getArgOperand(op)->getType(), + VecTy->getNumElements())); + } + + int ScalarCallCost = VecTy->getNumElements() * + TTI->getIntrinsicInstrCost(ID, ScalarTy, ScalarTys); + + int VecCallCost = TTI->getIntrinsicInstrCost(ID, VecTy, VecTys); + + DEBUG(dbgs() << "SLP: Call cost "<< VecCallCost - ScalarCallCost + << " (" << VecCallCost << "-" << ScalarCallCost << ")" + << " for " << *II << "\n"); + + return VecCallCost - ScalarCallCost; + } default: llvm_unreachable("Unknown instruction"); } @@ -1086,10 +1143,10 @@ bool BoUpSLP::isFullyVectorizableTinyTree() { return false; // Gathering cost would be too much for tiny trees. - if (VectorizableTree[0].NeedToGather || VectorizableTree[1].NeedToGather) - return false; + if (VectorizableTree[0].NeedToGather || VectorizableTree[1].NeedToGather) + return false; - return true; + return true; } int BoUpSLP::getTreeCost() { @@ -1555,6 +1612,32 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { E->VectorizedValue = S; return propagateMetadata(S, E->Scalars); } + case Instruction::Call: { + CallInst *CI = cast<CallInst>(VL0); + + setInsertPointAfterBundle(E->Scalars); + std::vector<Value *> OpVecs; + for (int j = 0, e = CI->getNumArgOperands(); j < e; ++j) { + ValueList OpVL; + for (int i = 0, e = E->Scalars.size(); i < e; ++i) { + CallInst *CEI = cast<CallInst>(E->Scalars[i]); + OpVL.push_back(CEI->getArgOperand(j)); + } + + Value *OpVec = vectorizeTree(OpVL); + DEBUG(dbgs() << "SLP: OpVec[" << j << "]: " << *OpVec << "\n"); + OpVecs.push_back(OpVec); + } + + Module *M = F->getParent(); + IntrinsicInst *II = cast<IntrinsicInst>(CI); + Intrinsic::ID ID = II->getIntrinsicID(); + Type *Tys[] = { VectorType::get(CI->getType(), E->Scalars.size()) }; + Function *CF = Intrinsic::getDeclaration(M, ID, Tys); + Value *V = Builder.CreateCall(CF, OpVecs); + E->VectorizedValue = V; + return V; + } default: llvm_unreachable("unknown inst"); } |