18#include "llvm/IR/IntrinsicsRISCV.h"
26#define DEBUG_TYPE "riscvtti"
29 "riscv-v-register-bit-width-lmul",
31 "The LMUL to use for getRegisterBitWidth queries. Affects LMUL used "
32 "by autovectorized code. Fractional LMULs are not supported."),
38 "Overrides result used for getMaximumVF query which is used "
39 "exclusively by SLP vectorizer."),
44 cl::desc(
"Set the lower bound of a trip count to decide on "
45 "vectorization while tail-folding."),
57 size_t NumInstr = OpCodes.size();
62 return LMULCost * NumInstr;
64 for (
auto Op : OpCodes) {
66 case RISCV::VRGATHER_VI:
69 case RISCV::VRGATHER_VV:
72 case RISCV::VSLIDEUP_VI:
73 case RISCV::VSLIDEDOWN_VI:
76 case RISCV::VSLIDEUP_VX:
77 case RISCV::VSLIDEDOWN_VX:
80 case RISCV::VREDMAX_VS:
81 case RISCV::VREDMIN_VS:
82 case RISCV::VREDMAXU_VS:
83 case RISCV::VREDMINU_VS:
84 case RISCV::VREDSUM_VS:
85 case RISCV::VREDAND_VS:
86 case RISCV::VREDOR_VS:
87 case RISCV::VREDXOR_VS:
88 case RISCV::VFREDMAX_VS:
89 case RISCV::VFREDMIN_VS:
90 case RISCV::VFREDUSUM_VS: {
97 case RISCV::VFREDOSUM_VS: {
106 case RISCV::VFMV_F_S:
107 case RISCV::VFMV_S_F:
109 case RISCV::VMXOR_MM:
110 case RISCV::VMAND_MM:
111 case RISCV::VMANDN_MM:
112 case RISCV::VMNAND_MM:
114 case RISCV::VFIRST_M:
133 assert(Ty->isIntegerTy() &&
134 "getIntImmCost can only estimate cost of materialising integers");
157 if (!BO || !BO->hasOneUse())
160 if (BO->getOpcode() != Instruction::Shl)
171 if (ShAmt == Trailing)
188 if (!Cmp || !Cmp->isEquality())
204 if ((CmpC & Mask) != CmpC)
211 return NewCmpC >= -2048 && NewCmpC <= 2048;
218 assert(Ty->isIntegerTy() &&
219 "getIntImmCost can only estimate cost of materialising integers");
227 bool Takes12BitImm =
false;
228 unsigned ImmArgIdx = ~0U;
231 case Instruction::GetElementPtr:
236 case Instruction::Store: {
241 if (Idx == 1 || !Inst)
246 if (!getTLI()->allowsMemoryAccessForAlignment(
254 case Instruction::Load:
257 case Instruction::And:
259 if (Imm == UINT64_C(0xffff) && ST->hasStdExtZbb())
262 if (Imm == UINT64_C(0xffffffff) &&
263 ((ST->hasStdExtZba() && ST->isRV64()) || ST->isRV32()))
266 if (ST->hasStdExtZbs() && (~Imm).isPowerOf2())
268 if (Inst && Idx == 1 && Imm.getBitWidth() <= ST->getXLen() &&
271 if (Inst && Idx == 1 && Imm.getBitWidth() == 64 &&
274 Takes12BitImm =
true;
276 case Instruction::Add:
277 Takes12BitImm =
true;
279 case Instruction::Or:
280 case Instruction::Xor:
282 if (ST->hasStdExtZbs() && Imm.isPowerOf2())
284 Takes12BitImm =
true;
286 case Instruction::Mul:
288 if (Imm.isPowerOf2() || Imm.isNegatedPowerOf2())
291 if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2())
294 Takes12BitImm =
true;
296 case Instruction::Sub:
297 case Instruction::Shl:
298 case Instruction::LShr:
299 case Instruction::AShr:
300 Takes12BitImm =
true;
311 if (Imm.getSignificantBits() <= 64 &&
334 return ST->hasVInstructions();
344 unsigned Opcode,
Type *InputTypeA,
Type *InputTypeB,
Type *AccumType,
348 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) ||
363 getRISCVInstructionCost(RISCV::VDOT4A_VV, LT.second,
CostKind);
370 switch (
II->getIntrinsicID()) {
374 case Intrinsic::vector_reduce_mul:
375 case Intrinsic::vector_reduce_fmul:
381 if (ST->hasVInstructions())
387 if (ST->hasVInstructions())
388 if (
unsigned MinVLen = ST->getRealMinVLen();
403 ST->useRVVForFixedLengthVectors() ? LMUL * ST->getRealMinVLen() : 0);
406 (ST->hasVInstructions() &&
429 return (ST->hasAUIPCADDIFusion() && ST->hasLUIADDIFusion()) ? 1 : 2;
435RISCVTTIImpl::getConstantPoolLoadCost(
Type *Ty,
440 return getStaticDataAddrGenerationCost(
CostKind) +
446 unsigned Size = Mask.size();
449 for (
unsigned I = 0;
I !=
Size; ++
I) {
450 if (
static_cast<unsigned>(Mask[
I]) ==
I)
456 for (
unsigned J =
I + 1; J !=
Size; ++J)
458 if (
static_cast<unsigned>(Mask[J]) != J %
I)
486 "Expected fixed vector type and non-empty mask");
489 unsigned NumOfDests =
divideCeil(Mask.size(), LegalNumElts);
493 if (NumOfDests <= 1 ||
495 Tp->getElementType()->getPrimitiveSizeInBits() ||
496 LegalNumElts >= Tp->getElementCount().getFixedValue())
499 unsigned VecTySize =
TTI.getDataLayout().getTypeStoreSize(Tp);
502 unsigned NumOfSrcs =
divideCeil(VecTySize, LegalVTSize);
506 unsigned NormalizedVF = LegalNumElts * std::max(NumOfSrcs, NumOfDests);
507 unsigned NumOfSrcRegs = NormalizedVF / LegalNumElts;
508 unsigned NumOfDestRegs = NormalizedVF / LegalNumElts;
510 assert(NormalizedVF >= Mask.size() &&
511 "Normalized mask expected to be not shorter than original mask.");
516 NormalizedMask, NumOfSrcRegs, NumOfDestRegs, NumOfDestRegs, []() {},
517 [&](
ArrayRef<int> RegMask,
unsigned SrcReg,
unsigned DestReg) {
520 if (!ReusedSingleSrcShuffles.
insert(std::make_pair(RegMask, SrcReg))
523 Cost +=
TTI.getShuffleCost(
526 SingleOpTy, RegMask,
CostKind, 0,
nullptr);
528 [&](
ArrayRef<int> RegMask,
unsigned Idx1,
unsigned Idx2,
bool NewReg) {
529 Cost +=
TTI.getShuffleCost(
532 SingleOpTy, RegMask,
CostKind, 0,
nullptr);
555 if (!VLen || Mask.empty())
559 LegalVT =
TTI.getTypeLegalizationCost(
565 if (NumOfDests <= 1 ||
567 Tp->getElementType()->getPrimitiveSizeInBits() ||
571 unsigned VecTySize =
TTI.getDataLayout().getTypeStoreSize(Tp);
574 unsigned NumOfSrcs =
divideCeil(VecTySize, LegalVTSize);
580 unsigned NormalizedVF =
585 assert(NormalizedVF >= Mask.size() &&
586 "Normalized mask expected to be not shorter than original mask.");
592 NormalizedMask, NumOfSrcRegs, NumOfDestRegs, NumOfDestRegs, []() {},
593 [&](
ArrayRef<int> RegMask,
unsigned SrcReg,
unsigned DestReg) {
596 if (!ReusedSingleSrcShuffles.
insert(std::make_pair(RegMask, SrcReg))
601 SingleOpTy, RegMask,
CostKind, 0,
nullptr);
603 [&](
ArrayRef<int> RegMask,
unsigned Idx1,
unsigned Idx2,
bool NewReg) {
605 SingleOpTy, RegMask,
CostKind, 0,
nullptr);
612 if ((NumOfDestRegs > 2 && NumShuffles <=
static_cast<int>(NumOfDestRegs)) ||
613 (NumOfDestRegs <= 2 && NumShuffles < 4))
628 if (!
LT.second.isFixedLengthVector())
636 auto GetSlideOpcode = [&](
int SlideAmt) {
638 bool IsVI =
isUInt<5>(std::abs(SlideAmt));
640 return IsVI ? RISCV::VSLIDEDOWN_VI : RISCV::VSLIDEDOWN_VX;
641 return IsVI ? RISCV::VSLIDEUP_VI : RISCV::VSLIDEUP_VX;
644 std::array<std::pair<int, int>, 2> SrcInfo;
648 if (SrcInfo[1].second == 0)
652 if (SrcInfo[0].second != 0) {
653 unsigned Opcode = GetSlideOpcode(SrcInfo[0].second);
654 FirstSlideCost = getRISCVInstructionCost(Opcode,
LT.second,
CostKind);
657 if (SrcInfo[1].first == -1)
658 return FirstSlideCost;
661 if (SrcInfo[1].second != 0) {
662 unsigned Opcode = GetSlideOpcode(SrcInfo[1].second);
663 SecondSlideCost = getRISCVInstructionCost(Opcode,
LT.second,
CostKind);
666 getRISCVInstructionCost(RISCV::VMERGE_VVM,
LT.second,
CostKind);
673 return FirstSlideCost + SecondSlideCost + MaskCost;
684 "Expected the Mask to match the return size if given");
686 "Expected the same scalar types");
702 FVTp && ST->hasVInstructions() && LT.second.isFixedLengthVector()) {
704 *
this, LT.second, ST->getRealVLen(),
706 if (VRegSplittingCost.
isValid())
707 return VRegSplittingCost;
712 if (Mask.size() >= 2) {
713 MVT EltTp = LT.second.getVectorElementType();
724 return 2 * LT.first * TLI->getLMULCost(LT.second);
726 if (Mask[0] == 0 || Mask[0] == 1) {
730 if (
equal(DeinterleaveMask, Mask))
731 return LT.first * getRISCVInstructionCost(RISCV::VNSRL_WI,
736 if (LT.second.getScalarSizeInBits() != 1 &&
739 unsigned NumSlides =
Log2_32(Mask.size() / SubVectorSize);
741 for (
unsigned I = 0;
I != NumSlides; ++
I) {
742 unsigned InsertIndex = SubVectorSize * (1 <<
I);
747 std::pair<InstructionCost, MVT> DestLT =
752 Cost += DestLT.first * TLI->getLMULCost(DestLT.second);
766 if (LT.first == 1 && (LT.second.getScalarSizeInBits() != 8 ||
767 LT.second.getVectorNumElements() <= 256)) {
772 getRISCVInstructionCost(RISCV::VRGATHER_VV, LT.second,
CostKind);
786 if (LT.first == 1 && (LT.second.getScalarSizeInBits() != 8 ||
787 LT.second.getVectorNumElements() <= 256)) {
788 auto &
C = SrcTy->getContext();
789 auto EC = SrcTy->getElementCount();
794 return 2 * IndexCost +
795 getRISCVInstructionCost({RISCV::VRGATHER_VV, RISCV::VRGATHER_VV},
814 if (!Mask.empty() && LT.first.isValid() && LT.first != 1 &&
842 SubLT.second.isValid() && SubLT.second.isFixedLengthVector()) {
843 if (std::optional<unsigned> VLen = ST->getRealVLen();
844 VLen && SubLT.second.getScalarSizeInBits() * Index % *VLen == 0 &&
845 SubLT.second.getSizeInBits() <= *VLen)
853 getRISCVInstructionCost(RISCV::VSLIDEDOWN_VI, LT.second,
CostKind);
860 getRISCVInstructionCost(RISCV::VSLIDEUP_VI, LT.second,
CostKind);
872 (1 + getRISCVInstructionCost({RISCV::VMV_S_X, RISCV::VMERGE_VVM},
879 if (IsLoad && LT.second.isVector() &&
881 LT.second.getVectorElementCount()))
885 Instruction::InsertElement);
886 if (LT.second.getScalarSizeInBits() == 1) {
894 (1 + getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI},
907 (1 + getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM,
908 RISCV::VMV_X_S, RISCV::VMV_V_X,
917 getRISCVInstructionCost(RISCV::VMV_V_X, LT.second,
CostKind);
923 getRISCVInstructionCost(RISCV::VRGATHER_VI, LT.second,
CostKind);
929 unsigned Opcodes[2] = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VX};
930 if (Index >= 0 && Index < 32)
931 Opcodes[0] = RISCV::VSLIDEDOWN_VI;
932 else if (Index < 0 && Index > -32)
933 Opcodes[1] = RISCV::VSLIDEUP_VI;
934 return LT.first * getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
938 if (!LT.second.isVector())
944 if (SrcTy->getElementType()->isIntegerTy(1)) {
956 MVT ContainerVT = LT.second;
957 if (LT.second.isFixedLengthVector())
958 ContainerVT = TLI->getContainerForFixedLengthVector(LT.second);
960 if (ContainerVT.
bitsLE(M1VT)) {
970 if (LT.second.isFixedLengthVector())
972 LenCost =
isInt<5>(LT.second.getVectorNumElements() - 1) ? 0 : 1;
973 unsigned Opcodes[] = {RISCV::VID_V, RISCV::VRSUB_VX, RISCV::VRGATHER_VV};
974 if (LT.second.isFixedLengthVector() &&
975 isInt<5>(LT.second.getVectorNumElements() - 1))
976 Opcodes[1] = RISCV::VRSUB_VI;
978 getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
979 return LT.first * (LenCost + GatherCost);
986 unsigned M1Opcodes[] = {RISCV::VID_V, RISCV::VRSUB_VX};
988 getRISCVInstructionCost(M1Opcodes, M1VT,
CostKind) + 3;
992 getRISCVInstructionCost({RISCV::VRGATHER_VV}, M1VT,
CostKind) * Ratio;
994 getRISCVInstructionCost({RISCV::VSLIDEDOWN_VX}, LT.second,
CostKind);
995 return FixedCost + LT.first * (GatherCost + SlideCost);
1029 Ty, DemandedElts, Insert, Extract,
CostKind);
1031 if (Insert && !Extract && LT.first.isValid() && LT.second.isVector()) {
1032 if (Ty->getScalarSizeInBits() == 1) {
1042 assert(LT.second.isFixedLengthVector());
1043 MVT ContainerVT = TLI->getContainerForFixedLengthVector(LT.second);
1047 getRISCVInstructionCost(RISCV::VSLIDE1DOWN_VX, LT.second,
CostKind);
1060 switch (MICA.
getID()) {
1061 case Intrinsic::vp_load_ff: {
1062 EVT DataTypeVT = TLI->getValueType(
DL, DataTy);
1063 if (!TLI->isLegalFirstFaultLoad(DataTypeVT, Alignment))
1070 case Intrinsic::experimental_vp_strided_load:
1071 case Intrinsic::experimental_vp_strided_store:
1073 case Intrinsic::masked_compressstore:
1074 case Intrinsic::masked_expandload:
1076 case Intrinsic::vp_scatter:
1077 case Intrinsic::vp_gather:
1078 case Intrinsic::masked_scatter:
1079 case Intrinsic::masked_gather:
1081 case Intrinsic::vp_load:
1082 case Intrinsic::vp_store:
1083 case Intrinsic::masked_load:
1084 case Intrinsic::masked_store:
1093 unsigned Opcode = MICA.
getID() == Intrinsic::masked_load ? Instruction::Load
1094 : Instruction::Store;
1109 bool UseMaskForCond,
bool UseMaskForGaps)
const {
1115 if (!UseMaskForGaps && Factor <= TLI->getMaxSupportedInterleaveFactor()) {
1119 if (LT.second.isVector()) {
1125 VTy->getElementCount().divideCoefficientBy(Factor));
1126 if (VTy->getElementCount().isKnownMultipleOf(Factor) &&
1127 TLI->isLegalInterleavedAccessType(SubVecTy, Factor, Alignment,
1132 if (ST->hasOptimizedSegmentLoadStore(Factor)) {
1135 MVT SubVecVT = getTLI()->getValueType(
DL, SubVecTy).getSimpleVT();
1136 Cost += Factor * TLI->getLMULCost(SubVecVT);
1137 return LT.first *
Cost;
1142 unsigned NumLoads = getEstimatedVLFor(VTy);
1158 if (UseMaskForGaps) {
1161 "Indices should not contain duplicate elements");
1162 unsigned NumOfFields = Indices.
size();
1163 bool IsTailGapOnly = NumOfFields > 1 && (NumOfFields == Indices.
back() + 1);
1164 if (IsTailGapOnly &&
1165 NumOfFields <= TLI->getMaxSupportedInterleaveFactor()) {
1167 if (LT.second.isVector() &&
1168 FVTy->getElementCount().isKnownMultipleOf(Factor)) {
1170 FVTy->getElementType(),
1171 FVTy->getElementCount().divideCoefficientBy(Factor));
1172 if (TLI->isLegalInterleavedAccessType(SubVecTy, NumOfFields, Alignment,
1175 unsigned NumAccesses = getEstimatedVLFor(FVTy);
1184 unsigned VF = FVTy->getNumElements() / Factor;
1191 if (Opcode == Instruction::Load) {
1193 for (
unsigned Index : Indices) {
1197 Mask.resize(VF * Factor, -1);
1201 Cost += ShuffleCost;
1219 UseMaskForCond, UseMaskForGaps);
1221 assert(Opcode == Instruction::Store &&
"Opcode must be a store");
1228 return MemCost + ShuffleCost;
1235 bool IsLoad = MICA.
getID() == Intrinsic::masked_gather ||
1236 MICA.
getID() == Intrinsic::vp_gather;
1237 unsigned Opcode = IsLoad ? Instruction::Load : Instruction::Store;
1243 if ((Opcode == Instruction::Load &&
1245 (Opcode == Instruction::Store &&
1253 unsigned NumLoads = getEstimatedVLFor(&VTy);
1260 unsigned Opcode = MICA.
getID() == Intrinsic::masked_expandload
1262 : Instruction::Store;
1266 bool IsLegal = (Opcode == Instruction::Store &&
1268 (Opcode == Instruction::Load &&
1292 if (Opcode == Instruction::Store)
1293 Opcodes.
append({RISCV::VCOMPRESS_VM});
1295 Opcodes.
append({RISCV::VSETIVLI, RISCV::VIOTA_M, RISCV::VRGATHER_VV});
1297 LT.first * getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
1316 unsigned NumLoads = getEstimatedVLFor(&VTy);
1327 for (
auto *Ty : Tys) {
1328 if (!Ty->isVectorTy())
1342 {Intrinsic::floor, MVT::f32, 9},
1343 {Intrinsic::floor, MVT::f64, 9},
1344 {Intrinsic::ceil, MVT::f32, 9},
1345 {Intrinsic::ceil, MVT::f64, 9},
1346 {Intrinsic::trunc, MVT::f32, 7},
1347 {Intrinsic::trunc, MVT::f64, 7},
1348 {Intrinsic::round, MVT::f32, 9},
1349 {Intrinsic::round, MVT::f64, 9},
1350 {Intrinsic::roundeven, MVT::f32, 9},
1351 {Intrinsic::roundeven, MVT::f64, 9},
1352 {Intrinsic::rint, MVT::f32, 7},
1353 {Intrinsic::rint, MVT::f64, 7},
1354 {Intrinsic::nearbyint, MVT::f32, 9},
1355 {Intrinsic::nearbyint, MVT::f64, 9},
1356 {Intrinsic::bswap, MVT::i16, 3},
1357 {Intrinsic::bswap, MVT::i32, 12},
1358 {Intrinsic::bswap, MVT::i64, 31},
1359 {Intrinsic::vp_bswap, MVT::i16, 3},
1360 {Intrinsic::vp_bswap, MVT::i32, 12},
1361 {Intrinsic::vp_bswap, MVT::i64, 31},
1362 {Intrinsic::vp_fshl, MVT::i8, 7},
1363 {Intrinsic::vp_fshl, MVT::i16, 7},
1364 {Intrinsic::vp_fshl, MVT::i32, 7},
1365 {Intrinsic::vp_fshl, MVT::i64, 7},
1366 {Intrinsic::vp_fshr, MVT::i8, 7},
1367 {Intrinsic::vp_fshr, MVT::i16, 7},
1368 {Intrinsic::vp_fshr, MVT::i32, 7},
1369 {Intrinsic::vp_fshr, MVT::i64, 7},
1370 {Intrinsic::bitreverse, MVT::i8, 17},
1371 {Intrinsic::bitreverse, MVT::i16, 24},
1372 {Intrinsic::bitreverse, MVT::i32, 33},
1373 {Intrinsic::bitreverse, MVT::i64, 52},
1374 {Intrinsic::vp_bitreverse, MVT::i8, 17},
1375 {Intrinsic::vp_bitreverse, MVT::i16, 24},
1376 {Intrinsic::vp_bitreverse, MVT::i32, 33},
1377 {Intrinsic::vp_bitreverse, MVT::i64, 52},
1378 {Intrinsic::ctpop, MVT::i8, 12},
1379 {Intrinsic::ctpop, MVT::i16, 19},
1380 {Intrinsic::ctpop, MVT::i32, 20},
1381 {Intrinsic::ctpop, MVT::i64, 21},
1382 {Intrinsic::ctlz, MVT::i8, 19},
1383 {Intrinsic::ctlz, MVT::i16, 28},
1384 {Intrinsic::ctlz, MVT::i32, 31},
1385 {Intrinsic::ctlz, MVT::i64, 35},
1386 {Intrinsic::cttz, MVT::i8, 16},
1387 {Intrinsic::cttz, MVT::i16, 23},
1388 {Intrinsic::cttz, MVT::i32, 24},
1389 {Intrinsic::cttz, MVT::i64, 25},
1390 {Intrinsic::vp_ctpop, MVT::i8, 12},
1391 {Intrinsic::vp_ctpop, MVT::i16, 19},
1392 {Intrinsic::vp_ctpop, MVT::i32, 20},
1393 {Intrinsic::vp_ctpop, MVT::i64, 21},
1394 {Intrinsic::vp_ctlz, MVT::i8, 19},
1395 {Intrinsic::vp_ctlz, MVT::i16, 28},
1396 {Intrinsic::vp_ctlz, MVT::i32, 31},
1397 {Intrinsic::vp_ctlz, MVT::i64, 35},
1398 {Intrinsic::vp_cttz, MVT::i8, 16},
1399 {Intrinsic::vp_cttz, MVT::i16, 23},
1400 {Intrinsic::vp_cttz, MVT::i32, 24},
1401 {Intrinsic::vp_cttz, MVT::i64, 25},
1408 switch (ICA.
getID()) {
1409 case Intrinsic::lrint:
1410 case Intrinsic::llrint:
1411 case Intrinsic::lround:
1412 case Intrinsic::llround: {
1416 if (ST->hasVInstructions() && LT.second.isVector()) {
1418 unsigned SrcEltSz =
DL.getTypeSizeInBits(SrcTy->getScalarType());
1419 unsigned DstEltSz =
DL.getTypeSizeInBits(RetTy->getScalarType());
1420 if (LT.second.getVectorElementType() == MVT::bf16) {
1421 if (!ST->hasVInstructionsBF16Minimal())
1424 Ops = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFCVT_X_F_V};
1426 Ops = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVT_X_F_V};
1427 }
else if (LT.second.getVectorElementType() == MVT::f16 &&
1428 !ST->hasVInstructionsF16()) {
1429 if (!ST->hasVInstructionsF16Minimal())
1432 Ops = {RISCV::VFWCVT_F_F_V, RISCV::VFCVT_X_F_V};
1434 Ops = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_X_F_V};
1436 }
else if (SrcEltSz > DstEltSz) {
1437 Ops = {RISCV::VFNCVT_X_F_W};
1438 }
else if (SrcEltSz < DstEltSz) {
1439 Ops = {RISCV::VFWCVT_X_F_V};
1441 Ops = {RISCV::VFCVT_X_F_V};
1446 if (SrcEltSz > DstEltSz)
1447 return SrcLT.first *
1448 getRISCVInstructionCost(
Ops, SrcLT.second,
CostKind);
1449 return LT.first * getRISCVInstructionCost(
Ops, LT.second,
CostKind);
1453 case Intrinsic::ceil:
1454 case Intrinsic::floor:
1455 case Intrinsic::trunc:
1456 case Intrinsic::rint:
1457 case Intrinsic::round:
1458 case Intrinsic::roundeven: {
1461 if (!LT.second.isVector() && TLI->isOperationCustom(
ISD::FCEIL, LT.second))
1462 return LT.first * 8;
1465 case Intrinsic::umin:
1466 case Intrinsic::umax:
1467 case Intrinsic::smin:
1468 case Intrinsic::smax: {
1470 if (LT.second.isScalarInteger() && ST->hasStdExtZbb())
1473 if (ST->hasVInstructions() && LT.second.isVector()) {
1475 switch (ICA.
getID()) {
1476 case Intrinsic::umin:
1477 Op = RISCV::VMINU_VV;
1479 case Intrinsic::umax:
1480 Op = RISCV::VMAXU_VV;
1482 case Intrinsic::smin:
1483 Op = RISCV::VMIN_VV;
1485 case Intrinsic::smax:
1486 Op = RISCV::VMAX_VV;
1489 return LT.first * getRISCVInstructionCost(
Op, LT.second,
CostKind);
1493 case Intrinsic::sadd_sat:
1494 case Intrinsic::ssub_sat:
1495 case Intrinsic::uadd_sat:
1496 case Intrinsic::usub_sat: {
1498 if (ST->hasVInstructions() && LT.second.isVector()) {
1500 switch (ICA.
getID()) {
1501 case Intrinsic::sadd_sat:
1502 Op = RISCV::VSADD_VV;
1504 case Intrinsic::ssub_sat:
1505 Op = RISCV::VSSUB_VV;
1507 case Intrinsic::uadd_sat:
1508 Op = RISCV::VSADDU_VV;
1510 case Intrinsic::usub_sat:
1511 Op = RISCV::VSSUBU_VV;
1514 return LT.first * getRISCVInstructionCost(
Op, LT.second,
CostKind);
1518 case Intrinsic::fma:
1519 case Intrinsic::fmuladd: {
1522 if (ST->hasVInstructions() && LT.second.isVector())
1524 getRISCVInstructionCost(RISCV::VFMADD_VV, LT.second,
CostKind);
1527 case Intrinsic::fabs: {
1529 if (ST->hasVInstructions() && LT.second.isVector()) {
1535 if (LT.second.getVectorElementType() == MVT::bf16 ||
1536 (LT.second.getVectorElementType() == MVT::f16 &&
1537 !ST->hasVInstructionsF16()))
1538 return LT.first * getRISCVInstructionCost(RISCV::VAND_VX, LT.second,
1543 getRISCVInstructionCost(RISCV::VFSGNJX_VV, LT.second,
CostKind);
1547 case Intrinsic::sqrt: {
1549 if (ST->hasVInstructions() && LT.second.isVector()) {
1552 MVT ConvType = LT.second;
1553 MVT FsqrtType = LT.second;
1556 if (LT.second.getVectorElementType() == MVT::bf16) {
1557 if (LT.second == MVT::nxv32bf16) {
1558 ConvOp = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFWCVTBF16_F_F_V,
1559 RISCV::VFNCVTBF16_F_F_W, RISCV::VFNCVTBF16_F_F_W};
1560 FsqrtOp = {RISCV::VFSQRT_V, RISCV::VFSQRT_V};
1561 ConvType = MVT::nxv16f16;
1562 FsqrtType = MVT::nxv16f32;
1564 ConvOp = {RISCV::VFWCVTBF16_F_F_V, RISCV::VFNCVTBF16_F_F_W};
1565 FsqrtOp = {RISCV::VFSQRT_V};
1566 FsqrtType = TLI->getTypeToPromoteTo(
ISD::FSQRT, FsqrtType);
1568 }
else if (LT.second.getVectorElementType() == MVT::f16 &&
1569 !ST->hasVInstructionsF16()) {
1570 if (LT.second == MVT::nxv32f16) {
1571 ConvOp = {RISCV::VFWCVT_F_F_V, RISCV::VFWCVT_F_F_V,
1572 RISCV::VFNCVT_F_F_W, RISCV::VFNCVT_F_F_W};
1573 FsqrtOp = {RISCV::VFSQRT_V, RISCV::VFSQRT_V};
1574 ConvType = MVT::nxv16f16;
1575 FsqrtType = MVT::nxv16f32;
1577 ConvOp = {RISCV::VFWCVT_F_F_V, RISCV::VFNCVT_F_F_W};
1578 FsqrtOp = {RISCV::VFSQRT_V};
1579 FsqrtType = TLI->getTypeToPromoteTo(
ISD::FSQRT, FsqrtType);
1582 FsqrtOp = {RISCV::VFSQRT_V};
1585 return LT.first * (getRISCVInstructionCost(FsqrtOp, FsqrtType,
CostKind) +
1586 getRISCVInstructionCost(ConvOp, ConvType,
CostKind));
1590 case Intrinsic::cttz:
1591 case Intrinsic::ctlz:
1592 case Intrinsic::ctpop: {
1594 if (ST->hasStdExtZvbb() && LT.second.isVector()) {
1596 switch (ICA.
getID()) {
1597 case Intrinsic::cttz:
1600 case Intrinsic::ctlz:
1603 case Intrinsic::ctpop:
1604 Op = RISCV::VCPOP_V;
1607 return LT.first * getRISCVInstructionCost(
Op, LT.second,
CostKind);
1611 case Intrinsic::abs: {
1613 if (ST->hasVInstructions() && LT.second.isVector()) {
1615 if (ST->hasStdExtZvabd())
1617 getRISCVInstructionCost({RISCV::VABS_V}, LT.second,
CostKind);
1622 getRISCVInstructionCost({RISCV::VRSUB_VI, RISCV::VMAX_VV},
1627 case Intrinsic::fshl:
1628 case Intrinsic::fshr: {
1635 if ((ST->hasStdExtZbb() || ST->hasStdExtZbkb()) && RetTy->isIntegerTy() &&
1637 (RetTy->getIntegerBitWidth() == 32 ||
1638 RetTy->getIntegerBitWidth() == 64) &&
1639 RetTy->getIntegerBitWidth() <= ST->getXLen()) {
1644 case Intrinsic::masked_udiv:
1647 case Intrinsic::masked_sdiv:
1650 case Intrinsic::masked_urem:
1653 case Intrinsic::masked_srem:
1656 case Intrinsic::get_active_lane_mask: {
1657 if (ST->hasVInstructions()) {
1666 getRISCVInstructionCost({RISCV::VSADDU_VX, RISCV::VMSLTU_VX},
1672 case Intrinsic::stepvector: {
1676 if (ST->hasVInstructions())
1677 return getRISCVInstructionCost(RISCV::VID_V, LT.second,
CostKind) +
1679 getRISCVInstructionCost(RISCV::VADD_VX, LT.second,
CostKind);
1680 return 1 + (LT.first - 1);
1682 case Intrinsic::vector_splice_left:
1683 case Intrinsic::vector_splice_right: {
1688 if (ST->hasVInstructions() && LT.second.isVector()) {
1690 getRISCVInstructionCost({RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VX},
1695 case Intrinsic::experimental_cttz_elts: {
1697 EVT ArgType = TLI->getValueType(
DL, ArgTy,
true);
1698 if (getTLI()->shouldExpandCttzElements(ArgType))
1715 case Intrinsic::experimental_vp_splice: {
1723 case Intrinsic::vp_merge: {
1731 case Intrinsic::fptoui_sat:
1732 case Intrinsic::fptosi_sat: {
1734 bool IsSigned = ICA.
getID() == Intrinsic::fptosi_sat;
1739 if (!SrcTy->isVectorTy())
1742 if (!SrcLT.first.isValid() || !DstLT.first.isValid())
1759 case Intrinsic::experimental_vector_extract_last_active: {
1781 unsigned EltWidth = getTLI()->getBitWidthForCttzElements(
1782 TLI->getVectorIdxTy(
getDataLayout()), MaskTy->getElementCount(),
1783 true, &VScaleRange);
1784 EltWidth = std::max(EltWidth, MaskTy->getScalarSizeInBits());
1792 if (StepLT.first > 1)
1796 unsigned Opcodes[] = {RISCV::VID_V, RISCV::VREDMAXU_VS, RISCV::VMV_X_S};
1798 Cost += MaskLT.first *
1799 getRISCVInstructionCost(RISCV::VCPOP_M, MaskLT.second,
CostKind);
1801 Cost += StepLT.first *
1802 getRISCVInstructionCost(Opcodes, StepLT.second,
CostKind);
1806 Cost += ValLT.first *
1807 getRISCVInstructionCost({RISCV::VSLIDEDOWN_VI, RISCV::VMV_X_S},
1813 if (ST->hasVInstructions() && RetTy->isVectorTy()) {
1815 LT.second.isVector()) {
1816 MVT EltTy = LT.second.getVectorElementType();
1818 ICA.
getID(), EltTy))
1819 return LT.first * Entry->Cost;
1832 if (ST->hasVInstructions() && PtrTy->
isVectorTy())
1850 if (ST->hasStdExtP() &&
1858 if (!ST->hasVInstructions() || Src->getScalarSizeInBits() > ST->getELen() ||
1859 Dst->getScalarSizeInBits() > ST->getELen())
1862 int ISD = TLI->InstructionOpcodeToISD(Opcode);
1877 if (Src->getScalarSizeInBits() == 1) {
1882 return getRISCVInstructionCost(RISCV::VMV_V_I, DstLT.second,
CostKind) +
1883 DstLT.first * getRISCVInstructionCost(RISCV::VMERGE_VIM,
1889 if (Dst->getScalarSizeInBits() == 1) {
1895 return SrcLT.first *
1896 getRISCVInstructionCost({RISCV::VAND_VI, RISCV::VMSNE_VI},
1908 if (!SrcLT.second.isVector() || !DstLT.second.isVector() ||
1909 !SrcLT.first.isValid() || !DstLT.first.isValid() ||
1911 SrcLT.second.getSizeInBits()) ||
1913 DstLT.second.getSizeInBits()) ||
1914 SrcLT.first > 1 || DstLT.first > 1)
1918 assert((SrcLT.first == 1) && (DstLT.first == 1) &&
"Illegal type");
1920 int PowDiff = (int)
Log2_32(DstLT.second.getScalarSizeInBits()) -
1921 (int)
Log2_32(SrcLT.second.getScalarSizeInBits());
1925 if ((PowDiff < 1) || (PowDiff > 3))
1927 unsigned SExtOp[] = {RISCV::VSEXT_VF2, RISCV::VSEXT_VF4, RISCV::VSEXT_VF8};
1928 unsigned ZExtOp[] = {RISCV::VZEXT_VF2, RISCV::VZEXT_VF4, RISCV::VZEXT_VF8};
1931 return getRISCVInstructionCost(
Op, DstLT.second,
CostKind);
1937 unsigned SrcEltSize = SrcLT.second.getScalarSizeInBits();
1938 unsigned DstEltSize = DstLT.second.getScalarSizeInBits();
1942 : RISCV::VFNCVT_F_F_W;
1944 for (; SrcEltSize != DstEltSize;) {
1948 MVT DstMVT = DstLT.second.changeVectorElementType(ElementMVT);
1950 (DstEltSize > SrcEltSize) ? DstEltSize >> 1 : DstEltSize << 1;
1958 unsigned FCVT = IsSigned ? RISCV::VFCVT_RTZ_X_F_V : RISCV::VFCVT_RTZ_XU_F_V;
1960 IsSigned ? RISCV::VFWCVT_RTZ_X_F_V : RISCV::VFWCVT_RTZ_XU_F_V;
1962 IsSigned ? RISCV::VFNCVT_RTZ_X_F_W : RISCV::VFNCVT_RTZ_XU_F_W;
1963 unsigned SrcEltSize = Src->getScalarSizeInBits();
1964 unsigned DstEltSize = Dst->getScalarSizeInBits();
1966 if ((SrcEltSize == 16) &&
1967 (!ST->hasVInstructionsF16() || ((DstEltSize / 2) > SrcEltSize))) {
1973 std::pair<InstructionCost, MVT> VecF32LT =
1976 VecF32LT.first * getRISCVInstructionCost(RISCV::VFWCVT_F_F_V,
1981 if (DstEltSize == SrcEltSize)
1982 Cost += getRISCVInstructionCost(FCVT, DstLT.second,
CostKind);
1983 else if (DstEltSize > SrcEltSize)
1984 Cost += getRISCVInstructionCost(FWCVT, DstLT.second,
CostKind);
1989 MVT VecVT = DstLT.second.changeVectorElementType(ElementVT);
1990 Cost += getRISCVInstructionCost(FNCVT, VecVT,
CostKind);
1991 if ((SrcEltSize / 2) > DstEltSize) {
2002 unsigned FCVT = IsSigned ? RISCV::VFCVT_F_X_V : RISCV::VFCVT_F_XU_V;
2003 unsigned FWCVT = IsSigned ? RISCV::VFWCVT_F_X_V : RISCV::VFWCVT_F_XU_V;
2004 unsigned FNCVT = IsSigned ? RISCV::VFNCVT_F_X_W : RISCV::VFNCVT_F_XU_W;
2005 unsigned SrcEltSize = Src->getScalarSizeInBits();
2006 unsigned DstEltSize = Dst->getScalarSizeInBits();
2009 if ((DstEltSize == 16) &&
2010 (!ST->hasVInstructionsF16() || ((SrcEltSize / 2) > DstEltSize))) {
2016 std::pair<InstructionCost, MVT> VecF32LT =
2019 Cost += VecF32LT.first * getRISCVInstructionCost(RISCV::VFNCVT_F_F_W,
2024 if (DstEltSize == SrcEltSize)
2025 Cost += getRISCVInstructionCost(FCVT, DstLT.second,
CostKind);
2026 else if (DstEltSize > SrcEltSize) {
2027 if ((DstEltSize / 2) > SrcEltSize) {
2031 unsigned Op = IsSigned ? Instruction::SExt : Instruction::ZExt;
2034 Cost += getRISCVInstructionCost(FWCVT, DstLT.second,
CostKind);
2036 Cost += getRISCVInstructionCost(FNCVT, DstLT.second,
CostKind);
2043unsigned RISCVTTIImpl::getEstimatedVLFor(
VectorType *Ty)
const {
2045 const unsigned EltSize =
DL.getTypeSizeInBits(Ty->getElementType());
2046 const unsigned MinSize =
DL.getTypeSizeInBits(Ty).getKnownMinValue();
2061 if (Ty->getScalarSizeInBits() > ST->getELen())
2065 if (Ty->getElementType()->isIntegerTy(1)) {
2069 if (IID == Intrinsic::umax || IID == Intrinsic::smin)
2075 if (IID == Intrinsic::maximum || IID == Intrinsic::minimum) {
2079 case Intrinsic::maximum:
2081 Opcodes = {RISCV::VFREDMAX_VS, RISCV::VFMV_F_S};
2083 Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMAX_VS,
2098 case Intrinsic::minimum:
2100 Opcodes = {RISCV::VFREDMIN_VS, RISCV::VFMV_F_S};
2102 Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMIN_VS,
2108 const unsigned EltTyBits =
DL.getTypeSizeInBits(DstTy);
2117 return ExtraCost + getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
2126 case Intrinsic::smax:
2127 SplitOp = RISCV::VMAX_VV;
2128 Opcodes = {RISCV::VREDMAX_VS, RISCV::VMV_X_S};
2130 case Intrinsic::smin:
2131 SplitOp = RISCV::VMIN_VV;
2132 Opcodes = {RISCV::VREDMIN_VS, RISCV::VMV_X_S};
2134 case Intrinsic::umax:
2135 SplitOp = RISCV::VMAXU_VV;
2136 Opcodes = {RISCV::VREDMAXU_VS, RISCV::VMV_X_S};
2138 case Intrinsic::umin:
2139 SplitOp = RISCV::VMINU_VV;
2140 Opcodes = {RISCV::VREDMINU_VS, RISCV::VMV_X_S};
2142 case Intrinsic::maxnum:
2143 SplitOp = RISCV::VFMAX_VV;
2144 Opcodes = {RISCV::VFREDMAX_VS, RISCV::VFMV_F_S};
2146 case Intrinsic::minnum:
2147 SplitOp = RISCV::VFMIN_VV;
2148 Opcodes = {RISCV::VFREDMIN_VS, RISCV::VFMV_F_S};
2153 (LT.first > 1) ? (LT.first - 1) *
2154 getRISCVInstructionCost(SplitOp, LT.second,
CostKind)
2156 return SplitCost + getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
2161 std::optional<FastMathFlags> FMF,
2167 if (Ty->getScalarSizeInBits() > ST->getELen())
2170 int ISD = TLI->InstructionOpcodeToISD(Opcode);
2178 Type *ElementTy = Ty->getElementType();
2183 if (LT.second == MVT::v1i1)
2184 return getRISCVInstructionCost(RISCV::VFIRST_M, LT.second,
CostKind) +
2202 return ((LT.first > 2) ? (LT.first - 2) : 0) *
2203 getRISCVInstructionCost(RISCV::VMAND_MM, LT.second,
CostKind) +
2204 getRISCVInstructionCost(RISCV::VMNAND_MM, LT.second,
CostKind) +
2205 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second,
CostKind) +
2214 return (LT.first - 1) *
2215 getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second,
CostKind) +
2216 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second,
CostKind) + 1;
2224 return (LT.first - 1) *
2225 getRISCVInstructionCost(RISCV::VMOR_MM, LT.second,
CostKind) +
2226 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second,
CostKind) +
2239 SplitOp = RISCV::VADD_VV;
2240 Opcodes = {RISCV::VMV_S_X, RISCV::VREDSUM_VS, RISCV::VMV_X_S};
2243 SplitOp = RISCV::VOR_VV;
2244 Opcodes = {RISCV::VREDOR_VS, RISCV::VMV_X_S};
2247 SplitOp = RISCV::VXOR_VV;
2248 Opcodes = {RISCV::VMV_S_X, RISCV::VREDXOR_VS, RISCV::VMV_X_S};
2251 SplitOp = RISCV::VAND_VV;
2252 Opcodes = {RISCV::VREDAND_VS, RISCV::VMV_X_S};
2256 if ((LT.second.getScalarType() == MVT::f16 && !ST->hasVInstructionsF16()) ||
2257 LT.second.getScalarType() == MVT::bf16)
2261 for (
unsigned i = 0; i < LT.first.getValue(); i++)
2264 return getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
2266 SplitOp = RISCV::VFADD_VV;
2267 Opcodes = {RISCV::VFMV_S_F, RISCV::VFREDUSUM_VS, RISCV::VFMV_F_S};
2272 (LT.first > 1) ? (LT.first - 1) *
2273 getRISCVInstructionCost(SplitOp, LT.second,
CostKind)
2275 return SplitCost + getRISCVInstructionCost(Opcodes, LT.second,
CostKind);
2279 unsigned Opcode,
bool IsUnsigned,
Type *ResTy,
VectorType *ValTy,
2290 if (Opcode != Instruction::Add && Opcode != Instruction::FAdd)
2296 if (IsUnsigned && Opcode == Instruction::Add &&
2297 LT.second.isFixedLengthVectorOf(MVT::i1)) {
2301 getRISCVInstructionCost(RISCV::VCPOP_M, LT.second,
CostKind);
2308 return (LT.first - 1) +
2315 assert(OpInfo.isConstant() &&
"non constant operand?");
2322 if (OpInfo.isUniform())
2328 return getConstantPoolLoadCost(Ty,
CostKind);
2337 EVT VT = TLI->getValueType(
DL, Src,
true);
2339 if (VT == MVT::Other ||
2345 if (Opcode == Instruction::Store && OpInfo.isConstant())
2360 if (Src->
isVectorTy() && LT.second.isVector() &&
2362 LT.second.getSizeInBits()))
2372 if (ST->hasVInstructions() && LT.second.isVector() &&
2374 BaseCost *= TLI->getLMULCost(LT.second);
2375 return Cost + BaseCost;
2384 Op1Info, Op2Info,
I);
2388 Op1Info, Op2Info,
I);
2393 Op1Info, Op2Info,
I);
2395 auto GetConstantMatCost =
2397 if (OpInfo.isUniform())
2402 return getConstantPoolLoadCost(ValTy,
CostKind);
2407 ConstantMatCost += GetConstantMatCost(Op1Info);
2409 ConstantMatCost += GetConstantMatCost(Op2Info);
2412 if (Opcode == Instruction::Select && ValTy->
isVectorTy()) {
2413 if (CondTy->isVectorTy()) {
2418 return ConstantMatCost +
2420 getRISCVInstructionCost(
2421 {RISCV::VMANDN_MM, RISCV::VMAND_MM, RISCV::VMOR_MM},
2425 return ConstantMatCost +
2426 LT.first * getRISCVInstructionCost(RISCV::VMERGE_VVM, LT.second,
2436 MVT InterimVT = LT.second.changeVectorElementType(MVT::i8);
2437 return ConstantMatCost +
2439 getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI},
2441 LT.first * getRISCVInstructionCost(
2442 {RISCV::VMANDN_MM, RISCV::VMAND_MM, RISCV::VMOR_MM},
2449 return ConstantMatCost +
2450 LT.first * getRISCVInstructionCost(
2451 {RISCV::VMV_V_X, RISCV::VMSNE_VI, RISCV::VMERGE_VVM},
2455 if ((Opcode == Instruction::ICmp) && ValTy->
isVectorTy() &&
2459 return ConstantMatCost + LT.first * getRISCVInstructionCost(RISCV::VMSLT_VV,
2464 if ((Opcode == Instruction::FCmp) && ValTy->
isVectorTy() &&
2469 return ConstantMatCost +
2470 getRISCVInstructionCost(RISCV::VMXOR_MM, LT.second,
CostKind);
2480 Op1Info, Op2Info,
I);
2489 return ConstantMatCost +
2490 LT.first * getRISCVInstructionCost(
2491 {RISCV::VMFLT_VV, RISCV::VMFLT_VV, RISCV::VMOR_MM},
2498 return ConstantMatCost +
2500 getRISCVInstructionCost({RISCV::VMFLT_VV, RISCV::VMNAND_MM},
2509 return ConstantMatCost +
2511 getRISCVInstructionCost(RISCV::VMFLT_VV, LT.second,
CostKind);
2524 return match(U, m_Select(m_Specific(I), m_Value(), m_Value())) &&
2525 U->getType()->isIntegerTy() &&
2526 !isa<ConstantData>(U->getOperand(1)) &&
2527 !isa<ConstantData>(U->getOperand(2));
2535 Op1Info, Op2Info,
I);
2542 return Opcode == Instruction::PHI ? 0 : 1;
2559 if (Opcode != Instruction::ExtractElement &&
2560 Opcode != Instruction::InsertElement)
2568 if (!LT.second.isVector()) {
2577 Type *ElemTy = FixedVecTy->getElementType();
2578 auto NumElems = FixedVecTy->getNumElements();
2579 auto Align =
DL.getPrefTypeAlign(ElemTy);
2584 return Opcode == Instruction::ExtractElement
2585 ? StoreCost * NumElems + LoadCost
2586 : (StoreCost + LoadCost) * NumElems + StoreCost;
2590 if (LT.second.isScalableVector() && !LT.first.isValid())
2598 if (Opcode == Instruction::ExtractElement) {
2604 return ExtendCost + ExtractCost;
2614 return ExtendCost + InsertCost + TruncCost;
2620 unsigned BaseCost = 1;
2622 unsigned SlideCost = Opcode == Instruction::InsertElement ? 2 : 1;
2627 if (LT.second.isFixedLengthVector()) {
2628 unsigned Width = LT.second.getVectorNumElements();
2629 Index = Index % Width;
2634 if (
auto VLEN = ST->getRealVLen()) {
2635 unsigned EltSize = LT.second.getScalarSizeInBits();
2636 unsigned M1Max = *VLEN / EltSize;
2637 Index = Index % M1Max;
2643 else if (Opcode == Instruction::InsertElement)
2651 ((Index == -1U) || (Index >= LT.second.getVectorMinNumElements() &&
2652 LT.second.isScalableVector()))) {
2654 Align VecAlign =
DL.getPrefTypeAlign(Val);
2655 Align SclAlign =
DL.getPrefTypeAlign(ScalarType);
2660 if (Opcode == Instruction::ExtractElement)
2696 BaseCost = Opcode == Instruction::InsertElement ? 3 : 4;
2698 return BaseCost + SlideCost;
2704 unsigned Index)
const {
2713 assert(Index < EC.getKnownMinValue() &&
"Unexpected reverse index");
2715 EC.getKnownMinValue() - 1 - Index,
nullptr,
2724std::optional<InstructionCost>
2730 if ((Opcode == Instruction::UDiv || Opcode == Instruction::URem) &&
2732 if (Opcode == Instruction::UDiv)
2739 return std::nullopt;
2761 if (std::optional<InstructionCost> CombinedCost =
2763 Op2Info, Args, CxtI))
2764 return *CombinedCost;
2768 unsigned ISDOpcode = TLI->InstructionOpcodeToISD(Opcode);
2771 if (!LT.second.isVector()) {
2781 if (TLI->isOperationLegalOrPromote(ISDOpcode, LT.second))
2782 if (
const auto *Entry =
CostTableLookup(DivTbl, ISDOpcode, LT.second))
2783 return Entry->Cost * LT.first;
2792 if ((LT.second.getVectorElementType() == MVT::f16 ||
2793 LT.second.getVectorElementType() == MVT::bf16) &&
2794 TLI->getOperationAction(ISDOpcode, LT.second) ==
2796 MVT PromotedVT = TLI->getTypeToPromoteTo(ISDOpcode, LT.second);
2800 CastCost += LT.first * Args.size() *
2808 LT.second = PromotedVT;
2811 auto getConstantMatCost =
2821 return getConstantPoolLoadCost(Ty,
CostKind);
2827 ConstantMatCost += getConstantMatCost(0, Op1Info);
2829 ConstantMatCost += getConstantMatCost(1, Op2Info);
2832 switch (ISDOpcode) {
2835 Op = RISCV::VADD_VV;
2840 Op = RISCV::VSLL_VV;
2845 Op = (Ty->getScalarSizeInBits() == 1) ? RISCV::VMAND_MM : RISCV::VAND_VV;
2850 Op = RISCV::VMUL_VV;
2854 Op = RISCV::VDIV_VV;
2858 Op = RISCV::VREM_VV;
2862 Op = RISCV::VFADD_VV;
2865 Op = RISCV::VFMUL_VV;
2868 Op = RISCV::VFDIV_VV;
2871 Op = RISCV::VFSGNJN_VV;
2876 return CastCost + ConstantMatCost +
2885 if (Ty->isFPOrFPVectorTy())
2887 return CastCost + ConstantMatCost + LT.first *
InstrCost;
2910 if (Info.isSameBase() && V !=
Base) {
2911 if (
GEP->hasAllConstantIndices())
2917 unsigned Stride =
DL.getTypeStoreSize(AccessTy);
2918 if (Info.isUnitStride() &&
2924 GEP->getType()->getPointerAddressSpace()))
2927 {TTI::OK_AnyValue, TTI::OP_None},
2928 {TTI::OK_AnyValue, TTI::OP_None}, {});
2945 if (ST->enableDefaultUnroll())
2955 if (L->getHeader()->getParent()->hasOptSize())
2959 L->getExitingBlocks(ExitingBlocks);
2961 <<
"Blocks: " << L->getNumBlocks() <<
"\n"
2962 <<
"Exit blocks: " << ExitingBlocks.
size() <<
"\n");
2966 if (ExitingBlocks.
size() > 2)
2971 if (L->getNumBlocks() > 4)
2979 for (
auto *BB : L->getBlocks()) {
2980 for (
auto &
I : *BB) {
2984 if (IsVectorized && (
I.getType()->isVectorTy() ||
2986 return V->getType()->isVectorTy();
3027 bool HasMask =
false;
3030 bool IsWrite) -> int64_t {
3031 if (
auto *TarExtTy =
3033 return TarExtTy->getIntParameter(0);
3039 case Intrinsic::riscv_vle_mask:
3040 case Intrinsic::riscv_vse_mask:
3041 case Intrinsic::riscv_vlseg2_mask:
3042 case Intrinsic::riscv_vlseg3_mask:
3043 case Intrinsic::riscv_vlseg4_mask:
3044 case Intrinsic::riscv_vlseg5_mask:
3045 case Intrinsic::riscv_vlseg6_mask:
3046 case Intrinsic::riscv_vlseg7_mask:
3047 case Intrinsic::riscv_vlseg8_mask:
3048 case Intrinsic::riscv_vsseg2_mask:
3049 case Intrinsic::riscv_vsseg3_mask:
3050 case Intrinsic::riscv_vsseg4_mask:
3051 case Intrinsic::riscv_vsseg5_mask:
3052 case Intrinsic::riscv_vsseg6_mask:
3053 case Intrinsic::riscv_vsseg7_mask:
3054 case Intrinsic::riscv_vsseg8_mask:
3057 case Intrinsic::riscv_vle:
3058 case Intrinsic::riscv_vse:
3059 case Intrinsic::riscv_vlseg2:
3060 case Intrinsic::riscv_vlseg3:
3061 case Intrinsic::riscv_vlseg4:
3062 case Intrinsic::riscv_vlseg5:
3063 case Intrinsic::riscv_vlseg6:
3064 case Intrinsic::riscv_vlseg7:
3065 case Intrinsic::riscv_vlseg8:
3066 case Intrinsic::riscv_vsseg2:
3067 case Intrinsic::riscv_vsseg3:
3068 case Intrinsic::riscv_vsseg4:
3069 case Intrinsic::riscv_vsseg5:
3070 case Intrinsic::riscv_vsseg6:
3071 case Intrinsic::riscv_vsseg7:
3072 case Intrinsic::riscv_vsseg8: {
3089 Ty = TarExtTy->getTypeParameter(0U);
3094 const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
3095 unsigned VLIndex = RVVIInfo->VLOperand;
3096 unsigned PtrOperandNo = VLIndex - 1 - HasMask;
3104 unsigned SegNum = getSegNum(Inst, PtrOperandNo, IsWrite);
3107 unsigned ElemSize = Ty->getScalarSizeInBits();
3111 Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
3112 Alignment, Mask, EVL);
3115 case Intrinsic::riscv_vlse_mask:
3116 case Intrinsic::riscv_vsse_mask:
3117 case Intrinsic::riscv_vlsseg2_mask:
3118 case Intrinsic::riscv_vlsseg3_mask:
3119 case Intrinsic::riscv_vlsseg4_mask:
3120 case Intrinsic::riscv_vlsseg5_mask:
3121 case Intrinsic::riscv_vlsseg6_mask:
3122 case Intrinsic::riscv_vlsseg7_mask:
3123 case Intrinsic::riscv_vlsseg8_mask:
3124 case Intrinsic::riscv_vssseg2_mask:
3125 case Intrinsic::riscv_vssseg3_mask:
3126 case Intrinsic::riscv_vssseg4_mask:
3127 case Intrinsic::riscv_vssseg5_mask:
3128 case Intrinsic::riscv_vssseg6_mask:
3129 case Intrinsic::riscv_vssseg7_mask:
3130 case Intrinsic::riscv_vssseg8_mask:
3133 case Intrinsic::riscv_vlse:
3134 case Intrinsic::riscv_vsse:
3135 case Intrinsic::riscv_vlsseg2:
3136 case Intrinsic::riscv_vlsseg3:
3137 case Intrinsic::riscv_vlsseg4:
3138 case Intrinsic::riscv_vlsseg5:
3139 case Intrinsic::riscv_vlsseg6:
3140 case Intrinsic::riscv_vlsseg7:
3141 case Intrinsic::riscv_vlsseg8:
3142 case Intrinsic::riscv_vssseg2:
3143 case Intrinsic::riscv_vssseg3:
3144 case Intrinsic::riscv_vssseg4:
3145 case Intrinsic::riscv_vssseg5:
3146 case Intrinsic::riscv_vssseg6:
3147 case Intrinsic::riscv_vssseg7:
3148 case Intrinsic::riscv_vssseg8: {
3165 Ty = TarExtTy->getTypeParameter(0U);
3170 const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
3171 unsigned VLIndex = RVVIInfo->VLOperand;
3172 unsigned PtrOperandNo = VLIndex - 2 - HasMask;
3184 Alignment =
Align(1);
3191 unsigned SegNum = getSegNum(Inst, PtrOperandNo, IsWrite);
3194 unsigned ElemSize = Ty->getScalarSizeInBits();
3198 Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
3199 Alignment, Mask, EVL, Stride);
3202 case Intrinsic::riscv_vloxei_mask:
3203 case Intrinsic::riscv_vluxei_mask:
3204 case Intrinsic::riscv_vsoxei_mask:
3205 case Intrinsic::riscv_vsuxei_mask:
3206 case Intrinsic::riscv_vloxseg2_mask:
3207 case Intrinsic::riscv_vloxseg3_mask:
3208 case Intrinsic::riscv_vloxseg4_mask:
3209 case Intrinsic::riscv_vloxseg5_mask:
3210 case Intrinsic::riscv_vloxseg6_mask:
3211 case Intrinsic::riscv_vloxseg7_mask:
3212 case Intrinsic::riscv_vloxseg8_mask:
3213 case Intrinsic::riscv_vluxseg2_mask:
3214 case Intrinsic::riscv_vluxseg3_mask:
3215 case Intrinsic::riscv_vluxseg4_mask:
3216 case Intrinsic::riscv_vluxseg5_mask:
3217 case Intrinsic::riscv_vluxseg6_mask:
3218 case Intrinsic::riscv_vluxseg7_mask:
3219 case Intrinsic::riscv_vluxseg8_mask:
3220 case Intrinsic::riscv_vsoxseg2_mask:
3221 case Intrinsic::riscv_vsoxseg3_mask:
3222 case Intrinsic::riscv_vsoxseg4_mask:
3223 case Intrinsic::riscv_vsoxseg5_mask:
3224 case Intrinsic::riscv_vsoxseg6_mask:
3225 case Intrinsic::riscv_vsoxseg7_mask:
3226 case Intrinsic::riscv_vsoxseg8_mask:
3227 case Intrinsic::riscv_vsuxseg2_mask:
3228 case Intrinsic::riscv_vsuxseg3_mask:
3229 case Intrinsic::riscv_vsuxseg4_mask:
3230 case Intrinsic::riscv_vsuxseg5_mask:
3231 case Intrinsic::riscv_vsuxseg6_mask:
3232 case Intrinsic::riscv_vsuxseg7_mask:
3233 case Intrinsic::riscv_vsuxseg8_mask:
3236 case Intrinsic::riscv_vloxei:
3237 case Intrinsic::riscv_vluxei:
3238 case Intrinsic::riscv_vsoxei:
3239 case Intrinsic::riscv_vsuxei:
3240 case Intrinsic::riscv_vloxseg2:
3241 case Intrinsic::riscv_vloxseg3:
3242 case Intrinsic::riscv_vloxseg4:
3243 case Intrinsic::riscv_vloxseg5:
3244 case Intrinsic::riscv_vloxseg6:
3245 case Intrinsic::riscv_vloxseg7:
3246 case Intrinsic::riscv_vloxseg8:
3247 case Intrinsic::riscv_vluxseg2:
3248 case Intrinsic::riscv_vluxseg3:
3249 case Intrinsic::riscv_vluxseg4:
3250 case Intrinsic::riscv_vluxseg5:
3251 case Intrinsic::riscv_vluxseg6:
3252 case Intrinsic::riscv_vluxseg7:
3253 case Intrinsic::riscv_vluxseg8:
3254 case Intrinsic::riscv_vsoxseg2:
3255 case Intrinsic::riscv_vsoxseg3:
3256 case Intrinsic::riscv_vsoxseg4:
3257 case Intrinsic::riscv_vsoxseg5:
3258 case Intrinsic::riscv_vsoxseg6:
3259 case Intrinsic::riscv_vsoxseg7:
3260 case Intrinsic::riscv_vsoxseg8:
3261 case Intrinsic::riscv_vsuxseg2:
3262 case Intrinsic::riscv_vsuxseg3:
3263 case Intrinsic::riscv_vsuxseg4:
3264 case Intrinsic::riscv_vsuxseg5:
3265 case Intrinsic::riscv_vsuxseg6:
3266 case Intrinsic::riscv_vsuxseg7:
3267 case Intrinsic::riscv_vsuxseg8: {
3284 Ty = TarExtTy->getTypeParameter(0U);
3289 const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
3290 unsigned VLIndex = RVVIInfo->VLOperand;
3291 unsigned PtrOperandNo = VLIndex - 2 - HasMask;
3304 unsigned SegNum = getSegNum(Inst, PtrOperandNo, IsWrite);
3307 unsigned ElemSize = Ty->getScalarSizeInBits();
3312 Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
3313 Align(1), Mask, EVL,
3322 if (Ty->isVectorTy()) {
3325 if ((EltTy->
isHalfTy() && !ST->hasVInstructionsF16()) ||
3331 if (
Size.isScalable() && ST->hasVInstructions())
3334 if (ST->useRVVForFixedLengthVectors())
3354 return std::max<unsigned>(1U, RegWidth.
getFixedValue() / ElemWidth);
3362 return ST->enableUnalignedVectorMem();
3368 if (ST->hasVendorXCVmem() && !ST->is64Bit())
3390 Align Alignment)
const {
3392 if (!VTy || VTy->isScalableTy())
3400 if (VTy->getElementType()->isIntegerTy(8))
3401 if (VTy->getElementCount().getFixedValue() > 256)
3402 return VTy->getPrimitiveSizeInBits() / ST->getRealMinVLen() <
3403 ST->getMaxLMULForFixedLengthVectors();
3408 Align Alignment)
const {
3410 if (!VTy || VTy->isScalableTy())
3421 if (!ST->hasVInstructions() || !ST->hasOptimizedZeroStrideLoad())
3424 return TLI->isLegalElementTypeForRVV(TLI->getValueType(
DL, ElementTy));
3433 const Instruction &
I,
bool &AllowPromotionWithoutCommonHeader)
const {
3434 bool Considerable =
false;
3435 AllowPromotionWithoutCommonHeader =
false;
3438 Type *ConsideredSExtType =
3440 if (
I.getType() != ConsideredSExtType)
3444 for (
const User *U :
I.users()) {
3446 Considerable =
true;
3450 if (GEPInst->getNumOperands() > 2) {
3451 AllowPromotionWithoutCommonHeader =
true;
3456 return Considerable;
3461 case Instruction::Add:
3462 case Instruction::Sub:
3463 case Instruction::Mul:
3464 case Instruction::And:
3465 case Instruction::Or:
3466 case Instruction::Xor:
3467 case Instruction::FAdd:
3468 case Instruction::FSub:
3469 case Instruction::FMul:
3470 case Instruction::FDiv:
3471 case Instruction::ICmp:
3472 case Instruction::FCmp:
3474 case Instruction::Shl:
3475 case Instruction::LShr:
3476 case Instruction::AShr:
3477 case Instruction::UDiv:
3478 case Instruction::SDiv:
3479 case Instruction::URem:
3480 case Instruction::SRem:
3481 case Instruction::Select:
3482 return Operand == 1;
3489 if (!
I->getType()->isVectorTy() || !ST->hasVInstructions())
3499 switch (
II->getIntrinsicID()) {
3500 case Intrinsic::fma:
3501 case Intrinsic::vp_fma:
3502 case Intrinsic::fmuladd:
3503 case Intrinsic::vp_fmuladd:
3504 return Operand == 0 || Operand == 1;
3505 case Intrinsic::vp_shl:
3506 case Intrinsic::vp_lshr:
3507 case Intrinsic::vp_ashr:
3508 case Intrinsic::vp_udiv:
3509 case Intrinsic::vp_sdiv:
3510 case Intrinsic::vp_urem:
3511 case Intrinsic::vp_srem:
3512 case Intrinsic::ssub_sat:
3513 case Intrinsic::vp_ssub_sat:
3514 case Intrinsic::usub_sat:
3515 case Intrinsic::vp_usub_sat:
3516 case Intrinsic::vp_select:
3517 return Operand == 1;
3519 case Intrinsic::vp_add:
3520 case Intrinsic::vp_mul:
3521 case Intrinsic::vp_and:
3522 case Intrinsic::vp_or:
3523 case Intrinsic::vp_xor:
3524 case Intrinsic::vp_fadd:
3525 case Intrinsic::vp_fmul:
3526 case Intrinsic::vp_icmp:
3527 case Intrinsic::vp_fcmp:
3528 case Intrinsic::smin:
3529 case Intrinsic::vp_smin:
3530 case Intrinsic::umin:
3531 case Intrinsic::vp_umin:
3532 case Intrinsic::smax:
3533 case Intrinsic::vp_smax:
3534 case Intrinsic::umax:
3535 case Intrinsic::vp_umax:
3536 case Intrinsic::sadd_sat:
3537 case Intrinsic::vp_sadd_sat:
3538 case Intrinsic::uadd_sat:
3539 case Intrinsic::vp_uadd_sat:
3541 case Intrinsic::vp_sub:
3542 case Intrinsic::vp_fsub:
3543 case Intrinsic::vp_fdiv:
3544 return Operand == 0 || Operand == 1;
3557 if (
I->isBitwiseLogicOp()) {
3558 if (!
I->getType()->isVectorTy()) {
3559 if (ST->hasStdExtZbb() || ST->hasStdExtZbkb()) {
3560 for (
auto &
Op :
I->operands()) {
3568 }
else if (
I->getOpcode() == Instruction::And && ST->hasStdExtZvkb()) {
3569 for (
auto &
Op :
I->operands()) {
3581 Ops.push_back(&Not);
3582 Ops.push_back(&InsertElt);
3590 if (!
I->getType()->isVectorTy() || !ST->hasVInstructions())
3598 if (!ST->sinkSplatOperands())
3621 for (
Use &U :
Op->uses()) {
3628 Use *InsertEltUse = &
Op->getOperandUse(0);
3631 Ops.push_back(&InsertElt->getOperandUse(1));
3632 Ops.push_back(InsertEltUse);
3642 if (!ST->hasStdExtZbb() && !ST->hasStdExtZbkb() && !IsZeroCmp)
3653 bool UnalignedScalar = ST->enableUnalignedScalarMem();
3654 Options.AllowOverlappingLoads = UnalignedScalar;
3655 Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
3657 if (ST->is64Bit()) {
3658 Options.LoadSizes = {8, 4, 2, 1};
3659 if (UnalignedScalar)
3660 Options.AllowedTailExpansions = {3, 5, 6};
3662 Options.LoadSizes = {4, 2, 1};
3663 if (UnalignedScalar)
3664 Options.AllowedTailExpansions = {3};
3667 if (IsZeroCmp && ST->hasVInstructions()) {
3668 unsigned VLenB = ST->getRealMinVLen() / 8;
3671 unsigned MinSize = ST->getXLen() / 8 + 1;
3672 unsigned MaxSize = VLenB * ST->getMaxLMULForFixedLengthVectors();
3686 if (
I->getOpcode() == Instruction::Or &&
3690 if (
I->getOpcode() == Instruction::Add ||
3691 I->getOpcode() == Instruction::Sub)
3709std::optional<Instruction *>
3715 if (
II.user_empty())
3720 const APInt *Scalar;
3725 return U->getType() == TargetVecTy && match(U, m_BitCast(m_Value()));
3729 unsigned TargetEltBW =
DL.getTypeSizeInBits(TargetVecTy->getElementType());
3730 unsigned SourceEltBW =
DL.getTypeSizeInBits(SourceVecTy->getElementType());
3731 if (TargetEltBW % SourceEltBW)
3733 unsigned TargetScale = TargetEltBW / SourceEltBW;
3734 if (VL % TargetScale || TargetScale == 1)
3736 Type *VLTy =
II.getOperand(2)->getType();
3737 ElementCount SourceEC = SourceVecTy->getElementCount();
3738 unsigned NewEltBW = SourceEltBW * TargetScale;
3740 !
DL.fitsInLegalInteger(NewEltBW))
3743 if (!TLI->isLegalElementTypeForRVV(TLI->getValueType(
DL, NewEltTy)))
3747 assert(SourceVecTy->canLosslesslyBitCastTo(RetTy) &&
3748 "Lossless bitcast between types expected");
3754 RetTy, Intrinsic::riscv_vmv_v_x,
3755 {PoisonValue::get(RetTy), ConstantInt::get(NewEltTy, NewScalar),
3756 ConstantInt::get(VLTy, VL / TargetScale)}),
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< 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)
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
Cost tables and simple lookup functions.
static cl::opt< int > InstrCost("inline-instr-cost", cl::Hidden, cl::init(5), cl::desc("Cost of a single instruction when inlining"))
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[]
static const Function * getCalledFunction(const Value *V)
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
static Type * getValueType(Value *V, bool LookThroughCmp=false)
Returns the "element type" of the given value/instruction V.
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.
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.
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 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 *CxtI=nullptr) const override
InstructionCost getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, FastMathFlags FMF, TTI::TargetCostKind CostKind) const override
InstructionCost getGEPCost(Type *PointeeType, const Value *Ptr, ArrayRef< const Value * > Operands, Type *AccessType, 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 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) 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
std::optional< unsigned > getMaxVScale() 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 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
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
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
@ 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
@ 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
@ 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)
@ FCMP_UNE
1 1 1 0 True if unordered or not 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)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
This class represents a range of values.
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)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
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.
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:
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
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)
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...
bool bitsLE(MVT VT) const
Return true if this has no more bits than VT.
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
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
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
MVT getVectorElementType() const
static MVT getIntegerVT(unsigned BitWidth)
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
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
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 *CxtI=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
InstructionCost getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) const override
unsigned getMinTripCountTailFoldingThreshold() 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 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.
bool getTgtMemIntrinsic(IntrinsicInst *Inst, MemIntrinsicInfo &Info) const override
InstructionCost getCostOfKeepingLiveOverCall(ArrayRef< Type * > Tys) 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 *CxtI) const
Check to see if this instruction is expected to be combined to a simpler operation during/before lowe...
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...
std::optional< unsigned > getMaxVScale() const override
bool shouldExpandReduction(const IntrinsicInst *II) const override
std::optional< unsigned > getVScaleForTuning() const override
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 getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy, ArrayRef< int > Mask, TTI::TargetCostKind CostKind, int Index, VectorType *SubTp, ArrayRef< const Value * > Args={}, const Instruction *CxtI=nullptr) const override
unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const override
InstructionCost getPointersChainCost(ArrayRef< const Value * > Ptrs, const Value *Base, const TTI::PointersChainInfo &Info, Type *AccessTy, TTI::TargetCostKind CostKind) 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
TargetTransformInfo::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override
static MVT getM1VT(MVT VT)
Given a vector (either fixed or scalable), return the scalable vector corresponding to a vector regis...
InstructionCost getVRGatherVVCost(MVT VT) const
Return the cost of a vrgather.vv instruction for the type VT.
InstructionCost getVRGatherVICost(MVT VT) const
Return the cost of a vrgather.vi (or vx) instruction for the type VT.
static unsigned computeVLMAX(unsigned VectorBits, unsigned EltSize, unsigned MinSize)
InstructionCost getLMULCost(MVT VT) const
Return the cost of LMUL for linear operations.
InstructionCost getVSlideVICost(MVT VT) const
Return the cost of a vslidedown.vi or vslideup.vi instruction for the type VT.
InstructionCost getVSlideVXCost(MVT VT) const
Return the cost of a vslidedown.vx or vslideup.vx instruction for the type VT.
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.
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)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
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.
LLVM_ABI bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
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.
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...
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.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
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.
user_iterator user_begin()
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 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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
@ C
The default llvm calling convention, compatible with C.
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.
@ 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.
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 constexpr unsigned RVVBitsPerBlock
initializer< Ty > init(const Ty &Val)
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.
@ BinaryOp
One of the operands is a binary op.
auto adjacent_find(R &&Range)
Provide wrappers to std::adjacent_find which finds the first pair of adjacent elements that are equal...
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...
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.
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.
DWARFExpression::Operation Op
OutputIt copy(R &&Range, OutputIt Out)
CostTblEntryT< uint16_t > CostTblEntry
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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.
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.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
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.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Information about a load/store intrinsic defined by the target.