[SLPVectorizer] Change canReuseExtract function parameter Opcode from unsigned to Value *, NFCI.

llvm-svn: 308739
This commit is contained in:
Dinar Temirbulatov 2017-07-21 13:32:36 +00:00
parent 04db368a3f
commit 3206409d91
1 changed files with 15 additions and 19 deletions

View File

@ -424,7 +424,7 @@ private:
/// \returns True if the ExtractElement/ExtractValue instructions in VL can /// \returns True if the ExtractElement/ExtractValue instructions in VL can
/// be vectorized to use the original vector (or aggregate "bitcast" to a vector). /// be vectorized to use the original vector (or aggregate "bitcast" to a vector).
bool canReuseExtract(ArrayRef<Value *> VL, unsigned Opcode) const; bool canReuseExtract(ArrayRef<Value *> VL, Value *OpValue) const;
/// Vectorize a single entry in the tree. /// Vectorize a single entry in the tree.
Value *vectorizeTree(TreeEntry *E); Value *vectorizeTree(TreeEntry *E);
@ -1280,7 +1280,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
} }
case Instruction::ExtractValue: case Instruction::ExtractValue:
case Instruction::ExtractElement: { case Instruction::ExtractElement: {
bool Reuse = canReuseExtract(VL, Opcode); bool Reuse = canReuseExtract(VL, VL0);
if (Reuse) { if (Reuse) {
DEBUG(dbgs() << "SLP: Reusing extract sequence.\n"); DEBUG(dbgs() << "SLP: Reusing extract sequence.\n");
} else { } else {
@ -1663,19 +1663,18 @@ unsigned BoUpSLP::canMapToVector(Type *T, const DataLayout &DL) const {
return N; return N;
} }
bool BoUpSLP::canReuseExtract(ArrayRef<Value *> VL, unsigned Opcode) const { bool BoUpSLP::canReuseExtract(ArrayRef<Value *> VL, Value *OpValue) const {
assert(Opcode == Instruction::ExtractElement || Instruction *E0 = cast<Instruction>(OpValue);
Opcode == Instruction::ExtractValue); assert(E0->getOpcode() == Instruction::ExtractElement ||
assert(Opcode == getSameOpcode(VL) && "Invalid opcode"); E0->getOpcode() == Instruction::ExtractValue);
assert(E0->getOpcode() == getSameOpcode(VL) && "Invalid opcode");
// Check if all of the extracts come from the same vector and from the // Check if all of the extracts come from the same vector and from the
// correct offset. // correct offset.
Value *VL0 = VL[0];
Instruction *E0 = cast<Instruction>(VL0);
Value *Vec = E0->getOperand(0); Value *Vec = E0->getOperand(0);
// We have to extract from a vector/aggregate with the same number of elements. // We have to extract from a vector/aggregate with the same number of elements.
unsigned NElts; unsigned NElts;
if (Opcode == Instruction::ExtractValue) { if (E0->getOpcode() == Instruction::ExtractValue) {
const DataLayout &DL = E0->getModule()->getDataLayout(); const DataLayout &DL = E0->getModule()->getDataLayout();
NElts = canMapToVector(Vec->getType(), DL); NElts = canMapToVector(Vec->getType(), DL);
if (!NElts) if (!NElts)
@ -1692,14 +1691,11 @@ bool BoUpSLP::canReuseExtract(ArrayRef<Value *> VL, unsigned Opcode) const {
return false; return false;
// Check that all of the indices extract from the correct offset. // Check that all of the indices extract from the correct offset.
if (!matchExtractIndex(E0, 0, Opcode)) for (unsigned I = 0, E = VL.size(); I < E; ++I) {
Instruction *Inst = cast<Instruction>(VL[I]);
if (!matchExtractIndex(Inst, I, Inst->getOpcode()))
return false; return false;
if (Inst->getOperand(0) != Vec)
for (unsigned i = 1, e = VL.size(); i < e; ++i) {
Instruction *E = cast<Instruction>(VL[i]);
if (!matchExtractIndex(E, i, Opcode))
return false;
if (E->getOperand(0) != Vec)
return false; return false;
} }
@ -1739,7 +1735,7 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
} }
case Instruction::ExtractValue: case Instruction::ExtractValue:
case Instruction::ExtractElement: { case Instruction::ExtractElement: {
if (canReuseExtract(VL, Opcode)) { if (canReuseExtract(VL, VL0)) {
int DeadCost = 0; int DeadCost = 0;
for (unsigned i = 0, e = VL.size(); i < e; ++i) { for (unsigned i = 0, e = VL.size(); i < e; ++i) {
Instruction *E = cast<Instruction>(VL[i]); Instruction *E = cast<Instruction>(VL[i]);
@ -2508,7 +2504,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
} }
case Instruction::ExtractElement: { case Instruction::ExtractElement: {
if (canReuseExtract(E->Scalars, Instruction::ExtractElement)) { if (canReuseExtract(E->Scalars, VL0)) {
Value *V = VL0->getOperand(0); Value *V = VL0->getOperand(0);
E->VectorizedValue = V; E->VectorizedValue = V;
return V; return V;
@ -2519,7 +2515,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
return V; return V;
} }
case Instruction::ExtractValue: { case Instruction::ExtractValue: {
if (canReuseExtract(E->Scalars, Instruction::ExtractValue)) { if (canReuseExtract(E->Scalars, VL0)) {
LoadInst *LI = cast<LoadInst>(VL0->getOperand(0)); LoadInst *LI = cast<LoadInst>(VL0->getOperand(0));
Builder.SetInsertPoint(LI); Builder.SetInsertPoint(LI);
PointerType *PtrTy = PointerType::get(VecTy, LI->getPointerAddressSpace()); PointerType *PtrTy = PointerType::get(VecTy, LI->getPointerAddressSpace());