diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -909,6 +909,41 @@ return TargetTTI->getCmpSelInstrCost(Opcode, ValTy, U->getType(), CostKind, I); } + case Instruction::InsertElement: { + auto *IE = cast(U); + auto *CI = dyn_cast(IE->getOperand(2)); + unsigned Idx = CI ? CI->getZExtValue() : -1; + return TargetTTI->getVectorInstrCost(Opcode, Ty, Idx); + } + case Instruction::ShuffleVector: { + auto *Shuffle = cast(U); + auto *VecTy = cast(U->getType()); + auto *VecSrcTy = cast(U->getOperand(0)->getType()); + + // TODO: Identify and add costs for insert subvector, etc. + int SubIndex; + if (Shuffle->isExtractSubvectorMask(SubIndex)) + return TargetTTI->getShuffleCost(TTI::SK_ExtractSubvector, VecSrcTy, + SubIndex, VecTy); + else if (Shuffle->changesLength()) + return CostKind == TTI::TCK_RecipThroughput ? -1 : 1; + else if (Shuffle->isIdentity()) + return 0; + else if (Shuffle->isReverse()) + return TargetTTI->getShuffleCost(TTI::SK_Reverse, VecTy, 0, nullptr); + else if (Shuffle->isSelect()) + return TargetTTI->getShuffleCost(TTI::SK_Select, VecTy, 0, nullptr); + else if (Shuffle->isTranspose()) + return TargetTTI->getShuffleCost(TTI::SK_Transpose, VecTy, 0, nullptr); + else if (Shuffle->isZeroEltSplat()) + return TargetTTI->getShuffleCost(TTI::SK_Broadcast, VecTy, 0, nullptr); + else if (Shuffle->isSingleSource()) + return TargetTTI->getShuffleCost(TTI::SK_PermuteSingleSrc, VecTy, 0, + nullptr); + + return TargetTTI->getShuffleCost(TTI::SK_PermuteTwoSrc, VecTy, 0, + nullptr); + } } // By default, just classify everything as 'basic'. return TTI::TCC_Basic; diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -1357,49 +1357,10 @@ return getVectorInstrCost(I->getOpcode(), EEI->getOperand(0)->getType(), Idx); } - case Instruction::InsertElement: { - const InsertElementInst *IE = cast(I); - ConstantInt *CI = dyn_cast(IE->getOperand(2)); - unsigned Idx = -1; - if (CI) - Idx = CI->getZExtValue(); - return getVectorInstrCost(I->getOpcode(), IE->getType(), Idx); - } + case Instruction::InsertElement: case Instruction::ExtractValue: - return 0; // Model all ExtractValue nodes as free. - case Instruction::ShuffleVector: { - const ShuffleVectorInst *Shuffle = cast(I); - auto *Ty = cast(Shuffle->getType()); - auto *SrcTy = cast(Shuffle->getOperand(0)->getType()); - - // TODO: Identify and add costs for insert subvector, etc. - int SubIndex; - if (Shuffle->isExtractSubvectorMask(SubIndex)) - return TTIImpl->getShuffleCost(SK_ExtractSubvector, SrcTy, SubIndex, Ty); - - if (Shuffle->changesLength()) - return -1; - - if (Shuffle->isIdentity()) - return 0; - - if (Shuffle->isReverse()) - return TTIImpl->getShuffleCost(SK_Reverse, Ty, 0, nullptr); - - if (Shuffle->isSelect()) - return TTIImpl->getShuffleCost(SK_Select, Ty, 0, nullptr); - - if (Shuffle->isTranspose()) - return TTIImpl->getShuffleCost(SK_Transpose, Ty, 0, nullptr); - - if (Shuffle->isZeroEltSplat()) - return TTIImpl->getShuffleCost(SK_Broadcast, Ty, 0, nullptr); - - if (Shuffle->isSingleSource()) - return TTIImpl->getShuffleCost(SK_PermuteSingleSrc, Ty, 0, nullptr); - - return TTIImpl->getShuffleCost(SK_PermuteTwoSrc, Ty, 0, nullptr); - } + case Instruction::ShuffleVector: + return getUserCost(I, CostKind); case Instruction::Call: return getUserCost(I, CostKind); default: diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp @@ -999,46 +999,6 @@ Idx = CI->getZExtValue(); return getVectorInstrCost(I->getOpcode(), I->getOperand(0)->getType(), Idx); } - case Instruction::InsertElement: { - ConstantInt *CI = dyn_cast(I->getOperand(2)); - unsigned Idx = -1; - if (CI) - Idx = CI->getZExtValue(); - return getVectorInstrCost(I->getOpcode(), I->getType(), Idx); - } - case Instruction::ShuffleVector: { - const ShuffleVectorInst *Shuffle = cast(I); - auto *Ty = cast(Shuffle->getType()); - auto *SrcTy = cast(Shuffle->getOperand(0)->getType()); - - // TODO: Identify and add costs for insert subvector, etc. - int SubIndex; - if (Shuffle->isExtractSubvectorMask(SubIndex)) - return getShuffleCost(TTI::SK_ExtractSubvector, SrcTy, SubIndex, Ty); - - if (Shuffle->changesLength()) - return BaseT::getUserCost(U, Operands, CostKind); - - if (Shuffle->isIdentity()) - return 0; - - if (Shuffle->isReverse()) - return getShuffleCost(TTI::SK_Reverse, Ty, 0, nullptr); - - if (Shuffle->isSelect()) - return getShuffleCost(TTI::SK_Select, Ty, 0, nullptr); - - if (Shuffle->isTranspose()) - return getShuffleCost(TTI::SK_Transpose, Ty, 0, nullptr); - - if (Shuffle->isZeroEltSplat()) - return getShuffleCost(TTI::SK_Broadcast, Ty, 0, nullptr); - - if (Shuffle->isSingleSource()) - return getShuffleCost(TTI::SK_PermuteSingleSrc, Ty, 0, nullptr); - - return getShuffleCost(TTI::SK_PermuteTwoSrc, Ty, 0, nullptr); - } case Instruction::FNeg: return getArithmeticInstrCost(I->getOpcode(), I->getType(), CostKind, TTI::OK_AnyValue, TTI::OK_AnyValue, diff --git a/llvm/test/CodeGen/SystemZ/splitMove_undefReg_mverifier.ll b/llvm/test/CodeGen/SystemZ/splitMove_undefReg_mverifier.ll --- a/llvm/test/CodeGen/SystemZ/splitMove_undefReg_mverifier.ll +++ b/llvm/test/CodeGen/SystemZ/splitMove_undefReg_mverifier.ll @@ -210,7 +210,7 @@ br i1 %E112, label %CF240, label %CF254 CF254: ; preds = %CF254, %CF267, %CF264, %CF240 - %Shuff113 = shufflevector <2 x i32> %I68, <2 x i32> zeroinitializer, <2 x i32> undef + %Shuff113 = shufflevector <2 x i32> %I68, <2 x i32> zeroinitializer, <2 x i32> %I114 = insertelement <4 x i16> zeroinitializer, i16 27357, i32 3 %B115 = and i16 %Sl102, %Sl11 %FC116 = uitofp i16 %B115 to double