diff options
author | Nadav Rotem <nrotem@apple.com> | 2013-06-19 17:33:16 +0000 |
---|---|---|
committer | Nadav Rotem <nrotem@apple.com> | 2013-06-19 17:33:16 +0000 |
commit | 80a6d6526c4ea4de90327c1404e2689a260a9fee (patch) | |
tree | 1ce8ce13b766cda1ba0f291bd7d2b8483de6bee0 /lib | |
parent | dd3ef1a13b57b9086de5473d2576b16acba98e82 (diff) | |
download | llvm-80a6d6526c4ea4de90327c1404e2689a260a9fee.tar.gz llvm-80a6d6526c4ea4de90327c1404e2689a260a9fee.tar.bz2 llvm-80a6d6526c4ea4de90327c1404e2689a260a9fee.tar.xz |
SLPVectorizer: handle scalars that are extracted from vectors (using ExtractElementInst).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184325 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Vectorize/VecUtils.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Transforms/Vectorize/VecUtils.cpp b/lib/Transforms/Vectorize/VecUtils.cpp index 1e97ed400b..e79f08a56d 100644 --- a/lib/Transforms/Vectorize/VecUtils.cpp +++ b/lib/Transforms/Vectorize/VecUtils.cpp @@ -331,6 +331,34 @@ int BoUpSLP::getTreeCost(ArrayRef<Value *> VL) { return getTreeCost_rec(VL, 0); } +static bool CanReuseExtract(ArrayRef<Value *> VL, unsigned VF, + VectorType *VecTy) { + // Check if all of the extracts come from the same vector and from the + // correct offset. + Value *VL0 = VL[0]; + ExtractElementInst *E0 = cast<ExtractElementInst>(VL0); + Value *Vec = E0->getOperand(0); + + // We have to extract from the same vector type. + if (Vec->getType() != VecTy) + return false; + + // Check that all of the indices extract from the correct offset. + ConstantInt *CI = dyn_cast<ConstantInt>(E0->getOperand(1)); + if (!CI || CI->getZExtValue()) + return false; + + for (unsigned i = 1, e = VF; i < e; ++i) { + ExtractElementInst *E = cast<ExtractElementInst>(VL[i]); + ConstantInt *CI = dyn_cast<ConstantInt>(E->getOperand(1)); + + if (!CI || CI->getZExtValue() != i || E->getOperand(0) != Vec) + return false; + } + + return true; +} + void BoUpSLP::getTreeUses_rec(ArrayRef<Value *> VL, unsigned Depth) { if (Depth == RecursionMaxDepth) return; @@ -386,6 +414,12 @@ void BoUpSLP::getTreeUses_rec(ArrayRef<Value *> VL, unsigned Depth) { } switch (Opcode) { + case Instruction::ExtractElement: { + VectorType *VecTy = VectorType::get(VL[0]->getType(), VL.size()); + // No need to follow ExtractElements that are going to be optimized away. + if (CanReuseExtract(VL, VL.size(), VecTy)) return; + // Fall through. + } case Instruction::ZExt: case Instruction::SExt: case Instruction::FPToUI: @@ -523,6 +557,11 @@ int BoUpSLP::getTreeCost_rec(ArrayRef<Value *> VL, unsigned Depth) { TTI->getVectorInstrCost(Instruction::ExtractElement, VecTy, i); switch (Opcode) { + case Instruction::ExtractElement: { + if (CanReuseExtract(VL, VL.size(), VecTy)) + return 0; + return getScalarizationCost(VecTy); + } case Instruction::ZExt: case Instruction::SExt: case Instruction::FPToUI: @@ -786,6 +825,11 @@ Value *BoUpSLP::vectorizeTree_rec(ArrayRef<Value *> VL, int VF) { } switch (Opcode) { + case Instruction::ExtractElement: { + if (CanReuseExtract(VL, VL.size(), VecTy)) + return VL0->getOperand(0); + return Scalarize(VL, VecTy); + } case Instruction::ZExt: case Instruction::SExt: case Instruction::FPToUI: |