diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3690,6 +3690,9 @@ TTI->getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy, None, 0); } + // No cost for "gathering" already vector value + if (isa(VL[0]->getType())) + return 0; if (E->getOpcode() == Instruction::ExtractElement && allSameType(VL) && allSameBlock(VL)) { SmallVector Mask; @@ -4591,6 +4594,9 @@ Value *BoUpSLP::gather(ArrayRef VL) { Value *Val0 = isa(VL[0]) ? cast(VL[0])->getValueOperand() : VL[0]; + // "Gathering" of vector values is already done + if (isa(Val0->getType())) + return Val0; FixedVectorType *VecTy = FixedVectorType::get(Val0->getType(), VL.size()); Value *Vec = PoisonValue::get(VecTy); unsigned InsIndex = 0;