42#define DEBUG_TYPE "gisel-known-bits"
50 "Analysis for ComputingKnownBits",
false,
true)
53 : MF(MF),
MRI(MF.getRegInfo()), TL(*MF.getSubtarget().getTargetLowering()),
58 switch (
MI->getOpcode()) {
59 case TargetOpcode::COPY:
61 case TargetOpcode::G_ASSERT_ALIGN: {
63 return Align(
MI->getOperand(2).getImm());
65 case TargetOpcode::G_FRAME_INDEX: {
66 int FrameIdx =
MI->getOperand(1).getIndex();
67 return MF.getFrameInfo().getObjectAlign(FrameIdx);
69 case TargetOpcode::G_INTRINSIC:
70 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
71 case TargetOpcode::G_INTRINSIC_CONVERGENT:
72 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
74 return TL.computeKnownAlignForTargetInstr(*
this, R, MRI,
Depth + 1);
79 const LLT Ty = MRI.getType(R);
89 const APInt &DemandedElts,
97 LLT Ty = MRI.getType(R);
98 unsigned BitWidth = Ty.getScalarSizeInBits();
103 LLT Ty = MRI.getType(R);
104 const APInt ScalarDemandedElts(1, 1);
105 APInt DemandedElts = Ty.isFixedVector()
107 : ScalarDemandedElts;
116 const APInt ScalarDemandedElts(1, 1);
119 switch (
MI.getOpcode()) {
123 case TargetOpcode::G_BUILD_VECTOR: {
125 if (!DemandedElts[
I])
133 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
136 LLT VecTy = MRI.getType(InVec);
144 if (Idx->ult(NumSrcElts))
150 case TargetOpcode::G_SHUFFLE_VECTOR: {
153 if (SrcTy.isScalableVector())
155 APInt DemandedLHS, DemandedRHS;
157 DemandedElts, DemandedLHS, DemandedRHS))
159 if (!DemandedLHS.
isZero() &&
162 if (!DemandedRHS.
isZero() &&
168 case TargetOpcode::G_OR:
173 case TargetOpcode::G_SELECT:
178 case TargetOpcode::G_SHL: {
208[[maybe_unused]]
static void
211 <<
"] Computed for: " <<
MI <<
"[" <<
Depth <<
"] Known: 0x"
222 const APInt &DemandedElts,
228 if (
Known.isUnknown())
253 const APInt &DemandedElts,
255 MachineInstr &
MI = *MRI.getVRegDef(R);
256 unsigned Opcode =
MI.getOpcode();
257 LLT DstTy = MRI.getType(R);
271 "DemandedElt width should equal the fixed vector number of elements");
274 "DemandedElt width should be 1 for scalars or scalable vectors");
299 TL.computeKnownBitsForTargetInstr(*
this, R,
Known, DemandedElts, MRI,
302 case TargetOpcode::G_BUILD_VECTOR: {
304 Known.Zero.setAllBits();
305 Known.One.setAllBits();
307 if (!DemandedElts[
I])
316 if (
Known.isUnknown())
321 case TargetOpcode::G_SPLAT_VECTOR: {
329 case TargetOpcode::G_FREEZE: {
337 case TargetOpcode::COPY:
338 case TargetOpcode::G_PHI:
339 case TargetOpcode::PHI: {
345 assert(
MI.getOperand(0).getSubReg() == 0 &&
"Is this code in SSA?");
348 for (
unsigned Idx = 1;
Idx <
MI.getNumOperands();
Idx += 2) {
349 const MachineOperand &Src =
MI.getOperand(Idx);
351 LLT SrcTy = MRI.getType(SrcReg);
359 if (SrcReg.
isVirtual() && Src.getSubReg() == 0 &&
361 APInt NowDemandedElts;
363 NowDemandedElts = APInt(1, 1);
366 NowDemandedElts = DemandedElts;
373 Depth + (Opcode != TargetOpcode::COPY));
378 if (
Known.isUnknown())
388 case TargetOpcode::G_STEP_VECTOR: {
389 APInt Step =
MI.getOperand(1).getCImm()->getValue();
397 const APInt MinNumElts =
403 .
umul_ov(MinNumElts, Overflow);
406 const APInt MaxValue = (MaxNumElts - 1).
umul_ov(Step, Overflow);
412 case TargetOpcode::G_VSCALE: {
414 const APInt &Multiplier =
MI.
getOperand(1).getCImm()->getValue();
418 case TargetOpcode::G_CONSTANT: {
422 case TargetOpcode::G_FRAME_INDEX: {
423 int FrameIdx =
MI.getOperand(1).getIndex();
424 TL.computeKnownBitsForStackObjectPointer(
425 Known, MF, MF.getFrameInfo().getObjectAlign(FrameIdx));
428 case TargetOpcode::G_SUB: {
437 case TargetOpcode::G_XOR: {
446 case TargetOpcode::G_PTR_ADD: {
450 LLT Ty = MRI.getType(
MI.getOperand(1).getReg());
455 case TargetOpcode::G_ADD: {
463 case TargetOpcode::G_AND: {
473 case TargetOpcode::G_OR: {
483 case TargetOpcode::G_MUL: {
491 case TargetOpcode::G_UMULH: {
499 case TargetOpcode::G_SMULH: {
507 case TargetOpcode::G_CLMUL: {
515 case TargetOpcode::G_UAVGFLOOR: {
523 case TargetOpcode::G_UAVGCEIL: {
531 case TargetOpcode::G_SAVGFLOOR: {
539 case TargetOpcode::G_SAVGCEIL: {
547 case TargetOpcode::G_ABDU: {
555 case TargetOpcode::G_ABDS: {
564 if (SignBits1 == 1) {
570 Known.Zero.setHighBits(std::min(SignBits0, SignBits1) - 1);
573 case TargetOpcode::G_SADDSAT: {
581 case TargetOpcode::G_UADDSAT: {
589 case TargetOpcode::G_SSUBSAT: {
597 case TargetOpcode::G_USUBSAT: {
605 case TargetOpcode::G_UDIV: {
614 case TargetOpcode::G_SDIV: {
623 case TargetOpcode::G_UREM: {
624 KnownBits LHSKnown(
Known.getBitWidth());
625 KnownBits RHSKnown(
Known.getBitWidth());
635 case TargetOpcode::G_SREM: {
636 KnownBits LHSKnown(
Known.getBitWidth());
637 KnownBits RHSKnown(
Known.getBitWidth());
647 case TargetOpcode::G_SELECT: {
648 computeKnownBitsMin(
MI.getOperand(2).getReg(),
MI.getOperand(3).getReg(),
652 case TargetOpcode::G_SMIN: {
662 case TargetOpcode::G_SMAX: {
672 case TargetOpcode::G_UMIN: {
681 case TargetOpcode::G_UMAX: {
690 case TargetOpcode::G_FCMP:
691 case TargetOpcode::G_ICMP: {
694 if (TL.getBooleanContents(DstTy.
isVector(),
695 Opcode == TargetOpcode::G_FCMP) ==
698 Known.Zero.setBitsFrom(1);
701 case TargetOpcode::G_SEXT: {
709 case TargetOpcode::G_ASSERT_SEXT:
710 case TargetOpcode::G_SEXT_INREG: {
716 case TargetOpcode::G_ANYEXT: {
722 case TargetOpcode::G_LOAD: {
723 const MachineMemOperand *MMO = *
MI.memoperands_begin();
725 if (
const MDNode *Ranges = MMO->
getRanges())
727 Known = KnownRange.anyext(
Known.getBitWidth());
730 case TargetOpcode::G_SEXTLOAD:
731 case TargetOpcode::G_ZEXTLOAD: {
734 const MachineMemOperand *MMO = *
MI.memoperands_begin();
736 if (
const MDNode *Ranges = MMO->
getRanges())
738 Known = Opcode == TargetOpcode::G_SEXTLOAD
739 ? KnownRange.sext(
Known.getBitWidth())
740 : KnownRange.zext(
Known.getBitWidth());
743 case TargetOpcode::G_ASHR: {
744 KnownBits LHSKnown, RHSKnown;
752 case TargetOpcode::G_LSHR: {
753 KnownBits LHSKnown, RHSKnown;
761 case TargetOpcode::G_SHL: {
762 KnownBits LHSKnown, RHSKnown;
770 case TargetOpcode::G_ROTL:
771 case TargetOpcode::G_ROTR: {
780 unsigned Amt = MaybeAmtOp->urem(
BitWidth);
783 if (Opcode == TargetOpcode::G_ROTL)
790 case TargetOpcode::G_FSHL:
791 case TargetOpcode::G_FSHR: {
797 const APInt Amt = *MaybeAmtOp;
802 Known = Opcode == TargetOpcode::G_FSHL
807 case TargetOpcode::G_INTTOPTR:
808 case TargetOpcode::G_PTRTOINT:
813 case TargetOpcode::G_ZEXT:
814 case TargetOpcode::G_TRUNC: {
820 case TargetOpcode::G_TRUNC_SSAT_S: {
826 case TargetOpcode::G_TRUNC_SSAT_U: {
832 case TargetOpcode::G_TRUNC_USAT_U: {
838 case TargetOpcode::G_ASSERT_ZEXT: {
842 unsigned SrcBitWidth =
MI.getOperand(2).getImm();
843 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
845 Known.Zero |= (~InMask);
846 Known.One &= (~Known.Zero);
849 case TargetOpcode::G_ASSERT_ALIGN: {
850 int64_t LogOfAlign =
Log2_64(
MI.getOperand(2).getImm());
855 Known.Zero.setLowBits(LogOfAlign);
856 Known.One.clearLowBits(LogOfAlign);
859 case TargetOpcode::G_MERGE_VALUES: {
860 unsigned NumOps =
MI.getNumOperands();
861 unsigned OpSize = MRI.getType(
MI.getOperand(1).getReg()).getSizeInBits();
863 for (
unsigned I = 0;
I !=
NumOps - 1; ++
I) {
864 KnownBits SrcOpKnown;
866 DemandedElts,
Depth + 1);
867 Known.insertBits(SrcOpKnown,
I * OpSize);
871 case TargetOpcode::G_UNMERGE_VALUES: {
872 unsigned NumOps =
MI.getNumOperands();
874 LLT SrcTy = MRI.getType(SrcReg);
880 unsigned DstIdx =
MI.findRegisterDefOperandIdx(R,
nullptr);
882 APInt SubDemandedElts = DemandedElts;
889 KnownBits SrcOpKnown;
893 Known = std::move(SrcOpKnown);
898 case TargetOpcode::G_BSWAP: {
904 case TargetOpcode::G_BITREVERSE: {
910 case TargetOpcode::G_CTPOP: {
917 Known.Zero.setBitsFrom(LowBits);
922 case TargetOpcode::G_UBFX: {
923 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
933 case TargetOpcode::G_SBFX: {
934 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
954 case TargetOpcode::G_UADDO:
955 case TargetOpcode::G_UADDE:
956 case TargetOpcode::G_SADDO:
957 case TargetOpcode::G_SADDE: {
958 if (
MI.getOperand(1).getReg() == R) {
961 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
964 Known.Zero.setBitsFrom(1);
968 assert(
MI.getOperand(0).getReg() == R &&
969 "We only compute knownbits for the sum here.");
972 if (Opcode == TargetOpcode::G_UADDE || Opcode == TargetOpcode::G_SADDE) {
976 Carry = Carry.trunc(1);
988 case TargetOpcode::G_USUBO:
989 case TargetOpcode::G_USUBE:
990 case TargetOpcode::G_SSUBO:
991 case TargetOpcode::G_SSUBE:
992 case TargetOpcode::G_UMULO:
993 case TargetOpcode::G_SMULO: {
994 if (
MI.getOperand(1).getReg() == R) {
997 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
1000 Known.Zero.setBitsFrom(1);
1004 case TargetOpcode::G_CTTZ:
1005 case TargetOpcode::G_CTTZ_ZERO_POISON: {
1006 KnownBits SrcOpKnown;
1012 Known.Zero.setBitsFrom(LowBits);
1015 case TargetOpcode::G_CTLZ:
1016 case TargetOpcode::G_CTLZ_ZERO_POISON: {
1017 KnownBits SrcOpKnown;
1023 case TargetOpcode::G_CTLS: {
1025 unsigned MinRedundantSignBits =
1028 unsigned MaxUpperRedundantSignBits = MRI.getType(
Reg).getScalarSizeInBits();
1031 APInt(
BitWidth, MaxUpperRedundantSignBits));
1036 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1043 LLT VecVT = MRI.getType(InVec);
1055 Known.Zero.setAllBits();
1056 Known.One.setAllBits();
1061 if (ConstEltNo && ConstEltNo->ult(NumSrcElts))
1068 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1073 LLT VecVT = MRI.getType(InVec);
1081 bool DemandedVal =
true;
1082 APInt DemandedVecElts = DemandedElts;
1083 if (ConstEltNo && ConstEltNo->ult(NumElts)) {
1084 unsigned EltIdx = ConstEltNo->getZExtValue();
1085 DemandedVal = !!DemandedElts[EltIdx];
1088 Known.setAllConflict();
1093 if (!!DemandedVecElts) {
1099 case TargetOpcode::G_INSERT_SUBVECTOR: {
1104 LLT SrcTy = MRI.getType(Src);
1105 LLT SubTy = MRI.getType(
Sub);
1106 APInt DemandedSubElts;
1107 APInt DemandedSrcElts;
1113 DemandedSrcElts = APInt(1, 1);
1116 DemandedSubElts = DemandedElts.
extractBits(NumSubElts, Idx);
1117 DemandedSrcElts = DemandedElts;
1118 DemandedSrcElts.
clearBits(Idx, Idx + NumSubElts);
1121 Known.setAllConflict();
1122 if (!!DemandedSubElts) {
1125 if (
Known.isUnknown())
1129 if (!!DemandedSrcElts) {
1136 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
1138 LLT SrcTy = MRI.getType(SrcReg);
1139 APInt DemandedSrcElts;
1141 DemandedSrcElts = APInt(1, 1);
1145 DemandedSrcElts = DemandedElts.
zext(NumSrcElts).
shl(Idx);
1150 case TargetOpcode::G_SHUFFLE_VECTOR: {
1151 APInt DemandedLHS, DemandedRHS;
1154 unsigned NumElts = MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
1156 DemandedElts, DemandedLHS, DemandedRHS))
1160 Known.Zero.setAllBits();
1161 Known.One.setAllBits();
1162 if (!!DemandedLHS) {
1168 if (
Known.isUnknown())
1170 if (!!DemandedRHS) {
1177 case TargetOpcode::G_CONCAT_VECTORS: {
1178 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
1181 Known.Zero.setAllBits();
1182 Known.One.setAllBits();
1183 unsigned NumSubVectorElts =
1184 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
1188 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
1189 if (!!DemandedSub) {
1195 if (
Known.isUnknown())
1200 case TargetOpcode::G_VECTOR_COMPRESS: {
1204 Register PassThru =
MI.getOperand(3).getReg();
1207 if (
Known.isUnknown())
1216 case TargetOpcode::G_ABS: {
1232 if (!Ty.isValid()) {
1236 unsigned BitWidth = Ty.getScalarSizeInBits();
1243 const APInt &DemandedElts,
1247 if (!Stack.empty()) {
1248 if (!getKnownBitsResult(R, DemandedElts,
Depth,
Known)) {
1249 Stack.push_back({R, DemandedElts,
Depth});
1257 Stack.push_back({R, DemandedElts,
Depth});
1258 while (!Stack.empty()) {
1259 WorkItem Item = Stack.back();
1260 size_t StackSize = Stack.size();
1261 Register ItemReg = std::get<0>(Item);
1262 const APInt &ItemDemandedElts = std::get<1>(Item);
1263 const unsigned ItemDepth = std::get<2>(Item);
1266 if (getKnownBitsResult(ItemReg, ItemDemandedElts, ItemDepth, ItemKnown)) {
1274 computeKnownBits(ItemReg, ItemKnown, ItemDemandedElts, ItemDepth);
1278 if (Stack.size() == StackSize) {
1279 assert((std::get<0>(Stack.back()) == ItemReg &&
1280 std::get<1>(Stack.back()) == ItemDemandedElts &&
1281 std::get<2>(Stack.back()) == ItemDepth) &&
1282 "The item we just evaluated must still be the top one.");
1284 setKnownBitsResult(ItemReg, ItemDemandedElts, ItemDepth, ItemKnown);
1291 if (!getKnownBitsResult(R, DemandedElts,
Depth,
Known))
1293 "Top level query must be in `results` after iteration is complete.");
1302 APInt DemandedElts =
1316void GISelValueTracking::computeKnownFPClassForFPTrunc(
1324 KnownFPClass KnownSrc;
1325 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1329 MRI.getType(
MI.getOperand(0).getReg()).getScalarType());
1330 const fltSemantics &SrcSem =
1334 MI.getOpcode() == TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND
1339 MF.getDenormalMode(DstSem),
1340 MF.getDenormalMode(SrcSem));
1343void GISelValueTracking::computeKnownFPClass(
Register R,
1344 const APInt &DemandedElts,
1348 assert(
Known.isUnknown() &&
"should not be called with known information");
1350 if (!DemandedElts) {
1358 MachineInstr &
MI = *MRI.getVRegDef(R);
1359 unsigned Opcode =
MI.getOpcode();
1360 LLT DstTy = MRI.getType(R);
1368 switch (Cst->getKind()) {
1370 Known = KnownFPClass(Cst->getScalarValue());
1376 for (
const APFloat &
C : *Cst)
1377 Known |= KnownFPClass(
C);
1392 KnownNotFromFlags |=
fcNan;
1394 KnownNotFromFlags |=
fcInf;
1398 InterestedClasses &= ~KnownNotFromFlags;
1401 [=, &
Known] {
Known.knownNot(KnownNotFromFlags); });
1411 TL.computeKnownFPClassForTargetInstr(*
this, R,
Known, DemandedElts, MRI,
1414 case TargetOpcode::G_FNEG: {
1416 computeKnownFPClass(Val, DemandedElts, InterestedClasses,
Known,
Depth + 1);
1420 case TargetOpcode::G_SELECT: {
1443 bool LookThroughFAbsFNeg = CmpLHS !=
LHS && CmpLHS !=
RHS;
1444 std::tie(TestedValue, MaskIfTrue, MaskIfFalse) =
1450 MaskIfTrue = TestedMask;
1451 MaskIfFalse = ~TestedMask;
1454 if (TestedValue ==
LHS) {
1456 FilterLHS = MaskIfTrue;
1457 }
else if (TestedValue ==
RHS) {
1459 FilterRHS = MaskIfFalse;
1462 KnownFPClass Known2;
1463 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses & FilterLHS,
Known,
1465 Known.setKnownFPClasses(
Known.getKnownFPClasses() & FilterLHS);
1467 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses & FilterRHS,
1474 case TargetOpcode::G_FCOPYSIGN: {
1475 Register Magnitude =
MI.getOperand(1).getReg();
1478 KnownFPClass KnownSign;
1480 computeKnownFPClass(Magnitude, DemandedElts, InterestedClasses,
Known,
1482 computeKnownFPClass(
Sign, DemandedElts, InterestedClasses, KnownSign,
1484 Known.copysign(KnownSign);
1487 case TargetOpcode::G_FMA:
1488 case TargetOpcode::G_FMAD: {
1492 const bool IsFMA = Opcode == TargetOpcode::G_FMA;
1502 FPClassTest InterestedSquared = InterestedClasses;
1506 if (InterestedClasses &
fcQNan) {
1511 KnownFPClass KnownSrc, KnownAddend;
1512 computeKnownFPClass(
C, DemandedElts, InterestedAddend, KnownAddend,
1514 computeKnownFPClass(
A, DemandedElts, InterestedSquared, KnownSrc,
1516 if (KnownNotFromFlags) {
1517 KnownSrc.
knownNot(KnownNotFromFlags);
1518 KnownAddend.
knownNot(KnownNotFromFlags);
1521 : KnownFPClass::fmuladd_square(KnownSrc, KnownAddend,
Mode);
1523 KnownFPClass KnownSrc[3];
1524 computeKnownFPClass(
A, DemandedElts, InterestedClasses, KnownSrc[0],
1526 if (KnownSrc[0].isUnknown())
1528 computeKnownFPClass(
B, DemandedElts, InterestedClasses, KnownSrc[1],
1530 if (KnownSrc[1].isUnknown())
1532 computeKnownFPClass(
C, DemandedElts, InterestedClasses, KnownSrc[2],
1534 if (KnownSrc[2].isUnknown())
1536 if (KnownNotFromFlags) {
1537 KnownSrc[0].
knownNot(KnownNotFromFlags);
1538 KnownSrc[1].
knownNot(KnownNotFromFlags);
1539 KnownSrc[2].
knownNot(KnownNotFromFlags);
1543 : KnownFPClass::fmuladd(KnownSrc[0], KnownSrc[1], KnownSrc[2],
1548 case TargetOpcode::G_FSQRT:
1549 case TargetOpcode::G_STRICT_FSQRT: {
1550 KnownFPClass KnownSrc;
1552 if (InterestedClasses &
fcQNan)
1555 if (InterestedClasses &
fcZero)
1559 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1568 case TargetOpcode::G_FABS: {
1573 computeKnownFPClass(Val, DemandedElts, InterestedClasses,
Known,
1579 case TargetOpcode::G_FATAN2: {
1597 KnownFPClass KnownY, KnownX;
1598 computeKnownFPClass(
Y, DemandedElts, InterestedY, KnownY,
Depth + 1);
1599 computeKnownFPClass(
X, DemandedElts, InterestedX, KnownX,
Depth + 1);
1605 case TargetOpcode::G_FSINH: {
1607 KnownFPClass KnownSrc;
1608 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1613 case TargetOpcode::G_FCOSH: {
1615 KnownFPClass KnownSrc;
1616 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1621 case TargetOpcode::G_FTANH: {
1623 KnownFPClass KnownSrc;
1624 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1629 case TargetOpcode::G_FASIN: {
1631 KnownFPClass KnownSrc;
1632 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1637 case TargetOpcode::G_FACOS: {
1639 KnownFPClass KnownSrc;
1640 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1645 case TargetOpcode::G_FATAN: {
1647 KnownFPClass KnownSrc;
1648 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1653 case TargetOpcode::G_FTAN: {
1655 KnownFPClass KnownSrc;
1656 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1661 case TargetOpcode::G_FSIN:
1662 case TargetOpcode::G_FCOS: {
1665 KnownFPClass KnownSrc;
1666 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1669 : KnownFPClass::sin(KnownSrc);
1672 case TargetOpcode::G_FSINCOS: {
1675 KnownFPClass KnownSrc;
1676 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1678 if (R ==
MI.getOperand(0).getReg())
1684 case TargetOpcode::G_FMAXNUM:
1685 case TargetOpcode::G_FMINNUM:
1686 case TargetOpcode::G_FMINNUM_IEEE:
1687 case TargetOpcode::G_FMAXIMUM:
1688 case TargetOpcode::G_FMINIMUM:
1689 case TargetOpcode::G_FMAXNUM_IEEE:
1690 case TargetOpcode::G_FMAXIMUMNUM:
1691 case TargetOpcode::G_FMINIMUMNUM: {
1694 KnownFPClass KnownLHS, KnownRHS;
1696 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses, KnownLHS,
1698 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses, KnownRHS,
1703 case TargetOpcode::G_FMINIMUM:
1706 case TargetOpcode::G_FMAXIMUM:
1709 case TargetOpcode::G_FMINIMUMNUM:
1712 case TargetOpcode::G_FMAXIMUMNUM:
1715 case TargetOpcode::G_FMINNUM:
1716 case TargetOpcode::G_FMINNUM_IEEE:
1719 case TargetOpcode::G_FMAXNUM:
1720 case TargetOpcode::G_FMAXNUM_IEEE:
1732 case TargetOpcode::G_FCANONICALIZE: {
1734 KnownFPClass KnownSrc;
1735 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1740 DenormalMode
Mode = MF->getDenormalMode(FPType);
1744 case TargetOpcode::G_VECREDUCE_FMAX:
1745 case TargetOpcode::G_VECREDUCE_FMIN:
1746 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1747 case TargetOpcode::G_VECREDUCE_FMINIMUM:
1748 case TargetOpcode::G_VECREDUCE_FMAXIMUMNUM:
1749 case TargetOpcode::G_VECREDUCE_FMINIMUMNUM: {
1755 computeKnownFPClass(Val,
MI.getFlags(), InterestedClasses,
Depth + 1);
1757 if (!
Known.isKnownNeverNaN())
1758 Known.setSignBit(std::nullopt);
1761 case TargetOpcode::G_FFLOOR:
1762 case TargetOpcode::G_FCEIL:
1763 case TargetOpcode::G_FRINT:
1764 case TargetOpcode::G_FNEARBYINT:
1765 case TargetOpcode::G_INTRINSIC_ROUND:
1766 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
1767 case TargetOpcode::G_INTRINSIC_TRUNC: {
1769 KnownFPClass KnownSrc;
1780 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1784 DenormalMode
Mode = MF->getDenormalMode(FltSem);
1788 case TargetOpcode::G_INTRINSIC_TRUNC:
1791 case TargetOpcode::G_FFLOOR:
1794 case TargetOpcode::G_FCEIL:
1803 case TargetOpcode::G_FEXP:
1804 case TargetOpcode::G_FEXP2:
1805 case TargetOpcode::G_FEXP10: {
1807 KnownFPClass KnownSrc;
1808 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1813 case TargetOpcode::G_FLOG:
1814 case TargetOpcode::G_FLOG2:
1815 case TargetOpcode::G_FLOG10: {
1839 KnownFPClass KnownSrc;
1840 if (InterestedSrcs !=
fcNone)
1841 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
1846 DenormalMode
Mode = MF->getDenormalMode(FltSem);
1851 case TargetOpcode::G_FPOW: {
1852 const bool WantNaN = (InterestedClasses &
fcNan) !=
fcNone;
1854 if (!WantNaN && !WantNegative)
1863 InterestedRHS |=
fcNan;
1872 KnownFPClass KnownLHS;
1873 computeKnownFPClass(
MI.getOperand(1).getReg(), DemandedElts, InterestedLHS,
1874 KnownLHS,
Depth + 1);
1881 KnownFPClass KnownRHS;
1882 computeKnownFPClass(
MI.getOperand(2).getReg(), DemandedElts, InterestedRHS,
1883 KnownRHS,
Depth + 1);
1887 case TargetOpcode::G_FPOWI: {
1892 LLT ExpTy = MRI.getType(Exp);
1894 Exp, ExpTy.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1897 if (InterestedClasses &
fcNan)
1898 InterestedSrcs |=
fcNan;
1899 if (!ExponentKnownBits.
isZero()) {
1900 if (InterestedClasses &
fcInf)
1906 KnownFPClass KnownSrc;
1907 if (InterestedSrcs !=
fcNone) {
1909 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
1916 case TargetOpcode::G_FLDEXP: {
1918 KnownFPClass KnownSrc;
1919 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1927 LLT ExpTy = MRI.getType(ExpReg);
1929 ExpReg, ExpTy.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1934 DenormalMode
Mode = MF->getDenormalMode(Flt);
1938 case TargetOpcode::G_FADD:
1939 case TargetOpcode::G_STRICT_FADD:
1940 case TargetOpcode::G_FSUB:
1941 case TargetOpcode::G_STRICT_FSUB: {
1946 Opcode == TargetOpcode::G_FADD || Opcode == TargetOpcode::G_STRICT_FADD;
1947 const bool IsStrict = Opcode == TargetOpcode::G_STRICT_FADD ||
1948 Opcode == TargetOpcode::G_STRICT_FSUB;
1956 bool WantNaN = (InterestedClasses &
fcNan) !=
fcNone;
1959 if (!WantNaN && !WantNegative && !WantNegZero) {
1969 if (InterestedClasses &
fcNan)
1970 InterestedSrcs |=
fcInf;
1974 KnownFPClass KnownSelf;
1975 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownSelf,
1981 KnownFPClass KnownLHS, KnownRHS;
1982 computeKnownFPClass(
RHS, DemandedElts, InterestedSrcs, KnownRHS,
Depth + 1);
1986 WantNegZero || !IsAdd) {
1989 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownLHS,
1999 case TargetOpcode::G_FMUL: {
2007 KnownFPClass KnownSrc;
2014 KnownFPClass KnownLHS;
2018 KnownFPClass KnownLHS, KnownRHS;
2034 case TargetOpcode::G_FDIV: {
2035 const bool WantNan = (InterestedClasses &
fcNan) !=
fcNone;
2050 KnownFPClass KnownSrc;
2051 computeKnownFPClass(
LHS, DemandedElts,
2060 if (!WantNan && !WantNegative && !WantPositive)
2063 KnownFPClass KnownLHS, KnownRHS;
2066 bool KnowSomethingUseful =
2071 if (KnowSomethingUseful)
2077 case TargetOpcode::G_FREM:
2078 case TargetOpcode::G_STRICT_FREM: {
2083 if (InterestedClasses &
fcNan) {
2111 FPClassTest InterestedSrcs = InterestedLHS | InterestedRHS;
2112 KnownFPClass KnownSrc;
2113 if (InterestedSrcs !=
fcNone)
2114 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownSrc,
2120 KnownFPClass KnownLHS;
2121 if (InterestedLHS !=
fcNone)
2122 computeKnownFPClass(
LHS, DemandedElts, InterestedLHS, KnownLHS,
2125 KnownFPClass KnownRHS;
2128 computeKnownFPClass(
RHS, DemandedElts, InterestedRHS, KnownRHS,
2135 case TargetOpcode::G_FFREXP: {
2137 if (R !=
MI.getOperand(0).getReg())
2156 KnownFPClass KnownSrc;
2157 computeKnownFPClass(Src, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
2163 case TargetOpcode::G_FPEXT: {
2165 KnownFPClass KnownSrc;
2166 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
2175 MF->getDenormalMode(DstSem),
2176 MF->getDenormalMode(SrcSem));
2179 case TargetOpcode::G_FPTRUNC:
2180 case TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND: {
2181 computeKnownFPClassForFPTrunc(
MI, DemandedElts, InterestedClasses,
Known,
2185 case TargetOpcode::G_SITOFP:
2186 case TargetOpcode::G_UITOFP: {
2197 if (Opcode == TargetOpcode::G_UITOFP)
2198 Known.signBitMustBeZero();
2205 LLT Ty = MRI.getType(Val);
2207 Val, Ty.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
2213 if (Opcode == TargetOpcode::G_SITOFP) {
2218 Known.signBitMustBeZero();
2220 Known.signBitMustBeOne();
2223 if (InterestedClasses &
fcInf) {
2230 if (Opcode == TargetOpcode::G_UITOFP)
2244 case TargetOpcode::G_BUILD_VECTOR:
2245 case TargetOpcode::G_CONCAT_VECTORS: {
2252 for (
unsigned Idx = 0;
Idx <
Merge.getNumSources(); ++
Idx) {
2254 bool NeedsElt = DemandedElts[
Idx];
2260 computeKnownFPClass(Src,
Known, InterestedClasses,
Depth + 1);
2263 KnownFPClass Known2;
2264 computeKnownFPClass(Src, Known2, InterestedClasses,
Depth + 1);
2269 if (
Known.isUnknown())
2276 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
2286 LLT VecTy = MRI.getType(Vec);
2291 if (CIdx && CIdx->ult(NumElts))
2293 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses,
Known,
2299 case TargetOpcode::G_INSERT_VECTOR_ELT: {
2305 LLT VecTy = MRI.getType(Vec);
2313 APInt DemandedVecElts = DemandedElts;
2314 bool NeedsElt =
true;
2316 if (CIdx && CIdx->ult(NumElts)) {
2317 DemandedVecElts.
clearBit(CIdx->getZExtValue());
2318 NeedsElt = DemandedElts[CIdx->getZExtValue()];
2323 computeKnownFPClass(Elt,
Known, InterestedClasses,
Depth + 1);
2325 if (
Known.isUnknown())
2332 if (!DemandedVecElts.
isZero()) {
2333 KnownFPClass Known2;
2334 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2,
2341 case TargetOpcode::G_SHUFFLE_VECTOR: {
2345 APInt DemandedLHS, DemandedRHS;
2347 assert(DemandedElts == APInt(1, 1));
2348 DemandedLHS = DemandedRHS = DemandedElts;
2350 unsigned NumElts = MRI.getType(Shuf.
getSrc1Reg()).getNumElements();
2352 DemandedLHS, DemandedRHS)) {
2358 if (!!DemandedLHS) {
2360 computeKnownFPClass(
LHS, DemandedLHS, InterestedClasses,
Known,
2364 if (
Known.isUnknown())
2370 if (!!DemandedRHS) {
2371 KnownFPClass Known2;
2373 computeKnownFPClass(
RHS, DemandedRHS, InterestedClasses, Known2,
2379 case TargetOpcode::G_PHI: {
2388 for (
unsigned Idx = 1;
Idx <
MI.getNumOperands();
Idx += 2) {
2389 const MachineOperand &Src =
MI.getOperand(Idx);
2392 computeKnownFPClass(SrcReg, DemandedElts, InterestedClasses,
Known,
2396 KnownFPClass Known2;
2397 computeKnownFPClass(SrcReg, DemandedElts, InterestedClasses, Known2,
2401 if (
Known.isUnknown())
2406 case TargetOpcode::G_FREEZE: {
2409 computeKnownFPClass(Src, DemandedElts, InterestedClasses,
Known,
2414 case TargetOpcode::COPY: {
2417 if (!Src.isVirtual())
2420 computeKnownFPClass(Src, DemandedElts, InterestedClasses,
Known,
Depth + 1);
2431 computeKnownFPClass(R, DemandedElts, InterestedClasses, KnownClasses,
Depth);
2432 return KnownClasses;
2438 computeKnownFPClass(R,
Known, InterestedClasses,
Depth);
2446 InterestedClasses &=
~fcNan;
2448 InterestedClasses &=
~fcInf;
2451 computeKnownFPClass(R, DemandedElts, InterestedClasses,
Depth);
2454 Result.setKnownFPClasses(Result.getKnownFPClasses() & ~
fcNan);
2456 Result.setKnownFPClasses(Result.getKnownFPClasses() & ~
fcInf);
2462 LLT Ty = MRI.getType(R);
2463 APInt DemandedElts =
2465 return computeKnownFPClass(R, DemandedElts, Flags, InterestedClasses,
Depth);
2480 switch (
DefMI->getOpcode()) {
2483 case TargetOpcode::G_FADD:
2484 case TargetOpcode::G_STRICT_FADD:
2485 case TargetOpcode::G_FSUB:
2486 case TargetOpcode::G_STRICT_FSUB:
2487 case TargetOpcode::G_FMUL:
2488 case TargetOpcode::G_STRICT_FMUL:
2489 case TargetOpcode::G_FDIV:
2490 case TargetOpcode::G_STRICT_FDIV:
2491 case TargetOpcode::G_FREM:
2492 case TargetOpcode::G_STRICT_FREM:
2493 case TargetOpcode::G_FMA:
2494 case TargetOpcode::G_STRICT_FMA:
2495 case TargetOpcode::G_FMAD:
2496 case TargetOpcode::G_FSQRT:
2497 case TargetOpcode::G_STRICT_FSQRT:
2501 case TargetOpcode::G_FSIN:
2502 case TargetOpcode::G_FCOS:
2503 case TargetOpcode::G_FSINCOS:
2504 case TargetOpcode::G_FTAN:
2505 case TargetOpcode::G_FASIN:
2506 case TargetOpcode::G_FACOS:
2507 case TargetOpcode::G_FATAN:
2508 case TargetOpcode::G_FATAN2:
2509 case TargetOpcode::G_FSINH:
2510 case TargetOpcode::G_FCOSH:
2511 case TargetOpcode::G_FTANH:
2512 case TargetOpcode::G_FEXP:
2513 case TargetOpcode::G_FEXP2:
2514 case TargetOpcode::G_FEXP10:
2515 case TargetOpcode::G_FLOG:
2516 case TargetOpcode::G_FLOG2:
2517 case TargetOpcode::G_FLOG10:
2518 case TargetOpcode::G_FPOW:
2519 case TargetOpcode::G_FPOWI:
2520 case TargetOpcode::G_FLDEXP:
2521 case TargetOpcode::G_STRICT_FLDEXP:
2522 case TargetOpcode::G_FFREXP:
2523 case TargetOpcode::G_INTRINSIC_TRUNC:
2524 case TargetOpcode::G_INTRINSIC_ROUND:
2525 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
2526 case TargetOpcode::G_FFLOOR:
2527 case TargetOpcode::G_FCEIL:
2528 case TargetOpcode::G_FRINT:
2529 case TargetOpcode::G_FNEARBYINT:
2530 case TargetOpcode::G_FPEXT:
2531 case TargetOpcode::G_FPTRUNC:
2532 case TargetOpcode::G_FCANONICALIZE:
2533 case TargetOpcode::G_FMINNUM:
2534 case TargetOpcode::G_FMAXNUM:
2535 case TargetOpcode::G_FMINNUM_IEEE:
2536 case TargetOpcode::G_FMAXNUM_IEEE:
2537 case TargetOpcode::G_FMINIMUM:
2538 case TargetOpcode::G_FMAXIMUM:
2539 case TargetOpcode::G_FMINIMUMNUM:
2540 case TargetOpcode::G_FMAXIMUMNUM:
2556 return Known.isKnownNeverLogicalZero(
2561unsigned GISelValueTracking::computeNumSignBitsMin(
Register Src0,
Register Src1,
2562 const APInt &DemandedElts,
2566 if (Src1SignBits == 1)
2576 const MDNode *Ranges = Ld->getRanges();
2582 switch (Ld->getOpcode()) {
2583 case TargetOpcode::G_SEXTLOAD:
2586 case TargetOpcode::G_ZEXTLOAD:
2599 const APInt &DemandedElts,
2602 unsigned Opcode =
MI.getOpcode();
2604 if (Opcode == TargetOpcode::G_CONSTANT)
2605 return MI.getOperand(1).getCImm()->getValue().getNumSignBits();
2613 LLT DstTy = MRI.getType(R);
2623 unsigned FirstAnswer = 1;
2625 case TargetOpcode::COPY: {
2627 if (Src.getReg().isVirtual() && Src.getSubReg() == 0 &&
2628 MRI.getType(Src.getReg()).isValid()) {
2635 case TargetOpcode::G_FREEZE: {
2641 case TargetOpcode::G_SEXT: {
2643 LLT SrcTy = MRI.getType(Src);
2644 unsigned Tmp = TyBits - SrcTy.getScalarSizeInBits();
2647 case TargetOpcode::G_ASSERT_SEXT:
2648 case TargetOpcode::G_SEXT_INREG: {
2651 unsigned SrcBits =
MI.getOperand(2).getImm();
2652 unsigned InRegBits = TyBits - SrcBits + 1;
2656 case TargetOpcode::G_LOAD: {
2663 case TargetOpcode::G_SEXTLOAD: {
2678 case TargetOpcode::G_ZEXTLOAD: {
2693 case TargetOpcode::G_AND:
2694 case TargetOpcode::G_OR:
2695 case TargetOpcode::G_XOR: {
2697 unsigned Src1NumSignBits =
2699 if (Src1NumSignBits != 1) {
2701 unsigned Src2NumSignBits =
2703 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits);
2707 case TargetOpcode::G_ASHR: {
2712 FirstAnswer = std::min<uint64_t>(FirstAnswer + *
C, TyBits);
2715 case TargetOpcode::G_SHL: {
2718 if (std::optional<ConstantRange> ShAmtRange =
2720 uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
2721 uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
2731 if (ExtOpc == TargetOpcode::G_SEXT || ExtOpc == TargetOpcode::G_ZEXT ||
2732 ExtOpc == TargetOpcode::G_ANYEXT) {
2733 LLT ExtTy = MRI.getType(Src1);
2735 LLT ExtendeeTy = MRI.getType(Extendee);
2739 if (SizeDiff <= MinShAmt) {
2743 return Tmp - MaxShAmt;
2749 return Tmp - MaxShAmt;
2753 case TargetOpcode::G_ROTL:
2754 case TargetOpcode::G_ROTR: {
2763 case TargetOpcode::G_SAVGFLOOR:
2764 case TargetOpcode::G_SAVGCEIL: {
2767 FirstAnswer = computeNumSignBitsMin(Src1, Src2, DemandedElts,
Depth + 1);
2770 case TargetOpcode::G_SREM: {
2778 case TargetOpcode::G_TRUNC: {
2780 LLT SrcTy = MRI.getType(Src);
2785 if (NumSrcSignBits > (NumSrcBits - TyBits))
2786 return NumSrcSignBits - (NumSrcBits - TyBits);
2789 case TargetOpcode::G_SELECT: {
2790 return computeNumSignBitsMin(
MI.getOperand(2).getReg(),
2791 MI.getOperand(3).getReg(), DemandedElts,
2794 case TargetOpcode::G_SMIN:
2795 case TargetOpcode::G_SMAX:
2796 case TargetOpcode::G_UMIN:
2797 case TargetOpcode::G_UMAX:
2799 return computeNumSignBitsMin(
MI.getOperand(1).getReg(),
2800 MI.getOperand(2).getReg(), DemandedElts,
2802 case TargetOpcode::G_SADDO:
2803 case TargetOpcode::G_SADDE:
2804 case TargetOpcode::G_UADDO:
2805 case TargetOpcode::G_UADDE:
2806 case TargetOpcode::G_SSUBO:
2807 case TargetOpcode::G_SSUBE:
2808 case TargetOpcode::G_USUBO:
2809 case TargetOpcode::G_USUBE:
2810 case TargetOpcode::G_SMULO:
2811 case TargetOpcode::G_UMULO: {
2815 if (
MI.getOperand(1).getReg() == R) {
2816 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
2823 case TargetOpcode::G_SUB: {
2825 unsigned Src2NumSignBits =
2827 if (Src2NumSignBits == 1)
2837 if ((Known2.
Zero | 1).isAllOnes())
2844 FirstAnswer = Src2NumSignBits;
2851 unsigned Src1NumSignBits =
2853 if (Src1NumSignBits == 1)
2858 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2861 case TargetOpcode::G_ADD: {
2863 unsigned Src2NumSignBits =
2865 if (Src2NumSignBits <= 2)
2869 unsigned Src1NumSignBits =
2871 if (Src1NumSignBits == 1)
2880 if ((Known1.
Zero | 1).isAllOnes())
2886 FirstAnswer = Src1NumSignBits;
2895 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2898 case TargetOpcode::G_MUL: {
2899 unsigned Src2NumSignBits =
2901 if (Src2NumSignBits == 1)
2903 unsigned Src1NumSignBits =
2905 if (Src1NumSignBits == 1)
2909 unsigned OutValidBits =
2910 (TyBits - Src1NumSignBits + 1) + (TyBits - Src2NumSignBits + 1);
2911 if (OutValidBits <= TyBits)
2912 FirstAnswer = TyBits - OutValidBits + 1;
2915 case TargetOpcode::G_FCMP:
2916 case TargetOpcode::G_ICMP: {
2917 bool IsFP = Opcode == TargetOpcode::G_FCMP;
2920 auto BC = TL.getBooleanContents(DstTy.
isVector(), IsFP);
2927 case TargetOpcode::G_UNMERGE_VALUES: {
2928 unsigned NumOps =
MI.getNumOperands();
2930 LLT SrcTy = MRI.getType(SrcReg);
2932 if ((SrcTy.isVector() && SrcTy.getScalarType() != DstTy.
getScalarType()) ||
2933 (SrcTy.isScalar() && DstTy.
isVector()))
2937 unsigned DstIdx =
MI.findRegisterDefOperandIdx(R,
nullptr);
2939 APInt SubDemandedElts = DemandedElts;
2941 if (SrcTy.isVector()) {
2943 DemandedElts.
zext(SrcTy.getNumElements()).
shl(DstIdx * DstLanes);
2946 unsigned SrcOpKnown =
2948 if (SrcTy.isVector()) {
2949 FirstAnswer = SrcOpKnown;
2950 }
else if (SrcOpKnown >= (
MI.getNumOperands() - DstIdx - 2) * TyBits) {
2951 FirstAnswer = SrcOpKnown >= (
MI.getNumOperands() - DstIdx - 1) * TyBits
2953 : SrcOpKnown % TyBits;
2957 case TargetOpcode::G_BUILD_VECTOR: {
2959 FirstAnswer = TyBits;
2960 APInt SingleDemandedElt(1, 1);
2962 if (!DemandedElts[
I])
2967 FirstAnswer = std::min(FirstAnswer, Tmp2);
2970 if (FirstAnswer == 1)
2975 case TargetOpcode::G_CONCAT_VECTORS: {
2976 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
2978 FirstAnswer = TyBits;
2981 unsigned NumSubVectorElts =
2982 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
2985 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
2990 FirstAnswer = std::min(FirstAnswer, Tmp2);
2993 if (FirstAnswer == 1)
2998 case TargetOpcode::G_VECTOR_COMPRESS: {
3002 Register PassThru =
MI.getOperand(3).getReg();
3011 FirstAnswer = std::min(Tmp, Tmp2);
3014 case TargetOpcode::G_INSERT_VECTOR_ELT: {
3016 Register InVec = Insert.getVectorReg();
3017 Register InVal = Insert.getElementReg();
3018 LLT VecVT = MRI.getType(InVec);
3024 bool DemandedVal =
true;
3025 APInt DemandedVecElts = DemandedElts;
3029 if (ConstEltNo && ConstEltNo->ult(NumElts)) {
3030 unsigned EltIdx = ConstEltNo->getZExtValue();
3031 DemandedVal = !!DemandedElts[EltIdx];
3036 unsigned Tmp = TyBits;
3039 if (MRI.getType(InVal).getSizeInBits() != TyBits)
3042 Tmp = std::min(Tmp, ValSignBits);
3044 if (!!DemandedVecElts) {
3045 unsigned VecSignBits =
3047 Tmp = std::min(Tmp, VecSignBits);
3051 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
3055 LLT VecVT = MRI.getType(InVec);
3060 APInt DemandedSrcElts =
3061 ConstEltNo && ConstEltNo->ult(NumSrcElts)
3066 case TargetOpcode::G_EXTRACT_SUBVECTOR: {
3069 LLT SrcTy = MRI.getType(SrcReg);
3070 APInt DemandedSrcElts;
3071 if (SrcTy.isScalableVector()) {
3072 DemandedSrcElts =
APInt(1, 1);
3074 uint64_t Idx =
MI.getOperand(2).getImm();
3075 unsigned NumSrcElts = SrcTy.getNumElements();
3076 DemandedSrcElts = DemandedElts.
zext(NumSrcElts).
shl(Idx);
3080 case TargetOpcode::G_SHUFFLE_VECTOR: {
3083 APInt DemandedLHS, DemandedRHS;
3085 unsigned NumElts = MRI.getType(Src1).getNumElements();
3087 DemandedElts, DemandedLHS, DemandedRHS))
3093 if (FirstAnswer == 1)
3095 if (!!DemandedRHS) {
3098 FirstAnswer = std::min(FirstAnswer, Tmp2);
3102 case TargetOpcode::G_SPLAT_VECTOR: {
3106 unsigned NumSrcBits = MRI.getType(Src).getSizeInBits();
3107 if (NumSrcSignBits > (NumSrcBits - TyBits))
3108 return NumSrcSignBits - (NumSrcBits - TyBits);
3111 case TargetOpcode::G_INTRINSIC:
3112 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
3113 case TargetOpcode::G_INTRINSIC_CONVERGENT:
3114 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
3117 TL.computeNumSignBitsForTargetInstr(*
this, R, DemandedElts, MRI,
Depth);
3119 FirstAnswer = std::max(FirstAnswer, NumBits);
3127 return std::max(FirstAnswer,
Known.countMinSignBits());
3131 LLT Ty = MRI.getType(R);
3132 APInt DemandedElts =
3141 unsigned Opcode =
MI.getOpcode();
3143 LLT Ty = MRI.getType(R);
3144 unsigned BitWidth = Ty.getScalarSizeInBits();
3146 if (Opcode == TargetOpcode::G_CONSTANT) {
3147 const APInt &ShAmt =
MI.getOperand(1).getCImm()->getValue();
3149 return std::nullopt;
3153 if (Opcode == TargetOpcode::G_BUILD_VECTOR) {
3154 const APInt *MinAmt =
nullptr, *MaxAmt =
nullptr;
3155 for (
unsigned I = 0, E =
MI.getNumOperands() - 1;
I != E; ++
I) {
3156 if (!DemandedElts[
I])
3159 if (
Op->getOpcode() != TargetOpcode::G_CONSTANT) {
3160 MinAmt = MaxAmt =
nullptr;
3164 const APInt &ShAmt =
Op->getOperand(1).getCImm()->getValue();
3166 return std::nullopt;
3167 if (!MinAmt || MinAmt->
ugt(ShAmt))
3169 if (!MaxAmt || MaxAmt->ult(ShAmt))
3172 assert(((!MinAmt && !MaxAmt) || (MinAmt && MaxAmt)) &&
3173 "Failed to find matching min/max shift amounts");
3174 if (MinAmt && MaxAmt)
3184 return std::nullopt;
3189 if (std::optional<ConstantRange> AmtRange =
3191 return AmtRange->getUnsignedMin().getZExtValue();
3192 return std::nullopt;
3210 Info = std::make_unique<GISelValueTracking>(MF, MaxDepth);
3222 return Result(MF, MaxDepth);
3228 bool PrintFPClass) {
3238 if (!MO.isReg() || MO.getReg().isPhysical())
3241 if (!
MRI.getType(
Reg).isValid())
3246 <<
" SignBitKnown:";
3254 unsigned SignedBits = VTA.computeNumSignBits(
Reg);
3255 bool IsKnownNeverZero = VTA.isKnownNeverZero(
Reg);
3256 OS <<
" " << MO <<
" KnownBits:" <<
Known
3257 <<
" SignBits:" << SignedBits
3258 <<
" IsKnownNeverZero:" << IsKnownNeverZero <<
'\n';
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Utilities for dealing with flags related to floating point properties and mode controls.
static void dumpResult(const MachineInstr &MI, const KnownBits &Known, unsigned Depth)
static void genUnknown(MachineRegisterInfo &MRI, Register Reg, KnownBits &Known)
static PreservedAnalyses printGISelValueTracking(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM, raw_ostream &OS, bool PrintFPClass)
static unsigned computeNumSignBitsFromRangeMetadata(const GAnyLoad *Ld, unsigned TyBits)
Compute the known number of sign bits with attached range metadata in the memory operand.
Provides analysis for querying information about KnownBits during GISel passes.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Implement a low-level type suitable for MachineInstr level instruction selection.
Contains matchers for matching SSA Machine Instructions.
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This file describes how to lower LLVM code to machine code.
static bool isAbsoluteValueULEOne(const Value *V)
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static constexpr const fltSemantics & PPCDoubleDouble()
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Class for arbitrary precision integers.
LLVM_ABI APInt umul_ov(const APInt &RHS, bool &Overflow) const
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
unsigned countl_zero() const
The APInt version of std::countl_zero.
unsigned logBase2() const
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
APInt shl(unsigned shiftAmt) const
Left-shift function.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
void clearBits(unsigned LoBit, unsigned HiBit)
Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This class represents a range of values.
static LLVM_ABI ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)
Initialize a range based on a known bits constraint.
LLVM_ABI KnownBits toKnownBits() const
Return known bits for values in this range.
LLVM_ABI ConstantRange zeroExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
LLVM_ABI APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
LLVM_ABI ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
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 APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Represents any generic load, including sign/zero extending variants.
static LLVM_ABI std::optional< GFConstant > getConstant(Register Const, const MachineRegisterInfo &MRI)
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
GISelValueTracking & get(MachineFunction &MF)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
GISelValueTracking Result
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
unsigned getMaxDepth() const
KnownBits getKnownBits(Register R)
Align computeKnownAlignment(Register R, unsigned Depth=0)
std::optional< ConstantRange > getValidShiftAmountRange(Register R, const APInt &DemandedElts, unsigned Depth)
If a G_SHL/G_ASHR/G_LSHR node with shift operand R has shift amounts that are all less than the eleme...
bool maskedValueIsZero(Register Val, const APInt &Mask)
std::optional< uint64_t > getValidMinimumShiftAmount(Register R, const APInt &DemandedElts, unsigned Depth=0)
If a G_SHL/G_ASHR/G_LSHR node with shift operand R has shift amounts that are all less than the eleme...
bool signBitIsZero(Register Op)
const DataLayout & getDataLayout() const
unsigned computeNumSignBits(Register R, const APInt &DemandedElts, unsigned Depth=0)
const MachineFunction & getMachineFunction() const
bool isKnownNeverNaN(Register Val, bool SNaN=false)
Returns true if Val can be assumed to never be a NaN.
bool isKnownNeverLogicalZero(Register Val, unsigned Depth=0)
Returns true if Val can be assumed to never be a zero, accounting for denormal flushing of the contai...
APInt getKnownOnes(Register R)
APInt getKnownZeroes(Register R)
void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
Evaluate a known-bits query with an explicit worklist instead of recursive descent.
bool isKnownNeverZero(Register R, unsigned Depth=0)
Return true if the value defined by R is provably never zero.
Represents an insert vector element.
Register getCondReg() const
Register getFalseReg() const
Register getTrueReg() const
Represents a G_SHUFFLE_VECTOR.
Register getSrc2Reg() const
Register getSrc1Reg() const
ArrayRef< int > getMask() const
void setKnownFPClasses(FPClassTest Classes)
static LLVM_ABI KnownFPClass atan2(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for atan2.
static LLVM_ABI KnownFPClass fma(const KnownFPClass &LHS, const KnownFPClass &RHS, const KnownFPClass &Addend, DenormalMode Mode)
Report known values for fma.
static LLVM_ABI KnownFPClass sin(const KnownFPClass &Src)
Report known values for sin.
static LLVM_ABI KnownFPClass fptrunc(const KnownFPClass &KnownSrc, const fltSemantics &DstTy, const fltSemantics &SrcTy, RoundingMode RM, DenormalMode DstMode, DenormalMode SrcMode)
Propagate known class for fptrunc and fptrunc_round.
static constexpr FPClassTest OrderedLessThanZeroMask
static LLVM_ABI KnownFPClass trunc(const KnownFPClass &Src, DenormalMode Mode)
Propagate known class for trunc.
static LLVM_ABI KnownFPClass fadd(const KnownFPClass &LHS, const KnownFPClass &RHS, RoundingMode RM, DenormalMode Mode)
Report known values for fadd.
static LLVM_ABI KnownFPClass fsub(const KnownFPClass &LHS, const KnownFPClass &RHS, RoundingMode RM, DenormalMode Mode)
Report known values for fsub.
static LLVM_ABI KnownFPClass fma_square(const KnownFPClass &Squared, const KnownFPClass &Addend, DenormalMode Mode)
Report known values for fma squared, squared, addend.
static LLVM_ABI KnownFPClass fadd_self(const KnownFPClass &Src, RoundingMode RM, DenormalMode Mode)
Report known values for fadd x, x.
static LLVM_ABI KnownFPClass frem(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for frem.
static LLVM_ABI KnownFPClass atan(const KnownFPClass &Src)
Report known values for atan.
static LLVM_ABI KnownFPClass ldexp(const KnownFPClass &Src, const APInt &ConstantRangeMin, const APInt &ConstantRangeMax, const fltSemantics &Flt, DenormalMode Mode)
Propagate known class for ldexp, assuming the exponent is known to be within [ConstantRangeMin,...
static LLVM_ABI KnownFPClass frexp_mant(const KnownFPClass &Src, DenormalMode Mode)
Propagate known class for mantissa component of frexp.
static LLVM_ABI KnownFPClass roundToIntegral(const KnownFPClass &Src, bool IsMultiUnitFPType, DenormalMode Mode)
Propagate known class for rounding intrinsics (rint, nearbyint, round, roundeven).
static LLVM_ABI KnownFPClass ceil(const KnownFPClass &Src, bool IsMultiUnitFPType, DenormalMode Mode)
Propagate known class for ceil.
static LLVM_ABI KnownFPClass fpext(const KnownFPClass &KnownSrc, const fltSemantics &DstTy, const fltSemantics &SrcTy, DenormalMode DstMode, DenormalMode SrcMode)
Propagate known class for fpext.
static LLVM_ABI KnownFPClass cos(const KnownFPClass &Src)
Report known values for cos.
static LLVM_ABI KnownFPClass cosh(const KnownFPClass &Src)
Report known values for cosh.
static LLVM_ABI KnownFPClass exp(const KnownFPClass &Src)
Report known values for exp, exp2 and exp10.
static LLVM_ABI KnownFPClass asin(const KnownFPClass &Src)
Report known values for asin.
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
static LLVM_ABI KnownFPClass minMaxLike(const KnownFPClass &LHS, const KnownFPClass &RHS, MinMaxKind Kind, DenormalMode Mode)
void knownNot(FPClassMask RuleOut)
static LLVM_ABI KnownFPClass canonicalize(const KnownFPClass &Src, const fltSemantics &Flt, DenormalMode Mode)
Apply the canonicalize intrinsic to this value.
std::optional< bool > getSignBit() const
std::nullopt if the sign bit is unknown, true if the sign bit is definitely set or false if the sign ...
static LLVM_ABI KnownFPClass floor(const KnownFPClass &Src, bool IsMultiUnitFPType, DenormalMode Mode)
Propagate known class for floor.
FPClassTest getKnownFPClasses() const
Floating-point classes the value could be one of.
static KnownFPClass getEmpty()
static LLVM_ABI KnownFPClass tan(const KnownFPClass &Src)
Report known values for tan.
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
static LLVM_ABI KnownFPClass fdiv_self(const KnownFPClass &Src, DenormalMode Mode)
Report known values for fdiv x, x.
static LLVM_ABI KnownFPClass sqrt(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for sqrt.
bool isKnownNever(FPClassMask Mask) const
Return true if it's known this can never be one of the mask entries.
static LLVM_ABI KnownFPClass square(const KnownFPClass &Src, DenormalMode Mode)
static LLVM_ABI KnownFPClass acos(const KnownFPClass &Src)
Report known values for acos.
static LLVM_ABI KnownFPClass log(const KnownFPClass &Src, DenormalMode Mode, bool IsMultiUnitFPType)
Propagate known class for log/log2/log10.
static LLVM_ABI KnownFPClass frem_self(const KnownFPClass &Src, DenormalMode Mode)
Report known values for frem x, x. Valid for all rounding modes.
static LLVM_ABI KnownFPClass powi(const KnownFPClass &Src, const KnownBits &N)
Propagate known class for powi.
static LLVM_ABI KnownFPClass fdiv(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for fdiv.
static LLVM_ABI KnownFPClass fmul(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for fmul.
static LLVM_ABI KnownFPClass pow(const KnownFPClass &LHS, const KnownFPClass &RHS)
Propagate known class for pow.
static LLVM_ABI KnownFPClass sinh(const KnownFPClass &Src)
Report known values for sinh.
static LLVM_ABI KnownFPClass tanh(const KnownFPClass &Src)
Report known values for tanh.
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr unsigned getScalarSizeInBits() const
LLT getScalarType() const
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr ElementCount getElementCount() const
constexpr unsigned getAddressSpace() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
TypeSize getValue() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
LLT getMemoryType() const
Return the memory type of the memory reference.
const MDNode * getRanges() const
Return the range tag for the memory reference.
LocationSize getSizeInBits() const
Return the size in bits of the memory reference.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
@ ZeroOrOneBooleanContent
@ ZeroOrNegativeOneBooleanContent
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Value * getOperand(unsigned i) const
LLVM_ABI void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI APInt fshr(const APInt &Hi, const APInt &Lo, const APInt &Shift)
Perform a funnel shift right.
operand_type_match m_Reg()
UnaryOp_match< SrcTy, TargetOpcode::G_FFLOOR > m_GFFloor(const SrcTy &Src)
operand_type_match m_Pred()
bind_ty< FPClassTest > m_FPClassTest(FPClassTest &T)
deferred_ty< Register > m_DeferredReg(Register &R)
Similar to m_SpecificReg/Type, but the specific value to match originated from an earlier sub-pattern...
BinaryOp_match< LHS, RHS, TargetOpcode::G_FSUB, false > m_GFSub(const LHS &L, const RHS &R)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
ClassifyOp_match< LHS, Test, TargetOpcode::G_IS_FPCLASS > m_GIsFPClass(const LHS &L, const Test &T)
Matches the register and immediate used in a fpclass test G_IS_FPCLASS val, 96.
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_FCMP > m_GFCmp(const Pred &P, const LHS &L, const RHS &R)
LLVM_ABI unsigned rot(unsigned SrcSignBits, unsigned BitWidth, std::optional< APInt > RotAmt, bool IsRotateRight)
Compute the number of sign bits after rotating a value.
unsigned getNumElements(Type *Ty)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
LLVM_ABI std::optional< APInt > isConstantOrConstantSplatVector(Register Def, const MachineRegisterInfo &MRI)
Determines if Def defines a constant integer or a splat vector of constant integers.
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth=0)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
LLVM_ABI std::optional< APInt > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
@ Known
Known to have no common set bits.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
LLVM_ABI const llvm::fltSemantics & getFltSemanticForLLT(LLT Ty)
Get the appropriate floating point arithmetic semantic based on the bit size of the given scalar LLT.
scope_exit(Callable) -> scope_exit< Callable >
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
std::tuple< Value *, FPClassTest, FPClassTest > fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, FPClassTest RHSClass, bool LookThroughSrc=true)
LLVM_ABI bool getShuffleDemandedElts(int SrcWidth, ArrayRef< int > Mask, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS, bool AllowUndefElts=false)
Transform a shuffle mask's output demanded element mask into demanded element masks for the 2 operand...
constexpr unsigned MaxAnalysisRecursionDepth
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)
Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
@ Dynamic
Denotes mode unknown at compile time.
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
static uint32_t extractBits(uint64_t Val, uint32_t Hi, uint32_t Lo)
LLVM_ABI void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
This struct is a compact representation of a valid (non-zero power of two) alignment.
A special type used by analysis passes to provide an address that identifies that particular analysis...
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
static LLVM_ABI KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
static LLVM_ABI KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
static LLVM_ABI KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
bool isNonNegative() const
Returns true if this value is known to be non-negative.
bool isZero() const
Returns true if value is all zero.
static LLVM_ABI KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
static LLVM_ABI KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
static LLVM_ABI KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
LLVM_ABI KnownBits ctlz(bool ZeroIsPoison=false) const
Compute known bits for the count of leading zeros.
static LLVM_ABI KnownBits fshl(const KnownBits &LHS, const KnownBits &RHS, const APInt &Amt)
Compute known bits for fshl(LHS, RHS, Amt).
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
unsigned getBitWidth() const
Get the bit width of this value.
static LLVM_ABI KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false, bool SelfAdd=false)
Compute knownbits resulting from addition of LHS and RHS.
static LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
bool isNonZero() const
Returns true if this value is known to be non-zero.
static LLVM_ABI KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
bool isEven() const
Return if the value is known even (the low bit is 0).
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
static LLVM_ABI KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
static LLVM_ABI KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
static LLVM_ABI KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
static LLVM_ABI KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
static LLVM_ABI KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
static LLVM_ABI KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
static LLVM_ABI KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
static LLVM_ABI KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
bool isNegative() const
Returns true if this value is known to be negative.
static LLVM_ABI KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry)
Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
static KnownBits sub(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from subtraction of LHS and RHS.
static LLVM_ABI KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
static LLVM_ABI KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
static LLVM_ABI KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
static LLVM_ABI KnownBits clmul(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for clmul(LHS, RHS).
static LLVM_ABI KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
static LLVM_ABI KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
bool isAllOnes() const
Returns true if value is all one bits.
static LLVM_ABI KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.