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 assert(
MI.getNumExplicitDefs() == 1 &&
80 "expected single return generic instruction");
85 const LLT Ty = MRI.getType(R);
95 const APInt &DemandedElts,
103 LLT Ty = MRI.getType(R);
104 unsigned BitWidth = Ty.getScalarSizeInBits();
109 LLT Ty = MRI.getType(R);
110 const APInt ScalarDemandedElts(1, 1);
111 APInt DemandedElts = Ty.isFixedVector()
113 : ScalarDemandedElts;
124 switch (
MI.getOpcode()) {
128 case TargetOpcode::G_OR:
133 case TargetOpcode::G_SELECT:
138 case TargetOpcode::G_SHL: {
168[[maybe_unused]]
static void
171 <<
"] Computed for: " <<
MI <<
"[" <<
Depth <<
"] Known: 0x"
182 const APInt &DemandedElts,
188 if (
Known.isUnknown())
213 const APInt &DemandedElts,
216 unsigned Opcode =
MI.getOpcode();
217 LLT DstTy = MRI.getType(R);
231 "DemandedElt width should equal the fixed vector number of elements");
234 "DemandedElt width should be 1 for scalars or scalable vectors");
259 TL.computeKnownBitsForTargetInstr(*
this, R,
Known, DemandedElts, MRI,
262 case TargetOpcode::G_BUILD_VECTOR: {
264 Known.Zero.setAllBits();
265 Known.One.setAllBits();
267 if (!DemandedElts[
I])
276 if (
Known.isUnknown())
281 case TargetOpcode::G_SPLAT_VECTOR: {
289 case TargetOpcode::COPY:
290 case TargetOpcode::G_PHI:
291 case TargetOpcode::PHI: {
297 assert(
MI.getOperand(0).getSubReg() == 0 &&
"Is this code in SSA?");
300 for (
unsigned Idx = 1; Idx <
MI.getNumOperands(); Idx += 2) {
303 LLT SrcTy = MRI.getType(SrcReg);
311 if (SrcReg.
isVirtual() && Src.getSubReg() == 0 &&
313 APInt NowDemandedElts;
314 if (!SrcTy.isFixedVector()) {
315 NowDemandedElts =
APInt(1, 1);
318 NowDemandedElts = DemandedElts;
325 Depth + (Opcode != TargetOpcode::COPY));
330 if (
Known.isUnknown())
340 case TargetOpcode::G_STEP_VECTOR: {
341 APInt Step =
MI.getOperand(1).getCImm()->getValue();
349 const APInt MinNumElts =
355 .
umul_ov(MinNumElts, Overflow);
358 const APInt MaxValue = (MaxNumElts - 1).
umul_ov(Step, Overflow);
364 case TargetOpcode::G_CONSTANT: {
368 case TargetOpcode::G_FRAME_INDEX: {
369 int FrameIdx =
MI.getOperand(1).getIndex();
370 TL.computeKnownBitsForStackObjectPointer(
371 Known, MF, MF.getFrameInfo().getObjectAlign(FrameIdx));
374 case TargetOpcode::G_SUB: {
383 case TargetOpcode::G_XOR: {
392 case TargetOpcode::G_PTR_ADD: {
396 LLT Ty = MRI.getType(
MI.getOperand(1).getReg());
397 if (DL.isNonIntegralAddressSpace(Ty.getAddressSpace()))
401 case TargetOpcode::G_ADD: {
409 case TargetOpcode::G_AND: {
419 case TargetOpcode::G_OR: {
429 case TargetOpcode::G_MUL: {
437 case TargetOpcode::G_UMULH: {
445 case TargetOpcode::G_SMULH: {
453 case TargetOpcode::G_UAVGFLOOR: {
461 case TargetOpcode::G_UAVGCEIL: {
469 case TargetOpcode::G_SAVGFLOOR: {
477 case TargetOpcode::G_SAVGCEIL: {
485 case TargetOpcode::G_ABDU: {
493 case TargetOpcode::G_ABDS: {
502 if (SignBits1 == 1) {
508 Known.Zero.setHighBits(std::min(SignBits0, SignBits1) - 1);
511 case TargetOpcode::G_SADDSAT: {
519 case TargetOpcode::G_UADDSAT: {
527 case TargetOpcode::G_SSUBSAT: {
535 case TargetOpcode::G_USUBSAT: {
543 case TargetOpcode::G_UDIV: {
552 case TargetOpcode::G_SDIV: {
561 case TargetOpcode::G_UREM: {
573 case TargetOpcode::G_SREM: {
585 case TargetOpcode::G_SELECT: {
586 computeKnownBitsMin(
MI.getOperand(2).getReg(),
MI.getOperand(3).getReg(),
590 case TargetOpcode::G_SMIN: {
600 case TargetOpcode::G_SMAX: {
610 case TargetOpcode::G_UMIN: {
619 case TargetOpcode::G_UMAX: {
628 case TargetOpcode::G_FCMP:
629 case TargetOpcode::G_ICMP: {
632 if (TL.getBooleanContents(DstTy.
isVector(),
633 Opcode == TargetOpcode::G_FCMP) ==
636 Known.Zero.setBitsFrom(1);
639 case TargetOpcode::G_SEXT: {
647 case TargetOpcode::G_ASSERT_SEXT:
648 case TargetOpcode::G_SEXT_INREG: {
654 case TargetOpcode::G_ANYEXT: {
660 case TargetOpcode::G_LOAD: {
668 case TargetOpcode::G_SEXTLOAD:
669 case TargetOpcode::G_ZEXTLOAD: {
676 Known = Opcode == TargetOpcode::G_SEXTLOAD
681 case TargetOpcode::G_ASHR: {
690 case TargetOpcode::G_LSHR: {
699 case TargetOpcode::G_SHL: {
708 case TargetOpcode::G_ROTL:
709 case TargetOpcode::G_ROTR: {
718 unsigned Amt = MaybeAmtOp->urem(
BitWidth);
721 if (Opcode == TargetOpcode::G_ROTL)
728 case TargetOpcode::G_FSHL:
729 case TargetOpcode::G_FSHR: {
735 const APInt Amt = *MaybeAmtOp;
740 Known = Opcode == TargetOpcode::G_FSHL
745 case TargetOpcode::G_INTTOPTR:
746 case TargetOpcode::G_PTRTOINT:
751 case TargetOpcode::G_ZEXT:
752 case TargetOpcode::G_TRUNC: {
758 case TargetOpcode::G_ASSERT_ZEXT: {
762 unsigned SrcBitWidth =
MI.getOperand(2).getImm();
763 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
765 Known.Zero |= (~InMask);
769 case TargetOpcode::G_ASSERT_ALIGN: {
770 int64_t LogOfAlign =
Log2_64(
MI.getOperand(2).getImm());
775 Known.Zero.setLowBits(LogOfAlign);
776 Known.One.clearLowBits(LogOfAlign);
779 case TargetOpcode::G_MERGE_VALUES: {
780 unsigned NumOps =
MI.getNumOperands();
781 unsigned OpSize = MRI.getType(
MI.getOperand(1).getReg()).getSizeInBits();
783 for (
unsigned I = 0;
I !=
NumOps - 1; ++
I) {
786 DemandedElts,
Depth + 1);
787 Known.insertBits(SrcOpKnown,
I * OpSize);
791 case TargetOpcode::G_UNMERGE_VALUES: {
792 unsigned NumOps =
MI.getNumOperands();
794 LLT SrcTy = MRI.getType(SrcReg);
796 if (SrcTy.isVector() && SrcTy.getScalarType() != DstTy.
getScalarType())
801 for (; DstIdx !=
NumOps - 1 &&
MI.getOperand(DstIdx).
getReg() != R;
805 APInt SubDemandedElts = DemandedElts;
806 if (SrcTy.isVector()) {
809 DemandedElts.
zext(SrcTy.getNumElements()).
shl(DstIdx * DstLanes);
815 if (SrcTy.isVector())
816 Known = std::move(SrcOpKnown);
821 case TargetOpcode::G_BSWAP: {
827 case TargetOpcode::G_BITREVERSE: {
833 case TargetOpcode::G_CTPOP: {
840 Known.Zero.setBitsFrom(LowBits);
845 case TargetOpcode::G_UBFX: {
846 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
856 case TargetOpcode::G_SBFX: {
857 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
874 case TargetOpcode::G_UADDO:
875 case TargetOpcode::G_UADDE:
876 case TargetOpcode::G_SADDO:
877 case TargetOpcode::G_SADDE: {
878 if (
MI.getOperand(1).getReg() == R) {
881 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
884 Known.Zero.setBitsFrom(1);
888 assert(
MI.getOperand(0).getReg() == R &&
889 "We only compute knownbits for the sum here.");
892 if (Opcode == TargetOpcode::G_UADDE || Opcode == TargetOpcode::G_SADDE) {
896 Carry = Carry.
trunc(1);
908 case TargetOpcode::G_USUBO:
909 case TargetOpcode::G_USUBE:
910 case TargetOpcode::G_SSUBO:
911 case TargetOpcode::G_SSUBE:
912 case TargetOpcode::G_UMULO:
913 case TargetOpcode::G_SMULO: {
914 if (
MI.getOperand(1).getReg() == R) {
917 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
920 Known.Zero.setBitsFrom(1);
924 case TargetOpcode::G_CTTZ:
925 case TargetOpcode::G_CTTZ_ZERO_POISON: {
932 Known.Zero.setBitsFrom(LowBits);
935 case TargetOpcode::G_CTLZ:
936 case TargetOpcode::G_CTLZ_ZERO_POISON: {
943 Known.Zero.setBitsFrom(LowBits);
946 case TargetOpcode::G_CTLS: {
950 unsigned MaxUpperRedundantSignBits = MRI.getType(Reg).getScalarSizeInBits();
958 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
965 LLT VecVT = MRI.getType(InVec);
977 Known.Zero.setAllBits();
978 Known.One.setAllBits();
983 if (ConstEltNo && ConstEltNo->ult(NumSrcElts))
990 case TargetOpcode::G_INSERT_VECTOR_ELT: {
992 Register InVec = Insert.getVectorReg();
993 Register InVal = Insert.getElementReg();
994 Register EltNo = Insert.getIndexReg();
995 LLT VecVT = MRI.getType(InVec);
1003 bool DemandedVal =
true;
1004 APInt DemandedVecElts = DemandedElts;
1005 if (ConstEltNo && ConstEltNo->ult(NumElts)) {
1006 unsigned EltIdx = ConstEltNo->getZExtValue();
1007 DemandedVal = !!DemandedElts[EltIdx];
1010 Known.setAllConflict();
1015 if (!!DemandedVecElts) {
1021 case TargetOpcode::G_SHUFFLE_VECTOR: {
1022 APInt DemandedLHS, DemandedRHS;
1025 unsigned NumElts = MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
1027 DemandedElts, DemandedLHS, DemandedRHS))
1031 Known.Zero.setAllBits();
1032 Known.One.setAllBits();
1033 if (!!DemandedLHS) {
1039 if (
Known.isUnknown())
1041 if (!!DemandedRHS) {
1048 case TargetOpcode::G_CONCAT_VECTORS: {
1049 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
1052 Known.Zero.setAllBits();
1053 Known.One.setAllBits();
1054 unsigned NumSubVectorElts =
1055 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
1059 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
1060 if (!!DemandedSub) {
1066 if (
Known.isUnknown())
1071 case TargetOpcode::G_ABS: {
1088 APInt DemandedElts =
1102void GISelValueTracking::computeKnownFPClassForFPTrunc(
1110 KnownFPClass KnownSrc;
1111 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1116void GISelValueTracking::computeKnownFPClass(
Register R,
1117 const APInt &DemandedElts,
1121 assert(
Known.isUnknown() &&
"should not be called with known information");
1123 if (!DemandedElts) {
1131 MachineInstr &
MI = *MRI.getVRegDef(R);
1132 unsigned Opcode =
MI.getOpcode();
1133 LLT DstTy = MRI.getType(R);
1141 switch (Cst->getKind()) {
1143 auto APF = Cst->getScalarValue();
1144 Known.KnownFPClasses = APF.classify();
1145 Known.SignBit = APF.isNegative();
1150 bool SignBitAllZero =
true;
1151 bool SignBitAllOne =
true;
1153 for (
auto C : *Cst) {
1154 Known.KnownFPClasses |=
C.classify();
1156 SignBitAllZero =
false;
1158 SignBitAllOne =
false;
1161 if (SignBitAllOne != SignBitAllZero)
1162 Known.SignBit = SignBitAllOne;
1177 KnownNotFromFlags |=
fcNan;
1179 KnownNotFromFlags |=
fcInf;
1183 InterestedClasses &= ~KnownNotFromFlags;
1186 [=, &
Known] {
Known.knownNot(KnownNotFromFlags); });
1192 const MachineFunction *MF =
MI.getMF();
1196 TL.computeKnownFPClassForTargetInstr(*
this, R,
Known, DemandedElts, MRI,
1199 case TargetOpcode::G_FNEG: {
1201 computeKnownFPClass(Val, DemandedElts, InterestedClasses,
Known,
Depth + 1);
1205 case TargetOpcode::G_SELECT: {
1228 bool LookThroughFAbsFNeg = CmpLHS !=
LHS && CmpLHS !=
RHS;
1229 std::tie(TestedValue, MaskIfTrue, MaskIfFalse) =
1235 MaskIfTrue = TestedMask;
1236 MaskIfFalse = ~TestedMask;
1239 if (TestedValue ==
LHS) {
1241 FilterLHS = MaskIfTrue;
1242 }
else if (TestedValue ==
RHS) {
1244 FilterRHS = MaskIfFalse;
1247 KnownFPClass Known2;
1248 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses & FilterLHS,
Known,
1250 Known.KnownFPClasses &= FilterLHS;
1252 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses & FilterRHS,
1259 case TargetOpcode::G_FCOPYSIGN: {
1260 Register Magnitude =
MI.getOperand(1).getReg();
1263 KnownFPClass KnownSign;
1265 computeKnownFPClass(Magnitude, DemandedElts, InterestedClasses,
Known,
1267 computeKnownFPClass(Sign, DemandedElts, InterestedClasses, KnownSign,
1269 Known.copysign(KnownSign);
1272 case TargetOpcode::G_FMA:
1273 case TargetOpcode::G_STRICT_FMA:
1274 case TargetOpcode::G_FMAD: {
1287 KnownFPClass KnownSrc, KnownAddend;
1288 computeKnownFPClass(
C, DemandedElts, InterestedClasses, KnownAddend,
1290 computeKnownFPClass(
A, DemandedElts, InterestedClasses, KnownSrc,
1292 if (KnownNotFromFlags) {
1293 KnownSrc.
knownNot(KnownNotFromFlags);
1294 KnownAddend.
knownNot(KnownNotFromFlags);
1298 KnownFPClass KnownSrc[3];
1299 computeKnownFPClass(
A, DemandedElts, InterestedClasses, KnownSrc[0],
1301 if (KnownSrc[0].isUnknown())
1303 computeKnownFPClass(
B, DemandedElts, InterestedClasses, KnownSrc[1],
1305 if (KnownSrc[1].isUnknown())
1307 computeKnownFPClass(
C, DemandedElts, InterestedClasses, KnownSrc[2],
1309 if (KnownSrc[2].isUnknown())
1311 if (KnownNotFromFlags) {
1312 KnownSrc[0].
knownNot(KnownNotFromFlags);
1313 KnownSrc[1].
knownNot(KnownNotFromFlags);
1314 KnownSrc[2].
knownNot(KnownNotFromFlags);
1320 case TargetOpcode::G_FSQRT:
1321 case TargetOpcode::G_STRICT_FSQRT: {
1322 KnownFPClass KnownSrc;
1324 if (InterestedClasses &
fcNan)
1328 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1337 case TargetOpcode::G_FABS: {
1342 computeKnownFPClass(Val, DemandedElts, InterestedClasses,
Known,
1348 case TargetOpcode::G_FATAN2: {
1351 KnownFPClass KnownY, KnownX;
1352 computeKnownFPClass(
Y, DemandedElts, InterestedClasses, KnownY,
Depth + 1);
1353 computeKnownFPClass(
X, DemandedElts, InterestedClasses, KnownX,
Depth + 1);
1357 case TargetOpcode::G_FSINH: {
1359 KnownFPClass KnownSrc;
1360 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1365 case TargetOpcode::G_FCOSH: {
1367 KnownFPClass KnownSrc;
1368 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1373 case TargetOpcode::G_FTANH: {
1375 KnownFPClass KnownSrc;
1376 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1381 case TargetOpcode::G_FASIN: {
1383 KnownFPClass KnownSrc;
1384 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1389 case TargetOpcode::G_FACOS: {
1391 KnownFPClass KnownSrc;
1392 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1397 case TargetOpcode::G_FATAN: {
1399 KnownFPClass KnownSrc;
1400 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1405 case TargetOpcode::G_FTAN: {
1407 KnownFPClass KnownSrc;
1408 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1413 case TargetOpcode::G_FSIN:
1414 case TargetOpcode::G_FCOS: {
1417 KnownFPClass KnownSrc;
1418 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1421 : KnownFPClass::sin(KnownSrc);
1424 case TargetOpcode::G_FSINCOS: {
1427 KnownFPClass KnownSrc;
1428 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1430 if (R ==
MI.getOperand(0).getReg())
1436 case TargetOpcode::G_FMAXNUM:
1437 case TargetOpcode::G_FMINNUM:
1438 case TargetOpcode::G_FMINNUM_IEEE:
1439 case TargetOpcode::G_FMAXIMUM:
1440 case TargetOpcode::G_FMINIMUM:
1441 case TargetOpcode::G_FMAXNUM_IEEE:
1442 case TargetOpcode::G_FMAXIMUMNUM:
1443 case TargetOpcode::G_FMINIMUMNUM: {
1446 KnownFPClass KnownLHS, KnownRHS;
1448 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses, KnownLHS,
1450 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses, KnownRHS,
1455 case TargetOpcode::G_FMINIMUM:
1458 case TargetOpcode::G_FMAXIMUM:
1461 case TargetOpcode::G_FMINIMUMNUM:
1464 case TargetOpcode::G_FMAXIMUMNUM:
1467 case TargetOpcode::G_FMINNUM:
1468 case TargetOpcode::G_FMINNUM_IEEE:
1471 case TargetOpcode::G_FMAXNUM:
1472 case TargetOpcode::G_FMAXNUM_IEEE:
1484 case TargetOpcode::G_FCANONICALIZE: {
1486 KnownFPClass KnownSrc;
1487 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1492 DenormalMode DenormMode = MF->getDenormalMode(FPType);
1496 case TargetOpcode::G_VECREDUCE_FMAX:
1497 case TargetOpcode::G_VECREDUCE_FMIN:
1498 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1499 case TargetOpcode::G_VECREDUCE_FMINIMUM: {
1505 computeKnownFPClass(Val,
MI.getFlags(), InterestedClasses,
Depth + 1);
1507 if (!
Known.isKnownNeverNaN())
1508 Known.SignBit.reset();
1511 case TargetOpcode::G_FFLOOR:
1512 case TargetOpcode::G_FCEIL:
1513 case TargetOpcode::G_FRINT:
1514 case TargetOpcode::G_FNEARBYINT:
1515 case TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND:
1516 case TargetOpcode::G_INTRINSIC_ROUND:
1517 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
1518 case TargetOpcode::G_INTRINSIC_TRUNC: {
1520 KnownFPClass KnownSrc;
1526 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1529 bool IsTrunc = Opcode == TargetOpcode::G_INTRINSIC_TRUNC;
1534 case TargetOpcode::G_FEXP:
1535 case TargetOpcode::G_FEXP2:
1536 case TargetOpcode::G_FEXP10: {
1538 KnownFPClass KnownSrc;
1539 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1544 case TargetOpcode::G_FLOG:
1545 case TargetOpcode::G_FLOG2:
1546 case TargetOpcode::G_FLOG10: {
1561 KnownFPClass KnownSrc;
1562 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1566 DenormalMode
Mode = MF->getDenormalMode(FltSem);
1570 case TargetOpcode::G_FPOWI: {
1575 LLT ExpTy = MRI.getType(Exp);
1577 Exp, ExpTy.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1580 if (InterestedClasses &
fcNan)
1581 InterestedSrcs |=
fcNan;
1582 if (!ExponentKnownBits.
isZero()) {
1583 if (InterestedClasses &
fcInf)
1589 KnownFPClass KnownSrc;
1590 if (InterestedSrcs !=
fcNone) {
1592 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
1599 case TargetOpcode::G_FLDEXP:
1600 case TargetOpcode::G_STRICT_FLDEXP: {
1602 KnownFPClass KnownSrc;
1603 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1611 LLT ExpTy = MRI.getType(ExpReg);
1613 ExpReg, ExpTy.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1618 DenormalMode
Mode = MF->getDenormalMode(Flt);
1622 case TargetOpcode::G_FADD:
1623 case TargetOpcode::G_STRICT_FADD:
1624 case TargetOpcode::G_FSUB:
1625 case TargetOpcode::G_STRICT_FSUB: {
1628 bool IsAdd = (Opcode == TargetOpcode::G_FADD ||
1629 Opcode == TargetOpcode::G_STRICT_FADD);
1633 bool WantNaN = (InterestedClasses &
fcNan) !=
fcNone;
1636 if (!WantNaN && !WantNegative && !WantNegZero) {
1646 if (InterestedClasses &
fcNan)
1647 InterestedSrcs |=
fcInf;
1651 KnownFPClass KnownSelf;
1652 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownSelf,
1658 KnownFPClass KnownLHS, KnownRHS;
1659 computeKnownFPClass(
RHS, DemandedElts, InterestedSrcs, KnownRHS,
Depth + 1);
1663 WantNegZero || !IsAdd) {
1666 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownLHS,
1676 case TargetOpcode::G_FMUL:
1677 case TargetOpcode::G_STRICT_FMUL: {
1685 KnownFPClass KnownSrc;
1692 KnownFPClass KnownLHS;
1696 KnownFPClass KnownLHS, KnownRHS;
1712 case TargetOpcode::G_FDIV:
1713 case TargetOpcode::G_FREM: {
1717 if (Opcode == TargetOpcode::G_FREM)
1724 if (Opcode == TargetOpcode::G_FDIV) {
1725 const bool WantNan = (InterestedClasses &
fcNan) !=
fcNone;
1731 KnownFPClass KnownSrc;
1732 computeKnownFPClass(
LHS, DemandedElts,
1737 const bool WantNan = (InterestedClasses &
fcNan) !=
fcNone;
1743 KnownFPClass KnownSrc;
1744 computeKnownFPClass(
LHS, DemandedElts,
1752 const bool WantNan = (InterestedClasses &
fcNan) !=
fcNone;
1754 const bool WantPositive = Opcode == TargetOpcode::G_FREM &&
1756 if (!WantNan && !WantNegative && !WantPositive) {
1760 KnownFPClass KnownLHS, KnownRHS;
1763 KnownRHS,
Depth + 1);
1769 if (KnowSomethingUseful || WantPositive) {
1773 if (Opcode == TargetOpcode::G_FDIV) {
1797 case TargetOpcode::G_FFREXP: {
1799 if (R !=
MI.getOperand(0).getReg())
1802 KnownFPClass KnownSrc;
1803 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1810 case TargetOpcode::G_FPEXT: {
1812 KnownFPClass KnownSrc;
1813 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1818 LLT SrcTy = MRI.getType(Src).getScalarType();
1824 case TargetOpcode::G_FPTRUNC: {
1825 computeKnownFPClassForFPTrunc(
MI, DemandedElts, InterestedClasses,
Known,
1829 case TargetOpcode::G_SITOFP:
1830 case TargetOpcode::G_UITOFP: {
1841 if (Opcode == TargetOpcode::G_UITOFP)
1842 Known.signBitMustBeZero();
1849 LLT Ty = MRI.getType(Val);
1851 Val, Ty.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1857 if (Opcode == TargetOpcode::G_SITOFP) {
1862 Known.signBitMustBeZero();
1864 Known.signBitMustBeOne();
1867 if (InterestedClasses &
fcInf) {
1874 if (Opcode == TargetOpcode::G_UITOFP)
1888 case TargetOpcode::G_BUILD_VECTOR:
1889 case TargetOpcode::G_CONCAT_VECTORS: {
1896 for (
unsigned Idx = 0; Idx <
Merge.getNumSources(); ++Idx) {
1898 bool NeedsElt = DemandedElts[Idx];
1904 computeKnownFPClass(Src,
Known, InterestedClasses,
Depth + 1);
1907 KnownFPClass Known2;
1908 computeKnownFPClass(Src, Known2, InterestedClasses,
Depth + 1);
1913 if (
Known.isUnknown())
1920 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1930 LLT VecTy = MRI.getType(Vec);
1935 if (CIdx && CIdx->ult(NumElts))
1937 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses,
Known,
1943 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1949 LLT VecTy = MRI.getType(Vec);
1957 APInt DemandedVecElts = DemandedElts;
1958 bool NeedsElt =
true;
1960 if (CIdx && CIdx->ult(NumElts)) {
1961 DemandedVecElts.
clearBit(CIdx->getZExtValue());
1962 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1967 computeKnownFPClass(Elt,
Known, InterestedClasses,
Depth + 1);
1969 if (
Known.isUnknown())
1976 if (!DemandedVecElts.
isZero()) {
1977 KnownFPClass Known2;
1978 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2,
1985 case TargetOpcode::G_SHUFFLE_VECTOR: {
1989 APInt DemandedLHS, DemandedRHS;
1991 assert(DemandedElts == APInt(1, 1));
1992 DemandedLHS = DemandedRHS = DemandedElts;
1994 unsigned NumElts = MRI.getType(Shuf.
getSrc1Reg()).getNumElements();
1996 DemandedLHS, DemandedRHS)) {
2002 if (!!DemandedLHS) {
2004 computeKnownFPClass(
LHS, DemandedLHS, InterestedClasses,
Known,
2008 if (
Known.isUnknown())
2014 if (!!DemandedRHS) {
2015 KnownFPClass Known2;
2017 computeKnownFPClass(
RHS, DemandedRHS, InterestedClasses, Known2,
2023 case TargetOpcode::G_PHI: {
2032 for (
unsigned Idx = 1; Idx <
MI.getNumOperands(); Idx += 2) {
2033 const MachineOperand &Src =
MI.getOperand(Idx);
2036 computeKnownFPClass(SrcReg, DemandedElts, InterestedClasses,
Known,
2040 KnownFPClass Known2;
2041 computeKnownFPClass(SrcReg, DemandedElts, InterestedClasses, Known2,
2045 if (
Known.isUnknown())
2050 case TargetOpcode::COPY: {
2053 if (!Src.isVirtual())
2056 computeKnownFPClass(Src, DemandedElts, InterestedClasses,
Known,
Depth + 1);
2067 computeKnownFPClass(R, DemandedElts, InterestedClasses, KnownClasses,
Depth);
2068 return KnownClasses;
2074 computeKnownFPClass(R,
Known, InterestedClasses,
Depth);
2082 InterestedClasses &=
~fcNan;
2084 InterestedClasses &=
~fcInf;
2087 computeKnownFPClass(R, DemandedElts, InterestedClasses,
Depth);
2090 Result.KnownFPClasses &=
~fcNan;
2092 Result.KnownFPClasses &=
~fcInf;
2098 LLT Ty = MRI.getType(R);
2099 APInt DemandedElts =
2101 return computeKnownFPClass(R, DemandedElts, Flags, InterestedClasses,
Depth);
2116 switch (
DefMI->getOpcode()) {
2119 case TargetOpcode::G_FADD:
2120 case TargetOpcode::G_STRICT_FADD:
2121 case TargetOpcode::G_FSUB:
2122 case TargetOpcode::G_STRICT_FSUB:
2123 case TargetOpcode::G_FMUL:
2124 case TargetOpcode::G_STRICT_FMUL:
2125 case TargetOpcode::G_FDIV:
2126 case TargetOpcode::G_FREM:
2127 case TargetOpcode::G_FMA:
2128 case TargetOpcode::G_STRICT_FMA:
2129 case TargetOpcode::G_FMAD:
2130 case TargetOpcode::G_FSQRT:
2131 case TargetOpcode::G_STRICT_FSQRT:
2135 case TargetOpcode::G_FSIN:
2136 case TargetOpcode::G_FCOS:
2137 case TargetOpcode::G_FSINCOS:
2138 case TargetOpcode::G_FTAN:
2139 case TargetOpcode::G_FASIN:
2140 case TargetOpcode::G_FACOS:
2141 case TargetOpcode::G_FATAN:
2142 case TargetOpcode::G_FATAN2:
2143 case TargetOpcode::G_FSINH:
2144 case TargetOpcode::G_FCOSH:
2145 case TargetOpcode::G_FTANH:
2146 case TargetOpcode::G_FEXP:
2147 case TargetOpcode::G_FEXP2:
2148 case TargetOpcode::G_FEXP10:
2149 case TargetOpcode::G_FLOG:
2150 case TargetOpcode::G_FLOG2:
2151 case TargetOpcode::G_FLOG10:
2152 case TargetOpcode::G_FPOWI:
2153 case TargetOpcode::G_FLDEXP:
2154 case TargetOpcode::G_STRICT_FLDEXP:
2155 case TargetOpcode::G_FFREXP:
2156 case TargetOpcode::G_INTRINSIC_TRUNC:
2157 case TargetOpcode::G_INTRINSIC_ROUND:
2158 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
2159 case TargetOpcode::G_FFLOOR:
2160 case TargetOpcode::G_FCEIL:
2161 case TargetOpcode::G_FRINT:
2162 case TargetOpcode::G_FNEARBYINT:
2163 case TargetOpcode::G_FPEXT:
2164 case TargetOpcode::G_FPTRUNC:
2165 case TargetOpcode::G_FCANONICALIZE:
2166 case TargetOpcode::G_FMINNUM:
2167 case TargetOpcode::G_FMAXNUM:
2168 case TargetOpcode::G_FMINNUM_IEEE:
2169 case TargetOpcode::G_FMAXNUM_IEEE:
2170 case TargetOpcode::G_FMINIMUM:
2171 case TargetOpcode::G_FMAXIMUM:
2172 case TargetOpcode::G_FMINIMUMNUM:
2173 case TargetOpcode::G_FMAXIMUMNUM:
2187unsigned GISelValueTracking::computeNumSignBitsMin(
Register Src0,
Register Src1,
2188 const APInt &DemandedElts,
2192 if (Src1SignBits == 1)
2209 case TargetOpcode::G_SEXTLOAD:
2212 case TargetOpcode::G_ZEXTLOAD:
2225 const APInt &DemandedElts,
2228 unsigned Opcode =
MI.getOpcode();
2230 if (Opcode == TargetOpcode::G_CONSTANT)
2231 return MI.getOperand(1).getCImm()->getValue().getNumSignBits();
2239 LLT DstTy = MRI.getType(R);
2249 unsigned FirstAnswer = 1;
2251 case TargetOpcode::COPY: {
2253 if (Src.getReg().isVirtual() && Src.getSubReg() == 0 &&
2254 MRI.getType(Src.getReg()).isValid()) {
2261 case TargetOpcode::G_SEXT: {
2263 LLT SrcTy = MRI.getType(Src);
2267 case TargetOpcode::G_ASSERT_SEXT:
2268 case TargetOpcode::G_SEXT_INREG: {
2271 unsigned SrcBits =
MI.getOperand(2).getImm();
2272 unsigned InRegBits = TyBits - SrcBits + 1;
2276 case TargetOpcode::G_LOAD: {
2283 case TargetOpcode::G_SEXTLOAD: {
2298 case TargetOpcode::G_ZEXTLOAD: {
2313 case TargetOpcode::G_AND:
2314 case TargetOpcode::G_OR:
2315 case TargetOpcode::G_XOR: {
2317 unsigned Src1NumSignBits =
2319 if (Src1NumSignBits != 1) {
2321 unsigned Src2NumSignBits =
2323 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits);
2327 case TargetOpcode::G_ASHR: {
2332 FirstAnswer = std::min<uint64_t>(FirstAnswer + *
C, TyBits);
2335 case TargetOpcode::G_SHL: {
2338 if (std::optional<ConstantRange> ShAmtRange =
2340 uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
2341 uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
2351 if (ExtOpc == TargetOpcode::G_SEXT || ExtOpc == TargetOpcode::G_ZEXT ||
2352 ExtOpc == TargetOpcode::G_ANYEXT) {
2353 LLT ExtTy = MRI.getType(Src1);
2355 LLT ExtendeeTy = MRI.getType(Extendee);
2359 if (SizeDiff <= MinShAmt) {
2363 return Tmp - MaxShAmt;
2369 return Tmp - MaxShAmt;
2373 case TargetOpcode::G_SREM: {
2381 case TargetOpcode::G_TRUNC: {
2383 LLT SrcTy = MRI.getType(Src);
2387 unsigned NumSrcBits = SrcTy.getScalarSizeInBits();
2389 if (NumSrcSignBits > (NumSrcBits - DstTyBits))
2390 return NumSrcSignBits - (NumSrcBits - DstTyBits);
2393 case TargetOpcode::G_SELECT: {
2394 return computeNumSignBitsMin(
MI.getOperand(2).getReg(),
2395 MI.getOperand(3).getReg(), DemandedElts,
2398 case TargetOpcode::G_SMIN:
2399 case TargetOpcode::G_SMAX:
2400 case TargetOpcode::G_UMIN:
2401 case TargetOpcode::G_UMAX:
2403 return computeNumSignBitsMin(
MI.getOperand(1).getReg(),
2404 MI.getOperand(2).getReg(), DemandedElts,
2406 case TargetOpcode::G_SADDO:
2407 case TargetOpcode::G_SADDE:
2408 case TargetOpcode::G_UADDO:
2409 case TargetOpcode::G_UADDE:
2410 case TargetOpcode::G_SSUBO:
2411 case TargetOpcode::G_SSUBE:
2412 case TargetOpcode::G_USUBO:
2413 case TargetOpcode::G_USUBE:
2414 case TargetOpcode::G_SMULO:
2415 case TargetOpcode::G_UMULO: {
2419 if (
MI.getOperand(1).getReg() == R) {
2420 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
2427 case TargetOpcode::G_SUB: {
2429 unsigned Src2NumSignBits =
2431 if (Src2NumSignBits == 1)
2441 if ((Known2.
Zero | 1).isAllOnes())
2448 FirstAnswer = Src2NumSignBits;
2455 unsigned Src1NumSignBits =
2457 if (Src1NumSignBits == 1)
2462 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2465 case TargetOpcode::G_ADD: {
2467 unsigned Src2NumSignBits =
2469 if (Src2NumSignBits <= 2)
2473 unsigned Src1NumSignBits =
2475 if (Src1NumSignBits == 1)
2484 if ((Known1.
Zero | 1).isAllOnes())
2490 FirstAnswer = Src1NumSignBits;
2499 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2502 case TargetOpcode::G_FCMP:
2503 case TargetOpcode::G_ICMP: {
2504 bool IsFP = Opcode == TargetOpcode::G_FCMP;
2507 auto BC = TL.getBooleanContents(DstTy.
isVector(), IsFP);
2514 case TargetOpcode::G_BUILD_VECTOR: {
2516 FirstAnswer = TyBits;
2517 APInt SingleDemandedElt(1, 1);
2519 if (!DemandedElts[
I])
2524 FirstAnswer = std::min(FirstAnswer, Tmp2);
2527 if (FirstAnswer == 1)
2532 case TargetOpcode::G_CONCAT_VECTORS: {
2533 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
2535 FirstAnswer = TyBits;
2538 unsigned NumSubVectorElts =
2539 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
2542 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
2547 FirstAnswer = std::min(FirstAnswer, Tmp2);
2550 if (FirstAnswer == 1)
2555 case TargetOpcode::G_SHUFFLE_VECTOR: {
2558 APInt DemandedLHS, DemandedRHS;
2560 unsigned NumElts = MRI.getType(Src1).getNumElements();
2562 DemandedElts, DemandedLHS, DemandedRHS))
2568 if (FirstAnswer == 1)
2570 if (!!DemandedRHS) {
2573 FirstAnswer = std::min(FirstAnswer, Tmp2);
2577 case TargetOpcode::G_SPLAT_VECTOR: {
2581 unsigned NumSrcBits = MRI.getType(Src).getSizeInBits();
2582 if (NumSrcSignBits > (NumSrcBits - TyBits))
2583 return NumSrcSignBits - (NumSrcBits - TyBits);
2586 case TargetOpcode::G_INTRINSIC:
2587 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
2588 case TargetOpcode::G_INTRINSIC_CONVERGENT:
2589 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
2592 TL.computeNumSignBitsForTargetInstr(*
this, R, DemandedElts, MRI,
Depth);
2594 FirstAnswer = std::max(FirstAnswer, NumBits);
2602 return std::max(FirstAnswer,
Known.countMinSignBits());
2606 LLT Ty = MRI.getType(R);
2607 APInt DemandedElts =
2616 unsigned Opcode =
MI.getOpcode();
2618 LLT Ty = MRI.getType(R);
2619 unsigned BitWidth = Ty.getScalarSizeInBits();
2621 if (Opcode == TargetOpcode::G_CONSTANT) {
2622 const APInt &ShAmt =
MI.getOperand(1).getCImm()->getValue();
2624 return std::nullopt;
2628 if (Opcode == TargetOpcode::G_BUILD_VECTOR) {
2629 const APInt *MinAmt =
nullptr, *MaxAmt =
nullptr;
2630 for (
unsigned I = 0, E =
MI.getNumOperands() - 1;
I != E; ++
I) {
2631 if (!DemandedElts[
I])
2634 if (
Op->getOpcode() != TargetOpcode::G_CONSTANT) {
2635 MinAmt = MaxAmt =
nullptr;
2639 const APInt &ShAmt =
Op->getOperand(1).getCImm()->getValue();
2641 return std::nullopt;
2642 if (!MinAmt || MinAmt->
ugt(ShAmt))
2644 if (!MaxAmt || MaxAmt->ult(ShAmt))
2647 assert(((!MinAmt && !MaxAmt) || (MinAmt && MaxAmt)) &&
2648 "Failed to find matching min/max shift amounts");
2649 if (MinAmt && MaxAmt)
2659 return std::nullopt;
2664 if (std::optional<ConstantRange> AmtRange =
2666 return AmtRange->getUnsignedMin().getZExtValue();
2667 return std::nullopt;
2685 Info = std::make_unique<GISelValueTracking>(MF, MaxDepth);
2697 return Result(MF, MaxDepth);
2712 if (!MO.isReg() || MO.getReg().isPhysical())
2715 if (!MRI.getType(Reg).isValid())
2718 unsigned SignedBits = VTA.computeNumSignBits(Reg);
2719 OS <<
" " << MO <<
" KnownBits:" <<
Known <<
" SignBits:" << SignedBits
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< 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 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
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > & Cond
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 make_scope_exit function, which executes user-defined cleanup logic at scope ex...
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 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.
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 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 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.
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
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)
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.
APInt getKnownOnes(Register R)
APInt getKnownZeroes(Register R)
void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
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
Register getSrc2Reg() const
Register getSrc1Reg() const
ArrayRef< int > getMask() const
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 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,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
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.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
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)
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
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.
DWARFExpression::Operation Op
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.
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
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.
void setAllZero()
Make all bits known to be zero and discard any previous information.
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).
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
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 sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
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 fshr(const KnownBits &LHS, const KnownBits &RHS, const APInt &Amt)
Compute known bits for fshr(LHS, RHS, Amt).
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.
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
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.
KnownBits anyext(unsigned BitWidth) const
Return known bits for an "any" extension of the value we're tracking, where we don't know anything ab...
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.
FPClassTest KnownFPClasses
Floating-point classes the value could be one of.
bool isKnownNeverInfinity() const
Return true if it's known this can never be an infinity.
bool cannotBeOrderedGreaterThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never greater tha...
static LLVM_ABI KnownFPClass sin(const KnownFPClass &Src)
Report known values for sin.
static LLVM_ABI KnownFPClass fdiv_self(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fdiv x, x.
static constexpr FPClassTest OrderedGreaterThanZeroMask
static constexpr FPClassTest OrderedLessThanZeroMask
void knownNot(FPClassTest RuleOut)
static LLVM_ABI KnownFPClass fmul(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fmul.
static LLVM_ABI KnownFPClass fadd_self(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fadd x, x.
static KnownFPClass square(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
static LLVM_ABI KnownFPClass fsub(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fsub.
static LLVM_ABI KnownFPClass canonicalize(const KnownFPClass &Src, DenormalMode DenormMode=DenormalMode::getDynamic())
Apply the canonicalize intrinsic to this value.
LLVM_ABI bool isKnownNeverLogicalZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a zero.
static LLVM_ABI KnownFPClass log(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for log/log2/log10.
static LLVM_ABI KnownFPClass atan(const KnownFPClass &Src)
Report known values for atan.
static LLVM_ABI KnownFPClass atan2(const KnownFPClass &LHS, const KnownFPClass &RHS)
Report known values for atan2.
static LLVM_ABI KnownFPClass fdiv(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fdiv.
static LLVM_ABI KnownFPClass roundToIntegral(const KnownFPClass &Src, bool IsTrunc, bool IsMultiUnitFPType)
Propagate known class for rounding intrinsics (trunc, floor, ceil, rint, nearbyint,...
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 minMaxLike(const KnownFPClass &LHS, const KnownFPClass &RHS, MinMaxKind Kind, DenormalMode DenormMode=DenormalMode::getDynamic())
static LLVM_ABI KnownFPClass exp(const KnownFPClass &Src)
Report known values for exp, exp2 and exp10.
static LLVM_ABI KnownFPClass frexp_mant(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for mantissa component of frexp.
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.
bool isKnownNever(FPClassTest Mask) const
Return true if it's known this can never be one of the mask entries.
static LLVM_ABI KnownFPClass fpext(const KnownFPClass &KnownSrc, const fltSemantics &DstTy, const fltSemantics &SrcTy)
Propagate known class for fpext.
static LLVM_ABI KnownFPClass fma(const KnownFPClass &LHS, const KnownFPClass &RHS, const KnownFPClass &Addend, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fma.
static LLVM_ABI KnownFPClass tan(const KnownFPClass &Src)
Report known values for tan.
static LLVM_ABI KnownFPClass fptrunc(const KnownFPClass &KnownSrc)
Propagate known class for fptrunc.
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 sqrt(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for sqrt.
static LLVM_ABI KnownFPClass fadd(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fadd.
static LLVM_ABI KnownFPClass fma_square(const KnownFPClass &Squared, const KnownFPClass &Addend, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fma squared, squared, addend.
static LLVM_ABI KnownFPClass acos(const KnownFPClass &Src)
Report known values for acos.
static LLVM_ABI KnownFPClass frem_self(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for frem.
static LLVM_ABI KnownFPClass powi(const KnownFPClass &Src, const KnownBits &N)
Propagate known class for powi.
static LLVM_ABI KnownFPClass ldexp(const KnownFPClass &Src, const APInt &ConstantRangeMin, const APInt &ConstantRangeMax, const fltSemantics &Flt, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for ldexp, assuming the exponent is known to be within [ConstantRangeMin,...
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.