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();
116[[maybe_unused]]
static void
119 <<
"] Computed for: " <<
MI <<
"[" <<
Depth <<
"] Known: 0x"
130 const APInt &DemandedElts,
161 const APInt &DemandedElts,
164 unsigned Opcode =
MI.getOpcode();
165 LLT DstTy = MRI.getType(R);
179 "DemandedElt width should equal the fixed vector number of elements");
182 "DemandedElt width should be 1 for scalars or scalable vectors");
207 TL.computeKnownBitsForTargetInstr(*
this, R, Known, DemandedElts, MRI,
210 case TargetOpcode::G_BUILD_VECTOR: {
215 if (!DemandedElts[
I])
229 case TargetOpcode::G_SPLAT_VECTOR: {
237 case TargetOpcode::COPY:
238 case TargetOpcode::G_PHI:
239 case TargetOpcode::PHI: {
245 assert(
MI.getOperand(0).getSubReg() == 0 &&
"Is this code in SSA?");
248 for (
unsigned Idx = 1; Idx <
MI.getNumOperands(); Idx += 2) {
251 LLT SrcTy = MRI.getType(SrcReg);
259 if (SrcReg.
isVirtual() && Src.getSubReg() == 0 &&
261 APInt NowDemandedElts;
262 if (!SrcTy.isFixedVector()) {
263 NowDemandedElts =
APInt(1, 1);
266 NowDemandedElts = DemandedElts;
273 Depth + (Opcode != TargetOpcode::COPY));
288 case TargetOpcode::G_CONSTANT: {
292 case TargetOpcode::G_FRAME_INDEX: {
293 int FrameIdx =
MI.getOperand(1).getIndex();
294 TL.computeKnownBitsForFrameIndex(FrameIdx, Known, MF);
297 case TargetOpcode::G_SUB: {
305 case TargetOpcode::G_XOR: {
314 case TargetOpcode::G_PTR_ADD: {
318 LLT Ty = MRI.getType(
MI.getOperand(1).getReg());
319 if (DL.isNonIntegralAddressSpace(Ty.getAddressSpace()))
323 case TargetOpcode::G_ADD: {
331 case TargetOpcode::G_AND: {
341 case TargetOpcode::G_OR: {
351 case TargetOpcode::G_MUL: {
359 case TargetOpcode::G_UMULH: {
367 case TargetOpcode::G_SMULH: {
375 case TargetOpcode::G_UDIV: {
384 case TargetOpcode::G_SDIV: {
393 case TargetOpcode::G_SELECT: {
394 computeKnownBitsMin(
MI.getOperand(2).getReg(),
MI.getOperand(3).getReg(),
395 Known, DemandedElts,
Depth + 1);
398 case TargetOpcode::G_SMIN: {
408 case TargetOpcode::G_SMAX: {
418 case TargetOpcode::G_UMIN: {
427 case TargetOpcode::G_UMAX: {
436 case TargetOpcode::G_FCMP:
437 case TargetOpcode::G_ICMP: {
440 if (TL.getBooleanContents(DstTy.
isVector(),
441 Opcode == TargetOpcode::G_FCMP) ==
447 case TargetOpcode::G_SEXT: {
455 case TargetOpcode::G_ASSERT_SEXT:
456 case TargetOpcode::G_SEXT_INREG: {
459 Known = Known.
sextInReg(
MI.getOperand(2).getImm());
462 case TargetOpcode::G_ANYEXT: {
468 case TargetOpcode::G_LOAD: {
476 case TargetOpcode::G_SEXTLOAD:
477 case TargetOpcode::G_ZEXTLOAD: {
484 Known = Opcode == TargetOpcode::G_SEXTLOAD
489 case TargetOpcode::G_ASHR: {
498 case TargetOpcode::G_LSHR: {
507 case TargetOpcode::G_SHL: {
516 case TargetOpcode::G_ROTL:
517 case TargetOpcode::G_ROTR: {
518 MachineInstr *AmtOpMI = MRI.getVRegDef(
MI.getOperand(2).getReg());
526 unsigned Amt = MaybeAmtOp->urem(
BitWidth);
529 if (Opcode == TargetOpcode::G_ROTL)
536 case TargetOpcode::G_INTTOPTR:
537 case TargetOpcode::G_PTRTOINT:
542 case TargetOpcode::G_ZEXT:
543 case TargetOpcode::G_TRUNC: {
549 case TargetOpcode::G_ASSERT_ZEXT: {
553 unsigned SrcBitWidth =
MI.getOperand(2).getImm();
554 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
556 Known.
Zero |= (~InMask);
557 Known.
One &= (~Known.Zero);
560 case TargetOpcode::G_ASSERT_ALIGN: {
561 int64_t LogOfAlign =
Log2_64(
MI.getOperand(2).getImm());
570 case TargetOpcode::G_MERGE_VALUES: {
571 unsigned NumOps =
MI.getNumOperands();
572 unsigned OpSize = MRI.getType(
MI.getOperand(1).getReg()).getSizeInBits();
574 for (
unsigned I = 0;
I !=
NumOps - 1; ++
I) {
577 DemandedElts,
Depth + 1);
582 case TargetOpcode::G_UNMERGE_VALUES: {
583 unsigned NumOps =
MI.getNumOperands();
585 LLT SrcTy = MRI.getType(SrcReg);
587 if (SrcTy.isVector() && SrcTy.getScalarType() != DstTy.
getScalarType())
592 for (; DstIdx !=
NumOps - 1 &&
MI.getOperand(DstIdx).
getReg() != R;
596 APInt SubDemandedElts = DemandedElts;
597 if (SrcTy.isVector()) {
600 DemandedElts.
zext(SrcTy.getNumElements()).
shl(DstIdx * DstLanes);
606 if (SrcTy.isVector())
607 Known = std::move(SrcOpKnown);
612 case TargetOpcode::G_BSWAP: {
618 case TargetOpcode::G_BITREVERSE: {
624 case TargetOpcode::G_CTPOP: {
636 case TargetOpcode::G_UBFX: {
637 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
647 case TargetOpcode::G_SBFX: {
648 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
665 case TargetOpcode::G_UADDO:
666 case TargetOpcode::G_UADDE:
667 case TargetOpcode::G_SADDO:
668 case TargetOpcode::G_SADDE: {
669 if (
MI.getOperand(1).getReg() == R) {
672 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
679 assert(
MI.getOperand(0).getReg() == R &&
680 "We only compute knownbits for the sum here.");
683 if (Opcode == TargetOpcode::G_UADDE || Opcode == TargetOpcode::G_SADDE) {
687 Carry = Carry.
trunc(1);
699 case TargetOpcode::G_USUBO:
700 case TargetOpcode::G_USUBE:
701 case TargetOpcode::G_SSUBO:
702 case TargetOpcode::G_SSUBE:
703 case TargetOpcode::G_UMULO:
704 case TargetOpcode::G_SMULO: {
705 if (
MI.getOperand(1).getReg() == R) {
708 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
715 case TargetOpcode::G_CTTZ:
716 case TargetOpcode::G_CTTZ_ZERO_UNDEF: {
726 case TargetOpcode::G_CTLZ:
727 case TargetOpcode::G_CTLZ_ZERO_UNDEF: {
737 case TargetOpcode::G_CTLS: {
741 unsigned MaxUpperRedundantSignBits = MRI.getType(Reg).getScalarSizeInBits();
746 Known =
Range.toKnownBits();
749 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
756 LLT VecVT = MRI.getType(InVec);
774 if (ConstEltNo && ConstEltNo->ult(NumSrcElts))
781 case TargetOpcode::G_SHUFFLE_VECTOR: {
782 APInt DemandedLHS, DemandedRHS;
785 unsigned NumElts = MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
787 DemandedElts, DemandedLHS, DemandedRHS))
808 case TargetOpcode::G_CONCAT_VECTORS: {
809 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
814 unsigned NumSubVectorElts =
815 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
819 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
831 case TargetOpcode::G_ABS: {
845 Ty = Ty.getScalarType();
854 LLT Ty = MRI.getType(R);
857 computeKnownFPClass(R, DemandedElts, InterestedClasses, Known,
Depth);
860void GISelValueTracking::computeKnownFPClassForFPTrunc(
868 KnownFPClass KnownSrc;
869 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
882void GISelValueTracking::computeKnownFPClass(
Register R,
883 const APInt &DemandedElts,
887 assert(Known.
isUnknown() &&
"should not be called with known information");
897 MachineInstr &
MI = *MRI.getVRegDef(R);
898 unsigned Opcode =
MI.getOpcode();
899 LLT DstTy = MRI.getType(R);
907 switch (Cst->getKind()) {
909 auto APF = Cst->getScalarValue();
911 Known.
SignBit = APF.isNegative();
916 bool SignBitAllZero =
true;
917 bool SignBitAllOne =
true;
919 for (
auto C : *Cst) {
922 SignBitAllZero =
false;
924 SignBitAllOne =
false;
927 if (SignBitAllOne != SignBitAllZero)
943 KnownNotFromFlags |=
fcNan;
945 KnownNotFromFlags |=
fcInf;
949 InterestedClasses &= ~KnownNotFromFlags;
952 [=, &Known] { Known.
knownNot(KnownNotFromFlags); });
958 const MachineFunction *MF =
MI.getMF();
962 TL.computeKnownFPClassForTargetInstr(*
this, R, Known, DemandedElts, MRI,
965 case TargetOpcode::G_FNEG: {
967 computeKnownFPClass(Val, DemandedElts, InterestedClasses, Known,
Depth + 1);
971 case TargetOpcode::G_SELECT: {
994 bool LookThroughFAbsFNeg = CmpLHS !=
LHS && CmpLHS !=
RHS;
995 std::tie(TestedValue, MaskIfTrue, MaskIfFalse) =
1001 MaskIfTrue = TestedMask;
1002 MaskIfFalse = ~TestedMask;
1005 if (TestedValue ==
LHS) {
1007 FilterLHS = MaskIfTrue;
1008 }
else if (TestedValue ==
RHS) {
1010 FilterRHS = MaskIfFalse;
1013 KnownFPClass Known2;
1014 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses & FilterLHS, Known,
1018 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses & FilterRHS,
1025 case TargetOpcode::G_FCOPYSIGN: {
1026 Register Magnitude =
MI.getOperand(1).getReg();
1029 KnownFPClass KnownSign;
1031 computeKnownFPClass(Magnitude, DemandedElts, InterestedClasses, Known,
1033 computeKnownFPClass(Sign, DemandedElts, InterestedClasses, KnownSign,
1038 case TargetOpcode::G_FMA:
1039 case TargetOpcode::G_STRICT_FMA:
1040 case TargetOpcode::G_FMAD: {
1055 KnownFPClass KnownAddend;
1056 computeKnownFPClass(
C, DemandedElts, InterestedClasses, KnownAddend,
1063 case TargetOpcode::G_FSQRT:
1064 case TargetOpcode::G_STRICT_FSQRT: {
1065 KnownFPClass KnownSrc;
1067 if (InterestedClasses &
fcNan)
1072 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1087 case TargetOpcode::G_FABS: {
1092 computeKnownFPClass(Val, DemandedElts, InterestedClasses, Known,
1098 case TargetOpcode::G_FSIN:
1099 case TargetOpcode::G_FCOS:
1100 case TargetOpcode::G_FSINCOS: {
1103 KnownFPClass KnownSrc;
1105 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1113 case TargetOpcode::G_FMAXNUM:
1114 case TargetOpcode::G_FMINNUM:
1115 case TargetOpcode::G_FMINNUM_IEEE:
1116 case TargetOpcode::G_FMAXIMUM:
1117 case TargetOpcode::G_FMINIMUM:
1118 case TargetOpcode::G_FMAXNUM_IEEE:
1119 case TargetOpcode::G_FMAXIMUMNUM:
1120 case TargetOpcode::G_FMINIMUMNUM: {
1123 KnownFPClass KnownLHS, KnownRHS;
1125 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses, KnownLHS,
1127 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses, KnownRHS,
1131 Known = KnownLHS | KnownRHS;
1134 if (NeverNaN && (Opcode == TargetOpcode::G_FMINNUM ||
1135 Opcode == TargetOpcode::G_FMAXNUM ||
1136 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1137 Opcode == TargetOpcode::G_FMAXIMUMNUM))
1140 if (Opcode == TargetOpcode::G_FMAXNUM ||
1141 Opcode == TargetOpcode::G_FMAXIMUMNUM ||
1142 Opcode == TargetOpcode::G_FMAXNUM_IEEE) {
1150 }
else if (Opcode == TargetOpcode::G_FMAXIMUM) {
1156 }
else if (Opcode == TargetOpcode::G_FMINNUM ||
1157 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1158 Opcode == TargetOpcode::G_FMINNUM_IEEE) {
1166 }
else if (Opcode == TargetOpcode::G_FMINIMUM) {
1198 }
else if ((Opcode == TargetOpcode::G_FMAXIMUM ||
1199 Opcode == TargetOpcode::G_FMINIMUM) ||
1200 Opcode == TargetOpcode::G_FMAXIMUMNUM ||
1201 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1202 Opcode == TargetOpcode::G_FMAXNUM_IEEE ||
1203 Opcode == TargetOpcode::G_FMINNUM_IEEE ||
1209 if ((Opcode == TargetOpcode::G_FMAXIMUM ||
1210 Opcode == TargetOpcode::G_FMAXNUM ||
1211 Opcode == TargetOpcode::G_FMAXIMUMNUM ||
1212 Opcode == TargetOpcode::G_FMAXNUM_IEEE) &&
1215 else if ((Opcode == TargetOpcode::G_FMINIMUM ||
1216 Opcode == TargetOpcode::G_FMINNUM ||
1217 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1218 Opcode == TargetOpcode::G_FMINNUM_IEEE) &&
1225 case TargetOpcode::G_FCANONICALIZE: {
1227 KnownFPClass KnownSrc;
1228 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1250 DenormalMode DenormMode = MF->getDenormalMode(FPType);
1269 case TargetOpcode::G_VECREDUCE_FMAX:
1270 case TargetOpcode::G_VECREDUCE_FMIN:
1271 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1272 case TargetOpcode::G_VECREDUCE_FMINIMUM: {
1278 computeKnownFPClass(Val,
MI.getFlags(), InterestedClasses,
Depth + 1);
1284 case TargetOpcode::G_TRUNC:
1285 case TargetOpcode::G_FFLOOR:
1286 case TargetOpcode::G_FCEIL:
1287 case TargetOpcode::G_FRINT:
1288 case TargetOpcode::G_FNEARBYINT:
1289 case TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND:
1290 case TargetOpcode::G_INTRINSIC_ROUND: {
1292 KnownFPClass KnownSrc;
1298 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1315 case TargetOpcode::G_FEXP:
1316 case TargetOpcode::G_FEXP2:
1317 case TargetOpcode::G_FEXP10: {
1323 KnownFPClass KnownSrc;
1324 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1333 case TargetOpcode::G_FLOG:
1334 case TargetOpcode::G_FLOG2:
1335 case TargetOpcode::G_FLOG10: {
1350 KnownFPClass KnownSrc;
1351 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1361 DenormalMode
Mode = MF->getDenormalMode(FltSem);
1368 case TargetOpcode::G_FPOWI: {
1373 LLT ExpTy = MRI.getType(Exp);
1375 Exp, ExpTy.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1377 if (ExponentKnownBits.
Zero[0]) {
1391 KnownFPClass KnownSrc;
1392 computeKnownFPClass(Val, DemandedElts,
fcNegative, KnownSrc,
Depth + 1);
1397 case TargetOpcode::G_FLDEXP:
1398 case TargetOpcode::G_STRICT_FLDEXP: {
1400 KnownFPClass KnownSrc;
1401 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1418 if ((InterestedClasses & ExpInfoMask) ==
fcNone)
1427 case TargetOpcode::G_INTRINSIC_ROUNDEVEN: {
1428 computeKnownFPClassForFPTrunc(
MI, DemandedElts, InterestedClasses, Known,
1432 case TargetOpcode::G_FADD:
1433 case TargetOpcode::G_STRICT_FADD:
1434 case TargetOpcode::G_FSUB:
1435 case TargetOpcode::G_STRICT_FSUB: {
1438 KnownFPClass KnownLHS, KnownRHS;
1440 (Opcode == TargetOpcode::G_FADD ||
1441 Opcode == TargetOpcode::G_STRICT_FADD) &&
1443 bool WantNaN = (InterestedClasses &
fcNan) !=
fcNone;
1446 if (!WantNaN && !WantNegative && !WantNegZero)
1452 if (InterestedClasses &
fcNan)
1453 InterestedSrcs |=
fcInf;
1454 computeKnownFPClass(
RHS, DemandedElts, InterestedSrcs, KnownRHS,
Depth + 1);
1459 (Opcode == TargetOpcode::G_FSUB ||
1460 Opcode == TargetOpcode::G_STRICT_FSUB)) {
1464 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownLHS,
1472 if (Opcode == TargetOpcode::G_FADD ||
1473 Opcode == TargetOpcode::G_STRICT_FADD) {
1500 case TargetOpcode::G_FMUL:
1501 case TargetOpcode::G_STRICT_FMUL: {
1514 KnownFPClass KnownLHS, KnownRHS;
1515 computeKnownFPClass(
RHS, DemandedElts, NeedForNan, KnownRHS,
Depth + 1);
1519 computeKnownFPClass(
LHS, DemandedElts, NeedForNan, KnownLHS,
Depth + 1);
1546 case TargetOpcode::G_FDIV:
1547 case TargetOpcode::G_FREM: {
1553 if (Opcode == TargetOpcode::G_FDIV) {
1564 const bool WantNan = (InterestedClasses &
fcNan) !=
fcNone;
1566 const bool WantPositive = Opcode == TargetOpcode::G_FREM &&
1568 if (!WantNan && !WantNegative && !WantPositive)
1571 KnownFPClass KnownLHS, KnownRHS;
1574 KnownRHS,
Depth + 1);
1576 bool KnowSomethingUseful =
1579 if (KnowSomethingUseful || WantPositive) {
1584 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses & InterestedLHS,
1585 KnownLHS,
Depth + 1);
1588 if (Opcode == TargetOpcode::G_FDIV) {
1629 case TargetOpcode::G_FPEXT: {
1633 computeKnownFPClass(R, DemandedElts, InterestedClasses, Known,
Depth + 1);
1637 LLT SrcTy = MRI.getType(Src).getScalarType();
1654 case TargetOpcode::G_FPTRUNC: {
1655 computeKnownFPClassForFPTrunc(
MI, DemandedElts, InterestedClasses, Known,
1659 case TargetOpcode::G_SITOFP:
1660 case TargetOpcode::G_UITOFP: {
1669 if (Opcode == TargetOpcode::G_UITOFP)
1673 LLT Ty = MRI.getType(Val);
1675 if (InterestedClasses &
fcInf) {
1680 if (Opcode == TargetOpcode::G_SITOFP)
1694 case TargetOpcode::G_BUILD_VECTOR:
1695 case TargetOpcode::G_CONCAT_VECTORS: {
1702 for (
unsigned Idx = 0; Idx <
Merge.getNumSources(); ++Idx) {
1704 bool NeedsElt = DemandedElts[Idx];
1710 computeKnownFPClass(Src, Known, InterestedClasses,
Depth + 1);
1713 KnownFPClass Known2;
1714 computeKnownFPClass(Src, Known2, InterestedClasses,
Depth + 1);
1726 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1736 LLT VecTy = MRI.getType(Vec);
1741 if (CIdx && CIdx->ult(NumElts))
1743 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
1749 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1755 LLT VecTy = MRI.getType(Vec);
1763 APInt DemandedVecElts = DemandedElts;
1764 bool NeedsElt =
true;
1766 if (CIdx && CIdx->ult(NumElts)) {
1767 DemandedVecElts.
clearBit(CIdx->getZExtValue());
1768 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1773 computeKnownFPClass(Elt, Known, InterestedClasses,
Depth + 1);
1782 if (!DemandedVecElts.
isZero()) {
1783 KnownFPClass Known2;
1784 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2,
1791 case TargetOpcode::G_SHUFFLE_VECTOR: {
1795 APInt DemandedLHS, DemandedRHS;
1797 assert(DemandedElts == APInt(1, 1));
1798 DemandedLHS = DemandedRHS = DemandedElts;
1801 DemandedElts, DemandedLHS,
1808 if (!!DemandedLHS) {
1810 computeKnownFPClass(
LHS, DemandedLHS, InterestedClasses, Known,
1820 if (!!DemandedRHS) {
1821 KnownFPClass Known2;
1823 computeKnownFPClass(
RHS, DemandedRHS, InterestedClasses, Known2,
1829 case TargetOpcode::COPY: {
1832 if (!Src.isVirtual())
1835 computeKnownFPClass(Src, DemandedElts, InterestedClasses, Known,
Depth + 1);
1846 computeKnownFPClass(R, DemandedElts, InterestedClasses, KnownClasses,
Depth);
1847 return KnownClasses;
1853 computeKnownFPClass(R, Known, InterestedClasses,
Depth);
1861 InterestedClasses &=
~fcNan;
1863 InterestedClasses &=
~fcInf;
1866 computeKnownFPClass(R, DemandedElts, InterestedClasses,
Depth);
1869 Result.KnownFPClasses &=
~fcNan;
1871 Result.KnownFPClasses &=
~fcInf;
1877 LLT Ty = MRI.getType(R);
1878 APInt DemandedElts =
1880 return computeKnownFPClass(R, DemandedElts, Flags, InterestedClasses,
Depth);
1884unsigned GISelValueTracking::computeNumSignBitsMin(
Register Src0,
Register Src1,
1885 const APInt &DemandedElts,
1889 if (Src1SignBits == 1)
1906 case TargetOpcode::G_SEXTLOAD:
1909 case TargetOpcode::G_ZEXTLOAD:
1922 const APInt &DemandedElts,
1925 unsigned Opcode =
MI.getOpcode();
1927 if (Opcode == TargetOpcode::G_CONSTANT)
1928 return MI.getOperand(1).getCImm()->getValue().getNumSignBits();
1936 LLT DstTy = MRI.getType(R);
1946 unsigned FirstAnswer = 1;
1948 case TargetOpcode::COPY: {
1950 if (Src.getReg().isVirtual() && Src.getSubReg() == 0 &&
1951 MRI.getType(Src.getReg()).isValid()) {
1958 case TargetOpcode::G_SEXT: {
1960 LLT SrcTy = MRI.getType(Src);
1964 case TargetOpcode::G_ASSERT_SEXT:
1965 case TargetOpcode::G_SEXT_INREG: {
1968 unsigned SrcBits =
MI.getOperand(2).getImm();
1969 unsigned InRegBits = TyBits - SrcBits + 1;
1973 case TargetOpcode::G_LOAD: {
1980 case TargetOpcode::G_SEXTLOAD: {
1995 case TargetOpcode::G_ZEXTLOAD: {
2010 case TargetOpcode::G_AND:
2011 case TargetOpcode::G_OR:
2012 case TargetOpcode::G_XOR: {
2014 unsigned Src1NumSignBits =
2016 if (Src1NumSignBits != 1) {
2018 unsigned Src2NumSignBits =
2020 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits);
2024 case TargetOpcode::G_ASHR: {
2029 FirstAnswer = std::min<uint64_t>(FirstAnswer + *
C, TyBits);
2032 case TargetOpcode::G_SHL: {
2035 if (std::optional<ConstantRange> ShAmtRange =
2037 uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
2038 uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
2048 if (ExtOpc == TargetOpcode::G_SEXT || ExtOpc == TargetOpcode::G_ZEXT ||
2049 ExtOpc == TargetOpcode::G_ANYEXT) {
2050 LLT ExtTy = MRI.getType(Src1);
2052 LLT ExtendeeTy = MRI.getType(Extendee);
2056 if (SizeDiff <= MinShAmt) {
2060 return Tmp - MaxShAmt;
2066 return Tmp - MaxShAmt;
2070 case TargetOpcode::G_TRUNC: {
2072 LLT SrcTy = MRI.getType(Src);
2076 unsigned NumSrcBits = SrcTy.getScalarSizeInBits();
2078 if (NumSrcSignBits > (NumSrcBits - DstTyBits))
2079 return NumSrcSignBits - (NumSrcBits - DstTyBits);
2082 case TargetOpcode::G_SELECT: {
2083 return computeNumSignBitsMin(
MI.getOperand(2).getReg(),
2084 MI.getOperand(3).getReg(), DemandedElts,
2087 case TargetOpcode::G_SMIN:
2088 case TargetOpcode::G_SMAX:
2089 case TargetOpcode::G_UMIN:
2090 case TargetOpcode::G_UMAX:
2092 return computeNumSignBitsMin(
MI.getOperand(1).getReg(),
2093 MI.getOperand(2).getReg(), DemandedElts,
2095 case TargetOpcode::G_SADDO:
2096 case TargetOpcode::G_SADDE:
2097 case TargetOpcode::G_UADDO:
2098 case TargetOpcode::G_UADDE:
2099 case TargetOpcode::G_SSUBO:
2100 case TargetOpcode::G_SSUBE:
2101 case TargetOpcode::G_USUBO:
2102 case TargetOpcode::G_USUBE:
2103 case TargetOpcode::G_SMULO:
2104 case TargetOpcode::G_UMULO: {
2108 if (
MI.getOperand(1).getReg() == R) {
2109 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
2116 case TargetOpcode::G_SUB: {
2118 unsigned Src2NumSignBits =
2120 if (Src2NumSignBits == 1)
2130 if ((Known2.
Zero | 1).isAllOnes())
2137 FirstAnswer = Src2NumSignBits;
2144 unsigned Src1NumSignBits =
2146 if (Src1NumSignBits == 1)
2151 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2154 case TargetOpcode::G_ADD: {
2156 unsigned Src2NumSignBits =
2158 if (Src2NumSignBits <= 2)
2162 unsigned Src1NumSignBits =
2164 if (Src1NumSignBits == 1)
2173 if ((Known1.
Zero | 1).isAllOnes())
2179 FirstAnswer = Src1NumSignBits;
2188 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2191 case TargetOpcode::G_FCMP:
2192 case TargetOpcode::G_ICMP: {
2193 bool IsFP = Opcode == TargetOpcode::G_FCMP;
2196 auto BC = TL.getBooleanContents(DstTy.
isVector(), IsFP);
2203 case TargetOpcode::G_BUILD_VECTOR: {
2205 FirstAnswer = TyBits;
2206 APInt SingleDemandedElt(1, 1);
2208 if (!DemandedElts[
I])
2213 FirstAnswer = std::min(FirstAnswer, Tmp2);
2216 if (FirstAnswer == 1)
2221 case TargetOpcode::G_CONCAT_VECTORS: {
2222 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
2224 FirstAnswer = TyBits;
2227 unsigned NumSubVectorElts =
2228 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
2231 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
2236 FirstAnswer = std::min(FirstAnswer, Tmp2);
2239 if (FirstAnswer == 1)
2244 case TargetOpcode::G_SHUFFLE_VECTOR: {
2247 APInt DemandedLHS, DemandedRHS;
2249 unsigned NumElts = MRI.getType(Src1).getNumElements();
2251 DemandedElts, DemandedLHS, DemandedRHS))
2257 if (FirstAnswer == 1)
2259 if (!!DemandedRHS) {
2262 FirstAnswer = std::min(FirstAnswer, Tmp2);
2266 case TargetOpcode::G_SPLAT_VECTOR: {
2270 unsigned NumSrcBits = MRI.getType(Src).getSizeInBits();
2271 if (NumSrcSignBits > (NumSrcBits - TyBits))
2272 return NumSrcSignBits - (NumSrcBits - TyBits);
2275 case TargetOpcode::G_INTRINSIC:
2276 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
2277 case TargetOpcode::G_INTRINSIC_CONVERGENT:
2278 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
2281 TL.computeNumSignBitsForTargetInstr(*
this, R, DemandedElts, MRI,
Depth);
2283 FirstAnswer = std::max(FirstAnswer, NumBits);
2303 Mask <<= Mask.getBitWidth() - TyBits;
2304 return std::max(FirstAnswer, Mask.countl_one());
2308 LLT Ty = MRI.getType(R);
2309 APInt DemandedElts =
2318 unsigned Opcode =
MI.getOpcode();
2320 LLT Ty = MRI.getType(R);
2321 unsigned BitWidth = Ty.getScalarSizeInBits();
2323 if (Opcode == TargetOpcode::G_CONSTANT) {
2324 const APInt &ShAmt =
MI.getOperand(1).getCImm()->getValue();
2326 return std::nullopt;
2330 if (Opcode == TargetOpcode::G_BUILD_VECTOR) {
2331 const APInt *MinAmt =
nullptr, *MaxAmt =
nullptr;
2332 for (
unsigned I = 0, E =
MI.getNumOperands() - 1;
I != E; ++
I) {
2333 if (!DemandedElts[
I])
2336 if (
Op->getOpcode() != TargetOpcode::G_CONSTANT) {
2337 MinAmt = MaxAmt =
nullptr;
2341 const APInt &ShAmt =
Op->getOperand(1).getCImm()->getValue();
2343 return std::nullopt;
2344 if (!MinAmt || MinAmt->
ugt(ShAmt))
2346 if (!MaxAmt || MaxAmt->ult(ShAmt))
2349 assert(((!MinAmt && !MaxAmt) || (MinAmt && MaxAmt)) &&
2350 "Failed to find matching min/max shift amounts");
2351 if (MinAmt && MaxAmt)
2361 return std::nullopt;
2366 if (std::optional<ConstantRange> AmtRange =
2368 return AmtRange->getUnsignedMin().getZExtValue();
2369 return std::nullopt;
2387 Info = std::make_unique<GISelValueTracking>(MF, MaxDepth);
2412 if (!MO.isReg() || MO.getReg().isPhysical())
2415 if (!
MRI.getType(Reg).isValid())
2417 KnownBits Known = VTA.getKnownBits(Reg);
2418 unsigned SignedBits = VTA.computeNumSignBits(Reg);
2419 OS <<
" " << MO <<
" KnownBits:" << Known <<
" SignBits:" << SignedBits
unsigned const MachineRegisterInfo * MRI
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.
static bool outputDenormalIsIEEEOrPosZero(const MachineFunction &MF, LLT Ty)
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")))
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file describes how to lower LLVM code to machine code.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Class for arbitrary precision integers.
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.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
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.
LLVM_ABI APInt rotr(unsigned rotateAmt) const
Rotate right by rotateAmt.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
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.
void setAllBits()
Set every bit to 1.
APInt shl(unsigned shiftAmt) const
Left-shift function.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
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 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)
APInt getKnownOnes(Register R)
APInt getKnownZeroes(Register R)
void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
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
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
constexpr LLT getScalarType() const
TypeSize getValue() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
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.
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.
#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()
operand_type_match m_Pred()
bind_ty< FPClassTest > m_FPClassTest(FPClassTest &T)
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 > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
LLVM_ABI std::optional< APInt > isConstantOrConstantSplatVector(MachineInstr &MI, const MachineRegisterInfo &MRI)
Determines if MI defines a constant integer or a splat vector of constant integers.
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
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.
@ 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...
Represent subnormal handling kind for floating point instruction inputs and outputs.
DenormalModeKind Input
Denormal treatment kind for floating point instruction inputs in the default floating-point environme...
constexpr bool outputsAreZero() const
Return true if output denormals should be flushed to 0.
@ PositiveZero
Denormals are flushed to positive zero.
@ IEEE
IEEE-754 denormal numbers preserved.
constexpr bool inputsAreZero() const
Return true if input denormals must be implicitly treated as 0.
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
static constexpr DenormalMode getIEEE()
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
LLVM_ABI KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension 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.
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 ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
bool isUnknown() const
Returns true if we don't know any bits.
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.
KnownBits byteSwap() const
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.
KnownBits reverseBits() const
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 LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from addition of LHS and RHS.
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
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 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).
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.
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
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...
LLVM_ABI KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
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.
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 constexpr FPClassTest OrderedGreaterThanZeroMask
static constexpr FPClassTest OrderedLessThanZeroMask
void knownNot(FPClassTest RuleOut)
void copysign(const KnownFPClass &Sign)
bool isKnownNeverSubnormal() const
Return true if it's known this can never be a subnormal.
LLVM_ABI bool isKnownNeverLogicalZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a zero.
bool isKnownNeverPosZero() const
Return true if it's known this can never be a literal positive zero.
std::optional< bool > SignBit
std::nullopt if the sign bit is unknown, true if the sign bit is definitely set or false if the sign ...
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.
bool isKnownNeverNegZero() const
Return true if it's known this can never be a negative zero.
void propagateNaN(const KnownFPClass &Src, bool PreserveSign=false)
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
void signBitMustBeOne()
Assume the sign bit is one.
void signBitMustBeZero()
Assume the sign bit is zero.
LLVM_ABI bool isKnownNeverLogicalPosZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a positive zero.
bool isKnownNeverPosInfinity() const
Return true if it's known this can never be +infinity.
LLVM_ABI bool isKnownNeverLogicalNegZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a negative zero.