Skip to content

Commit 46075e0

Browse files
committed
[SLP] simplify interface for gather(); NFC
The implementation of gather() should be reduced too, but this change by itself makes things a little clearer: we don't try to gather to a different type or number-of-values than whatever is passed in as the value list itself.
1 parent 6a0ed57 commit 46075e0

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ class BoUpSLP {
15181518
void setInsertPointAfterBundle(TreeEntry *E);
15191519

15201520
/// \returns a vector from a collection of scalars in \p VL.
1521-
Value *Gather(ArrayRef<Value *> VL, FixedVectorType *Ty);
1521+
Value *gather(ArrayRef<Value *> VL);
15221522

15231523
/// \returns whether the VectorizableTree is fully vectorizable and will
15241524
/// be beneficial even the tree height is tiny.
@@ -4133,10 +4133,12 @@ void BoUpSLP::setInsertPointAfterBundle(TreeEntry *E) {
41334133
Builder.SetCurrentDebugLocation(Front->getDebugLoc());
41344134
}
41354135

4136-
Value *BoUpSLP::Gather(ArrayRef<Value *> VL, FixedVectorType *Ty) {
4137-
Value *Vec = UndefValue::get(Ty);
4138-
// Generate the 'InsertElement' instruction.
4139-
for (unsigned i = 0; i < Ty->getNumElements(); ++i) {
4136+
Value *BoUpSLP::gather(ArrayRef<Value *> VL) {
4137+
Value *Val0 =
4138+
isa<StoreInst>(VL[0]) ? cast<StoreInst>(VL[0])->getValueOperand() : VL[0];
4139+
FixedVectorType *VecTy = FixedVectorType::get(Val0->getType(), VL.size());
4140+
Value *Vec = UndefValue::get(VecTy);
4141+
for (unsigned i = 0; i < VecTy->getNumElements(); ++i) {
41404142
Vec = Builder.CreateInsertElement(Vec, VL[i], Builder.getInt32(i));
41414143
if (auto *Insrt = dyn_cast<InsertElementInst>(Vec)) {
41424144
GatherSeq.insert(Insrt);
@@ -4193,10 +4195,6 @@ Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL) {
41934195
}
41944196
}
41954197

4196-
Type *ScalarTy = S.OpValue->getType();
4197-
if (StoreInst *SI = dyn_cast<StoreInst>(S.OpValue))
4198-
ScalarTy = SI->getValueOperand()->getType();
4199-
42004198
// Check that every instruction appears once in this bundle.
42014199
SmallVector<int, 4> ReuseShuffleIndicies;
42024200
SmallVector<Value *, 4> UniqueValues;
@@ -4216,18 +4214,17 @@ Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL) {
42164214
else
42174215
VL = UniqueValues;
42184216
}
4219-
auto *VecTy = FixedVectorType::get(ScalarTy, VL.size());
42204217

4221-
Value *V = Gather(VL, VecTy);
4218+
Value *Vec = gather(VL);
42224219
if (!ReuseShuffleIndicies.empty()) {
4223-
V = Builder.CreateShuffleVector(V, UndefValue::get(VecTy),
4224-
ReuseShuffleIndicies, "shuffle");
4225-
if (auto *I = dyn_cast<Instruction>(V)) {
4220+
Vec = Builder.CreateShuffleVector(Vec, UndefValue::get(Vec->getType()),
4221+
ReuseShuffleIndicies, "shuffle");
4222+
if (auto *I = dyn_cast<Instruction>(Vec)) {
42264223
GatherSeq.insert(I);
42274224
CSEBlocks.insert(I->getParent());
42284225
}
42294226
}
4230-
return V;
4227+
return Vec;
42314228
}
42324229

42334230
Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
@@ -4238,32 +4235,30 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
42384235
return E->VectorizedValue;
42394236
}
42404237

4241-
Instruction *VL0 = E->getMainOp();
4242-
Type *ScalarTy = VL0->getType();
4243-
if (StoreInst *SI = dyn_cast<StoreInst>(VL0))
4244-
ScalarTy = SI->getValueOperand()->getType();
4245-
auto *VecTy = FixedVectorType::get(ScalarTy, E->Scalars.size());
4246-
42474238
bool NeedToShuffleReuses = !E->ReuseShuffleIndices.empty();
4248-
42494239
if (E->State == TreeEntry::NeedToGather) {
42504240
setInsertPointAfterBundle(E);
4251-
auto *V = Gather(E->Scalars, VecTy);
4241+
Value *Vec = gather(E->Scalars);
42524242
if (NeedToShuffleReuses) {
4253-
V = Builder.CreateShuffleVector(V, UndefValue::get(VecTy),
4254-
E->ReuseShuffleIndices, "shuffle");
4255-
if (auto *I = dyn_cast<Instruction>(V)) {
4243+
Vec = Builder.CreateShuffleVector(Vec, UndefValue::get(Vec->getType()),
4244+
E->ReuseShuffleIndices, "shuffle");
4245+
if (auto *I = dyn_cast<Instruction>(Vec)) {
42564246
GatherSeq.insert(I);
42574247
CSEBlocks.insert(I->getParent());
42584248
}
42594249
}
4260-
E->VectorizedValue = V;
4261-
return V;
4250+
E->VectorizedValue = Vec;
4251+
return Vec;
42624252
}
42634253

42644254
assert(E->State == TreeEntry::Vectorize && "Unhandled state");
42654255
unsigned ShuffleOrOp =
42664256
E->isAltShuffle() ? (unsigned)Instruction::ShuffleVector : E->getOpcode();
4257+
Instruction *VL0 = E->getMainOp();
4258+
Type *ScalarTy = VL0->getType();
4259+
if (auto *Store = dyn_cast<StoreInst>(VL0))
4260+
ScalarTy = Store->getValueOperand()->getType();
4261+
auto *VecTy = FixedVectorType::get(ScalarTy, E->Scalars.size());
42674262
switch (ShuffleOrOp) {
42684263
case Instruction::PHI: {
42694264
auto *PH = cast<PHINode>(VL0);

0 commit comments

Comments
 (0)