Skip to content

Commit 9f449c3

Browse files
authored
[SLP] NFC. Use TreeEntry::getOperand if setOperandsInOrder is called (#92727)
already.
1 parent 1ef081b commit 9f449c3

File tree

1 file changed

+17
-55
lines changed

1 file changed

+17
-55
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6916,15 +6916,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
69166916
std::nullopt, CurrentOrder);
69176917
LLVM_DEBUG(dbgs() << "SLP: added inserts bundle.\n");
69186918

6919-
constexpr int NumOps = 2;
6920-
ValueList VectorOperands[NumOps];
6921-
for (int I = 0; I < NumOps; ++I) {
6922-
for (Value *V : VL)
6923-
VectorOperands[I].push_back(cast<Instruction>(V)->getOperand(I));
6924-
6925-
TE->setOperand(I, VectorOperands[I]);
6926-
}
6927-
buildTree_rec(VectorOperands[NumOps - 1], Depth + 1, {TE, NumOps - 1});
6919+
TE->setOperandsInOrder();
6920+
buildTree_rec(TE->getOperand(1), Depth + 1, {TE, 1});
69286921
return;
69296922
}
69306923
case Instruction::Load: {
@@ -7024,14 +7017,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
70247017
LLVM_DEBUG(dbgs() << "SLP: added a vector of casts.\n");
70257018

70267019
TE->setOperandsInOrder();
7027-
for (unsigned I : seq<unsigned>(0, VL0->getNumOperands())) {
7028-
ValueList Operands;
7029-
// Prepare the operand vector.
7030-
for (Value *V : VL)
7031-
Operands.push_back(cast<Instruction>(V)->getOperand(I));
7032-
7033-
buildTree_rec(Operands, Depth + 1, {TE, I});
7034-
}
7020+
for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
7021+
buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
70357022
return;
70367023
}
70377024
case Instruction::ICmp:
@@ -7116,14 +7103,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
71167103
}
71177104

71187105
TE->setOperandsInOrder();
7119-
for (unsigned I : seq<unsigned>(0, VL0->getNumOperands())) {
7120-
ValueList Operands;
7121-
// Prepare the operand vector.
7122-
for (Value *V : VL)
7123-
Operands.push_back(cast<Instruction>(V)->getOperand(I));
7124-
7125-
buildTree_rec(Operands, Depth + 1, {TE, I});
7126-
}
7106+
for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
7107+
buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
71277108
return;
71287109
}
71297110
case Instruction::GetElementPtr: {
@@ -7182,30 +7163,17 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
71827163
return;
71837164
}
71847165
case Instruction::Store: {
7185-
// Check if the stores are consecutive or if we need to swizzle them.
7186-
ValueList Operands(VL.size());
7187-
auto *OIter = Operands.begin();
7188-
for (Value *V : VL) {
7189-
auto *SI = cast<StoreInst>(V);
7190-
*OIter = SI->getValueOperand();
7191-
++OIter;
7192-
}
7193-
// Check that the sorted pointer operands are consecutive.
7194-
if (CurrentOrder.empty()) {
7195-
// Original stores are consecutive and does not require reordering.
7196-
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
7197-
ReuseShuffleIndices);
7198-
TE->setOperandsInOrder();
7199-
buildTree_rec(Operands, Depth + 1, {TE, 0});
7200-
LLVM_DEBUG(dbgs() << "SLP: added a vector of stores.\n");
7201-
} else {
7166+
bool Consecutive = CurrentOrder.empty();
7167+
if (!Consecutive)
72027168
fixupOrderingIndices(CurrentOrder);
7203-
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
7204-
ReuseShuffleIndices, CurrentOrder);
7205-
TE->setOperandsInOrder();
7206-
buildTree_rec(Operands, Depth + 1, {TE, 0});
7169+
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
7170+
ReuseShuffleIndices, CurrentOrder);
7171+
TE->setOperandsInOrder();
7172+
buildTree_rec(TE->getOperand(0), Depth + 1, {TE, 0});
7173+
if (Consecutive)
7174+
LLVM_DEBUG(dbgs() << "SLP: added a vector of stores.\n");
7175+
else
72077176
LLVM_DEBUG(dbgs() << "SLP: added a vector of jumbled stores.\n");
7208-
}
72097177
return;
72107178
}
72117179
case Instruction::Call: {
@@ -7305,14 +7273,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
73057273
}
73067274

73077275
TE->setOperandsInOrder();
7308-
for (unsigned I : seq<unsigned>(0, VL0->getNumOperands())) {
7309-
ValueList Operands;
7310-
// Prepare the operand vector.
7311-
for (Value *V : VL)
7312-
Operands.push_back(cast<Instruction>(V)->getOperand(I));
7313-
7314-
buildTree_rec(Operands, Depth + 1, {TE, I});
7315-
}
7276+
for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
7277+
buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
73167278
return;
73177279
}
73187280
default:

0 commit comments

Comments
 (0)