41#define DEBUG_TYPE "gisel-known-bits"
49 "Analysis for ComputingKnownBits",
false,
true)
52 : MF(MF),
MRI(MF.getRegInfo()), TL(*MF.getSubtarget().getTargetLowering()),
57 switch (
MI->getOpcode()) {
58 case TargetOpcode::COPY:
60 case TargetOpcode::G_ASSERT_ALIGN: {
62 return Align(
MI->getOperand(2).getImm());
64 case TargetOpcode::G_FRAME_INDEX: {
65 int FrameIdx =
MI->getOperand(1).getIndex();
66 return MF.getFrameInfo().getObjectAlign(FrameIdx);
68 case TargetOpcode::G_INTRINSIC:
69 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
70 case TargetOpcode::G_INTRINSIC_CONVERGENT:
71 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
73 return TL.computeKnownAlignForTargetInstr(*
this, R, MRI,
Depth + 1);
78 assert(
MI.getNumExplicitDefs() == 1 &&
79 "expected single return generic instruction");
84 const LLT Ty = MRI.getType(R);
94 const APInt &DemandedElts,
102 LLT Ty = MRI.getType(R);
103 unsigned BitWidth = Ty.getScalarSizeInBits();
115[[maybe_unused]]
static void
118 <<
"] Computed for: " <<
MI <<
"[" <<
Depth <<
"] Known: 0x"
129 const APInt &DemandedElts,
160 const APInt &DemandedElts,
163 unsigned Opcode =
MI.getOpcode();
164 LLT DstTy = MRI.getType(R);
178 "DemandedElt width should equal the fixed vector number of elements");
181 "DemandedElt width should be 1 for scalars or scalable vectors");
206 TL.computeKnownBitsForTargetInstr(*
this, R, Known, DemandedElts, MRI,
209 case TargetOpcode::G_BUILD_VECTOR: {
214 if (!DemandedElts[
I])
228 case TargetOpcode::G_SPLAT_VECTOR: {
236 case TargetOpcode::COPY:
237 case TargetOpcode::G_PHI:
238 case TargetOpcode::PHI: {
244 assert(
MI.getOperand(0).getSubReg() == 0 &&
"Is this code in SSA?");
247 for (
unsigned Idx = 1; Idx <
MI.getNumOperands(); Idx += 2) {
257 if (SrcReg.
isVirtual() && Src.getSubReg() == 0 &&
258 MRI.getType(SrcReg).isValid()) {
261 Depth + (Opcode != TargetOpcode::COPY));
276 case TargetOpcode::G_CONSTANT: {
280 case TargetOpcode::G_FRAME_INDEX: {
281 int FrameIdx =
MI.getOperand(1).getIndex();
282 TL.computeKnownBitsForFrameIndex(FrameIdx, Known, MF);
285 case TargetOpcode::G_SUB: {
293 case TargetOpcode::G_XOR: {
302 case TargetOpcode::G_PTR_ADD: {
306 LLT Ty = MRI.getType(
MI.getOperand(1).getReg());
307 if (DL.isNonIntegralAddressSpace(Ty.getAddressSpace()))
311 case TargetOpcode::G_ADD: {
319 case TargetOpcode::G_AND: {
329 case TargetOpcode::G_OR: {
339 case TargetOpcode::G_MUL: {
347 case TargetOpcode::G_UMULH: {
355 case TargetOpcode::G_SMULH: {
363 case TargetOpcode::G_SELECT: {
364 computeKnownBitsMin(
MI.getOperand(2).getReg(),
MI.getOperand(3).getReg(),
365 Known, DemandedElts,
Depth + 1);
368 case TargetOpcode::G_SMIN: {
378 case TargetOpcode::G_SMAX: {
388 case TargetOpcode::G_UMIN: {
397 case TargetOpcode::G_UMAX: {
406 case TargetOpcode::G_FCMP:
407 case TargetOpcode::G_ICMP: {
410 if (TL.getBooleanContents(DstTy.
isVector(),
411 Opcode == TargetOpcode::G_FCMP) ==
417 case TargetOpcode::G_SEXT: {
425 case TargetOpcode::G_ASSERT_SEXT:
426 case TargetOpcode::G_SEXT_INREG: {
429 Known = Known.
sextInReg(
MI.getOperand(2).getImm());
432 case TargetOpcode::G_ANYEXT: {
438 case TargetOpcode::G_LOAD: {
446 case TargetOpcode::G_SEXTLOAD:
447 case TargetOpcode::G_ZEXTLOAD: {
454 Known = Opcode == TargetOpcode::G_SEXTLOAD
459 case TargetOpcode::G_ASHR: {
468 case TargetOpcode::G_LSHR: {
477 case TargetOpcode::G_SHL: {
486 case TargetOpcode::G_INTTOPTR:
487 case TargetOpcode::G_PTRTOINT:
492 case TargetOpcode::G_ZEXT:
493 case TargetOpcode::G_TRUNC: {
499 case TargetOpcode::G_ASSERT_ZEXT: {
503 unsigned SrcBitWidth =
MI.getOperand(2).getImm();
504 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
506 Known.
Zero |= (~InMask);
507 Known.
One &= (~Known.Zero);
510 case TargetOpcode::G_ASSERT_ALIGN: {
511 int64_t LogOfAlign =
Log2_64(
MI.getOperand(2).getImm());
520 case TargetOpcode::G_MERGE_VALUES: {
521 unsigned NumOps =
MI.getNumOperands();
522 unsigned OpSize = MRI.getType(
MI.getOperand(1).getReg()).getSizeInBits();
524 for (
unsigned I = 0;
I !=
NumOps - 1; ++
I) {
527 DemandedElts,
Depth + 1);
532 case TargetOpcode::G_UNMERGE_VALUES: {
533 unsigned NumOps =
MI.getNumOperands();
535 LLT SrcTy = MRI.getType(SrcReg);
537 if (SrcTy.isVector() && SrcTy.getScalarType() != DstTy.
getScalarType())
542 for (; DstIdx !=
NumOps - 1 &&
MI.getOperand(DstIdx).
getReg() != R;
546 APInt SubDemandedElts = DemandedElts;
547 if (SrcTy.isVector()) {
550 DemandedElts.
zext(SrcTy.getNumElements()).
shl(DstIdx * DstLanes);
556 if (SrcTy.isVector())
557 Known = std::move(SrcOpKnown);
562 case TargetOpcode::G_BSWAP: {
568 case TargetOpcode::G_BITREVERSE: {
574 case TargetOpcode::G_CTPOP: {
586 case TargetOpcode::G_UBFX: {
587 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
597 case TargetOpcode::G_SBFX: {
598 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
613 case TargetOpcode::G_UADDO:
614 case TargetOpcode::G_UADDE:
615 case TargetOpcode::G_SADDO:
616 case TargetOpcode::G_SADDE:
617 case TargetOpcode::G_USUBO:
618 case TargetOpcode::G_USUBE:
619 case TargetOpcode::G_SSUBO:
620 case TargetOpcode::G_SSUBE:
621 case TargetOpcode::G_UMULO:
622 case TargetOpcode::G_SMULO: {
623 if (
MI.getOperand(1).getReg() == R) {
626 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
633 case TargetOpcode::G_CTLZ:
634 case TargetOpcode::G_CTLZ_ZERO_UNDEF: {
644 case TargetOpcode::G_SHUFFLE_VECTOR: {
645 APInt DemandedLHS, DemandedRHS;
648 unsigned NumElts = MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
650 DemandedElts, DemandedLHS, DemandedRHS))
671 case TargetOpcode::G_CONCAT_VECTORS: {
672 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
677 unsigned NumSubVectorElts =
678 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
682 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
694 case TargetOpcode::G_ABS: {
708 Ty = Ty.getScalarType();
717 LLT Ty = MRI.getType(R);
720 computeKnownFPClass(R, DemandedElts, InterestedClasses, Known,
Depth);
723void GISelValueTracking::computeKnownFPClassForFPTrunc(
731 KnownFPClass KnownSrc;
732 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
745void GISelValueTracking::computeKnownFPClass(
Register R,
746 const APInt &DemandedElts,
750 assert(Known.
isUnknown() &&
"should not be called with known information");
760 MachineInstr &
MI = *MRI.getVRegDef(R);
761 unsigned Opcode =
MI.getOpcode();
762 LLT DstTy = MRI.getType(R);
770 switch (Cst->getKind()) {
772 auto APF = Cst->getScalarValue();
774 Known.
SignBit = APF.isNegative();
779 bool SignBitAllZero =
true;
780 bool SignBitAllOne =
true;
782 for (
auto C : *Cst) {
785 SignBitAllZero =
false;
787 SignBitAllOne =
false;
790 if (SignBitAllOne != SignBitAllZero)
806 KnownNotFromFlags |=
fcNan;
808 KnownNotFromFlags |=
fcInf;
812 InterestedClasses &= ~KnownNotFromFlags;
814 auto ClearClassesFromFlags =
821 const MachineFunction *MF =
MI.getMF();
825 TL.computeKnownFPClassForTargetInstr(*
this, R, Known, DemandedElts, MRI,
828 case TargetOpcode::G_FNEG: {
830 computeKnownFPClass(Val, DemandedElts, InterestedClasses, Known,
Depth + 1);
834 case TargetOpcode::G_SELECT: {
857 bool LookThroughFAbsFNeg = CmpLHS !=
LHS && CmpLHS !=
RHS;
858 std::tie(TestedValue, MaskIfTrue, MaskIfFalse) =
864 MaskIfTrue = TestedMask;
865 MaskIfFalse = ~TestedMask;
868 if (TestedValue ==
LHS) {
870 FilterLHS = MaskIfTrue;
871 }
else if (TestedValue ==
RHS) {
873 FilterRHS = MaskIfFalse;
877 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses & FilterLHS, Known,
881 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses & FilterRHS,
888 case TargetOpcode::G_FCOPYSIGN: {
889 Register Magnitude =
MI.getOperand(1).getReg();
892 KnownFPClass KnownSign;
894 computeKnownFPClass(Magnitude, DemandedElts, InterestedClasses, Known,
896 computeKnownFPClass(Sign, DemandedElts, InterestedClasses, KnownSign,
901 case TargetOpcode::G_FMA:
902 case TargetOpcode::G_STRICT_FMA:
903 case TargetOpcode::G_FMAD: {
918 KnownFPClass KnownAddend;
919 computeKnownFPClass(
C, DemandedElts, InterestedClasses, KnownAddend,
926 case TargetOpcode::G_FSQRT:
927 case TargetOpcode::G_STRICT_FSQRT: {
928 KnownFPClass KnownSrc;
930 if (InterestedClasses &
fcNan)
935 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
950 case TargetOpcode::G_FABS: {
955 computeKnownFPClass(Val, DemandedElts, InterestedClasses, Known,
961 case TargetOpcode::G_FSIN:
962 case TargetOpcode::G_FCOS:
963 case TargetOpcode::G_FSINCOS: {
966 KnownFPClass KnownSrc;
968 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
976 case TargetOpcode::G_FMAXNUM:
977 case TargetOpcode::G_FMINNUM:
978 case TargetOpcode::G_FMINNUM_IEEE:
979 case TargetOpcode::G_FMAXIMUM:
980 case TargetOpcode::G_FMINIMUM:
981 case TargetOpcode::G_FMAXNUM_IEEE:
982 case TargetOpcode::G_FMAXIMUMNUM:
983 case TargetOpcode::G_FMINIMUMNUM: {
986 KnownFPClass KnownLHS, KnownRHS;
988 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses, KnownLHS,
990 computeKnownFPClass(
RHS, DemandedElts, InterestedClasses, KnownRHS,
994 Known = KnownLHS | KnownRHS;
997 if (NeverNaN && (Opcode == TargetOpcode::G_FMINNUM ||
998 Opcode == TargetOpcode::G_FMAXNUM ||
999 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1000 Opcode == TargetOpcode::G_FMAXIMUMNUM))
1003 if (Opcode == TargetOpcode::G_FMAXNUM ||
1004 Opcode == TargetOpcode::G_FMAXIMUMNUM ||
1005 Opcode == TargetOpcode::G_FMAXNUM_IEEE) {
1013 }
else if (Opcode == TargetOpcode::G_FMAXIMUM) {
1019 }
else if (Opcode == TargetOpcode::G_FMINNUM ||
1020 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1021 Opcode == TargetOpcode::G_FMINNUM_IEEE) {
1029 }
else if (Opcode == TargetOpcode::G_FMINIMUM) {
1061 }
else if ((Opcode == TargetOpcode::G_FMAXIMUM ||
1062 Opcode == TargetOpcode::G_FMINIMUM) ||
1063 Opcode == TargetOpcode::G_FMAXIMUMNUM ||
1064 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1065 Opcode == TargetOpcode::G_FMAXNUM_IEEE ||
1066 Opcode == TargetOpcode::G_FMINNUM_IEEE ||
1072 if ((Opcode == TargetOpcode::G_FMAXIMUM ||
1073 Opcode == TargetOpcode::G_FMAXNUM ||
1074 Opcode == TargetOpcode::G_FMAXIMUMNUM ||
1075 Opcode == TargetOpcode::G_FMAXNUM_IEEE) &&
1078 else if ((Opcode == TargetOpcode::G_FMINIMUM ||
1079 Opcode == TargetOpcode::G_FMINNUM ||
1080 Opcode == TargetOpcode::G_FMINIMUMNUM ||
1081 Opcode == TargetOpcode::G_FMINNUM_IEEE) &&
1088 case TargetOpcode::G_FCANONICALIZE: {
1090 KnownFPClass KnownSrc;
1091 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1113 DenormalMode DenormMode = MF->getDenormalMode(FPType);
1132 case TargetOpcode::G_VECREDUCE_FMAX:
1133 case TargetOpcode::G_VECREDUCE_FMIN:
1134 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1135 case TargetOpcode::G_VECREDUCE_FMINIMUM: {
1141 computeKnownFPClass(Val,
MI.getFlags(), InterestedClasses,
Depth + 1);
1147 case TargetOpcode::G_TRUNC:
1148 case TargetOpcode::G_FFLOOR:
1149 case TargetOpcode::G_FCEIL:
1150 case TargetOpcode::G_FRINT:
1151 case TargetOpcode::G_FNEARBYINT:
1152 case TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND:
1153 case TargetOpcode::G_INTRINSIC_ROUND: {
1155 KnownFPClass KnownSrc;
1161 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1178 case TargetOpcode::G_FEXP:
1179 case TargetOpcode::G_FEXP2:
1180 case TargetOpcode::G_FEXP10: {
1186 KnownFPClass KnownSrc;
1187 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1196 case TargetOpcode::G_FLOG:
1197 case TargetOpcode::G_FLOG2:
1198 case TargetOpcode::G_FLOG10: {
1213 KnownFPClass KnownSrc;
1214 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
Depth + 1);
1224 DenormalMode
Mode = MF->getDenormalMode(FltSem);
1231 case TargetOpcode::G_FPOWI: {
1236 LLT ExpTy = MRI.getType(Exp);
1238 Exp, ExpTy.
isVector() ? DemandedElts : APInt(1, 1),
Depth + 1);
1240 if (ExponentKnownBits.
Zero[0]) {
1254 KnownFPClass KnownSrc;
1255 computeKnownFPClass(Val, DemandedElts,
fcNegative, KnownSrc,
Depth + 1);
1260 case TargetOpcode::G_FLDEXP:
1261 case TargetOpcode::G_STRICT_FLDEXP: {
1263 KnownFPClass KnownSrc;
1264 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1281 if ((InterestedClasses & ExpInfoMask) ==
fcNone)
1290 case TargetOpcode::G_INTRINSIC_ROUNDEVEN: {
1291 computeKnownFPClassForFPTrunc(
MI, DemandedElts, InterestedClasses, Known,
1295 case TargetOpcode::G_FADD:
1296 case TargetOpcode::G_STRICT_FADD:
1297 case TargetOpcode::G_FSUB:
1298 case TargetOpcode::G_STRICT_FSUB: {
1301 KnownFPClass KnownLHS, KnownRHS;
1303 (Opcode == TargetOpcode::G_FADD ||
1304 Opcode == TargetOpcode::G_STRICT_FADD) &&
1306 bool WantNaN = (InterestedClasses &
fcNan) !=
fcNone;
1309 if (!WantNaN && !WantNegative && !WantNegZero)
1315 if (InterestedClasses &
fcNan)
1316 InterestedSrcs |=
fcInf;
1317 computeKnownFPClass(
RHS, DemandedElts, InterestedSrcs, KnownRHS,
Depth + 1);
1322 (Opcode == TargetOpcode::G_FSUB ||
1323 Opcode == TargetOpcode::G_STRICT_FSUB)) {
1327 computeKnownFPClass(
LHS, DemandedElts, InterestedSrcs, KnownLHS,
1335 if (Opcode == Instruction::FAdd) {
1362 case TargetOpcode::G_FMUL:
1363 case TargetOpcode::G_STRICT_FMUL: {
1376 KnownFPClass KnownLHS, KnownRHS;
1377 computeKnownFPClass(
RHS, DemandedElts, NeedForNan, KnownRHS,
Depth + 1);
1381 computeKnownFPClass(
LHS, DemandedElts, NeedForNan, KnownLHS,
Depth + 1);
1408 case TargetOpcode::G_FDIV:
1409 case TargetOpcode::G_FREM: {
1415 if (Opcode == TargetOpcode::G_FDIV) {
1426 const bool WantNan = (InterestedClasses &
fcNan) !=
fcNone;
1428 const bool WantPositive = Opcode == TargetOpcode::G_FREM &&
1430 if (!WantNan && !WantNegative && !WantPositive)
1433 KnownFPClass KnownLHS, KnownRHS;
1436 KnownRHS,
Depth + 1);
1438 bool KnowSomethingUseful =
1441 if (KnowSomethingUseful || WantPositive) {
1446 computeKnownFPClass(
LHS, DemandedElts, InterestedClasses & InterestedLHS,
1447 KnownLHS,
Depth + 1);
1450 if (Opcode == Instruction::FDiv) {
1491 case TargetOpcode::G_FPEXT: {
1495 computeKnownFPClass(R, DemandedElts, InterestedClasses, Known,
Depth + 1);
1499 LLT SrcTy = MRI.getType(Src).getScalarType();
1516 case TargetOpcode::G_FPTRUNC: {
1517 computeKnownFPClassForFPTrunc(
MI, DemandedElts, InterestedClasses, Known,
1521 case TargetOpcode::G_SITOFP:
1522 case TargetOpcode::G_UITOFP: {
1531 if (Opcode == TargetOpcode::G_UITOFP)
1535 LLT Ty = MRI.getType(Val);
1537 if (InterestedClasses &
fcInf) {
1542 if (Opcode == TargetOpcode::G_SITOFP)
1556 case TargetOpcode::G_BUILD_VECTOR:
1557 case TargetOpcode::G_CONCAT_VECTORS: {
1564 for (
unsigned Idx = 0; Idx <
Merge.getNumSources(); ++Idx) {
1566 bool NeedsElt = DemandedElts[Idx];
1572 computeKnownFPClass(Src, Known, InterestedClasses,
Depth + 1);
1575 KnownFPClass Known2;
1576 computeKnownFPClass(Src, Known2, InterestedClasses,
Depth + 1);
1588 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1598 LLT VecTy = MRI.getType(Vec);
1603 if (CIdx && CIdx->ult(NumElts))
1605 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
1611 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1617 LLT VecTy = MRI.getType(Vec);
1625 APInt DemandedVecElts = DemandedElts;
1626 bool NeedsElt =
true;
1628 if (CIdx && CIdx->ult(NumElts)) {
1629 DemandedVecElts.
clearBit(CIdx->getZExtValue());
1630 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1635 computeKnownFPClass(Elt, Known, InterestedClasses,
Depth + 1);
1644 if (!DemandedVecElts.
isZero()) {
1645 KnownFPClass Known2;
1646 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2,
1653 case TargetOpcode::G_SHUFFLE_VECTOR: {
1657 APInt DemandedLHS, DemandedRHS;
1659 assert(DemandedElts == APInt(1, 1));
1660 DemandedLHS = DemandedRHS = DemandedElts;
1663 DemandedElts, DemandedLHS,
1670 if (!!DemandedLHS) {
1672 computeKnownFPClass(
LHS, DemandedLHS, InterestedClasses, Known,
1682 if (!!DemandedRHS) {
1683 KnownFPClass Known2;
1685 computeKnownFPClass(
RHS, DemandedRHS, InterestedClasses, Known2,
1691 case TargetOpcode::COPY: {
1694 if (!Src.isVirtual())
1697 computeKnownFPClass(Src, DemandedElts, InterestedClasses, Known,
Depth + 1);
1708 computeKnownFPClass(R, DemandedElts, InterestedClasses, KnownClasses,
Depth);
1709 return KnownClasses;
1715 computeKnownFPClass(R, Known, InterestedClasses,
Depth);
1723 InterestedClasses &=
~fcNan;
1725 InterestedClasses &=
~fcInf;
1728 computeKnownFPClass(R, DemandedElts, InterestedClasses,
Depth);
1731 Result.KnownFPClasses &=
~fcNan;
1733 Result.KnownFPClasses &=
~fcInf;
1739 LLT Ty = MRI.getType(R);
1740 APInt DemandedElts =
1742 return computeKnownFPClass(R, DemandedElts, Flags, InterestedClasses,
Depth);
1746unsigned GISelValueTracking::computeNumSignBitsMin(
Register Src0,
Register Src1,
1747 const APInt &DemandedElts,
1751 if (Src1SignBits == 1)
1768 case TargetOpcode::G_SEXTLOAD:
1771 case TargetOpcode::G_ZEXTLOAD:
1784 const APInt &DemandedElts,
1787 unsigned Opcode =
MI.getOpcode();
1789 if (Opcode == TargetOpcode::G_CONSTANT)
1790 return MI.getOperand(1).getCImm()->getValue().getNumSignBits();
1798 LLT DstTy = MRI.getType(R);
1808 unsigned FirstAnswer = 1;
1810 case TargetOpcode::COPY: {
1812 if (Src.getReg().isVirtual() && Src.getSubReg() == 0 &&
1813 MRI.getType(Src.getReg()).isValid()) {
1820 case TargetOpcode::G_SEXT: {
1822 LLT SrcTy = MRI.getType(Src);
1826 case TargetOpcode::G_ASSERT_SEXT:
1827 case TargetOpcode::G_SEXT_INREG: {
1830 unsigned SrcBits =
MI.getOperand(2).getImm();
1831 unsigned InRegBits = TyBits - SrcBits + 1;
1835 case TargetOpcode::G_LOAD: {
1842 case TargetOpcode::G_SEXTLOAD: {
1857 case TargetOpcode::G_ZEXTLOAD: {
1872 case TargetOpcode::G_AND:
1873 case TargetOpcode::G_OR:
1874 case TargetOpcode::G_XOR: {
1876 unsigned Src1NumSignBits =
1878 if (Src1NumSignBits != 1) {
1880 unsigned Src2NumSignBits =
1882 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits);
1886 case TargetOpcode::G_ASHR: {
1891 FirstAnswer = std::min<uint64_t>(FirstAnswer + *
C, TyBits);
1894 case TargetOpcode::G_SHL: {
1897 if (std::optional<ConstantRange> ShAmtRange =
1899 uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
1900 uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
1910 if (ExtOpc == TargetOpcode::G_SEXT || ExtOpc == TargetOpcode::G_ZEXT ||
1911 ExtOpc == TargetOpcode::G_ANYEXT) {
1912 LLT ExtTy = MRI.getType(Src1);
1914 LLT ExtendeeTy = MRI.getType(Extendee);
1918 if (SizeDiff <= MinShAmt) {
1922 return Tmp - MaxShAmt;
1928 return Tmp - MaxShAmt;
1932 case TargetOpcode::G_TRUNC: {
1934 LLT SrcTy = MRI.getType(Src);
1938 unsigned NumSrcBits = SrcTy.getScalarSizeInBits();
1940 if (NumSrcSignBits > (NumSrcBits - DstTyBits))
1941 return NumSrcSignBits - (NumSrcBits - DstTyBits);
1944 case TargetOpcode::G_SELECT: {
1945 return computeNumSignBitsMin(
MI.getOperand(2).getReg(),
1946 MI.getOperand(3).getReg(), DemandedElts,
1949 case TargetOpcode::G_SMIN:
1950 case TargetOpcode::G_SMAX:
1951 case TargetOpcode::G_UMIN:
1952 case TargetOpcode::G_UMAX:
1954 return computeNumSignBitsMin(
MI.getOperand(1).getReg(),
1955 MI.getOperand(2).getReg(), DemandedElts,
1957 case TargetOpcode::G_SADDO:
1958 case TargetOpcode::G_SADDE:
1959 case TargetOpcode::G_UADDO:
1960 case TargetOpcode::G_UADDE:
1961 case TargetOpcode::G_SSUBO:
1962 case TargetOpcode::G_SSUBE:
1963 case TargetOpcode::G_USUBO:
1964 case TargetOpcode::G_USUBE:
1965 case TargetOpcode::G_SMULO:
1966 case TargetOpcode::G_UMULO: {
1970 if (
MI.getOperand(1).getReg() == R) {
1971 if (TL.getBooleanContents(DstTy.
isVector(),
false) ==
1978 case TargetOpcode::G_SUB: {
1980 unsigned Src2NumSignBits =
1982 if (Src2NumSignBits == 1)
1992 if ((Known2.
Zero | 1).isAllOnes())
1999 FirstAnswer = Src2NumSignBits;
2006 unsigned Src1NumSignBits =
2008 if (Src1NumSignBits == 1)
2013 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2016 case TargetOpcode::G_ADD: {
2018 unsigned Src2NumSignBits =
2020 if (Src2NumSignBits <= 2)
2024 unsigned Src1NumSignBits =
2026 if (Src1NumSignBits == 1)
2035 if ((Known1.
Zero | 1).isAllOnes())
2041 FirstAnswer = Src1NumSignBits;
2050 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2053 case TargetOpcode::G_FCMP:
2054 case TargetOpcode::G_ICMP: {
2055 bool IsFP = Opcode == TargetOpcode::G_FCMP;
2058 auto BC = TL.getBooleanContents(DstTy.
isVector(), IsFP);
2065 case TargetOpcode::G_BUILD_VECTOR: {
2067 FirstAnswer = TyBits;
2068 APInt SingleDemandedElt(1, 1);
2070 if (!DemandedElts[
I])
2075 FirstAnswer = std::min(FirstAnswer, Tmp2);
2078 if (FirstAnswer == 1)
2083 case TargetOpcode::G_CONCAT_VECTORS: {
2084 if (MRI.getType(
MI.getOperand(0).getReg()).isScalableVector())
2086 FirstAnswer = TyBits;
2089 unsigned NumSubVectorElts =
2090 MRI.getType(
MI.getOperand(1).getReg()).getNumElements();
2093 DemandedElts.
extractBits(NumSubVectorElts,
I * NumSubVectorElts);
2098 FirstAnswer = std::min(FirstAnswer, Tmp2);
2101 if (FirstAnswer == 1)
2106 case TargetOpcode::G_SHUFFLE_VECTOR: {
2109 APInt DemandedLHS, DemandedRHS;
2111 unsigned NumElts = MRI.getType(Src1).getNumElements();
2113 DemandedElts, DemandedLHS, DemandedRHS))
2119 if (FirstAnswer == 1)
2121 if (!!DemandedRHS) {
2124 FirstAnswer = std::min(FirstAnswer, Tmp2);
2128 case TargetOpcode::G_SPLAT_VECTOR: {
2132 unsigned NumSrcBits = MRI.getType(Src).getSizeInBits();
2133 if (NumSrcSignBits > (NumSrcBits - TyBits))
2134 return NumSrcSignBits - (NumSrcBits - TyBits);
2137 case TargetOpcode::G_INTRINSIC:
2138 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
2139 case TargetOpcode::G_INTRINSIC_CONVERGENT:
2140 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
2143 TL.computeNumSignBitsForTargetInstr(*
this, R, DemandedElts, MRI,
Depth);
2145 FirstAnswer = std::max(FirstAnswer, NumBits);
2165 Mask <<= Mask.getBitWidth() - TyBits;
2166 return std::max(FirstAnswer, Mask.countl_one());
2170 LLT Ty = MRI.getType(R);
2171 APInt DemandedElts =
2180 unsigned Opcode =
MI.getOpcode();
2182 LLT Ty = MRI.getType(R);
2183 unsigned BitWidth = Ty.getScalarSizeInBits();
2185 if (Opcode == TargetOpcode::G_CONSTANT) {
2186 const APInt &ShAmt =
MI.getOperand(1).getCImm()->getValue();
2188 return std::nullopt;
2192 if (Opcode == TargetOpcode::G_BUILD_VECTOR) {
2193 const APInt *MinAmt =
nullptr, *MaxAmt =
nullptr;
2194 for (
unsigned I = 0, E =
MI.getNumOperands() - 1;
I != E; ++
I) {
2195 if (!DemandedElts[
I])
2198 if (
Op->getOpcode() != TargetOpcode::G_CONSTANT) {
2199 MinAmt = MaxAmt =
nullptr;
2203 const APInt &ShAmt =
Op->getOperand(1).getCImm()->getValue();
2205 return std::nullopt;
2206 if (!MinAmt || MinAmt->
ugt(ShAmt))
2208 if (!MaxAmt || MaxAmt->ult(ShAmt))
2211 assert(((!MinAmt && !MaxAmt) || (MinAmt && MaxAmt)) &&
2212 "Failed to find matching min/max shift amounts");
2213 if (MinAmt && MaxAmt)
2223 return std::nullopt;
2228 if (std::optional<ConstantRange> AmtRange =
2230 return AmtRange->getUnsignedMin().getZExtValue();
2231 return std::nullopt;
2249 Info = std::make_unique<GISelValueTracking>(MF, MaxDepth);
2274 if (!MO.isReg() || MO.getReg().isPhysical())
2277 if (!
MRI.getType(Reg).isValid())
2279 KnownBits Known = VTA.getKnownBits(Reg);
2280 unsigned SignedBits = VTA.computeNumSignBits(Reg);
2281 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.
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 unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
#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 bool outputDenormalIsIEEEOrPosZero(const Function &F, const Type *Ty)
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.
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.
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)
KnownBits getKnownBits(MachineInstr &MI)
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.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
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.
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.
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.
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
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.
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.
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.
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
bool isNegative() const
Returns true if this value is known to be negative.
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 know 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 know 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 know this can never be interpreted as a negative zero.