36#define DEBUG_TYPE "instcombine"
55 unsigned Opc =
I->getOpcode();
57 case Instruction::Add:
58 case Instruction::Sub:
59 case Instruction::Mul:
60 case Instruction::And:
62 case Instruction::Xor:
63 case Instruction::AShr:
64 case Instruction::LShr:
65 case Instruction::Shl:
66 case Instruction::UDiv:
67 case Instruction::URem: {
73 if (
Opc == Instruction::LShr ||
Opc == Instruction::AShr)
77 case Instruction::Trunc:
78 case Instruction::ZExt:
79 case Instruction::SExt:
83 if (
I->getOperand(0)->getType() == Ty)
84 return I->getOperand(0);
89 Opc == Instruction::SExt);
92 if (
Trunc->getType()->getScalarSizeInBits() <=
93 Ty->getScalarSizeInBits()) {
94 NewTrunc->setHasNoSignedWrap(
Trunc->hasNoSignedWrap());
95 NewTrunc->setHasNoUnsignedWrap(
Trunc->hasNoUnsignedWrap());
98 if (
Trunc->hasNoUnsignedWrap())
103 case Instruction::Select: {
112 case Instruction::PHI: {
123 case Instruction::FPToUI:
124 case Instruction::FPToSI:
126 I->getOperand(0), Ty);
128 case Instruction::Call:
130 switch (
II->getIntrinsicID()) {
133 case Intrinsic::vscale: {
135 I->getModule(), Intrinsic::vscale, {Ty});
139 case Intrinsic::umin:
140 case Intrinsic::umax:
141 case Intrinsic::smin:
142 case Intrinsic::smax: {
148 I->getModule(),
II->getIntrinsicID(), {Ty});
152 case Intrinsic::abs: {
156 I->getModule(),
II->getIntrinsicID(), {Ty});
158 {Arg, ConstantInt::getFalse(I->getContext())});
164 case Instruction::ShuffleVector: {
187 Processed[
V] = Result;
201InstCombinerImpl::isEliminableCastPair(
const CastInst *CI1,
218 if ((Res == Instruction::IntToPtr && SrcTy != DstIntPtrTy) ||
219 (Res == Instruction::PtrToInt && DstTy != SrcIntPtrTy))
241 if (CSrc->hasOneUse())
261 if (CI.
getOpcode() != Instruction::BitCast ||
291 if (SrcTy && DestTy &&
292 SrcTy->getNumElements() == DestTy->getNumElements() &&
293 SrcTy->getPrimitiveSizeInBits() == DestTy->getPrimitiveSizeInBits()) {
306class TypeEvaluationHelper {
311 [[nodiscard]]
static bool canEvaluateTruncated(
Value *V,
Type *Ty,
317 [[nodiscard]]
static bool canEvaluateZExtd(
Value *V,
Type *Ty,
318 unsigned &BitsToClear,
325 [[nodiscard]]
static bool canEvaluateSExtd(
Value *V,
Type *Ty,
326 unsigned MaxTypeEvalDepth);
329 explicit TypeEvaluationHelper(
unsigned MaxTypeEvalDepth)
330 : MaxTypeEvalDepth(MaxTypeEvalDepth) {}
334 [[nodiscard]]
static bool canAlwaysEvaluateInType(
Value *
V,
Type *Ty);
337 [[nodiscard]]
bool allPendingVisited()
const {
339 [
this](
Value *
V) {
return Visited.contains(
V); });
347 if (
Depth >= MaxTypeEvalDepth)
350 if (canAlwaysEvaluateInType(
V, Ty))
359 const auto [It,
Inserted] = Visited.insert({
V,
false});
376 return It->getSecond();
437 if (!
I->hasOneUse()) {
438 for (Use &U :
I->uses()) {
446 Pending.push_back(
U.getUser());
460 [[nodiscard]]
bool canNotEvaluateInType(
Value *
V,
Type *Ty);
462 [[nodiscard]]
bool canEvaluateTruncatedImpl(
Value *
V,
Type *Ty,
463 InstCombinerImpl &IC,
465 [[nodiscard]]
bool canEvaluateTruncatedPred(
Value *
V,
Type *Ty,
466 InstCombinerImpl &IC,
468 [[nodiscard]]
bool canEvaluateZExtdImpl(
Value *
V,
Type *Ty,
469 unsigned &BitsToClear,
470 InstCombinerImpl &IC,
472 [[nodiscard]]
bool canEvaluateSExtdImpl(
Value *
V,
Type *Ty);
473 [[nodiscard]]
bool canEvaluateSExtdPred(
Value *
V,
Type *Ty);
478 const unsigned MaxTypeEvalDepth;
482 SmallDenseMap<Value *, bool, 8> Visited;
485 SmallVector<Value *, 8> Pending;
492bool TypeEvaluationHelper::canAlwaysEvaluateInType(
Value *
V,
Type *Ty) {
506bool TypeEvaluationHelper::canNotEvaluateInType(
Value *
V,
Type *Ty) {
528bool TypeEvaluationHelper::canEvaluateTruncated(
Value *
V,
Type *Ty,
531 TypeEvaluationHelper TYH(IC.
CLOpts.max_type_eval_depth);
532 return TYH.canEvaluateTruncatedImpl(
V, Ty, IC, CtxI) &&
535 TYH.allPendingVisited();
538bool TypeEvaluationHelper::canEvaluateTruncatedImpl(
Value *
V,
Type *Ty,
541 return canEvaluate(
V, Ty, [
this, &IC, CtxI](
Value *
V,
Type *Ty) {
542 return canEvaluateTruncatedPred(
V, Ty, IC, CtxI);
546bool TypeEvaluationHelper::canEvaluateTruncatedPred(
Value *
V,
Type *Ty,
550 Type *OrigTy =
V->getType();
551 switch (
I->getOpcode()) {
552 case Instruction::Add:
553 case Instruction::Sub:
554 case Instruction::Mul:
555 case Instruction::And:
556 case Instruction::Or:
557 case Instruction::Xor:
559 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
560 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
562 case Instruction::UDiv:
563 case Instruction::URem: {
573 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
574 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
578 case Instruction::Shl: {
585 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
586 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
589 case Instruction::LShr: {
606 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
607 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
610 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
611 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
615 case Instruction::AShr: {
625 unsigned ShiftedBits = OrigBitWidth -
BitWidth;
628 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
629 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
632 case Instruction::Trunc:
635 case Instruction::ZExt:
636 case Instruction::SExt:
640 case Instruction::Select: {
642 return canEvaluateTruncatedImpl(
SI->getTrueValue(), Ty, IC, CtxI) &&
643 canEvaluateTruncatedImpl(
SI->getFalseValue(), Ty, IC, CtxI);
645 case Instruction::PHI: {
652 return canEvaluateTruncatedImpl(IncValue, Ty, IC, CtxI);
655 case Instruction::FPToUI:
656 case Instruction::FPToSI: {
663 Semantics,
I->getOpcode() == Instruction::FPToSI);
666 case Instruction::ShuffleVector:
667 return canEvaluateTruncatedImpl(
I->getOperand(0), Ty, IC, CtxI) &&
668 canEvaluateTruncatedImpl(
I->getOperand(1), Ty, IC, CtxI);
670 case Instruction::Call: {
675 return canEvaluateTruncatedImpl(AbsOp, Ty, IC, CtxI);
682 Value *Op0 = MM->getLHS();
683 Value *Op1 = MM->getRHS();
685 if (MM->isSigned()) {
696 return canEvaluateTruncatedImpl(Op0, Ty, IC, CtxI) &&
697 canEvaluateTruncatedImpl(Op1, Ty, IC, CtxI);
720 Value *VecInput =
nullptr;
729 unsigned VecWidth = VecType->getPrimitiveSizeInBits();
731 unsigned ShiftAmount = ShiftVal ? ShiftVal->
getZExtValue() : 0;
733 if ((VecWidth % DestWidth != 0) || (ShiftAmount % DestWidth != 0))
738 unsigned NumVecElts = VecWidth / DestWidth;
739 if (VecType->getElementType() != DestType) {
744 unsigned Elt = ShiftAmount / DestWidth;
746 Elt = NumVecElts - 1 - Elt;
766 Type *SrcType = Src->getType();
771 unsigned SrcBits = SrcType->getScalarSizeInBits();
772 unsigned DstBits = DstType->getScalarSizeInBits();
773 uint64_t TruncRatio = SrcBits / DstBits;
774 if ((SrcBits % DstBits) != 0)
779 const APInt *ShiftAmount =
nullptr;
787 auto VecElts = VecOpTy->getElementCount();
789 uint64_t BitCastNumElts = VecElts.getKnownMinValue() * TruncRatio;
797 if (Cst->
uge(std::numeric_limits<uint64_t>::max() / TruncRatio))
801 ? (VecOpIdx + 1) * TruncRatio - 1
802 : VecOpIdx * TruncRatio;
808 if (ShiftAmount->
uge(SrcBits) || ShiftAmount->
urem(DstBits) != 0)
814 assert(IdxOfs < TruncRatio &&
815 "IdxOfs is expected to be less than TruncRatio.");
830 shouldChangeType(
Trunc.getSrcTy(),
Trunc.getType())) &&
831 "Don't narrow to an illegal scalar type");
837 unsigned WideWidth =
Trunc.getSrcTy()->getScalarSizeInBits();
843 BinaryOperator *Or0, *Or1;
847 Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
854 if (Or0->
getOpcode() == BinaryOperator::LShr) {
860 Or1->
getOpcode() == BinaryOperator::LShr &&
861 "Illegal or(shift,shift) pair");
870 unsigned MaxShiftAmountWidth =
Log2_32(NarrowWidth);
871 APInt HiBitMask = ~APInt::getLowBitsSet(WideWidth, MaxShiftAmountWidth);
878 if (ShVal0 != ShVal1)
884 unsigned Mask = Width - 1;
897 Value *ShAmt = matchShiftAmount(ShAmt0, ShAmt1, NarrowWidth);
900 ShAmt = matchShiftAmount(ShAmt1, ShAmt0, NarrowWidth);
918 Value *NarrowShAmt =
Builder.CreateZExtOrTrunc(ShAmt, DestTy);
921 X =
Y =
Builder.CreateTrunc(ShVal0, DestTy);
922 if (ShVal0 != ShVal1)
923 Y =
Builder.CreateTrunc(ShVal1, DestTy);
924 Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr;
941 BinaryOperator *BinOp;
948 case Instruction::And:
949 case Instruction::Or:
950 case Instruction::Xor:
951 case Instruction::Add:
952 case Instruction::Sub:
953 case Instruction::Mul: {
980 case Instruction::LShr:
981 case Instruction::AShr: {
986 unsigned MaxShiftAmt = SrcWidth - DestWidth;
990 APInt(SrcWidth, MaxShiftAmt)))) {
992 bool IsExact = OldShift->isExact();
997 OldShift->getOpcode() == Instruction::AShr
998 ?
Builder.CreateAShr(
A, ShAmt, OldShift->getName(), IsExact)
999 :
Builder.CreateLShr(
A, ShAmt, OldShift->getName(), IsExact);
1009 if (Instruction *NarrowOr = narrowFunnelShift(
Trunc))
1031 Value *NarrowOp = Builder.CreateTrunc(ShufVec, NewTruncTy);
1046 assert((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
1047 "Unexpected instruction for shrinking");
1056 Builder.CreateCast(Opcode, Elt,
Trunc.getType()->getScalarType());
1068 Type *DestTy =
Trunc.getType(), *SrcTy = Src->getType();
1070 unsigned SrcWidth = SrcTy->getScalarSizeInBits();
1076 if ((DestTy->
isVectorTy() || shouldChangeType(SrcTy, DestTy)) &&
1077 TypeEvaluationHelper::canEvaluateTruncated(Src, DestTy, *
this, &
Trunc)) {
1082 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1095 if (DestWidth * 2 < SrcWidth) {
1096 auto *NewDestTy = DestITy->getExtendedType();
1097 if (shouldChangeType(SrcTy, NewDestTy) &&
1098 TypeEvaluationHelper::canEvaluateTruncated(Src, NewDestTy, *
this,
1101 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1102 " to reduce the width of operand of"
1110 if (DestWidth == 1 &&
1111 (
Trunc.hasNoUnsignedWrap() ||
Trunc.hasNoSignedWrap()) &&
1120 if (DestWidth == 1) {
1128 Constant *Log2C1 = ConstantInt::get(SrcTy,
C1->exactLogBase2());
1142 Constant *One = ConstantInt::get(SrcTy,
APInt(SrcWidth, 1));
1150 Constant *One = ConstantInt::get(SrcTy,
APInt(SrcWidth, 1));
1164 if (
Trunc.hasNoUnsignedWrap() ||
Trunc.hasNoSignedWrap()) {
1188 Trunc,
Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat,
A,
B));
1197 Trunc,
Builder.CreateBinaryIntrinsic(Intrinsic::usub_sat,
A,
B));
1201 unsigned AWidth =
A->getType()->getScalarSizeInBits();
1202 unsigned MaxShiftAmt = SrcWidth - std::max(DestWidth, AWidth);
1204 bool IsExact = OldSh->isExact();
1209 APInt(SrcWidth, MaxShiftAmt)))) {
1210 auto GetNewShAmt = [&](
unsigned Width) {
1211 Constant *MaxAmt = ConstantInt::get(SrcTy, Width - 1,
false);
1220 if (
A->getType() == DestTy) {
1221 Constant *ShAmt = GetNewShAmt(DestWidth);
1223 return IsExact ? BinaryOperator::CreateExactAShr(
A, ShAmt)
1224 : BinaryOperator::CreateAShr(
A, ShAmt);
1228 if (Src->hasOneUse()) {
1229 Constant *ShAmt = GetNewShAmt(AWidth);
1246 if (Src->hasOneUse() &&
1254 APInt Threshold =
APInt(
C->getType()->getScalarSizeInBits(), DestWidth);
1259 bool NUW =
Trunc.hasNoUnsignedWrap() && WideShl->hasNoUnsignedWrap();
1260 bool NSW =
Trunc.hasNoSignedWrap() && WideShl->hasNoSignedWrap();
1261 Value *NewTrunc =
Builder.CreateTrunc(
A, DestTy,
A->getName() +
".tr",
1265 NewShl->setHasNoUnsignedWrap(NUW);
1266 NewShl->setHasNoSignedWrap(NSW);
1285 Value *SExtVal =
nullptr;
1295 {ConstantInt::get(SrcTy, 0),
A});
1297 Intrinsic::smin, {SrcTy},
1298 {
SMax, ConstantInt::get(SrcTy, TruncatedMax)});
1311 unsigned AWidth =
A->getType()->getScalarSizeInBits();
1312 if (AWidth == DestWidth && AWidth >
Log2_32(SrcWidth)) {
1313 Value *WidthDiff = ConstantInt::get(
A->getType(), SrcWidth - AWidth);
1315 Builder.CreateIntrinsic(Intrinsic::ctlz, {
Trunc.getType()}, {
A,
B});
1316 return BinaryOperator::CreateAdd(NarrowCtlz, WidthDiff);
1321 if (
Trunc.getFunction() &&
1322 Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) {
1324 Trunc.getFunction()->getFnAttribute(Attribute::VScaleRange);
1326 if (
Log2_32(*MaxVScale) < DestWidth)
1338 Trunc,
Builder.CreateIntrinsic(DestTy, CI->getIntrinsicID(),
1339 {CI->getLHS(), CI->getRHS()}));
1341 if (DestWidth == 1 &&
1342 (
Trunc.hasNoUnsignedWrap() ||
Trunc.hasNoSignedWrap()) &&
1347 if (!
Trunc.hasNoSignedWrap() &&
1349 Trunc.setHasNoSignedWrap(
true);
1352 if (!
Trunc.hasNoUnsignedWrap() &&
1355 Trunc.setHasNoUnsignedWrap(
true);
1364 Value *
Right = ConstantInt::get(
V1->getType(),
C1->countr_zero());
1372 Value *
Right = ConstantInt::get(
V1->getType(),
C1->countr_one());
1380 Value *
Right = ConstantInt::get(
V1->getType(),
C1->countr_zero());
1411 Value *In = Cmp->getOperand(0);
1412 Value *Sh = ConstantInt::get(In->getType(),
1413 In->getType()->getScalarSizeInBits() - 1);
1414 In = Builder.CreateLShr(In, Sh, In->getName() +
".lobit");
1415 if (In->getType() != Zext.
getType())
1416 In = Builder.CreateIntCast(In, Zext.
getType(),
false );
1426 if (Op1CV->
isZero() && Cmp->isEquality()) {
1431 uint32_t ShAmt = KnownZeroMask.logBase2();
1432 bool IsExpectShAmt = KnownZeroMask.isPowerOf2() &&
1434 if (IsExpectShAmt &&
1435 (Cmp->getOperand(0)->getType() == Zext.
getType() ||
1437 Value *In = Cmp->getOperand(0);
1441 In = Builder.CreateLShr(In, ConstantInt::get(In->getType(), ShAmt),
1442 In->getName() +
".lobit");
1447 In =
Builder.CreateXor(In, ConstantInt::get(
In->getType(), 1));
1458 if (
Cmp->isEquality()) {
1467 Value *Shift =
And->getOperand(
X ==
And->getOperand(0) ? 1 : 0);
1474 Builder.CreateAnd(Lshr, ConstantInt::get(
X->getType(), 1));
1502bool TypeEvaluationHelper::canEvaluateZExtd(
Value *
V,
Type *Ty,
1503 unsigned &BitsToClear,
1506 TypeEvaluationHelper TYH(IC.
CLOpts.max_type_eval_depth);
1507 return TYH.canEvaluateZExtdImpl(
V, Ty, BitsToClear, IC, CtxI);
1509bool TypeEvaluationHelper::canEvaluateZExtdImpl(
Value *
V,
Type *Ty,
1510 unsigned &BitsToClear,
1514 if (
Depth >= MaxTypeEvalDepth)
1517 if (canAlwaysEvaluateInType(
V, Ty))
1521 if (canNotEvaluateInType(
V, Ty))
1529 switch (
I->getOpcode()) {
1530 case Instruction::ZExt:
1531 case Instruction::SExt:
1532 case Instruction::Trunc:
1534 case Instruction::And:
1535 case Instruction::Or:
1536 case Instruction::Xor:
1537 case Instruction::Add:
1538 case Instruction::Sub:
1539 case Instruction::Mul:
1540 if (!canEvaluateZExtdImpl(
I->getOperand(0), Ty, BitsToClear, IC, CtxI) ||
1541 !canEvaluateZExtdImpl(
I->getOperand(1), Ty, Tmp, IC, CtxI))
1544 if (BitsToClear == 0 && Tmp == 0)
1549 if (Tmp == 0 &&
I->isBitwiseLogicOp()) {
1552 unsigned VSize =
V->getType()->getScalarSizeInBits();
1558 if (
I->getOpcode() == Instruction::And)
1567 case Instruction::Shl: {
1572 if (!canEvaluateZExtdImpl(
I->getOperand(0), Ty, BitsToClear, IC, CtxI))
1574 BitsToClear = ShiftAmt < BitsToClear ? BitsToClear - ShiftAmt : 0;
1579 case Instruction::LShr: {
1584 if (!canEvaluateZExtdImpl(
I->getOperand(0), Ty, BitsToClear, IC, CtxI))
1586 BitsToClear += ShiftAmt;
1587 if (BitsToClear >
V->getType()->getScalarSizeInBits())
1588 BitsToClear =
V->getType()->getScalarSizeInBits();
1594 case Instruction::Select:
1595 if (!canEvaluateZExtdImpl(
I->getOperand(1), Ty, Tmp, IC, CtxI) ||
1596 !canEvaluateZExtdImpl(
I->getOperand(2), Ty, BitsToClear, IC, CtxI) ||
1603 case Instruction::PHI: {
1619 case Instruction::Call:
1623 if (
II->getIntrinsicID() == Intrinsic::vscale)
1647 Type *SrcTy = Src->getType(), *DestTy = Zext.
getType();
1650 if (SrcTy->isIntOrIntVectorTy(1) && Zext.
hasNonNeg())
1659 bool EvaluateAsSigned =
1660 Zext.
hasNonNeg() && TypeEvaluationHelper::canEvaluateSExtd(
1661 Src, DestTy,
CLOpts.max_type_eval_depth);
1664 unsigned BitsToClear = 0;
1665 if (shouldChangeType(SrcTy, DestTy) &&
1666 (EvaluateAsSigned || TypeEvaluationHelper::canEvaluateZExtd(
1667 Src, DestTy, BitsToClear, *
this, &Zext))) {
1669 "Can't clear more bits than in SrcTy");
1673 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1674 " to avoid zero extend: "
1681 if (
SrcOp->hasOneUse())
1684 uint32_t SrcBitsKept = SrcTy->getScalarSizeInBits() - BitsToClear;
1690 if (EvaluateAsSigned
1701 return BinaryOperator::CreateAnd(Res,
C);
1712 Value *
A = CSrc->getOperand(0);
1713 unsigned SrcSize =
A->getType()->getScalarSizeInBits();
1714 unsigned MidSize = CSrc->getType()->getScalarSizeInBits();
1720 if (SrcSize < DstSize) {
1722 Constant *AndConst = ConstantInt::get(
A->getType(), AndValue);
1727 if (SrcSize == DstSize) {
1729 return BinaryOperator::CreateAnd(
A, ConstantInt::get(
A->getType(),
1732 if (SrcSize > DstSize) {
1735 return BinaryOperator::CreateAnd(
Trunc,
1736 ConstantInt::get(
Trunc->getType(),
1742 return transformZExtICmp(Cmp, Zext);
1752 return BinaryOperator::CreateXor(
Builder.CreateAnd(
X, ZC), ZC);
1758 SrcTy->getScalarSizeInBits());
1759 Value *Neg =
Builder.CreateSub(ConstantInt::get(DestTy, 0),
X);
1760 return BinaryOperator::CreateAnd(Neg, ConstantInt::get(DestTy, Mask));
1770 return BinaryOperator::CreateAnd(
X, ZextC);
1787 unsigned TypeWidth = Src->getType()->getScalarSizeInBits();
1788 if (
Log2_32(*MaxVScale) < TypeWidth)
1797 SrcTy->getScalarSizeInBits() >
1816 Value *Op0 = Cmp->getOperand(0), *Op1 = Cmp->getOperand(1);
1827 Value *In = Builder.CreateAShr(Op0, Sh, Op0->
getName() +
".lobit");
1828 if (In->getType() != Sext.
getType())
1829 In = Builder.CreateIntCast(In, Sext.
getType(),
true );
1838 if (Cmp->hasOneUse() &&
1839 Cmp->isEquality() && (Op1C->isZero() || Op1C->getValue().isPowerOf2())){
1843 if (KnownZeroMask.isPowerOf2()) {
1844 Value *In = Cmp->getOperand(0);
1847 if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) {
1857 unsigned ShiftAmt = KnownZeroMask.countr_zero();
1861 ConstantInt::get(
In->getType(), ShiftAmt));
1871 unsigned ShiftAmt = KnownZeroMask.countl_zero();
1875 ConstantInt::get(
In->getType(), ShiftAmt));
1878 In =
Builder.CreateAShr(In, ConstantInt::get(
In->getType(),
1879 KnownZeroMask.getBitWidth() - 1),
"sext");
1899bool TypeEvaluationHelper::canEvaluateSExtd(
Value *
V,
Type *Ty,
1900 unsigned MaxTypeEvalDepth) {
1901 TypeEvaluationHelper TYH(MaxTypeEvalDepth);
1902 return TYH.canEvaluateSExtdImpl(
V, Ty) && TYH.allPendingVisited();
1905bool TypeEvaluationHelper::canEvaluateSExtdImpl(
Value *
V,
Type *Ty) {
1906 return canEvaluate(
V, Ty, [
this](
Value *
V,
Type *Ty) {
1907 return canEvaluateSExtdPred(
V, Ty);
1911bool TypeEvaluationHelper::canEvaluateSExtdPred(
Value *
V,
Type *Ty) {
1913 "Can't sign extend type to a smaller type");
1916 switch (
I->getOpcode()) {
1917 case Instruction::SExt:
1918 case Instruction::ZExt:
1919 case Instruction::Trunc:
1921 case Instruction::And:
1922 case Instruction::Or:
1923 case Instruction::Xor:
1924 case Instruction::Add:
1925 case Instruction::Sub:
1926 case Instruction::Mul:
1928 return canEvaluateSExtdImpl(
I->getOperand(0), Ty) &&
1929 canEvaluateSExtdImpl(
I->getOperand(1), Ty);
1934 case Instruction::Select:
1935 return canEvaluateSExtdImpl(
I->getOperand(1), Ty) &&
1936 canEvaluateSExtdImpl(
I->getOperand(2), Ty);
1938 case Instruction::PHI: {
1944 if (!canEvaluateSExtdImpl(IncValue, Ty))
1966 Type *SrcTy = Src->getType(), *DestTy = Sext.
getType();
1973 CI->setNonNeg(
true);
1981 unsigned XBitSize =
X->getType()->getScalarSizeInBits();
1982 unsigned TruncatedBits = XBitSize - SrcBitSize;
1987 ResTrunc->setHasNoSignedWrap(
true);
1998 if (Src->hasOneUse() &&
2000 C->ule(TruncatedBits) &&
2001 (*
C == TruncatedBits ||
2008 if (Src->hasOneUse() &&
X->getType() == DestTy) {
2010 Constant *ShAmt = ConstantInt::get(DestTy, DestBitSize - SrcBitSize);
2011 return BinaryOperator::CreateAShr(
Builder.CreateShl(
X, ShAmt), ShAmt);
2016 bool ShouldExtendExpression =
true;
2017 Value *TruncSrc =
nullptr;
2022 ShouldExtendExpression =
false;
2023 if (ShouldExtendExpression && shouldChangeType(SrcTy, DestTy) &&
2024 TypeEvaluationHelper::canEvaluateSExtd(Src, DestTy,
2025 CLOpts.max_type_eval_depth)) {
2028 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
2029 " to avoid sign extend: "
2040 Value *ShAmt = ConstantInt::get(DestTy, DestBitSize - SrcBitSize);
2041 return BinaryOperator::CreateAShr(
Builder.CreateShl(Res, ShAmt,
"sext"),
2046 return transformSExtICmp(Cmp, Sext);
2063 Constant *BA =
nullptr, *CA =
nullptr;
2070 assert(WideCurrShAmt &&
"Constant folding of ImmConstant cannot fail");
2079 return BinaryOperator::CreateAShr(
A, NewShAmt);
2087 Type *XTy =
X->getType();
2089 Constant *ShlAmtC = ConstantInt::get(XTy, XBitSize - SrcBitSize);
2090 Constant *AshrAmtC = ConstantInt::get(XTy, XBitSize - 1);
2092 return BinaryOperator::CreateAShr(
Builder.CreateShl(
X, ShlAmtC),
2106 if (
Log2_32(*MaxVScale) < (SrcBitSize - 1))
2117 Sext,
Builder.CreateIntrinsic(DestTy, CI->getIntrinsicID(),
2118 {CI->getLHS(), CI->getRHS()}));
2140 bool PreferBFloat) {
2161 if (Ty->getScalarType()->isPPC_FP128Ty())
2181 Type *MinType =
nullptr;
2183 unsigned NumElts = CVVTy->getNumElements();
2187 for (
unsigned I = 0;
I != NumElts; ++
I) {
2212 return FPExt->getOperand(0)->getType();
2240 return V->getType();
2246 Type *SrcTy = V->getType();
2247 assert(SrcTy->isIntOrIntVectorTy() &&
"Expected an integer type");
2248 int SrcSize = (int)SrcTy->getScalarSizeInBits() - IsSigned;
2253 if (SrcSize <= DestNumSigBits)
2262 int SrcNumSigBits =
F->getType()->getFPMantissaWidth();
2269 if (SrcNumSigBits > 0 && DestNumSigBits > 0 &&
2270 SrcNumSigBits <= DestNumSigBits)
2277 int SigBits = (int)SrcTy->getScalarSizeInBits() -
2280 if (SigBits <= DestNumSigBits)
2287 if (SigBits <= DestNumSigBits)
2296 assert((Opcode == CastInst::SIToFP || Opcode == CastInst::UIToFP) &&
2298 Value *Src =
I.getOperand(0);
2299 Type *FPTy =
I.getType();
2316 if (BO && BO->hasOneUse()) {
2319 unsigned OpWidth = BO->getType()->getFPMantissaWidth();
2322 unsigned SrcWidth = std::max(LHSWidth, RHSWidth);
2323 unsigned DstWidth = Ty->getFPMantissaWidth();
2329 auto IsLosslesslyConvertibleToDst = [&](
Type *SrcTy) {
2331 SrcTy->getScalarType()->getFltSemantics(),
2332 Ty->getScalarType()->getFltSemantics(),
true);
2334 bool OperandsFitDst = IsLosslesslyConvertibleToDst(LHSMinType) &&
2335 IsLosslesslyConvertibleToDst(RHSMinType);
2343 switch (BO->getOpcode()) {
2345 case Instruction::FAdd:
2346 case Instruction::FSub:
2365 if (OpWidth >= 2 * DstWidth + 1 && OperandsFitDst) {
2366 Value *LHS =
Builder.CreateFPTrunc(BO->getOperand(0), Ty);
2367 Value *RHS =
Builder.CreateFPTrunc(BO->getOperand(1), Ty);
2373 case Instruction::FMul:
2379 if (OpWidth >= LHSWidth + RHSWidth && OperandsFitDst) {
2380 Value *LHS =
Builder.CreateFPTrunc(BO->getOperand(0), Ty);
2381 Value *RHS =
Builder.CreateFPTrunc(BO->getOperand(1), Ty);
2385 case Instruction::FDiv:
2392 if (OpWidth >= 2 * DstWidth && OperandsFitDst) {
2393 Value *LHS =
Builder.CreateFPTrunc(BO->getOperand(0), Ty);
2394 Value *RHS =
Builder.CreateFPTrunc(BO->getOperand(1), Ty);
2398 case Instruction::FRem: {
2403 if (SrcWidth == OpWidth)
2406 if (LHSWidth == SrcWidth) {
2407 LHS =
Builder.CreateFPTrunc(BO->getOperand(0), LHSMinType);
2408 RHS =
Builder.CreateFPTrunc(BO->getOperand(1), LHSMinType);
2410 LHS =
Builder.CreateFPTrunc(BO->getOperand(0), RHSMinType);
2411 RHS =
Builder.CreateFPTrunc(BO->getOperand(1), RHSMinType);
2414 Value *ExactResult =
Builder.CreateFRemFMF(LHS, RHS, BO);
2423 if (
Op &&
Op->hasOneUse()) {
2426 FMF &= FPMO->getFastMathFlags();
2443 Builder.CreateSelectFMF(
Cond,
X, NarrowY, FMF,
"narrow.sel",
Op);
2451 Builder.CreateSelectFMF(
Cond, NarrowY,
X, FMF,
"narrow.sel",
Op);
2457 switch (
II->getIntrinsicID()) {
2459 case Intrinsic::ceil:
2460 case Intrinsic::fabs:
2461 case Intrinsic::floor:
2462 case Intrinsic::nearbyint:
2463 case Intrinsic::rint:
2464 case Intrinsic::round:
2465 case Intrinsic::roundeven:
2466 case Intrinsic::trunc: {
2467 Value *Src =
II->getArgOperand(0);
2468 if (!Src->hasOneUse())
2474 if (
II->getIntrinsicID() != Intrinsic::fabs) {
2476 if (!FPExtSrc || FPExtSrc->
getSrcTy() != Ty)
2486 II->getOperandBundlesAsDefs(OpBundles);
2528template <
typename FPToIntTy>
2530 constexpr bool IsSaturating = std::is_same_v<FPToIntTy, IntrinsicInst>;
2536 Value *
X = OpI->getOperand(0);
2537 Type *XType =
X->getType();
2538 Type *DestType = FI.getType();
2541 bool IsOutputSigned;
2542 if constexpr (IsSaturating)
2543 IsOutputSigned = FI.getIntrinsicID() == Intrinsic::fptosi_sat;
2554 if constexpr (!IsSaturating) {
2562 if (OutputSize > OpI->getType()->getFPMantissaWidth())
2574 if constexpr (IsSaturating) {
2577 if (IsInputSigned != IsOutputSigned || DestWidth < SrcWidth)
2581 if (DestWidth > SrcWidth) {
2582 if (IsInputSigned && IsOutputSigned)
2586 if (DestWidth < SrcWidth)
2589 assert(XType == DestType &&
"Unexpected types for int to FP to int casts");
2628 bool IsSigned = FI.
getOpcode() == Instruction::FPToSI;
2640 Type *IntTy =
X->getType();
2644 unsigned IntWidth = IntTy->getScalarSizeInBits();
2646 if (Precision + IsSigned < IntWidth)
2652 APSInt Divisor(IntWidth, !IsSigned);
2653 bool IsExact =
false;
2666 Constant *
C = ConstantInt::get(IntTy, Divisor);
2667 return IsSigned ? BinaryOperator::CreateSDiv(
X,
C)
2668 : BinaryOperator::CreateUDiv(
X,
C);
2705 unsigned SourceWidth = Src->getType()->getScalarSizeInBits();
2706 unsigned InputWidth =
X->getType()->getScalarSizeInBits();
2707 if (!
DL.isLegalInteger(SourceWidth) &&
2708 shouldChangeType(SourceWidth, InputWidth)) {
2727 UI->setNonNeg(
true);
2744 DL.getPointerSizeInBits(AS)) {
2756 auto UsesPointerAsInt = [](
User *U) {
2767 Base->getType()->getPointerAddressSpace() &&
2784 if (!
GEP || !
GEP->hasOneUse())
2787 Ptr =
GEP->getPointerOperand();
2796 Type *IdxTy =
DL.getIndexType(PtrTy);
2798 Res->
getType() == IntTy && IntTy == IdxTy) {
2811 return Builder.CreateZExtOrTrunc(Res, IntTy);
2822 unsigned TySize = Ty->getScalarSizeInBits();
2823 unsigned PtrSize =
DL.getPointerSizeInBits(AS);
2824 if (TySize != PtrSize) {
2826 SrcTy->getWithNewType(
DL.getIntPtrType(CI.
getContext(), AS));
2837 return BinaryOperator::CreateAnd(
Builder.CreatePtrToInt(Ptr, Ty), Mask);
2842 Value *Vec, *Scalar, *Index;
2848 Value *NewCast =
Builder.CreatePtrToInt(Scalar, Ty->getScalarType());
2865 return BinaryOperator::CreateAnd(
Builder.CreatePtrToAddr(Ptr), Mask);
2898 if (SrcTy->getElementType() != DestTy->getElementType()) {
2903 if (SrcTy->getElementType()->getPrimitiveSizeInBits() !=
2904 DestTy->getElementType()->getPrimitiveSizeInBits())
2917 assert(SrcElts != DestElts &&
"Element counts should be different.");
2926 if (SrcElts > DestElts) {
2935 ShuffleMask = ShuffleMaskStorage;
2937 ShuffleMask = ShuffleMask.take_back(DestElts);
2939 ShuffleMask = ShuffleMask.take_front(DestElts);
2950 unsigned DeltaElts = DestElts - SrcElts;
2952 ShuffleMaskStorage.insert(ShuffleMaskStorage.begin(), DeltaElts, NullElt);
2954 ShuffleMaskStorage.append(DeltaElts, NullElt);
2955 ShuffleMask = ShuffleMaskStorage;
2962 return Value % Ty->getPrimitiveSizeInBits() == 0;
2966 return Value / Ty->getPrimitiveSizeInBits();
2983 "Shift should be a multiple of the element type size");
2991 if (
V->getType() == VecEltTy) {
2994 if (
C->isNullValue())
2999 ElementIndex = Elements.size() - ElementIndex - 1;
3002 if (Elements[ElementIndex])
3005 Elements[ElementIndex] =
V;
3024 C->getType()->getPrimitiveSizeInBits()));
3028 for (
unsigned i = 0; i != NumElts; ++i) {
3029 unsigned ShiftI = i * ElementSize;
3031 Instruction::LShr,
C, ConstantInt::get(
C->getType(), ShiftI));
3043 if (!
V->hasOneUse())
return false;
3046 if (!
I)
return false;
3047 switch (
I->getOpcode()) {
3048 default:
return false;
3049 case Instruction::BitCast:
3050 if (
I->getOperand(0)->getType()->isVectorTy())
3054 case Instruction::ZExt:
3056 I->getOperand(0)->getType()->getPrimitiveSizeInBits(),
3061 case Instruction::Or:
3066 case Instruction::Shl: {
3069 if (!CI)
return false;
3106 DestVecTy->getElementType(),
3114 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
3115 if (!Elements[i])
continue;
3129 Value *VecOp, *Index;
3147 if (DestType->
isVectorTy() && FixedVType && FixedVType->getNumElements() == 1)
3174 if (
X->getType()->isFPOrFPVectorTy() &&
3175 Y->getType()->isIntOrIntVectorTy()) {
3177 Builder.CreateBitCast(BO->
getOperand(0),
Y->getType());
3181 if (
X->getType()->isIntOrIntVectorTy() &&
3182 Y->getType()->isFPOrFPVectorTy()) {
3184 Builder.CreateBitCast(BO->
getOperand(1),
X->getType());
3220 Value *CastedC = Builder.CreateBitCast(
C, DestTy);
3243 CondVTy->getElementCount() != DestVecTy->getElementCount())
3252 SrcVecTy->getElementCount())))) {
3255 Value *CastedTVal = Builder.CreateBitCast(TVal, DestTy);
3256 Value *CastedFVal = Builder.CreateBitCast(FVal, DestTy);
3264 if ((DestVecTy !=
nullptr) != (SrcVecTy !=
nullptr))
3271 Value *CastedVal = Builder.CreateBitCast(FVal, DestTy);
3278 Value *CastedVal = Builder.CreateBitCast(TVal, DestTy);
3309 Type *SrcTy = Src->getType();
3313 SmallSetVector<PHINode *, 4> OldPhiNodes;
3321 while (!PhiWorklist.
empty()) {
3323 for (
Value *IncValue : OldPN->incoming_values()) {
3332 Value *Addr = LI->getOperand(0);
3341 if (LI->hasOneUse() && LI->isSimple())
3349 if (OldPhiNodes.
insert(PNode))
3360 Type *TyA = BCI->getOperand(0)->getType();
3361 Type *TyB = BCI->getType();
3362 if (TyA != DestTy || TyB != SrcTy)
3369 for (
auto *OldPN : OldPhiNodes) {
3370 for (User *
V : OldPN->users()) {
3372 if (!
SI->isSimple() ||
SI->getOperand(0) != OldPN)
3376 Type *TyB = BCI->getOperand(0)->getType();
3377 Type *TyA = BCI->getType();
3378 if (TyA != DestTy || TyB != SrcTy)
3384 if (!OldPhiNodes.contains(
PHI))
3393 SmallDenseMap<PHINode *, PHINode *> NewPNodes;
3394 for (
auto *OldPN : OldPhiNodes) {
3395 Builder.SetInsertPoint(OldPN);
3396 PHINode *NewPN =
Builder.CreatePHI(DestTy, OldPN->getNumOperands());
3397 NewPNodes[OldPN] = NewPN;
3401 for (
auto *OldPN : OldPhiNodes) {
3402 PHINode *NewPN = NewPNodes[OldPN];
3403 for (
unsigned j = 0, e = OldPN->getNumOperands(); j != e; ++j) {
3404 Value *
V = OldPN->getOperand(j);
3405 Value *NewV =
nullptr;
3418 NewV = BCI->getOperand(0);
3420 NewV = NewPNodes[PrevPN];
3423 NewPN->
addIncoming(NewV, OldPN->getIncomingBlock(j));
3437 for (
auto *OldPN : OldPhiNodes) {
3438 PHINode *NewPN = NewPNodes[OldPN];
3441 assert(
SI->isSimple() &&
SI->getOperand(0) == OldPN);
3445 SI->setOperand(0, NewBC);
3450 Type *TyB = BCI->getOperand(0)->getType();
3451 Type *TyA = BCI->getType();
3452 assert(TyA == DestTy && TyB == SrcTy);
3483 if (
X->getType() != FTy)
3488 return Builder.CreateCopySign(Builder.CreateBitCast(
Y, FTy),
X);
3495 Type *SrcTy = Src->getType();
3500 if (DestTy == Src->getType())
3526 if (SrcVTy->getNumElements() == 1) {
3530 Value *Elem =
Builder.CreateExtractElement(Src, uint64_t{0});
3538 return new BitCastInst(InsElt->getOperand(1), DestTy);
3548 DestTy->
isIntegerTy() &&
Y->getType()->isIntegerTy() &&
3551 if (
DL.isBigEndian())
3552 IndexC = SrcVTy->getNumElements() - 1 - IndexC;
3558 unsigned EltWidth =
Y->getType()->getScalarSizeInBits();
3562 return BinaryOperator::CreateOr(AndX, ZextY);
3570 Value *ShufOp0 = Shuf->getOperand(0);
3571 Value *ShufOp1 = Shuf->getOperand(1);
3574 if (Shuf->hasOneUse() && DestTy->
isVectorTy() &&
3576 ShufElts == SrcVecElts) {
3597 if (DestTy->
isIntegerTy() && ShufElts.getKnownMinValue() % 2 == 0 &&
3598 Shuf->hasOneUse() && Shuf->isReverse() &&
match(ShufOp1,
m_Poison())) {
3599 unsigned IntrinsicNum = 0;
3601 SrcTy->getScalarSizeInBits() == 8) {
3602 IntrinsicNum = Intrinsic::bswap;
3603 }
else if (SrcTy->getScalarSizeInBits() == 1) {
3604 IntrinsicNum = Intrinsic::bitreverse;
3606 if (IntrinsicNum != 0) {
3607 assert(ShufOp0->
getType() == SrcTy &&
"Unexpected shuffle mask");
3610 Value *ScalarX =
Builder.CreateBitCast(ShufOp0, DestTy);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static std::optional< bool > isBigEndian(const SmallDenseMap< int64_t, int64_t, 8 > &MemOffset2Idx, int64_t LowestIdx)
Given a map from byte offsets in memory to indices in a load/store, determine if that map corresponds...
This file defines the DenseMap class.
static bool isSigned(unsigned Opcode)
static bool collectInsertionElements(Value *V, unsigned Shift, SmallVectorImpl< Value * > &Elements, Type *VecEltTy, bool isBigEndian)
V is a value which is inserted into a vector of VecEltTy.
static bool hasStoreUsersOnly(CastInst &CI)
Check if all users of CI are StoreInsts.
static Value * foldCopySignIdioms(BitCastInst &CI, InstCombiner::BuilderTy &Builder, const SimplifyQuery &SQ)
Fold (bitcast (or (and (bitcast X to int), signmask), nneg Y) to fp) to copysign((bitcast Y to fp),...
static Type * shrinkFPConstantVector(Value *V, bool PreferBFloat)
static Instruction * canonicalizeBitCastExtElt(BitCastInst &BitCast, InstCombinerImpl &IC)
Canonicalize scalar bitcasts of extracted elements into a bitcast of the vector followed by extract e...
static Instruction * shrinkSplatShuffle(TruncInst &Trunc, InstCombiner::BuilderTy &Builder)
Try to narrow the width of a splat shuffle.
static Instruction * foldFPtoI(Instruction &FI, InstCombiner &IC)
static Instruction * foldBitCastSelect(BitCastInst &BitCast, InstCombiner::BuilderTy &Builder)
Change the type of a select if we can eliminate a bitcast.
static Instruction * foldBitCastBitwiseLogic(BitCastInst &BitCast, InstCombiner::BuilderTy &Builder)
Change the type of a bitwise logic operation if we can eliminate a bitcast.
static bool fitsInFPType(APFloat F, const fltSemantics &Sem)
Return a Constant* for the specified floating-point constant if it fits in the specified FP type with...
static Instruction * optimizeVectorResizeWithIntegerBitCasts(Value *InVal, VectorType *DestTy, InstCombinerImpl &IC)
This input value (which is known to have vector type) is being zero extended or truncated to the spec...
static Instruction * shrinkInsertElt(CastInst &Trunc, InstCombiner::BuilderTy &Builder)
Try to narrow the width of an insert element.
SmallDenseMap< Value *, Value *, 8 > EvaluatedMap
static Type * getMinimumFPType(Value *V, Type *PreferredTy, InstCombiner &IC)
Find the minimum FP type we can safely truncate to.
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty)
static Value * optimizeIntegerToVectorInsertions(BitCastInst &CI, InstCombinerImpl &IC)
If the input is an 'or' instruction, we may be doing shifts and ors to assemble the elements of the v...
static Type * shrinkFPConstant(LLVMContext &Ctx, const APFloat &F, bool PreferBFloat)
static Instruction * foldVecExtTruncToExtElt(TruncInst &Trunc, InstCombinerImpl &IC)
Whenever an element is extracted from a vector, optionally shifted down, and then truncated,...
static Value * EvaluateInDifferentTypeImpl(Value *V, Type *Ty, bool isSigned, InstCombinerImpl &IC, EvaluatedMap &Processed)
static unsigned getTypeSizeIndex(unsigned Value, Type *Ty)
static Instruction * foldVecTruncToExtElt(TruncInst &Trunc, InstCombinerImpl &IC)
Given a vector that is bitcast to an integer, optionally logically right-shifted, and truncated,...
This file provides internal interfaces used to implement the InstCombine.
This file provides the interface for the instcombine pass implementation.
uint64_t IntrinsicInst * II
This file contains the declarations for profiling metadata utility functions.
SmallVector< MachineOperand, 4 > Cond
This file provides utility classes that use RAII to save and restore values.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static SymbolRef::Type getType(const Symbol *Sym)
static const fltSemantics & IEEEsingle()
static constexpr roundingMode rmTowardZero
static const fltSemantics & BFloat()
static const fltSemantics & IEEEdouble()
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
static LLVM_ABI bool isLosslesslyConvertibleTo(const fltSemantics &From, const fltSemantics &To, bool IgnoreNaNs=false)
Returns whether converting a value from From to To is known to preserve all information.
static const fltSemantics & IEEEhalf()
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
const fltSemantics & getSemantics() const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
Class for arbitrary precision integers.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
uint64_t getZExtValue() const
Get zero extended value.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
An arbitrary precision integer that knows its signedness.
This class represents a conversion between pointers from one address space to another.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
BinaryOps getOpcode() const
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
This class represents a no-op cast from one type to another.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
This is the base class for all instructions that perform data casts.
Type * getSrcTy() const
Return the source type, as a convenience.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
static LLVM_ABI unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, const DataLayout *DL)
Determine how a pair of casts can be eliminated, if they can be at all.
static LLVM_ABI CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static LLVM_ABI CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
static LLVM_ABI CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
static LLVM_ABI CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Type * getDestTy() const
Return the destination type, as a convenience.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_ULE
unsigned less or equal
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
bool uge(uint64_t Num) const
This function will return true iff this constant represents a value with active bits bigger than 64 b...
This is an important base class in LLVM.
static LLVM_ABI Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
This class represents an extension of floating point types.
This class represents a cast from floating point to signed integer.
This class represents a cast from floating point to unsigned integer.
This class represents a truncation of floating point types.
Convenience struct for specifying and reasoning about fast-math flags.
void setNoInfs(bool B=true)
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
This instruction compares its operands according to the predicate given to the constructor.
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Instruction * visitZExt(ZExtInst &Zext)
Instruction * foldCmpLoadFromIndexedGlobal(LoadInst *LI, CmpPredicate Pred, Constant *RHSC, Instruction &CtxI, ConstantInt *AndCst=nullptr)
Try to fold cmp pred (load (gep GV, ...)), cmpcst where GV is a global variable with a constant initi...
Instruction * visitAddrSpaceCast(AddrSpaceCastInst &CI)
Instruction * foldExtractionOfVectorDeinterleave(ZExtInst &RootZExt)
Instruction * visitSExt(SExtInst &Sext)
Instruction * foldOpIntoPhi(Instruction &I, PHINode *PN, bool AllowMultipleUses=false)
Given a binary operator, cast instruction, or select which has a PHI node as operand #0,...
Instruction * visitFPToSI(FPToSIInst &FI)
Instruction * visitTrunc(TruncInst &CI)
Instruction * visitUIToFP(CastInst &CI)
Instruction * visitPtrToInt(PtrToIntInst &CI)
Instruction * FoldOpIntoSelect(Instruction &Op, SelectInst *SI, bool FoldWithMultiUse=false, bool SimplifyBothArms=false)
Given an instruction with a select as one operand and a constant as the other operand,...
Instruction * foldItoFPtoI(FPToIntTy &FI)
fpto{s/u}i.sat --> X or zext(X) or sext(X) or trunc(X) This is safe if the intermediate type has enou...
Instruction * visitSIToFP(CastInst &CI)
Instruction * commonCastTransforms(CastInst &CI)
Implement the transforms common to all CastInst visitors.
Instruction * eraseInstFromFunction(Instruction &I) override
Combiner aware instruction erasure.
Instruction * visitFPTrunc(FPTruncInst &CI)
const InstCombineCLOptions & CLOpts
Value * foldPtrToIntOrAddrOfGEP(Type *IntTy, Value *Ptr)
Instruction * visitBitCast(BitCastInst &CI)
Instruction * visitIntToPtr(IntToPtrInst &CI)
Instruction * visitFPToUI(FPToUIInst &FI)
Instruction * visitPtrToAddr(PtrToAddrInst &CI)
Value * EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned)
Given an expression that CanEvaluateTruncated or CanEvaluateSExtd returns true for,...
bool SimplifyDemandedInstructionBits(Instruction &Inst)
Tries to simplify operands to an integer instruction based on its demanded bits.
Instruction * visitFPExt(CastInst &CI)
LoadInst * combineLoadToNewType(LoadInst &LI, Type *NewTy, const Twine &Suffix="")
Helper to combine a load to a new type.
The core instruction combiner logic.
const DataLayout & getDataLayout() const
LLVM_ABI bool canBeCastedExactlyIntToFP(Value *V, Type *FPTy, bool IsSigned, const Instruction *CtxI=nullptr) const
unsigned ComputeMaxSignificantBits(const Value *Op, const Instruction *CtxI=nullptr, unsigned Depth=0) const
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
InstructionWorklist & Worklist
A worklist of the instructions that need to be simplified.
Instruction * InsertNewInstWith(Instruction *New, BasicBlock::iterator Old)
Same as InsertNewInstBefore, but also sets the debug loc.
unsigned ComputeNumSignBits(const Value *Op, const Instruction *CtxI=nullptr, unsigned Depth=0) const
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const Instruction *CtxI=nullptr, unsigned Depth=0) const
LLVM_ABI bool isKnownExactCastIntToFP(CastInst &I) const
Return true if the cast from integer to FP can be proven to be exact for all possible inputs (the con...
IRBuilder< TargetFolder, IRBuilderInstCombineInserter > BuilderTy
An IRBuilder that automatically inserts new instructions into the worklist.
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
void computeKnownBits(const Value *V, KnownBits &Known, const Instruction *CtxI, unsigned Depth=0) const
const SimplifyQuery & getSimplifyQuery() const
LLVM_ABI bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
LLVM_ABI void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
LLVM_ABI bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
Instruction * user_back()
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
LLVM_ABI bool hasNonNeg() const LLVM_READONLY
Determine whether the the nneg flag is set.
iterator_range< user_iterator > users()
LLVM_ABI FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
This class represents a cast from an integer to a pointer.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
A wrapper class for inspecting calls to intrinsic functions.
bool isKnownNever(FPClassMask Mask) const
Return true if it's known this can never be one of the mask entries.
This is an important class for using LLVM in a threaded context.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
op_range incoming_values()
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class represents a cast from a pointer to an address (non-capturing ptrtoint).
Value * getPointerOperand()
Gets the pointer operand.
This class represents a cast from a pointer to an integer.
Value * getPointerOperand()
Gets the pointer operand.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
This class represents a sign extension of integer types.
This class represents the LLVM 'select' instruction.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
bool insert(const value_type &X)
Insert a new element into the SetVector.
This instruction constructs a fixed permutation of two input vectors.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class represents a truncation of integer types.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM_ABI Type * getWithNewType(Type *EltTy) const
Given vector type, change the element type, whilst keeping the old number of elements.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isX86_AMXTy() const
Return true if this is X86 AMX.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
LLVM_ABI int getFPMantissaWidth() const
Return the width of the mantissa of this type.
LLVM_ABI const fltSemantics & getFltSemantics() const
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
This class represents zero extension of integer types.
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
CheckType m_SpecificType(LLT Ty)
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
auto m_Poison()
Match an arbitrary poison constant.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1)
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
ap_match< APFloat > m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
auto m_BinOp()
Match an arbitrary binary operation and ignore it.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
match_combine_or< CastInst_match< OpTy, UIToFPInst >, CastInst_match< OpTy, SIToFPInst > > m_IToFP(const OpTy &Op)
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Constant()
Match an arbitrary Constant and ignore it.
NoWrapTrunc_match< OpTy, TruncInst::NoSignedWrap > m_NSWTrunc(const OpTy &Op)
Matches trunc nsw.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
auto m_VScale()
Matches a call to llvm.vscale().
match_combine_or< CastInst_match< OpTy, FPToUIInst >, CastInst_match< OpTy, FPToSIInst > > m_FPToI(const OpTy &Op)
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1)
is_zero< true > m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op, true > m_c_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations in either order.
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
match_immconstant_ty m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1)
FNeg_match< OpTy, true > m_FNegOrFSubNegZero(const OpTy &X)
Match fneg X or fsub -0.0, X.
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
Exact_match< T > m_Exact(const T &SubPattern)
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
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 cl::opt< bool > ProfcheckDisableMetadataFixes
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
SaveAndRestore(T &) -> SaveAndRestore< T >
LLVM_ABI Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Function *CtxF=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
auto dyn_cast_or_null(const Y &Val)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
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.
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
@ SMax
Signed integer max implemented in terms of select(cmp()).
@ And
Bitwise or logical AND of integers.
@ SMin
Signed integer min implemented in terms of select(cmp()).
DWARFExpression::Operation Op
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
LLVM_ABI Constant * ConstantFoldIntegerCast(Constant *C, Type *DestTy, bool IsSigned, const DataLayout &DL)
Constant fold a zext, sext or trunc, depending on IsSigned and whether the DestTy is wider or narrowe...
LLVM_ABI bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the give value is known to be non-negative.
LLVM_ABI Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
A utility class that uses RAII to save and restore the value of a variable.
SimplifyQuery getWithInstruction(const Instruction *I) const