@@ -3045,7 +3045,9 @@ class BoUpSLP {
30453045
30463046 /// \returns a vector from a collection of scalars in \p VL. if \p Root is not
30473047 /// specified, the starting vector value is poison.
3048- Value *gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy);
3048+ Value *
3049+ gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy,
3050+ function_ref<Value *(Value *, Value *, ArrayRef<int>)> CreateShuffle);
30493051
30503052 /// \returns whether the VectorizableTree is fully vectorizable and will
30513053 /// be beneficial even the tree height is tiny.
@@ -9167,8 +9169,9 @@ class BaseShuffleAnalysis {
91679169 int VF = Mask.size();
91689170 if (auto *FTy = dyn_cast<FixedVectorType>(V1->getType()))
91699171 VF = FTy->getNumElements();
9170- if (V2 &&
9171- !isUndefVector(V2, buildUseMask(VF, Mask, UseMask::SecondArg)).all()) {
9172+ if (V2 && !isUndefVector</*IsPoisonOnly=*/true>(
9173+ V2, buildUseMask(VF, Mask, UseMask::SecondArg))
9174+ .all()) {
91729175 // Peek through shuffles.
91739176 Value *Op1 = V1;
91749177 Value *Op2 = V2;
@@ -13454,7 +13457,9 @@ void BoUpSLP::setInsertPointAfterBundle(const TreeEntry *E) {
1345413457 Builder.SetCurrentDebugLocation(Front->getDebugLoc());
1345513458}
1345613459
13457- Value *BoUpSLP::gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy) {
13460+ Value *BoUpSLP::gather(
13461+ ArrayRef<Value *> VL, Value *Root, Type *ScalarTy,
13462+ function_ref<Value *(Value *, Value *, ArrayRef<int>)> CreateShuffle) {
1345813463 // List of instructions/lanes from current block and/or the blocks which are
1345913464 // part of the current loop. These instructions will be inserted at the end to
1346013465 // make it possible to optimize loops and hoist invariant instructions out of
@@ -13560,7 +13565,7 @@ Value *BoUpSLP::gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy) {
1356013565 if (isa<PoisonValue>(Vec)) {
1356113566 Vec = OriginalRoot;
1356213567 } else {
13563- Vec = Builder.CreateShuffleVector (Root, Vec, Mask);
13568+ Vec = CreateShuffle (Root, Vec, Mask);
1356413569 if (auto *OI = dyn_cast<Instruction>(OriginalRoot);
1356513570 OI && OI->hasNUses(0))
1356613571 eraseInstruction(OI);
@@ -14022,7 +14027,10 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
1402214027 }
1402314028 Value *gather(ArrayRef<Value *> VL, unsigned MaskVF = 0,
1402414029 Value *Root = nullptr) {
14025- return R.gather(VL, Root, ScalarTy);
14030+ return R.gather(VL, Root, ScalarTy,
14031+ [&](Value *V1, Value *V2, ArrayRef<int> Mask) {
14032+ return createShuffle(V1, V2, Mask);
14033+ });
1402614034 }
1402714035 Value *createFreeze(Value *V) { return Builder.CreateFreeze(V); }
1402814036 /// Finalize emission of the shuffles.
0 commit comments