19#include "llvm/IR/IntrinsicsRISCV.h"
28#define DEBUG_TYPE "riscvtti"
36 size_t NumInstr = OpCodes.size();
41 return LMULCost * NumInstr;
43 for (
auto Op : OpCodes) {
45 case RISCV::VRGATHER_VI:
46 Cost +=
TLI->getVRGatherVICost(VT);
48 case RISCV::VRGATHER_VV:
49 Cost +=
TLI->getVRGatherVVCost(VT);
51 case RISCV::VSLIDEUP_VI:
52 case RISCV::VSLIDEDOWN_VI:
53 Cost +=
TLI->getVSlideVICost(VT);
55 case RISCV::VSLIDEUP_VX:
56 case RISCV::VSLIDEDOWN_VX:
57 Cost +=
TLI->getVSlideVXCost(VT);
59 case RISCV::VREDMAX_VS:
60 case RISCV::VREDMIN_VS:
61 case RISCV::VREDMAXU_VS:
62 case RISCV::VREDMINU_VS:
63 case RISCV::VREDSUM_VS:
64 case RISCV::VREDAND_VS:
65 case RISCV::VREDOR_VS:
66 case RISCV::VREDXOR_VS:
67 case RISCV::VFREDMAX_VS:
68 case RISCV::VFREDMIN_VS:
69 case RISCV::VFREDUSUM_VS: {
76 case RISCV::VFREDOSUM_VS: {
93 case RISCV::VMANDN_MM:
94 case RISCV::VMNAND_MM:
115 assert(Ty->isIntegerTy() &&
116 "getIntImmCost can only estimate cost of materialising integers");
139 if (!BO || !BO->hasOneUse())
142 if (BO->getOpcode() != Instruction::Shl)
153 if (ShAmt == Trailing)
170 if (!Cmp || !Cmp->isEquality())
186 if ((CmpC & Mask) != CmpC)
193 return NewCmpC >= -2048 && NewCmpC <= 2048;
200 assert(Ty->isIntegerTy() &&
201 "getIntImmCost can only estimate cost of materialising integers");
209 bool Takes12BitImm =
false;
210 unsigned ImmArgIdx = ~0U;
213 case Instruction::GetElementPtr:
218 case Instruction::Store: {
223 if (Idx == 1 || !Inst)
228 if (!getTLI()->allowsMemoryAccessForAlignment(
229 Ty->getContext(),
DL, getTLI()->getValueType(
DL, Ty),
236 case Instruction::Load:
239 case Instruction::And:
241 if (
Imm == UINT64_C(0xffff) && ST->hasStdExtZbb())
244 if (
Imm == UINT64_C(0xffffffff) && (!ST->is64Bit() || ST->hasStdExtZba()))
247 if (ST->hasStdExtZbs() && (~
Imm).isPowerOf2())
249 if (Inst && Idx == 1 &&
Imm.getBitWidth() <= ST->getXLen() &&
252 if (Inst && Idx == 1 &&
Imm.getBitWidth() == 64 &&
255 Takes12BitImm =
true;
257 case Instruction::Add:
258 Takes12BitImm =
true;
260 case Instruction::Or:
261 case Instruction::Xor:
263 if (ST->hasStdExtZbs() &&
Imm.isPowerOf2())
265 Takes12BitImm =
true;
267 case Instruction::Mul:
269 if (
Imm.isPowerOf2() ||
Imm.isNegatedPowerOf2())
272 if ((
Imm + 1).isPowerOf2() || (
Imm - 1).isPowerOf2())
275 Takes12BitImm =
true;
277 case Instruction::Sub:
278 case Instruction::Shl:
279 case Instruction::LShr:
280 case Instruction::AShr:
281 Takes12BitImm =
true;
292 if (
Imm.getSignificantBits() <= 64 &&
308 if (!ST->hasStdExtZibi())
313 const auto Pred =
Cond.getPredicate();
315 if (
C && (
C->isZero() ||
324 return Imm == -1 || (
Imm >= 1 &&
Imm <= 31);
336 return ST->hasVInstructions();
340 unsigned Opcode,
Type *InputTypeA,
Type *InputTypeB,
Type *AccumType,
344 if (Opcode == Instruction::FAdd)
353 if (!ST->hasStdExtZvdot4a8i() || ST->getELen() < 64 ||
354 Opcode != Instruction::Add || !BinOp || *BinOp != Instruction::Mul ||
355 InputTypeA != InputTypeB || !InputTypeA->
isIntegerTy(8) ||
371 getRISCVInstructionCost(RISCV::VDOT4A_VV, DotLT.second, CostKind);
380 std::pair<InstructionCost, MVT> AccLT =
388 bool WidenFirst =
false;
389 if (VF.
isScalable() && AccLT.second.isScalableVector()) {
390 MVT NarrowMVT = AccLT.second.changeVectorElementType(MVT::i32);
403 WideLT.first * getRISCVInstructionCost(RISCV::VSEXT_VF2,
404 WideLT.second, CostKind) +
406 getRISCVInstructionCost(RISCV::VADD_VV, AccLT.second, CostKind);
410 std::pair<InstructionCost, MVT> RedLT =
412 Cost += RedLT.first * getRISCVInstructionCost(RISCV::VADD_VV,
413 RedLT.second, CostKind) +
414 AccLT.first * getRISCVInstructionCost(RISCV::VWADD_WV,
415 AccLT.second, CostKind);
418 Cost += DotLT.first * getRISCVInstructionCost(RISCV::VSLIDEDOWN_VI,
419 DotLT.second, CostKind);
430 switch (
II->getIntrinsicID()) {
434 case Intrinsic::vector_reduce_mul:
435 case Intrinsic::vector_reduce_fmul:
441 if (ST->hasVInstructions())
442 if (
unsigned MinVLen = ST->getRealMinVLen();
451 std::clamp<unsigned>(ST->getCLOpts().v_register_bit_width_lmul, 1, 8));
457 ST->useRVVForFixedLengthVectors() ? LMUL * ST->getRealMinVLen() : 0);
460 (ST->hasVInstructions() &&
483 return (ST->hasAUIPCADDIFusion() && ST->hasLUIADDIFusion()) ? 1 : 2;
489RISCVTTIImpl::getConstantPoolLoadCost(
Type *Ty,
495 Cost = getStaticDataAddrGenerationCost(CostKind) +
506 unsigned Size = Mask.size();
509 for (
unsigned I = 0;
I !=
Size; ++
I) {
510 if (
static_cast<unsigned>(Mask[
I]) ==
I)
516 for (
unsigned J =
I + 1; J !=
Size; ++J)
518 if (
static_cast<unsigned>(Mask[J]) != J %
I)
546 "Expected fixed vector type and non-empty mask");
549 unsigned NumOfDests =
divideCeil(Mask.size(), LegalNumElts);
553 if (NumOfDests <= 1 ||
555 Tp->getElementType()->getPrimitiveSizeInBits() ||
556 LegalNumElts >= Tp->getElementCount().getFixedValue())
559 unsigned VecTySize =
TTI.getDataLayout().getTypeStoreSize(Tp);
562 unsigned NumOfSrcs =
divideCeil(VecTySize, LegalVTSize);
566 unsigned NormalizedVF = LegalNumElts * std::max(NumOfSrcs, NumOfDests);
567 unsigned NumOfSrcRegs = NormalizedVF / LegalNumElts;
568 unsigned NumOfDestRegs = NormalizedVF / LegalNumElts;
570 assert(NormalizedVF >= Mask.size() &&
571 "Normalized mask expected to be not shorter than original mask.");
576 NormalizedMask, NumOfSrcRegs, NumOfDestRegs, NumOfDestRegs, []() {},
577 [&](
ArrayRef<int> RegMask,
unsigned SrcReg,
unsigned DestReg) {
580 if (!ReusedSingleSrcShuffles.
insert(std::make_pair(RegMask, SrcReg))
583 Cost +=
TTI.getShuffleCost(
586 SingleOpTy, CostKind, RegMask, 0,
nullptr);
588 [&](
ArrayRef<int> RegMask,
unsigned Idx1,
unsigned Idx2,
bool NewReg) {
589 Cost +=
TTI.getShuffleCost(
592 SingleOpTy, CostKind, RegMask, 0,
nullptr);
615 if (!VLen || Mask.empty())
619 LegalVT =
TTI.getTypeLegalizationCost(
625 if (NumOfDests <= 1 ||
627 Tp->getElementType()->getPrimitiveSizeInBits() ||
631 unsigned VecTySize =
TTI.getDataLayout().getTypeStoreSize(Tp);
634 unsigned NumOfSrcs =
divideCeil(VecTySize, LegalVTSize);
640 unsigned NormalizedVF =
645 assert(NormalizedVF >= Mask.size() &&
646 "Normalized mask expected to be not shorter than original mask.");
652 NormalizedMask, NumOfSrcRegs, NumOfDestRegs, NumOfDestRegs, []() {},
653 [&](
ArrayRef<int> RegMask,
unsigned SrcReg,
unsigned DestReg) {
656 if (!ReusedSingleSrcShuffles.
insert(std::make_pair(RegMask, SrcReg))
661 SingleOpTy, CostKind, RegMask, 0,
nullptr);
663 [&](
ArrayRef<int> RegMask,
unsigned Idx1,
unsigned Idx2,
bool NewReg) {
665 SingleOpTy, CostKind, RegMask, 0,
nullptr);
672 if ((NumOfDestRegs > 2 && NumShuffles <=
static_cast<int>(NumOfDestRegs)) ||
673 (NumOfDestRegs <= 2 && NumShuffles < 4))
688 if (!
LT.second.isFixedLengthVector())
696 auto GetSlideOpcode = [&](
int SlideAmt) {
698 bool IsVI =
isUInt<5>(std::abs(SlideAmt));
700 return IsVI ? RISCV::VSLIDEDOWN_VI : RISCV::VSLIDEDOWN_VX;
701 return IsVI ? RISCV::VSLIDEUP_VI : RISCV::VSLIDEUP_VX;
704 std::array<std::pair<int, int>, 2> SrcInfo;
708 if (SrcInfo[1].second == 0)
711 if (ST->hasStdExtZvzip() &&
LT.second.getScalarSizeInBits() != 1) {
713 if (
isPairEven(SrcInfo, Mask, Factor) && Factor == 1)
714 return getRISCVInstructionCost(RISCV::VPAIRE_VV,
LT.second, CostKind);
715 if (
isPairOdd(SrcInfo, Mask, Factor) && Factor == 1)
716 return getRISCVInstructionCost(RISCV::VPAIRO_VV,
LT.second, CostKind);
720 if (SrcInfo[0].second != 0) {
721 unsigned Opcode = GetSlideOpcode(SrcInfo[0].second);
722 FirstSlideCost = getRISCVInstructionCost(Opcode,
LT.second, CostKind);
725 if (SrcInfo[1].first == -1)
726 return FirstSlideCost;
729 if (SrcInfo[1].second != 0) {
730 unsigned Opcode = GetSlideOpcode(SrcInfo[1].second);
731 SecondSlideCost = getRISCVInstructionCost(Opcode,
LT.second, CostKind);
734 getRISCVInstructionCost(RISCV::VMERGE_VVM,
LT.second, CostKind);
741 return FirstSlideCost + SecondSlideCost + MaskCost;
744MVT RISCVTTIImpl::getZvzipVZIPCostVT(
MVT InterleavedVT)
const {
748 MVT CostVT = InterleavedVT;
751 CostVT = TLI->getContainerForFixedLengthVector(SourceVT)
760 LMULOctuple * std::min(ST->getELen(), ST->getRealMinVLen()))
765MVT RISCVTTIImpl::getZvzipVUNZIPCostVT(
MVT InterleavedVT)
const {
769 MVT CostVT = InterleavedVT;
774 CostVT = TLI->getContainerForFixedLengthVector(InterleavedVT);
792 if (!ST->hasStdExtZvzip() ||
Mask.size() < 2 ||
793 DstTy->getScalarSizeInBits() == 1)
796 unsigned NumSrcElts = SrcTy->getElementCount().getKnownMinValue();
797 unsigned NumDstElts = DstTy->getElementCount().getKnownMinValue();
798 unsigned NumInputElts;
803 if (NumSrcElts != NumDstElts)
805 NumInputElts = NumSrcElts;
819 if (NumSrcElts != NumDstElts && NumSrcElts * 2 != NumDstElts)
821 NumInputElts = NumSrcElts * 2;
836 unsigned DeinterleaveIndex;
838 DeinterleaveIndex) &&
839 count_if(Mask, [](
int Idx) {
return Idx >= 0; }) > 1)
844 SmallVector<unsigned, 2> StartIndexes;
848 unsigned HalfNumElts =
Mask.size() / 2;
849 if ((StartIndexes[0] != 0 && StartIndexes[1] != 0) ||
850 StartIndexes[0] % HalfNumElts != 0 || StartIndexes[1] % HalfNumElts != 0)
854 MVT CostVT = getZvzipVZIPCostVT(DstLT.second);
859 DstLT.first * getRISCVInstructionCost(RISCV::VZIP_VV, CostVT, CostKind);
866 if (NumSrcElts == NumDstElts) {
869 for (
unsigned Start : StartIndexes) {
870 unsigned ExtractIndex =
Start % NumSrcElts;
871 if (ExtractIndex != 0)
873 CostKind, {}, ExtractIndex, HalfSrcTy);
887 "Expected the Mask to match the return size if given");
889 "Expected the same scalar types");
892 if (VIC == TTI::VectorInstrContext::SplatOpFolded &&
908 FVTp && ST->hasVInstructions() && LT.second.isFixedLengthVector()) {
910 *
this, LT.second, ST->getRealVLen(),
912 if (VRegSplittingCost.
isValid())
913 return VRegSplittingCost;
918 if (Mask.size() >= 2) {
919 MVT EltTp = LT.second.getVectorElementType();
924 getVZIPCost(Kind, DstTy, SrcTy, Mask, CostKind);
931 unsigned Opcode = Index == 0 ? RISCV::VUNZIPE_V : RISCV::VUNZIPO_V;
932 if (
MVT CostVT = getZvzipVUNZIPCostVT(LT.second); CostVT.
isValid())
933 return LT.first * getRISCVInstructionCost(Opcode, CostVT, CostKind);
946 return 2 * LT.first * TLI->getLMULCost(LT.second);
948 if (Mask[0] == 0 || Mask[0] == 1) {
952 if (
equal(DeinterleaveMask, Mask))
953 return LT.first * getRISCVInstructionCost(RISCV::VNSRL_WI,
954 LT.second, CostKind);
959 if (LT.second.getScalarSizeInBits() != 1 &&
962 unsigned NumSlides =
Log2_32(Mask.size() / SubVectorSize);
964 for (
unsigned I = 0;
I != NumSlides; ++
I) {
965 unsigned InsertIndex = SubVectorSize * (1 <<
I);
970 std::pair<InstructionCost, MVT> DestLT =
975 Cost += DestLT.first * TLI->getLMULCost(DestLT.second);
977 CostKind, {}, InsertIndex, SubTp);
989 if (LT.first == 1 && (LT.second.getScalarSizeInBits() != 8 ||
990 LT.second.getVectorNumElements() <= 256)) {
995 getRISCVInstructionCost(RISCV::VRGATHER_VV, LT.second, CostKind);
1007 getVZIPCost(Kind, DstTy, SrcTy, Mask, CostKind);
1013 if (LT.first == 1 && (LT.second.getScalarSizeInBits() != 8 ||
1014 LT.second.getVectorNumElements() <= 256)) {
1015 auto &
C = SrcTy->getContext();
1016 auto EC = SrcTy->getElementCount();
1021 return 2 * IndexCost +
1022 getRISCVInstructionCost({RISCV::VRGATHER_VV, RISCV::VRGATHER_VV},
1023 LT.second, CostKind) +
1041 if (!Mask.empty() && LT.first.isValid() && LT.first != 1 &&
1069 SubLT.second.isValid() && SubLT.second.isFixedLengthVector()) {
1070 if (std::optional<unsigned> VLen = ST->getRealVLen();
1071 VLen && SubLT.second.getScalarSizeInBits() * Index % *VLen == 0 &&
1072 SubLT.second.getSizeInBits() <= *VLen)
1080 getRISCVInstructionCost(RISCV::VSLIDEDOWN_VI, LT.second, CostKind);
1087 getRISCVInstructionCost(RISCV::VSLIDEUP_VI, LT.second, CostKind);
1099 (1 + getRISCVInstructionCost({RISCV::VMV_S_X, RISCV::VMERGE_VVM},
1100 LT.second, CostKind));
1106 if (IsLoad && LT.second.isVector() &&
1108 LT.second.getVectorElementCount()))
1112 Instruction::InsertElement);
1113 if (LT.second.getScalarSizeInBits() == 1) {
1121 (1 + getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI},
1122 LT.second, CostKind));
1134 (1 + getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM,
1135 RISCV::VMV_X_S, RISCV::VMV_V_X,
1137 LT.second, CostKind));
1144 getRISCVInstructionCost(RISCV::VMV_V_X, LT.second, CostKind);
1150 getRISCVInstructionCost(RISCV::VRGATHER_VI, LT.second, CostKind);
1156 unsigned Opcodes[2] = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VX};
1157 if (Index >= 0 && Index < 32)
1158 Opcodes[0] = RISCV::VSLIDEDOWN_VI;
1159 else if (Index < 0 && Index > -32)
1160 Opcodes[1] = RISCV::VSLIDEUP_VI;
1161 return LT.first * getRISCVInstructionCost(Opcodes, LT.second, CostKind);
1165 if (!LT.second.isVector())
1171 if (SrcTy->getElementType()->isIntegerTy(1)) {
1184 if (LT.second.isFixedLengthVector())
1185 ContainerVT = TLI->getContainerForFixedLengthVector(LT.second);
1197 if (LT.second.isFixedLengthVector())
1199 LenCost =
isInt<5>(LT.second.getVectorNumElements() - 1) ? 0 : 1;
1200 unsigned Opcodes[] = {RISCV::VID_V, RISCV::VRSUB_VX, RISCV::VRGATHER_VV};
1201 if (LT.second.isFixedLengthVector() &&
1202 isInt<5>(LT.second.getVectorNumElements() - 1))
1203 Opcodes[1] = RISCV::VRSUB_VI;
1205 getRISCVInstructionCost(Opcodes, LT.second, CostKind);
1206 return LT.first * (LenCost + GatherCost);
1213 unsigned M1Opcodes[] = {RISCV::VID_V, RISCV::VRSUB_VX};
1215 getRISCVInstructionCost(M1Opcodes, M1VT, CostKind) + 3;
1219 getRISCVInstructionCost({RISCV::VRGATHER_VV}, M1VT, CostKind) * Ratio;
1221 getRISCVInstructionCost({RISCV::VSLIDEDOWN_VX}, LT.second, CostKind);
1222 return FixedCost + LT.first * (GatherCost + SlideCost);
1256 Ty, DemandedElts, Insert, Extract, CostKind);
1258 if (Insert && !Extract && LT.first.isValid() && LT.second.isVector()) {
1259 if (Ty->getScalarSizeInBits() == 1) {
1269 assert(LT.second.isFixedLengthVector());
1270 MVT ContainerVT = TLI->getContainerForFixedLengthVector(LT.second);
1274 getRISCVInstructionCost(RISCV::VSLIDE1DOWN_VX, LT.second, CostKind);
1287 switch (MICA.
getID()) {
1288 case Intrinsic::vp_load_ff: {
1289 EVT DataTypeVT = TLI->getValueType(
DL, DataTy);
1290 if (!TLI->isLegalFirstFaultLoad(DataTypeVT, Alignment))
1294 return getMemoryOpCost(Instruction::Load, DataTy, Alignment, AS, CostKind,
1297 case Intrinsic::experimental_vp_strided_load:
1298 case Intrinsic::experimental_vp_strided_store:
1300 case Intrinsic::masked_compressstore:
1301 case Intrinsic::masked_expandload:
1303 case Intrinsic::vp_scatter:
1304 case Intrinsic::vp_gather:
1305 case Intrinsic::masked_scatter:
1306 case Intrinsic::masked_gather:
1308 case Intrinsic::vp_load:
1309 case Intrinsic::vp_store:
1310 case Intrinsic::masked_load:
1311 case Intrinsic::masked_store:
1320 unsigned Opcode = MICA.
getID() == Intrinsic::masked_load ? Instruction::Load
1321 : Instruction::Store;
1332 if (MICA.
getID() == Intrinsic::vp_load ||
1333 MICA.
getID() == Intrinsic::vp_store) {
1345 bool UseMaskForCond,
bool UseMaskForGaps)
const {
1351 if (!UseMaskForGaps && Factor <= TLI->getMaxSupportedInterleaveFactor()) {
1355 if (LT.second.isVector()) {
1361 VTy->getElementCount().divideCoefficientBy(Factor));
1362 if (VTy->getElementCount().isKnownMultipleOf(Factor) &&
1363 TLI->isLegalInterleavedAccessType(
SubVecTy, Factor, Alignment,
1368 if (ST->hasOptimizedSegmentLoadStore(Factor)) {
1369 unsigned VecSizeInBits =
1370 getEstimatedVLFor(VTy) * VTy->getScalarSizeInBits();
1371 unsigned VLENForTuning =
1373 unsigned DLENForTuning = VLENForTuning / ST->getDLenFactor();
1375 MVT SubVecVT = getTLI()->getValueType(
DL,
SubVecTy).getSimpleVT();
1376 Cost += Factor * TLI->getLMULCost(SubVecVT);
1382 unsigned NumLoads = getEstimatedVLFor(VTy);
1398 if (UseMaskForGaps) {
1401 "Indices should not contain duplicate elements");
1402 unsigned NumOfFields = Indices.
size();
1403 bool IsTailGapOnly = NumOfFields > 1 && (NumOfFields == Indices.
back() + 1);
1404 if (IsTailGapOnly &&
1405 NumOfFields <= TLI->getMaxSupportedInterleaveFactor()) {
1407 if (LT.second.isVector() &&
1408 FVTy->getElementCount().isKnownMultipleOf(Factor)) {
1410 FVTy->getElementType(),
1411 FVTy->getElementCount().divideCoefficientBy(Factor));
1412 if (TLI->isLegalInterleavedAccessType(
SubVecTy, NumOfFields, Alignment,
1415 unsigned NumAccesses = getEstimatedVLFor(FVTy);
1424 unsigned VF = FVTy->getNumElements() / Factor;
1431 if (Opcode == Instruction::Load) {
1433 for (
unsigned Index : Indices) {
1437 Mask.resize(VF * Factor, -1);
1440 CostKind, Mask, 0,
nullptr, {});
1441 Cost += ShuffleCost;
1459 UseMaskForCond, UseMaskForGaps);
1461 assert(Opcode == Instruction::Store &&
"Opcode must be a store");
1467 CostKind, Mask, 0,
nullptr, {});
1468 return MemCost + ShuffleCost;
1475 bool IsLoad = MICA.
getID() == Intrinsic::masked_gather ||
1476 MICA.
getID() == Intrinsic::vp_gather;
1477 unsigned Opcode = IsLoad ? Instruction::Load : Instruction::Store;
1485 if ((Opcode == Instruction::Load &&
1487 (Opcode == Instruction::Store &&
1493 if (MICA.
getID() == Intrinsic::vp_gather ||
1494 MICA.
getID() == Intrinsic::vp_scatter) {
1497 if (DataLT.first > 1)
1499 if (PtrLT.first > 1)
1507 unsigned NumLoads = getEstimatedVLFor(&VTy);
1514 unsigned Opcode = MICA.
getID() == Intrinsic::masked_expandload
1516 : Instruction::Store;
1520 bool IsLegal = (Opcode == Instruction::Store &&
1522 (Opcode == Instruction::Load &&
1546 if (Opcode == Instruction::Store)
1547 Opcodes.
append({RISCV::VCOMPRESS_VM});
1549 Opcodes.
append({RISCV::VSETIVLI, RISCV::VIOTA_M, RISCV::VRGATHER_VV});
1551 LT.first * getRISCVInstructionCost(Opcodes, LT.second, CostKind);
1576 unsigned NumLoads = getEstimatedVLFor(&VTy);
1579 uint64_t CacheLineBytes = ST->getCacheLineSize();
1580 if (!CacheLineBytes)
1581 CacheLineBytes = 64;
1584 int64_t Stride = StrideCI->getSExtValue();
1586 if (Stride != std::numeric_limits<int64_t>::min() && Stride != 0) {
1587 uint64_t AbsStride = (uint64_t)std::abs(Stride);
1588 if (AbsStride < CacheLineBytes) {
1589 uint64_t MaxCombines = ST->getMaxVectorCoalesceElts();
1590 if ((CacheLineBytes / AbsStride) >= MaxCombines)
1591 NumLoads =
divideCeil(NumLoads, MaxCombines);
1595 NumLoads =
divideCeil((NumLoads * AbsStride), CacheLineBytes);
1609 for (
auto *Ty : Tys) {
1610 if (!Ty->isVectorTy())
1624 {Intrinsic::floor, MVT::f32, 9},
1625 {Intrinsic::floor, MVT::f64, 9},
1626 {Intrinsic::ceil, MVT::f32, 9},
1627 {Intrinsic::ceil, MVT::f64, 9},
1628 {Intrinsic::trunc, MVT::f32, 7},
1629 {Intrinsic::trunc, MVT::f64, 7},
1630 {Intrinsic::round, MVT::f32, 9},
1631 {Intrinsic::round, MVT::f64, 9},
1632 {Intrinsic::roundeven, MVT::f32, 9},
1633 {Intrinsic::roundeven, MVT::f64, 9},
1634 {Intrinsic::rint, MVT::f32, 7},
1635 {Intrinsic::rint, MVT::f64, 7},
1636 {Intrinsic::nearbyint, MVT::f32, 9},
1637 {Intrinsic::nearbyint, MVT::f64, 9},
1638 {Intrinsic::bswap, MVT::i16, 3},
1639 {Intrinsic::bswap, MVT::i32, 12},
1640 {Intrinsic::bswap, MVT::i64, 31},
1641 {Intrinsic::bitreverse, MVT::i8, 17},
1642 {Intrinsic::bitreverse, MVT::i16, 24},
1643 {Intrinsic::bitreverse, MVT::i32, 33},
1644 {Intrinsic::bitreverse, MVT::i64, 52},
1645 {Intrinsic::ctpop, MVT::i8, 12},
1646 {Intrinsic::ctpop, MVT::i16, 19},
1647 {Intrinsic::ctpop, MVT::i32, 20},
1648 {Intrinsic::ctpop, MVT::i64, 21},
1649 {Intrinsic::ctlz, MVT::i8, 19},
1650 {Intrinsic::ctlz, MVT::i16, 28},
1651 {Intrinsic::ctlz, MVT::i32, 31},
1652 {Intrinsic::ctlz, MVT::i64, 35},
1653 {Intrinsic::cttz, MVT::i8, 16},
1654 {Intrinsic::cttz, MVT::i16, 23},
1655 {Intrinsic::cttz, MVT::i32, 24},
1656 {Intrinsic::cttz, MVT::i64, 25},
1663 switch (ICA.
getID()) {
1664 case Intrinsic::lrint:
1665 case Intrinsic::llrint:
1666 case Intrinsic::lround:
1667 case Intrinsic::llround: {
1671 if (ST->hasVInstructions() && LT.second.isVector()) {
1673 unsigned SrcEltSz =
DL.getTypeSizeInBits(SrcTy->getScalarType());
1674 unsigned DstEltSz =
DL.getTypeSizeInBits(RetTy->getScalarType());
1675 if (LT.second.getVectorElementType() == MVT::bf16) {
1676 if (!ST->hasVInstructionsBF16Minimal())
1679 Ops = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFCVT_X_F_V};
1681 Ops = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVT_X_F_V};
1682 }
else if (LT.second.getVectorElementType() == MVT::f16 &&
1683 !ST->hasVInstructionsF16()) {
1684 if (!ST->hasVInstructionsF16Minimal())
1687 Ops = {RISCV::VFWCVT_F_F_V, RISCV::VFCVT_X_F_V};
1689 Ops = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_X_F_V};
1691 }
else if (SrcEltSz > DstEltSz) {
1692 Ops = {RISCV::VFNCVT_X_F_W};
1693 }
else if (SrcEltSz < DstEltSz) {
1694 Ops = {RISCV::VFWCVT_X_F_V};
1696 Ops = {RISCV::VFCVT_X_F_V};
1701 if (SrcEltSz > DstEltSz)
1702 return SrcLT.first *
1703 getRISCVInstructionCost(
Ops, SrcLT.second, CostKind);
1704 return LT.first * getRISCVInstructionCost(
Ops, LT.second, CostKind);
1708 case Intrinsic::ceil:
1709 case Intrinsic::floor:
1710 case Intrinsic::trunc:
1711 case Intrinsic::rint:
1712 case Intrinsic::round:
1713 case Intrinsic::roundeven: {
1716 if (!LT.second.isVector() && TLI->isOperationCustom(
ISD::FCEIL, LT.second))
1717 return LT.first * 8;
1720 case Intrinsic::minimum:
1721 case Intrinsic::maximum: {
1725 if (!LT.second.isVector() && LT.second.isFloatingPoint() &&
1737 return Cost * LT.first;
1741 case Intrinsic::umin:
1742 case Intrinsic::umax:
1743 case Intrinsic::smin:
1744 case Intrinsic::smax: {
1746 if (LT.second.isScalarInteger() && ST->hasStdExtZbb())
1749 if (ST->hasVInstructions() && LT.second.isVector()) {
1751 switch (ICA.
getID()) {
1752 case Intrinsic::umin:
1753 Op = RISCV::VMINU_VV;
1755 case Intrinsic::umax:
1756 Op = RISCV::VMAXU_VV;
1758 case Intrinsic::smin:
1759 Op = RISCV::VMIN_VV;
1761 case Intrinsic::smax:
1762 Op = RISCV::VMAX_VV;
1765 return LT.first * getRISCVInstructionCost(
Op, LT.second, CostKind);
1769 case Intrinsic::sadd_sat:
1770 case Intrinsic::ssub_sat:
1771 case Intrinsic::uadd_sat:
1772 case Intrinsic::usub_sat: {
1774 if (ST->hasVInstructions() && LT.second.isVector()) {
1776 switch (ICA.
getID()) {
1777 case Intrinsic::sadd_sat:
1778 Op = RISCV::VSADD_VV;
1780 case Intrinsic::ssub_sat:
1781 Op = RISCV::VSSUB_VV;
1783 case Intrinsic::uadd_sat:
1784 Op = RISCV::VSADDU_VV;
1786 case Intrinsic::usub_sat:
1787 Op = RISCV::VSSUBU_VV;
1790 return LT.first * getRISCVInstructionCost(
Op, LT.second, CostKind);
1794 case Intrinsic::fma:
1795 case Intrinsic::fmuladd: {
1798 if (ST->hasVInstructions() && LT.second.isVector())
1800 getRISCVInstructionCost(RISCV::VFMADD_VV, LT.second, CostKind);
1803 case Intrinsic::fabs: {
1805 if (ST->hasVInstructions() && LT.second.isVector()) {
1811 if (LT.second.getVectorElementType() == MVT::bf16 ||
1812 (LT.second.getVectorElementType() == MVT::f16 &&
1813 !ST->hasVInstructionsF16()))
1814 return LT.first * getRISCVInstructionCost(RISCV::VAND_VX, LT.second,
1819 getRISCVInstructionCost(RISCV::VFSGNJX_VV, LT.second, CostKind);
1823 case Intrinsic::sqrt: {
1825 if (ST->hasVInstructions() && LT.second.isVector()) {
1828 MVT ConvType = LT.second;
1829 MVT FsqrtType = LT.second;
1832 if (LT.second.getVectorElementType() == MVT::bf16) {
1833 if (LT.second == MVT::nxv32bf16) {
1834 ConvOp = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVTBF16_F_F_V,
1835 RISCV::VFNCVTBF16_F_F_W, RISCV::VFNCVTBF16_F_F_W};
1836 FsqrtOp = {RISCV::VFSQRT_V, RISCV::VFSQRT_V};
1837 ConvType = MVT::nxv16f16;
1838 FsqrtType = MVT::nxv16f32;
1840 ConvOp = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFNCVTBF16_F_F_W};
1841 FsqrtOp = {RISCV::VFSQRT_V};
1842 FsqrtType = TLI->getTypeToPromoteTo(
ISD::FSQRT, FsqrtType);
1844 }
else if (LT.second.getVectorElementType() == MVT::f16 &&
1845 !ST->hasVInstructionsF16()) {
1846 if (LT.second == MVT::nxv32f16) {
1847 ConvOp = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_F_F_V,
1848 RISCV::VFNCVT_F_F_W, RISCV::VFNCVT_F_F_W};
1849 FsqrtOp = {RISCV::VFSQRT_V, RISCV::VFSQRT_V};
1850 ConvType = MVT::nxv16f16;
1851 FsqrtType = MVT::nxv16f32;
1853 ConvOp = {RISCV::VFWCVT_F_F_V, RISCV::VFNCVT_F_F_W};
1854 FsqrtOp = {RISCV::VFSQRT_V};
1855 FsqrtType = TLI->getTypeToPromoteTo(
ISD::FSQRT, FsqrtType);
1858 FsqrtOp = {RISCV::VFSQRT_V};
1861 return LT.first * (getRISCVInstructionCost(FsqrtOp, FsqrtType, CostKind) +
1862 getRISCVInstructionCost(ConvOp, ConvType, CostKind));
1866 case Intrinsic::cttz:
1867 case Intrinsic::ctlz:
1868 case Intrinsic::ctpop: {
1870 if (ST->hasStdExtZvbb() && LT.second.isVector()) {
1872 switch (ICA.
getID()) {
1873 case Intrinsic::cttz:
1876 case Intrinsic::ctlz:
1879 case Intrinsic::ctpop:
1880 Op = RISCV::VCPOP_V;
1883 return LT.first * getRISCVInstructionCost(
Op, LT.second, CostKind);
1887 case Intrinsic::abs: {
1889 if (ST->hasVInstructions() && LT.second.isVector()) {
1891 if (ST->hasStdExtZvabd())
1893 getRISCVInstructionCost({RISCV::VABD_VX}, LT.second, CostKind);
1898 getRISCVInstructionCost({RISCV::VRSUB_VI, RISCV::VMAX_VV},
1899 LT.second, CostKind);
1903 case Intrinsic::fshl:
1904 case Intrinsic::fshr: {
1911 if ((ST->hasStdExtZbb() || ST->hasStdExtZbkb()) && RetTy->isIntegerTy() &&
1913 (RetTy->getIntegerBitWidth() == 32 ||
1914 RetTy->getIntegerBitWidth() == 64) &&
1915 RetTy->getIntegerBitWidth() <= ST->getXLen()) {
1920 case Intrinsic::clmul: {
1922 if (!LT.second.isVector() && ST->hasStdExtZvbc() && !ST->hasStdExtZbkc()) {
1925 if (!ST->is64Bit() || LT.second != MVT::i64)
1931 return LT.first * getRISCVInstructionCost(
1932 {RISCV::VMV_S_X, RISCV::VCLMUL_VX, RISCV::VMV_X_S},
1937 case Intrinsic::masked_udiv:
1940 case Intrinsic::masked_sdiv:
1943 case Intrinsic::masked_urem:
1946 case Intrinsic::masked_srem:
1949 case Intrinsic::get_active_lane_mask: {
1950 if (ST->hasVInstructions()) {
1959 getRISCVInstructionCost({RISCV::VSADDU_VX, RISCV::VMSLTU_VX},
1960 LT.second, CostKind);
1965 case Intrinsic::stepvector: {
1969 if (ST->hasVInstructions())
1970 return getRISCVInstructionCost(RISCV::VID_V, LT.second, CostKind) +
1972 getRISCVInstructionCost(RISCV::VADD_VX, LT.second, CostKind);
1973 return 1 + (LT.first - 1);
1975 case Intrinsic::vector_splice_left:
1976 case Intrinsic::vector_splice_right: {
1981 if (ST->hasVInstructions() && LT.second.isVector()) {
1983 getRISCVInstructionCost({RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VX},
1984 LT.second, CostKind);
1988 case Intrinsic::experimental_cttz_elts: {
1989 if (!ST->hasVInstructions())
1994 if (!LT.second.isVector())
1998 if (LT.second.getVectorElementType() != MVT::i1)
1999 Cost += getRISCVInstructionCost(RISCV::VMSNE_VI, LT.second, CostKind);
2001 Cost += getRISCVInstructionCost(RISCV::VFIRST_M, LT.second, CostKind);
2013 return LT.first *
Cost;
2015 case Intrinsic::experimental_vp_splice: {
2023 case Intrinsic::vp_merge: {
2031 case Intrinsic::fptoui_sat:
2032 case Intrinsic::fptosi_sat: {
2034 bool IsSigned = ICA.
getID() == Intrinsic::fptosi_sat;
2039 if (!SrcTy->isVectorTy())
2042 if (!SrcLT.first.isValid() || !DstLT.first.isValid())
2059 case Intrinsic::experimental_vector_extract_last_active: {
2081 unsigned EltWidth = getTLI()->getBitWidthForCttzElements(
2082 TLI->getVectorIdxTy(
getDataLayout()), MaskTy->getElementCount(),
2083 true, &VScaleRange);
2084 EltWidth = std::max(EltWidth, MaskTy->getScalarSizeInBits());
2092 if (StepLT.first > 1)
2096 unsigned Opcodes[] = {RISCV::VID_V, RISCV::VREDMAXU_VS, RISCV::VMV_X_S};
2098 Cost += MaskLT.first *
2099 getRISCVInstructionCost(RISCV::VCPOP_M, MaskLT.second, CostKind);
2101 Cost += StepLT.first *
2102 getRISCVInstructionCost(Opcodes, StepLT.second, CostKind);
2106 Cost += ValLT.first *
2107 getRISCVInstructionCost({RISCV::VSLIDEDOWN_VI, RISCV::VMV_X_S},
2108 ValLT.second, CostKind);
2111 case Intrinsic::vector_interleave2:
2112 case Intrinsic::vector_deinterleave2: {
2113 if (!ST->hasStdExtZvzip())
2116 bool IsInterleave = ICA.
getID() == Intrinsic::vector_interleave2;
2117 Type *InterleavedTy = IsInterleave ? RetTy : ICA.
getArgTypes().front();
2121 [](
const Value *Arg) { return isa<UndefValue>(Arg); }))
2128 unsigned HalfVF = HalfFVT->getNumElements();
2133 for (
unsigned Start = 0; Start != 2; ++Start)
2140 if (!LT.second.isScalableVector())
2143 if (
MVT CostVT = getZvzipVZIPCostVT(LT.second); CostVT.
isValid())
2145 getRISCVInstructionCost(RISCV::VZIP_VV, CostVT, CostKind);
2146 }
else if (
MVT CostVT = getZvzipVUNZIPCostVT(LT.second); CostVT.
isValid()) {
2148 getRISCVInstructionCost({RISCV::VUNZIPE_V, RISCV::VUNZIPO_V},
2155 if (ST->hasVInstructions() && RetTy->isVectorTy()) {
2157 LT.second.isVector()) {
2158 MVT EltTy = LT.second.getVectorElementType();
2160 ICA.
getID(), EltTy))
2161 return LT.first * Entry->Cost;
2174 if (ST->hasVInstructions() && PtrTy->
isVectorTy())
2192 if (ST->hasStdExtP() &&
2200 if (!ST->hasVInstructions() || Src->getScalarSizeInBits() > ST->getELen() ||
2201 Dst->getScalarSizeInBits() > ST->getELen())
2204 int ISD = TLI->InstructionOpcodeToISD(Opcode);
2219 if (Src->getScalarSizeInBits() == 1) {
2224 return getRISCVInstructionCost(RISCV::VMV_V_I, DstLT.second, CostKind) +
2225 DstLT.first * getRISCVInstructionCost(RISCV::VMERGE_VIM,
2226 DstLT.second, CostKind) +
2231 if (Dst->getScalarSizeInBits() == 1) {
2237 return SrcLT.first *
2238 getRISCVInstructionCost({RISCV::VAND_VI, RISCV::VMSNE_VI},
2239 SrcLT.second, CostKind) +
2250 if (!SrcLT.second.isVector() || !DstLT.second.isVector() ||
2251 !SrcLT.first.isValid() || !DstLT.first.isValid() ||
2253 SrcLT.second.getSizeInBits()) ||
2255 DstLT.second.getSizeInBits()) ||
2256 SrcLT.first > 1 || DstLT.first > 1)
2260 assert((SrcLT.first == 1) && (DstLT.first == 1) &&
"Illegal type");
2262 int PowDiff = (int)
Log2_32(DstLT.second.getScalarSizeInBits()) -
2263 (int)
Log2_32(SrcLT.second.getScalarSizeInBits());
2267 if ((PowDiff < 1) || (PowDiff > 3))
2269 unsigned SExtOp[] = {RISCV::VSEXT_VF2, RISCV::VSEXT_VF4, RISCV::VSEXT_VF8};
2270 unsigned ZExtOp[] = {RISCV::VZEXT_VF2, RISCV::VZEXT_VF4, RISCV::VZEXT_VF8};
2273 return getRISCVInstructionCost(
Op, DstLT.second, CostKind);
2279 unsigned SrcEltSize = SrcLT.second.getScalarSizeInBits();
2280 unsigned DstEltSize = DstLT.second.getScalarSizeInBits();
2284 : RISCV::VFNCVT_F_F_W;
2286 for (; SrcEltSize != DstEltSize;) {
2290 MVT DstMVT = DstLT.second.changeVectorElementType(ElementMVT);
2292 (DstEltSize > SrcEltSize) ? DstEltSize >> 1 : DstEltSize << 1;
2293 Cost += getRISCVInstructionCost(
Op, DstMVT, CostKind);
2300 unsigned FCVT = IsSigned ? RISCV::VFCVT_RTZ_X_F_V : RISCV::VFCVT_RTZ_XU_F_V;
2302 IsSigned ? RISCV::VFWCVT_RTZ_X_F_V : RISCV::VFWCVT_RTZ_XU_F_V;
2304 IsSigned ? RISCV::VFNCVT_RTZ_X_F_W : RISCV::VFNCVT_RTZ_XU_F_W;
2305 unsigned SrcEltSize = Src->getScalarSizeInBits();
2306 unsigned DstEltSize = Dst->getScalarSizeInBits();
2308 if ((SrcEltSize == 16) &&
2309 (!ST->hasVInstructionsF16() || ((DstEltSize / 2) > SrcEltSize))) {
2315 std::pair<InstructionCost, MVT> VecF32LT =
2318 VecF32LT.first * getRISCVInstructionCost(RISCV::VFWCVT_F_F_V,
2319 VecF32LT.second, CostKind);
2323 if (DstEltSize == SrcEltSize)
2324 Cost += getRISCVInstructionCost(FCVT, DstLT.second, CostKind);
2325 else if (DstEltSize > SrcEltSize)
2326 Cost += getRISCVInstructionCost(FWCVT, DstLT.second, CostKind);
2331 MVT VecVT = DstLT.second.changeVectorElementType(ElementVT);
2332 Cost += getRISCVInstructionCost(FNCVT, VecVT, CostKind);
2333 if ((SrcEltSize / 2) > DstEltSize) {
2344 unsigned FCVT = IsSigned ? RISCV::VFCVT_F_X_V : RISCV::VFCVT_F_XU_V;
2345 unsigned FWCVT = IsSigned ? RISCV::VFWCVT_F_X_V : RISCV::VFWCVT_F_XU_V;
2346 unsigned FNCVT = IsSigned ? RISCV::VFNCVT_F_X_W : RISCV::VFNCVT_F_XU_W;
2347 unsigned SrcEltSize = Src->getScalarSizeInBits();
2348 unsigned DstEltSize = Dst->getScalarSizeInBits();
2351 if ((DstEltSize == 16) &&
2352 (!ST->hasVInstructionsF16() || ((SrcEltSize / 2) > DstEltSize))) {
2358 std::pair<InstructionCost, MVT> VecF32LT =
2361 Cost += VecF32LT.first * getRISCVInstructionCost(RISCV::VFNCVT_F_F_W,
2362 DstLT.second, CostKind);
2366 if (DstEltSize == SrcEltSize)
2367 Cost += getRISCVInstructionCost(FCVT, DstLT.second, CostKind);
2368 else if (DstEltSize > SrcEltSize) {
2369 if ((DstEltSize / 2) > SrcEltSize) {
2373 unsigned Op = IsSigned ? Instruction::SExt : Instruction::ZExt;
2376 Cost += getRISCVInstructionCost(FWCVT, DstLT.second, CostKind);
2378 Cost += getRISCVInstructionCost(FNCVT, DstLT.second, CostKind);
2385unsigned RISCVTTIImpl::getEstimatedVLFor(
VectorType *Ty)
const {
2387 const unsigned EltSize =
DL.getTypeSizeInBits(Ty->getElementType());
2388 const unsigned MinSize =
DL.getTypeSizeInBits(Ty).getKnownMinValue();
2403 if (Ty->getScalarSizeInBits() > ST->getELen())
2407 if (Ty->getElementType()->isIntegerTy(1)) {
2411 if (IID == Intrinsic::umax || IID == Intrinsic::smin)
2417 if (IID == Intrinsic::maximum || IID == Intrinsic::minimum) {
2421 case Intrinsic::maximum:
2423 Opcodes = {RISCV::VFREDMAX_VS, RISCV::VFMV_F_S};
2425 Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMAX_VS,
2430 Type *DstTy = Ty->getScalarType();
2440 case Intrinsic::minimum:
2442 Opcodes = {RISCV::VFREDMIN_VS, RISCV::VFMV_F_S};
2444 Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMIN_VS,
2449 Type *DstTy = Ty->getScalarType();
2450 const unsigned EltTyBits =
DL.getTypeSizeInBits(DstTy);
2459 return ExtraCost + getRISCVInstructionCost(Opcodes, LT.second, CostKind);
2468 case Intrinsic::smax:
2469 SplitOp = RISCV::VMAX_VV;
2470 Opcodes = {RISCV::VREDMAX_VS, RISCV::VMV_X_S};
2472 case Intrinsic::smin:
2473 SplitOp = RISCV::VMIN_VV;
2474 Opcodes = {RISCV::VREDMIN_VS, RISCV::VMV_X_S};
2476 case Intrinsic::umax:
2477 SplitOp = RISCV::VMAXU_VV;
2478 Opcodes = {RISCV::VREDMAXU_VS, RISCV::VMV_X_S};
2480 case Intrinsic::umin:
2481 SplitOp = RISCV::VMINU_VV;
2482 Opcodes = {RISCV::VREDMINU_VS, RISCV::VMV_X_S};
2484 case Intrinsic::maxnum:
2485 SplitOp = RISCV::VFMAX_VV;
2486 Opcodes = {RISCV::VFREDMAX_VS, RISCV::VFMV_F_S};
2488 case Intrinsic::minnum:
2489 SplitOp = RISCV::VFMIN_VV;
2490 Opcodes = {RISCV::VFREDMIN_VS, RISCV::VFMV_F_S};
2495 (LT.first > 1) ? (LT.first - 1) *
2496 getRISCVInstructionCost(SplitOp, LT.second, CostKind)
2498 return SplitCost + getRISCVInstructionCost(Opcodes, LT.second, CostKind);
2503 std::optional<FastMathFlags> FMF,
2509 if (Ty->getScalarSizeInBits() > ST->getELen())
2512 int ISD = TLI->InstructionOpcodeToISD(Opcode);
2520 Type *ElementTy = Ty->getElementType();
2525 if (LT.second == MVT::v1i1)
2526 return getRISCVInstructionCost(RISCV::VFIRST_M, LT.second, CostKind) +
2544 return ((LT.first > 2) ? (LT.first - 2) : 0) *
2545 getRISCVInstructionCost(RISCV::VMAND_MM, LT.second, CostKind) +
2546 getRISCVInstructionCost(RISCV::VMNAND_MM, LT.second, CostKind) +
2547 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
2556 return (LT.first - 1) *
2557 getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second, CostKind) +
2558 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) + 1;
2566 return (LT.first - 1) *
2567 getRISCVInstructionCost(RISCV::VMOR_MM, LT.second, CostKind) +
2568 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind) +
2581 SplitOp = RISCV::VADD_VV;
2582 Opcodes = {RISCV::VMV_S_X, RISCV::VREDSUM_VS, RISCV::VMV_X_S};
2585 SplitOp = RISCV::VOR_VV;
2586 Opcodes = {RISCV::VREDOR_VS, RISCV::VMV_X_S};
2589 SplitOp = RISCV::VXOR_VV;
2590 Opcodes = {RISCV::VMV_S_X, RISCV::VREDXOR_VS, RISCV::VMV_X_S};
2593 SplitOp = RISCV::VAND_VV;
2594 Opcodes = {RISCV::VREDAND_VS, RISCV::VMV_X_S};
2598 if ((LT.second.getScalarType() == MVT::f16 && !ST->hasVInstructionsF16()) ||
2599 LT.second.getScalarType() == MVT::bf16)
2603 for (
unsigned i = 0; i < LT.first.getValue(); i++)
2606 return getRISCVInstructionCost(Opcodes, LT.second, CostKind);
2608 SplitOp = RISCV::VFADD_VV;
2609 Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDUSUM_VS, RISCV::VFMV_F_S};
2614 (LT.first > 1) ? (LT.first - 1) *
2615 getRISCVInstructionCost(SplitOp, LT.second, CostKind)
2617 return SplitCost + getRISCVInstructionCost(Opcodes, LT.second, CostKind);
2621 unsigned Opcode,
bool IsUnsigned,
Type *ResTy,
VectorType *ValTy,
2632 if (Opcode != Instruction::Add && Opcode != Instruction::FAdd)
2638 if (IsUnsigned && Opcode == Instruction::Add && LT.first == 1 &&
2639 LT.second.isVectorOf(MVT::i1)) {
2642 return getRISCVInstructionCost(RISCV::VCPOP_M, LT.second, CostKind);
2649 return (LT.first - 1) +
2656 assert(OpInfo.isConstant() &&
"non constant operand?");
2663 if (OpInfo.isUniform())
2669 return getConstantPoolLoadCost(Ty, CostKind);
2678 EVT VT = TLI->getValueType(
DL, Src,
true);
2680 if (VT == MVT::Other ||
2683 CostKind, OpInfo,
I);
2686 if (Opcode == Instruction::Store && OpInfo.isConstant())
2701 if (Src->
isVectorTy() && LT.second.isVector() &&
2703 LT.second.getSizeInBits()))
2707 CostKind, OpInfo,
I);
2713 if (ST->hasVInstructions() && LT.second.isVector() &&
2715 BaseCost *= TLI->getLMULCost(LT.second);
2716 return Cost + BaseCost;
2725 Op1Info, Op2Info,
I);
2729 Op1Info, Op2Info,
I);
2734 Op1Info, Op2Info,
I);
2736 auto GetConstantMatCost =
2738 if (OpInfo.isUniform())
2743 return getConstantPoolLoadCost(ValTy, CostKind);
2748 ConstantMatCost += GetConstantMatCost(Op1Info);
2750 ConstantMatCost += GetConstantMatCost(Op2Info);
2753 if (Opcode == Instruction::Select && LT.second.isVector()) {
2754 if (CondTy->isVectorTy()) {
2759 return ConstantMatCost +
2761 getRISCVInstructionCost(
2762 {RISCV::VMANDN_MM, RISCV::VMAND_MM, RISCV::VMOR_MM},
2763 LT.second, CostKind);
2766 return ConstantMatCost +
2767 LT.first * getRISCVInstructionCost(RISCV::VMERGE_VVM, LT.second,
2777 MVT InterimVT = LT.second.changeVectorElementType(MVT::i8);
2778 return ConstantMatCost +
2780 getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI},
2781 InterimVT, CostKind) +
2782 LT.first * getRISCVInstructionCost(
2783 {RISCV::VMANDN_MM, RISCV::VMAND_MM, RISCV::VMOR_MM},
2784 LT.second, CostKind);
2790 return ConstantMatCost +
2791 LT.first * getRISCVInstructionCost(
2792 {RISCV::VMV_V_X, RISCV::VMSNE_VI, RISCV::VMERGE_VVM},
2793 LT.second, CostKind);
2796 if ((Opcode == Instruction::ICmp) && ValTy->
isVectorTy() &&
2800 return ConstantMatCost + LT.first * getRISCVInstructionCost(RISCV::VMSLT_VV,
2805 if ((Opcode == Instruction::FCmp) && ValTy->
isVectorTy() &&
2810 return ConstantMatCost +
2811 getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second, CostKind);
2821 Op1Info, Op2Info,
I);
2830 return ConstantMatCost +
2831 LT.first * getRISCVInstructionCost(
2832 {RISCV::VMFLT_VV, RISCV::VMFLT_VV, RISCV::VMOR_MM},
2833 LT.second, CostKind);
2839 return ConstantMatCost +
2841 getRISCVInstructionCost({RISCV::VMFLT_VV, RISCV::VMNAND_MM},
2842 LT.second, CostKind);
2850 return ConstantMatCost +
2852 getRISCVInstructionCost(RISCV::VMFLT_VV, LT.second, CostKind);
2865 return match(U, m_Select(m_Specific(I), m_Value(), m_Value())) &&
2866 U->getType()->isIntegerTy() &&
2867 !isa<ConstantData>(U->getOperand(1)) &&
2868 !isa<ConstantData>(U->getOperand(2));
2876 Op1Info, Op2Info,
I);
2883 return Opcode == Instruction::PHI ? 0 : 1;
2900 if (Opcode != Instruction::ExtractElement &&
2901 Opcode != Instruction::InsertElement)
2907 if (Opcode == Instruction::InsertElement &&
2908 VIC == TTI::VectorInstrContext::SplatOpFolded &&
2909 ST->sinkSplatOperands() && Index == 0)
2916 if (!LT.second.isVector()) {
2926 auto NumElems = FixedVecTy->getNumElements();
2932 return Opcode == Instruction::ExtractElement
2933 ? StoreCost * NumElems + LoadCost
2934 : (StoreCost + LoadCost) * NumElems + StoreCost;
2938 if (LT.second.isScalableVector() && !LT.first.isValid())
2946 if (Opcode == Instruction::ExtractElement) {
2952 return ExtendCost + ExtractCost;
2962 return ExtendCost + InsertCost + TruncCost;
2969 if (LT.second.isFloatingPoint())
2970 MoveOpc = Opcode == Instruction::InsertElement ? RISCV::VFMV_S_F
2974 Opcode == Instruction::InsertElement ? RISCV::VMV_S_X : RISCV::VMV_X_S;
2976 getRISCVInstructionCost(MoveOpc, LT.second, CostKind);
2978 InstructionCost SlideCost = Opcode == Instruction::InsertElement ? 2 : 1;
2983 if (LT.second.isFixedLengthVector()) {
2984 unsigned Width = LT.second.getVectorNumElements();
2985 Index = Index % Width;
2990 if (
auto VLEN = ST->getRealVLen()) {
2991 unsigned EltSize = LT.second.getScalarSizeInBits();
2992 unsigned M1Max = *VLEN / EltSize;
2993 Index = Index % M1Max;
2999 else if (Opcode == Instruction::InsertElement)
3007 ((Index == -1U) || (Index >= LT.second.getVectorMinNumElements() &&
3008 LT.second.isScalableVector()))) {
3010 Align VecAlign =
DL.getPrefTypeAlign(Val);
3011 Align SclAlign =
DL.getPrefTypeAlign(ScalarType);
3016 if (Opcode == Instruction::ExtractElement)
3017 return getMemoryOpCost(Instruction::Store, Val, VecAlign, 0, CostKind) +
3024 return getMemoryOpCost(Instruction::Store, Val, VecAlign, 0, CostKind) +
3052 Opcode == Instruction::InsertElement
3053 ? getRISCVInstructionCost({RISCV::VSLIDE1DOWN_VX,
3054 RISCV::VSLIDE1DOWN_VX,
3055 RISCV::VSLIDEUP_VX},
3056 LT.second, CostKind)
3057 : getRISCVInstructionCost({RISCV::VSLIDEDOWN_VX, RISCV::VMV_X_S,
3058 RISCV::VSRL_VX, RISCV::VMV_X_S},
3059 LT.second, CostKind);
3061 return BaseCost + SlideCost;
3067 unsigned Index)
const {
3076 assert(Index < EC.getKnownMinValue() &&
"Unexpected reverse index");
3078 EC.getKnownMinValue() - 1 - Index,
nullptr,
3087std::optional<InstructionCost>
3093 if ((Opcode == Instruction::UDiv || Opcode == Instruction::URem) &&
3095 if (Opcode == Instruction::UDiv)
3102 return std::nullopt;
3114 Args, CtxI, TLibInfo, Scalars);
3118 Args, CtxI, TLibInfo, Scalars);
3123 Args, CtxI, TLibInfo, Scalars);
3125 if (std::optional<InstructionCost> CombinedCost =
3127 Op2Info, Args, CtxI))
3128 return *CombinedCost;
3132 unsigned ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
3135 if (!LT.second.isVector()) {
3136 if (ISDOpcode ==
ISD::MUL && !ST->hasStdExtZmmul())
3148 if (TLI->isOperationLegalOrPromote(ISDOpcode, LT.second))
3149 if (
const auto *Entry =
CostTableLookup(DivTbl, ISDOpcode, LT.second))
3150 return Entry->Cost * LT.first;
3153 Args, CtxI, TLibInfo, Scalars);
3159 if ((LT.second.getVectorElementType() == MVT::f16 ||
3160 LT.second.getVectorElementType() == MVT::bf16) &&
3161 TLI->getOperationAction(ISDOpcode, LT.second) ==
3163 MVT PromotedVT = TLI->getTypeToPromoteTo(ISDOpcode, LT.second);
3167 CastCost += LT.first * Args.size() *
3175 LT.second = PromotedVT;
3178 auto getConstantMatCost =
3180 if (OpInfo.isUniform() &&
3189 return getConstantPoolLoadCost(Ty, CostKind);
3195 ConstantMatCost += getConstantMatCost(0, Op1Info);
3197 ConstantMatCost += getConstantMatCost(1, Op2Info);
3200 switch (ISDOpcode) {
3203 Op = RISCV::VADD_VV;
3208 Op = RISCV::VSLL_VV;
3213 Op = (Ty->getScalarSizeInBits() == 1) ? RISCV::VMAND_MM : RISCV::VAND_VV;
3218 Op = RISCV::VMUL_VV;
3222 Op = RISCV::VDIV_VV;
3226 Op = RISCV::VREM_VV;
3230 Op = RISCV::VFADD_VV;
3233 Op = RISCV::VFMUL_VV;
3236 Op = RISCV::VFDIV_VV;
3239 Op = RISCV::VFSGNJN_VV;
3244 return CastCost + ConstantMatCost +
3246 Args, CtxI, TLibInfo, Scalars);
3253 if (Ty->isFPOrFPVectorTy())
3255 return CastCost + ConstantMatCost + LT.first * InstrCost;
3278 if (Info.isSameBase() && V !=
Base) {
3279 if (
GEP->hasAllConstantIndices())
3285 unsigned Stride =
DL.getTypeStoreSize(AccessTy);
3286 if (Info.isUnitStride() &&
3292 GEP->getType()->getPointerAddressSpace()))
3295 {TTI::OK_AnyValue, TTI::OP_None},
3296 {TTI::OK_AnyValue, TTI::OP_None}, {});
3300 Indices, CostKind, AccessTy);
3312 if (ST->enableDefaultUnroll())
3318 if (!L->isInnermost()) {
3334 if (L->getHeader()->getParent()->hasOptSize())
3338 L->getExitingBlocks(ExitingBlocks);
3340 <<
"Blocks: " << L->getNumBlocks() <<
"\n"
3341 <<
"Exit blocks: " << ExitingBlocks.
size() <<
"\n");
3345 if (ExitingBlocks.
size() > 2)
3350 if (L->getNumBlocks() > 4)
3358 for (
auto *BB : L->getBlocks()) {
3359 for (
auto &
I : *BB) {
3363 if (IsVectorized && (
I.getType()->isVectorTy() ||
3365 return V->getType()->isVectorTy();
3404 bool HasMask =
false;
3407 bool IsWrite) -> int64_t {
3408 if (
auto *TarExtTy =
3410 return TarExtTy->getIntParameter(0);
3416 case Intrinsic::riscv_vle_mask:
3417 case Intrinsic::riscv_vse_mask:
3418 case Intrinsic::riscv_vlseg2_mask:
3419 case Intrinsic::riscv_vlseg3_mask:
3420 case Intrinsic::riscv_vlseg4_mask:
3421 case Intrinsic::riscv_vlseg5_mask:
3422 case Intrinsic::riscv_vlseg6_mask:
3423 case Intrinsic::riscv_vlseg7_mask:
3424 case Intrinsic::riscv_vlseg8_mask:
3425 case Intrinsic::riscv_vsseg2_mask:
3426 case Intrinsic::riscv_vsseg3_mask:
3427 case Intrinsic::riscv_vsseg4_mask:
3428 case Intrinsic::riscv_vsseg5_mask:
3429 case Intrinsic::riscv_vsseg6_mask:
3430 case Intrinsic::riscv_vsseg7_mask:
3431 case Intrinsic::riscv_vsseg8_mask:
3434 case Intrinsic::riscv_vle:
3435 case Intrinsic::riscv_vse:
3436 case Intrinsic::riscv_vlseg2:
3437 case Intrinsic::riscv_vlseg3:
3438 case Intrinsic::riscv_vlseg4:
3439 case Intrinsic::riscv_vlseg5:
3440 case Intrinsic::riscv_vlseg6:
3441 case Intrinsic::riscv_vlseg7:
3442 case Intrinsic::riscv_vlseg8:
3443 case Intrinsic::riscv_vsseg2:
3444 case Intrinsic::riscv_vsseg3:
3445 case Intrinsic::riscv_vsseg4:
3446 case Intrinsic::riscv_vsseg5:
3447 case Intrinsic::riscv_vsseg6:
3448 case Intrinsic::riscv_vsseg7:
3449 case Intrinsic::riscv_vsseg8: {
3466 Ty = TarExtTy->getTypeParameter(0U);
3471 const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
3472 unsigned VLIndex = RVVIInfo->VLOperand;
3473 unsigned PtrOperandNo = VLIndex - 1 - HasMask;
3481 unsigned SegNum = getSegNum(Inst, PtrOperandNo, IsWrite);
3484 unsigned ElemSize = Ty->getScalarSizeInBits();
3488 Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
3489 Alignment, Mask, EVL);
3492 case Intrinsic::riscv_vlse_mask:
3493 case Intrinsic::riscv_vsse_mask:
3494 case Intrinsic::riscv_vlsseg2_mask:
3495 case Intrinsic::riscv_vlsseg3_mask:
3496 case Intrinsic::riscv_vlsseg4_mask:
3497 case Intrinsic::riscv_vlsseg5_mask:
3498 case Intrinsic::riscv_vlsseg6_mask:
3499 case Intrinsic::riscv_vlsseg7_mask:
3500 case Intrinsic::riscv_vlsseg8_mask:
3501 case Intrinsic::riscv_vssseg2_mask:
3502 case Intrinsic::riscv_vssseg3_mask:
3503 case Intrinsic::riscv_vssseg4_mask:
3504 case Intrinsic::riscv_vssseg5_mask:
3505 case Intrinsic::riscv_vssseg6_mask:
3506 case Intrinsic::riscv_vssseg7_mask:
3507 case Intrinsic::riscv_vssseg8_mask:
3510 case Intrinsic::riscv_vlse:
3511 case Intrinsic::riscv_vsse:
3512 case Intrinsic::riscv_vlsseg2:
3513 case Intrinsic::riscv_vlsseg3:
3514 case Intrinsic::riscv_vlsseg4:
3515 case Intrinsic::riscv_vlsseg5:
3516 case Intrinsic::riscv_vlsseg6:
3517 case Intrinsic::riscv_vlsseg7:
3518 case Intrinsic::riscv_vlsseg8:
3519 case Intrinsic::riscv_vssseg2:
3520 case Intrinsic::riscv_vssseg3:
3521 case Intrinsic::riscv_vssseg4:
3522 case Intrinsic::riscv_vssseg5:
3523 case Intrinsic::riscv_vssseg6:
3524 case Intrinsic::riscv_vssseg7:
3525 case Intrinsic::riscv_vssseg8: {
3542 Ty = TarExtTy->getTypeParameter(0U);
3547 const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
3548 unsigned VLIndex = RVVIInfo->VLOperand;
3549 unsigned PtrOperandNo = VLIndex - 2 - HasMask;
3558 unsigned PointerAlign = Alignment.valueOrOne().value();
3561 Alignment =
Align(1);
3568 unsigned SegNum = getSegNum(Inst, PtrOperandNo, IsWrite);
3571 unsigned ElemSize = Ty->getScalarSizeInBits();
3575 Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
3576 Alignment, Mask, EVL, Stride);
3579 case Intrinsic::riscv_vloxei_mask:
3580 case Intrinsic::riscv_vluxei_mask:
3581 case Intrinsic::riscv_vsoxei_mask:
3582 case Intrinsic::riscv_vsuxei_mask:
3583 case Intrinsic::riscv_vloxseg2_mask:
3584 case Intrinsic::riscv_vloxseg3_mask:
3585 case Intrinsic::riscv_vloxseg4_mask:
3586 case Intrinsic::riscv_vloxseg5_mask:
3587 case Intrinsic::riscv_vloxseg6_mask:
3588 case Intrinsic::riscv_vloxseg7_mask:
3589 case Intrinsic::riscv_vloxseg8_mask:
3590 case Intrinsic::riscv_vluxseg2_mask:
3591 case Intrinsic::riscv_vluxseg3_mask:
3592 case Intrinsic::riscv_vluxseg4_mask:
3593 case Intrinsic::riscv_vluxseg5_mask:
3594 case Intrinsic::riscv_vluxseg6_mask:
3595 case Intrinsic::riscv_vluxseg7_mask:
3596 case Intrinsic::riscv_vluxseg8_mask:
3597 case Intrinsic::riscv_vsoxseg2_mask:
3598 case Intrinsic::riscv_vsoxseg3_mask:
3599 case Intrinsic::riscv_vsoxseg4_mask:
3600 case Intrinsic::riscv_vsoxseg5_mask:
3601 case Intrinsic::riscv_vsoxseg6_mask:
3602 case Intrinsic::riscv_vsoxseg7_mask:
3603 case Intrinsic::riscv_vsoxseg8_mask:
3604 case Intrinsic::riscv_vsuxseg2_mask:
3605 case Intrinsic::riscv_vsuxseg3_mask:
3606 case Intrinsic::riscv_vsuxseg4_mask:
3607 case Intrinsic::riscv_vsuxseg5_mask:
3608 case Intrinsic::riscv_vsuxseg6_mask:
3609 case Intrinsic::riscv_vsuxseg7_mask:
3610 case Intrinsic::riscv_vsuxseg8_mask:
3613 case Intrinsic::riscv_vloxei:
3614 case Intrinsic::riscv_vluxei:
3615 case Intrinsic::riscv_vsoxei:
3616 case Intrinsic::riscv_vsuxei:
3617 case Intrinsic::riscv_vloxseg2:
3618 case Intrinsic::riscv_vloxseg3:
3619 case Intrinsic::riscv_vloxseg4:
3620 case Intrinsic::riscv_vloxseg5:
3621 case Intrinsic::riscv_vloxseg6:
3622 case Intrinsic::riscv_vloxseg7:
3623 case Intrinsic::riscv_vloxseg8:
3624 case Intrinsic::riscv_vluxseg2:
3625 case Intrinsic::riscv_vluxseg3:
3626 case Intrinsic::riscv_vluxseg4:
3627 case Intrinsic::riscv_vluxseg5:
3628 case Intrinsic::riscv_vluxseg6:
3629 case Intrinsic::riscv_vluxseg7:
3630 case Intrinsic::riscv_vluxseg8:
3631 case Intrinsic::riscv_vsoxseg2:
3632 case Intrinsic::riscv_vsoxseg3:
3633 case Intrinsic::riscv_vsoxseg4:
3634 case Intrinsic::riscv_vsoxseg5:
3635 case Intrinsic::riscv_vsoxseg6:
3636 case Intrinsic::riscv_vsoxseg7:
3637 case Intrinsic::riscv_vsoxseg8:
3638 case Intrinsic::riscv_vsuxseg2:
3639 case Intrinsic::riscv_vsuxseg3:
3640 case Intrinsic::riscv_vsuxseg4:
3641 case Intrinsic::riscv_vsuxseg5:
3642 case Intrinsic::riscv_vsuxseg6:
3643 case Intrinsic::riscv_vsuxseg7:
3644 case Intrinsic::riscv_vsuxseg8: {
3661 Ty = TarExtTy->getTypeParameter(0U);
3666 const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
3667 unsigned VLIndex = RVVIInfo->VLOperand;
3668 unsigned PtrOperandNo = VLIndex - 2 - HasMask;
3681 unsigned SegNum = getSegNum(Inst, PtrOperandNo, IsWrite);
3684 unsigned ElemSize = Ty->getScalarSizeInBits();
3689 Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
3690 Align(1), Mask, EVL,
3699 if (Ty->isVectorTy()) {
3702 if ((EltTy->
isHalfTy() && !ST->hasVInstructionsF16()) ||
3708 if (
Size.isScalable() && ST->hasVInstructions())
3711 if (ST->useRVVForFixedLengthVectors())
3719 if (std::optional<unsigned> MaxVF = ST->getCLOpts().v_slp_max_vf)
3731 return std::max<unsigned>(1U, RegWidth.
getFixedValue() / ElemWidth);
3735 return ST->getCLOpts().v_min_trip_count;
3739 return ST->enableUnalignedVectorMem();
3745 if (ST->hasVendorXCVmem() && !ST->is64Bit())
3756 unsigned C1NumRegs =
C1.NumRegs + (
C1.NumBaseAdds != 0);
3758 return std::tie(
C1.Insns, C1NumRegs,
C1.AddRecCost,
3759 C1.NumIVMuls,
C1.NumBaseAdds,
3760 C1.ScaleCost,
C1.ImmCost,
C1.SetupCost) <
3767 Align Alignment)
const {
3777 if (VTy->getElementType()->isIntegerTy(8)) {
3778 uint64_t MaxEltCount = VTy->getElementCount().getKnownMinValue();
3779 if (VTy->isScalableTy())
3782 if (MaxEltCount > 256)
3791 Align Alignment)
const {
3798 if (!ST->hasVInstructions() || !ST->hasOptimizedZeroStrideLoad())
3801 return TLI->isLegalElementTypeForRVV(TLI->getValueType(
DL, ElementTy));
3810 const Instruction &
I,
bool &AllowPromotionWithoutCommonHeader)
const {
3811 bool Considerable =
false;
3812 AllowPromotionWithoutCommonHeader =
false;
3815 Type *ConsideredSExtType =
3817 if (
I.getType() != ConsideredSExtType)
3821 for (
const User *U :
I.users()) {
3823 Considerable =
true;
3827 if (GEPInst->getNumOperands() > 2) {
3828 AllowPromotionWithoutCommonHeader =
true;
3833 return Considerable;
3839 case Instruction::Add:
3840 case Instruction::Sub:
3841 case Instruction::Mul:
3842 case Instruction::And:
3843 case Instruction::Or:
3844 case Instruction::Xor:
3845 case Instruction::FAdd:
3846 case Instruction::FSub:
3847 case Instruction::FMul:
3848 case Instruction::FDiv:
3849 case Instruction::ICmp:
3850 case Instruction::FCmp:
3852 case Instruction::Shl:
3853 case Instruction::LShr:
3854 case Instruction::AShr:
3855 case Instruction::UDiv:
3856 case Instruction::SDiv:
3857 case Instruction::URem:
3858 case Instruction::SRem:
3859 case Instruction::Select:
3860 return Operand == 1;
3861 case Instruction::Call:
3862 switch (IntrinsicID) {
3863 case Intrinsic::fma:
3864 case Intrinsic::fmuladd:
3865 return Operand == 0 || Operand == 1;
3866 case Intrinsic::vp_udiv:
3867 case Intrinsic::vp_sdiv:
3868 case Intrinsic::vp_urem:
3869 case Intrinsic::vp_srem:
3870 case Intrinsic::ssub_sat:
3871 case Intrinsic::usub_sat:
3872 return Operand == 1;
3874 case Intrinsic::smin:
3875 case Intrinsic::umin:
3876 case Intrinsic::smax:
3877 case Intrinsic::umax:
3878 case Intrinsic::sadd_sat:
3879 case Intrinsic::uadd_sat:
3880 return Operand == 0 || Operand == 1;
3890 if (!
I->getType()->isVectorTy() || !ST->hasVInstructions())
3896 IntrinsicID =
II->getIntrinsicID();
3904 GatherUseOps)
const {
3905 if (Scalars.
empty() || !ST->hasVInstructions() || !ST->sinkSplatOperands() ||
3910 if (SplatIt == Scalars.
end() || (*SplatIt)->getType()->isIntegerTy(1) ||
3916 if (!GatherUseOps(UserOps) || UserOps.
empty())
3936 if (
I->isBitwiseLogicOp()) {
3937 if (!
I->getType()->isVectorTy()) {
3938 if (ST->hasStdExtZbb() || ST->hasStdExtZbkb()) {
3939 for (
auto &
Op :
I->operands()) {
3947 }
else if (
I->getOpcode() == Instruction::And && ST->hasStdExtZvkb()) {
3948 for (
auto &
Op :
I->operands()) {
3960 Ops.push_back(&Not);
3961 Ops.push_back(&InsertElt);
3969 if (!
I->getType()->isVectorTy() || !ST->hasVInstructions())
3977 if (!ST->sinkSplatOperands())
3980 for (
auto OpIdx :
enumerate(
I->operands())) {
4000 for (
Use &U :
Op->uses()) {
4007 Use *InsertEltUse = &
Op->getOperandUse(0);
4010 Ops.push_back(&InsertElt->getOperandUse(1));
4011 Ops.push_back(InsertEltUse);
4012 Ops.push_back(&OpIdx.value());
4021 if (!ST->hasStdExtZbb() && !ST->hasStdExtZbkb() && !IsZeroCmp)
4024 Options.AllowOverlappingLoads =
true;
4025 Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
4027 if (ST->is64Bit()) {
4028 Options.LoadSizes = {8, 4, 2, 1};
4029 Options.AllowedTailExpansions = {3, 5, 6};
4031 Options.LoadSizes = {4, 2, 1};
4032 Options.AllowedTailExpansions = {3};
4035 if (IsZeroCmp && ST->hasVInstructions()) {
4036 unsigned VLenB = ST->getRealMinVLen() / 8;
4039 unsigned MinSize = ST->getXLen() / 8 + 1;
4040 unsigned MaxSize = VLenB * 8;
4049 if (ST->getCLOpts().or_like_select) {
4054 if (
I->getOpcode() == Instruction::Or &&
4058 if (
I->getOpcode() == Instruction::Add ||
4059 I->getOpcode() == Instruction::Sub)
4077std::optional<Instruction *>
4083 if (
is_contained({Intrinsic::riscv_vsetvli, Intrinsic::riscv_vsetvlimax},
4084 II.getIntrinsicID())) {
4087 if (!ST->hasVInstructions())
4090 bool HasAVL =
II.getIntrinsicID() == Intrinsic::riscv_vsetvli;
4091 unsigned Offset = HasAVL ? 1 : 0;
4092 unsigned BitWidth =
II.getType()->getIntegerBitWidth();
4117 Value *AVL =
II.getArgOperand(0);
4146 II.getRange().value_or(ConstantRange::getFull(
BitWidth));
4148 if (NewRange != OldRange) {
4149 II.addRangeRetAttr(NewRange);
4159 if (
II.user_empty())
4164 const APInt *Scalar;
4169 return U->getType() == TargetVecTy && match(U, m_BitCast(m_Value()));
4173 unsigned TargetEltBW =
DL.getTypeSizeInBits(TargetVecTy->getElementType());
4174 unsigned SourceEltBW =
DL.getTypeSizeInBits(SourceVecTy->getElementType());
4175 if (TargetEltBW % SourceEltBW)
4177 unsigned TargetScale = TargetEltBW / SourceEltBW;
4178 if (VL % TargetScale || TargetScale == 1)
4180 Type *VLTy =
II.getOperand(2)->getType();
4181 ElementCount SourceEC = SourceVecTy->getElementCount();
4182 unsigned NewEltBW = SourceEltBW * TargetScale;
4184 !
DL.fitsInLegalInteger(NewEltBW))
4187 if (!TLI->isLegalElementTypeForRVV(TLI->getValueType(
DL, NewEltTy)))
4191 assert(SourceVecTy->canLosslesslyBitCastTo(RetTy) &&
4192 "Lossless bitcast between types expected");
4198 RetTy, Intrinsic::riscv_vmv_v_x,
4199 {PoisonValue::get(RetTy), ConstantInt::get(NewEltTy, NewScalar),
4200 ConstantInt::get(VLTy, VL / TargetScale)}),
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool shouldSplit(Instruction *InsertPoint, DenseSet< Value * > &PrevConditionValues, DenseSet< Value * > &ConditionValues, DominatorTree &DT, DenseSet< Instruction * > &Unhoistables)
Cost tables and simple lookup functions.
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
This file provides the interface for the instcombine pass implementation.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
SmallVector< MachineOperand, 4 > Cond
uint64_t IntrinsicInst * II
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
static LLVM_ABI APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
int64_t getSExtValue() const
Get sign extended value.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
Get the last element.
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
LLVM_ABI StringRef getKindAsString() const
Return the attribute's kind as a string.
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const override
TTI::ShuffleKind improveShuffleKindFromMask(TTI::ShuffleKind Kind, ArrayRef< int > Mask, VectorType *SrcTy, int &Index, VectorType *&SubTy) const
bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, bool HasBaseReg, int64_t Scale, unsigned AddrSpace, Instruction *I=nullptr, int64_t ScalableOffset=0) const override
InstructionCost getScalarizationOverhead(VectorType *InTy, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getIndexedVectorInstrCostFromEnd(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
std::pair< InstructionCost, MVT > getTypeLegalizationCost(Type *Ty) const
bool isLegalAddImmediate(int64_t imm) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
std::optional< unsigned > getVScaleForTuning() const override
InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
InstructionCost getAddressComputationCost(Type *PtrTy, ScalarEvolution *, const SCEV *, TTI::TargetCostKind) const override
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, TTI::TargetCostKind CostKind, Type *AccessType) const override
unsigned getRegUsageForType(Type *Ty) const override
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Opd2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
Value * getArgOperand(unsigned i) const
unsigned arg_size() const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static bool isFPPredicate(Predicate P)
static bool isIntPredicate(Predicate P)
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
This class represents a range of values.
LLVM_ABI ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
LLVM_ABI APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
LLVM_ABI bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other?
LLVM_ABI ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
static LLVM_ABI ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
LLVM_ABI ConstantRange multiply(const ConstantRange &Other, unsigned NoWrapKind=0) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
LLVM_ABI APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
LLVM_ABI ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
LLVM_ABI ConstantRange udiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned division of a value in...
A parsed version of the target data layout string in and methods for querying it.
Convenience struct for specifying and reasoning about fast-math flags.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static FixedVectorType * getDoubleElementsVectorType(FixedVectorType *VTy)
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
static FixedVectorType * getHalfElementsVectorType(FixedVectorType *VTy)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This instruction compares its operands according to the predicate given to the constructor.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
The core instruction combiner logic.
const DataLayout & getDataLayout() const
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
const SimplifyQuery & getSimplifyQuery() const
static InstructionCost getInvalid(CostType Val=0)
CostType getValue() const
This function is intended to be used as sparingly as possible, since the class provides the full rang...
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
user_iterator user_begin()
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
FastMathFlags getFlags() const
const SmallVectorImpl< Type * > & getArgTypes() const
Type * getReturnType() const
const SmallVectorImpl< const Value * > & getArgs() const
VectorInstrContext getVectorInstrContext() const
Intrinsic::ID getID() const
bool isTypeBasedOnly() const
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
Represents a single loop in the control flow graph.
static MVT getFloatingPointVT(unsigned BitWidth)
@ INVALID_SIMPLE_VALUE_TYPE
unsigned getVectorMinNumElements() const
Given a vector type, return the minimum number of elements it contains.
uint64_t getScalarSizeInBits() const
MVT changeVectorElementType(MVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
static MVT getScalableVectorVT(MVT VT, unsigned NumElements)
MVT changeTypeToInteger()
Return the type converted to an equivalently sized integer or vector with integer element type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
bool bitsGT(MVT VT) const
Return true if this has more bits than VT.
bool isFixedLengthVector() const
ElementCount getVectorElementCount() const
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
MVT getVectorElementType() const
bool isValid() const
Return true if this is a valid simple valuetype.
static MVT getIntegerVT(unsigned BitWidth)
MVT getDoubleNumVectorElementsVT() const
MVT getHalfNumVectorElementsVT() const
Return a VT for a vector type with the same element type but half the number of elements.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
Information for memory intrinsic cost model.
Align getAlignment() const
unsigned getAddressSpace() const
Type * getDataType() const
bool getVariableMask() const
const Value * getStrideVal() const
Intrinsic::ID getID() const
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *ValTy, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
bool shouldCopyAttributeWhenOutliningFrom(const Function *Caller, const Attribute &Attr) const override
InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index, const Value *Op0, const Value *Op1, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
bool isLegalMaskedExpandLoad(Type *DataType, Align Alignment) const override
InstructionCost getStridedMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
bool isLegalMaskedLoadStore(Type *DataType, Align Alignment) const
TargetTransformInfo::VectorInstrContext getBuildVectorContextHint(ArrayRef< int > Mask, ArrayRef< Value * > Scalars, function_ref< bool(SmallVectorImpl< TargetTransformInfo::BuildVectorUseOp > &)> GatherUseOps) const override
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
unsigned getMinTripCountTailFoldingThreshold() const override
bool preferLoopExitWithEqualityComparison(const ICmpInst &Cond, const APInt &PostIncExitValue) const override
TTI::AddressingModeKind getPreferredAddressingMode(const Loop *L, ScalarEvolution *SE) const override
InstructionCost getAddressComputationCost(Type *PTy, ScalarEvolution *SE, const SCEV *Ptr, TTI::TargetCostKind CostKind) const override
InstructionCost getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, TTI::TargetCostKind CostKind, ArrayRef< int > Mask, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
InstructionCost getStoreImmCost(Type *VecTy, TTI::OperandValueInfo OpInfo, TTI::TargetCostKind CostKind) const
Return the cost of materializing an immediate for a value operand of a store instruction.
InstructionCost getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, ArrayRef< const Value * > Args={}, const Instruction *CtxI=nullptr, const TargetLibraryInfo *TLibInfo=nullptr, ArrayRef< const Value * > Scalars={}) const override
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const override
InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) const override
bool hasActiveVectorLength() const override
InstructionCost getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, TTI::CastContextHint CCH, TTI::TargetCostKind CostKind, const Instruction *I=nullptr) const override
InstructionCost getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, CmpInst::Predicate VecPred, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Op1Info={TTI::OK_AnyValue, TTI::OP_None}, TTI::OperandValueInfo Op2Info={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getIndexedVectorInstrCostFromEnd(unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index) const override
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP, OptimizationRemarkEmitter *ORE) const override
bool isLegalBroadcastLoad(Type *ElementTy, ElementCount NumElements) const override
InstructionCost getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind, Instruction *Inst=nullptr) const override
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const override
Try to calculate op costs for min/max reduction operations.
bool canSplatOperand(Instruction *I, int Operand) const
Return true if the (vector) instruction I will be lowered to an instruction with a scalar splat opera...
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, const TargetTransformInfo::LSRCost &C2) const override
bool isLegalStridedLoadStore(Type *DataType, Align Alignment) const override
unsigned getRegUsageForType(Type *Ty) const override
InstructionCost getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, bool UseMaskForCond=false, bool UseMaskForGaps=false) const override
bool isLegalMaskedScatter(Type *DataType, Align Alignment) const override
bool isLegalMaskedCompressStore(Type *DataTy, Align Alignment) const override
InstructionCost getGatherScatterOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
InstructionCost getPartialReductionCost(unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType, ElementCount VF, TTI::PartialReductionExtendKind OpAExtend, TTI::PartialReductionExtendKind OpBExtend, std::optional< unsigned > BinOp, TTI::TargetCostKind CostKind, std::optional< FastMathFlags > FMF) const override
bool shouldTreatInstructionLikeSelect(const Instruction *I) const override
InstructionCost getExpandCompressMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
bool preferAlternateOpcodeVectorization() const override
bool isProfitableToSinkOperands(Instruction *I, SmallVectorImpl< Use * > &Ops) const override
Check if sinking I's operands to I's basic block is profitable, because the operands can be folded in...
bool shouldExpandReduction(const IntrinsicInst *II) const override
std::optional< unsigned > getVScaleForTuning() const override
std::optional< InstructionCost > getCombinedArithmeticInstructionCost(unsigned ISDOpcode, Type *Ty, TTI::TargetCostKind CostKind, TTI::OperandValueInfo Opd1Info, TTI::OperandValueInfo Opd2Info, ArrayRef< const Value * > Args, const Instruction *CtxI) const
Check to see if this instruction is expected to be combined to a simpler operation during/before lowe...
InstructionCost getMemIntrinsicInstrCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const override
Get memory intrinsic cost based on arguments.
bool isLegalMaskedGather(Type *DataType, Align Alignment) const override
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, const TTI::TargetCostKind CostKind) const override
unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const override
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override
InstructionCost getScalarizationOverhead(VectorType *Ty, const APInt &DemandedElts, bool Insert, bool Extract, TTI::TargetCostKind CostKind, bool ForPoisonSrc=true, ArrayRef< Value * > VL={}, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None) const override
Estimate the overhead of scalarizing an instruction.
InstructionCost getMemoryOpCost(unsigned Opcode, Type *Src, Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind, TTI::OperandValueInfo OpdInfo={TTI::OK_AnyValue, TTI::OP_None}, const Instruction *I=nullptr) const override
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA, TTI::TargetCostKind CostKind) const override
Get intrinsic cost based on arguments.
InstructionCost getMaskedMemoryOpCost(const MemIntrinsicCostAttributes &MICA, TTI::TargetCostKind CostKind) const
InstructionCost getArithmeticReductionCost(unsigned Opcode, VectorType *Ty, std::optional< FastMathFlags > FMF, TTI::TargetCostKind CostKind) const override
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override
void getPeelingPreferences(Loop *L, ScalarEvolution &SE, TTI::PeelingPreferences &PP) const override
std::optional< Instruction * > instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const override
bool shouldConsiderAddressTypePromotion(const Instruction &I, bool &AllowPromotionWithoutCommonHeader) const override
See if I should be considered for address type promotion.
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
static MVT getM1VT(MVT VT)
Given a vector (either fixed or scalable), return the scalable vector corresponding to a vector regis...
static unsigned computeVLMAX(unsigned VectorBits, unsigned EltSize, unsigned MinSize)
static RISCVVType::VLMUL getLMUL(MVT VT)
This class represents an analyzed expression in the program.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
The main scalar evolution driver.
LLVM_ABI unsigned getSmallConstantTripCount(const Loop *L)
Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
static LLVM_ABI bool isZeroEltSplatMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses all elements with the same value as the first element of exa...
static LLVM_ABI bool isSingleSourceMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector.
static LLVM_ABI bool isDeInterleaveMaskOfFactor(ArrayRef< int > Mask, unsigned Factor, unsigned &Index)
Check if the mask is a DE-interleave mask of the given factor Factor like: <Index,...
static LLVM_ABI bool isIdentityMask(ArrayRef< int > Mask, int NumSrcElts)
Return true if this shuffle mask chooses elements from exactly one source vector without lane crossin...
static LLVM_ABI bool isInterleaveMask(ArrayRef< int > Mask, unsigned Factor, unsigned NumInputElts, SmallVectorImpl< unsigned > &StartIndexes)
Return true if the mask interleaves one or more input vectors together.
Implements a dense probed hash-table based set with some number of buckets stored inline.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
static constexpr TypeSize getScalable(ScalarTy MinimumSize)
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVM_ABI Type * getWithNewBitWidth(unsigned NewBitWidth) const
Given an integer or vector type, change the lane bitwidth to NewBitwidth, whilst keeping the old numb...
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVM_ABI Type * getWithNewType(Type *EltTy) const
Given vector type, change the element type, whilst keeping the old number of elements.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
LLVM_ABI bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
std::pair< iterator, bool > insert(const ValueT &V)
constexpr bool isKnownMultipleOf(ScalarTy RHS) const
This function tells the caller whether the element count is known at compile time to be a multiple of...
constexpr ScalarTy getFixedValue() const
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr bool isKnownEven() const
A return value of true indicates we know at compile time that the number of elements (vscale * Min) i...
constexpr bool isFixed() const
Returns true if the quantity is not scaled by vscale.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
constexpr LeafTy divideCoefficientBy(ScalarTy RHS) const
We do not provide the '/' operator here because division for polynomial types does not work in the sa...
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A unsign-divided by B, rounded by the given rounding mode.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ISD namespace - This namespace contains an enum which represents all of the SelectionDAG node types a...
@ ADD
Simple integer binary arithmetic operators.
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
@ FADD
Simple binary floating point operators.
@ SIGN_EXTEND
Conversion operators.
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
@ SHL
Shift and rotation operations.
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ FMINIMUM
FMINIMUM/FMAXIMUM - Same semantics as the llvm.minimum/maximum intrinsics.
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - Same semantics as the llvm.minimumnum/maximumnum intrinsics.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
auto m_Poison()
Match an arbitrary poison constant.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool match(Val *V, const Pattern &P)
auto m_Value()
Match an arbitrary value and ignore it.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
int getIntMatCost(const APInt &Val, unsigned Size, const MCSubtargetInfo &STI, bool CompressionCost, bool FreeZeroes)
static unsigned decodeVSEW(unsigned VSEW)
LLVM_ABI std::pair< unsigned, bool > decodeVLMUL(VLMUL VLMul)
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul)
static constexpr unsigned RVVBitsPerBlock
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
const CostTblEntryT< CostType > * CostTableLookup(ArrayRef< CostTblEntryT< CostType > > Tbl, int ISD, MVT Ty)
Find in cost table.
LLVM_ABI bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name)
Returns true if Name is applied to TheLoop and enabled.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ None
The instruction is not folded.
@ BinaryOp
One of the operands is a binary op.
@ SplatOpFolded
All of the value's users support splatting the value.
auto adjacent_find(R &&Range)
Provide wrappers to std::adjacent_find which finds the first pair of adjacent elements that are equal...
bool isPairEven(const std::array< std::pair< int, int >, 2 > &SrcInfo, ArrayRef< int > Mask, unsigned &Factor)
Given a shuffle which can be represented as a pair of two slides, see if it is a pair-even idiom.
bool isPairOdd(const std::array< std::pair< int, int >, 2 > &SrcInfo, ArrayRef< int > Mask, unsigned &Factor)
Given a shuffle which can be represented as a pair of two slides, see if it is a pair-odd idiom.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
LLVM_ABI llvm::SmallVector< int, 16 > createStrideMask(unsigned Start, unsigned Stride, unsigned VF)
Create a stride shuffle mask.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
auto find_if_not(R &&Range, UnaryPredicate P)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
constexpr int PoisonMaskElem
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
LLVM_ABI bool isMaskedSlidePair(ArrayRef< int > Mask, int NumElts, std::array< std::pair< int, int >, 2 > &SrcInfo)
Does this shuffle mask represent either one slide shuffle or a pair of two slide shuffles,...
LLVM_ABI llvm::SmallVector< int, 16 > createInterleaveMask(unsigned VF, unsigned NumVecs)
Create an interleave shuffle mask.
LLVM_ABI ConstantRange computeConstantRangeIncludingKnownBits(const WithCache< const Value * > &V, bool ForSigned, const SimplifyQuery &SQ)
Combine constant ranges from computeConstantRange() and computeKnownBits().
DWARFExpression::Operation Op
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
CostTblEntryT< uint16_t > CostTblEntry
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
LLVM_ABI void processShuffleMasks(ArrayRef< int > Mask, unsigned NumOfSrcRegs, unsigned NumOfDestRegs, unsigned NumOfUsedRegs, function_ref< void()> NoInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned)> SingleInputAction, function_ref< void(ArrayRef< int >, unsigned, unsigned, bool)> ManyInputsAction)
Splits and processes shuffle mask depending on the number of input and output registers.
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Information about a load/store intrinsic defined by the target.
SimplifyQuery getWithInstruction(const Instruction *I) const