@@ -1518,7 +1518,7 @@ class BoUpSLP {
1518
1518
void setInsertPointAfterBundle (TreeEntry *E);
1519
1519
1520
1520
// / \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);
1522
1522
1523
1523
// / \returns whether the VectorizableTree is fully vectorizable and will
1524
1524
// / be beneficial even the tree height is tiny.
@@ -4133,10 +4133,12 @@ void BoUpSLP::setInsertPointAfterBundle(TreeEntry *E) {
4133
4133
Builder.SetCurrentDebugLocation (Front->getDebugLoc ());
4134
4134
}
4135
4135
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) {
4140
4142
Vec = Builder.CreateInsertElement (Vec, VL[i], Builder.getInt32 (i));
4141
4143
if (auto *Insrt = dyn_cast<InsertElementInst>(Vec)) {
4142
4144
GatherSeq.insert (Insrt);
@@ -4193,10 +4195,6 @@ Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL) {
4193
4195
}
4194
4196
}
4195
4197
4196
- Type *ScalarTy = S.OpValue ->getType ();
4197
- if (StoreInst *SI = dyn_cast<StoreInst>(S.OpValue ))
4198
- ScalarTy = SI->getValueOperand ()->getType ();
4199
-
4200
4198
// Check that every instruction appears once in this bundle.
4201
4199
SmallVector<int , 4 > ReuseShuffleIndicies;
4202
4200
SmallVector<Value *, 4 > UniqueValues;
@@ -4216,18 +4214,17 @@ Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL) {
4216
4214
else
4217
4215
VL = UniqueValues;
4218
4216
}
4219
- auto *VecTy = FixedVectorType::get (ScalarTy, VL.size ());
4220
4217
4221
- Value *V = Gather (VL, VecTy );
4218
+ Value *Vec = gather (VL);
4222
4219
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 )) {
4226
4223
GatherSeq.insert (I);
4227
4224
CSEBlocks.insert (I->getParent ());
4228
4225
}
4229
4226
}
4230
- return V ;
4227
+ return Vec ;
4231
4228
}
4232
4229
4233
4230
Value *BoUpSLP::vectorizeTree (TreeEntry *E) {
@@ -4238,32 +4235,30 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
4238
4235
return E->VectorizedValue ;
4239
4236
}
4240
4237
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
-
4247
4238
bool NeedToShuffleReuses = !E->ReuseShuffleIndices .empty ();
4248
-
4249
4239
if (E->State == TreeEntry::NeedToGather) {
4250
4240
setInsertPointAfterBundle (E);
4251
- auto *V = Gather (E->Scalars , VecTy );
4241
+ Value *Vec = gather (E->Scalars );
4252
4242
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 )) {
4256
4246
GatherSeq.insert (I);
4257
4247
CSEBlocks.insert (I->getParent ());
4258
4248
}
4259
4249
}
4260
- E->VectorizedValue = V ;
4261
- return V ;
4250
+ E->VectorizedValue = Vec ;
4251
+ return Vec ;
4262
4252
}
4263
4253
4264
4254
assert (E->State == TreeEntry::Vectorize && " Unhandled state" );
4265
4255
unsigned ShuffleOrOp =
4266
4256
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 ());
4267
4262
switch (ShuffleOrOp) {
4268
4263
case Instruction::PHI: {
4269
4264
auto *PH = cast<PHINode>(VL0);
0 commit comments