@@ -3067,23 +3067,23 @@ bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) {
30673067 m_ConstantInt (InsIdx))))
30683068 return false ;
30693069
3070- auto *VecTy = dyn_cast<FixedVectorType>(I.getType ());
3070+ auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType ());
30713071 auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcVec->getType ());
30723072 // We can try combining vectors with different element sizes.
3073- if (!VecTy || !SrcVecTy ||
3074- SrcVecTy->getElementType () != VecTy ->getElementType ())
3073+ if (!DstVecTy || !SrcVecTy ||
3074+ SrcVecTy->getElementType () != DstVecTy ->getElementType ())
30753075 return false ;
30763076
3077- unsigned NumElts = VecTy ->getNumElements ();
3077+ unsigned NumDstElts = DstVecTy ->getNumElements ();
30783078 unsigned NumSrcElts = SrcVecTy->getNumElements ();
3079- if (InsIdx >= NumElts || NumElts == 1 )
3079+ if (InsIdx >= NumDstElts || NumDstElts == 1 )
30803080 return false ;
30813081
30823082 // Insertion into poison is a cheaper single operand shuffle.
30833083 TargetTransformInfo::ShuffleKind SK;
3084- SmallVector<int > Mask (NumElts , PoisonMaskElem);
3084+ SmallVector<int > Mask (NumDstElts , PoisonMaskElem);
30853085
3086- bool NeedExpOrNarrow = NumSrcElts != NumElts ;
3086+ bool NeedExpOrNarrow = NumSrcElts != NumDstElts ;
30873087 bool NeedDstSrcSwap = isa<PoisonValue>(DstVec) && !isa<UndefValue>(SrcVec);
30883088 if (NeedDstSrcSwap) {
30893089 SK = TargetTransformInfo::SK_PermuteSingleSrc;
@@ -3096,38 +3096,38 @@ bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) {
30963096 SK = TargetTransformInfo::SK_PermuteTwoSrc;
30973097 std::iota (Mask.begin (), Mask.end (), 0 );
30983098 if (!NeedExpOrNarrow)
3099- Mask[InsIdx] = ExtIdx + NumElts ;
3099+ Mask[InsIdx] = ExtIdx + NumDstElts ;
31003100 else
3101- Mask[InsIdx] = NumElts ;
3101+ Mask[InsIdx] = NumDstElts ;
31023102 }
31033103
31043104 // Cost
31053105 auto *Ins = cast<InsertElementInst>(&I);
31063106 auto *Ext = cast<ExtractElementInst>(I.getOperand (1 ));
31073107 InstructionCost InsCost =
3108- TTI.getVectorInstrCost (*Ins, VecTy , CostKind, InsIdx);
3108+ TTI.getVectorInstrCost (*Ins, DstVecTy , CostKind, InsIdx);
31093109 InstructionCost ExtCost =
3110- TTI.getVectorInstrCost (*Ext, VecTy , CostKind, ExtIdx);
3110+ TTI.getVectorInstrCost (*Ext, DstVecTy , CostKind, ExtIdx);
31113111 InstructionCost OldCost = ExtCost + InsCost;
31123112
31133113 InstructionCost NewCost = 0 ;
31143114 SmallVector<int > ExtToVecMask;
31153115 if (!NeedExpOrNarrow) {
31163116 // Ignore 'free' identity insertion shuffle.
31173117 // TODO: getShuffleCost should return TCC_Free for Identity shuffles.
3118- if (!ShuffleVectorInst::isIdentityMask (Mask, NumElts ))
3119- NewCost += TTI.getShuffleCost (SK, VecTy , Mask, CostKind, 0 , nullptr ,
3118+ if (!ShuffleVectorInst::isIdentityMask (Mask, NumDstElts ))
3119+ NewCost += TTI.getShuffleCost (SK, DstVecTy , Mask, CostKind, 0 , nullptr ,
31203120 {DstVec, SrcVec});
31213121 } else {
31223122 // When creating length-changing-vector, always create with a Mask whose
31233123 // first element has an ExtIdx, so that the first element of the vector
31243124 // being created is always the target to be extracted.
3125- ExtToVecMask.assign (NumElts , PoisonMaskElem);
3125+ ExtToVecMask.assign (NumDstElts , PoisonMaskElem);
31263126 ExtToVecMask[0 ] = ExtIdx;
31273127 // Add cost for expanding or narrowing
31283128 NewCost = TTI.getShuffleCost (TargetTransformInfo::SK_PermuteSingleSrc,
3129- VecTy , ExtToVecMask, CostKind);
3130- NewCost += TTI.getShuffleCost (SK, VecTy , Mask, CostKind);
3129+ DstVecTy , ExtToVecMask, CostKind);
3130+ NewCost += TTI.getShuffleCost (SK, DstVecTy , Mask, CostKind);
31313131 }
31323132
31333133 if (!Ext->hasOneUse ())
@@ -3149,7 +3149,7 @@ bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) {
31493149
31503150 // Canonicalize undef param to RHS to help further folds.
31513151 if (isa<UndefValue>(DstVec) && !isa<UndefValue>(SrcVec)) {
3152- ShuffleVectorInst::commuteShuffleMask (Mask, NumElts );
3152+ ShuffleVectorInst::commuteShuffleMask (Mask, NumDstElts );
31533153 std::swap (DstVec, SrcVec);
31543154 }
31553155
0 commit comments