Go to the documentation of this file.
21 using namespace PatternMatch;
23 #define DEBUG_TYPE "instcombine"
32 Offset = CI->getZExtValue();
49 if (
I->getOpcode() == Instruction::Shl) {
51 Scale = UINT64_C(1) <<
RHS->getZExtValue();
53 return I->getOperand(0);
58 Scale =
RHS->getZExtValue();
60 return I->getOperand(0);
69 Offset +=
RHS->getZExtValue();
107 bool AllocIsScalable = isa<ScalableVectorType>(AllocElTy);
108 bool CastIsScalable = isa<ScalableVectorType>(CastElTy);
109 if (AllocIsScalable != CastIsScalable)
return nullptr;
111 Align AllocElTyAlign =
DL.getABITypeAlign(AllocElTy);
112 Align CastElTyAlign =
DL.getABITypeAlign(CastElTy);
113 if (CastElTyAlign < AllocElTyAlign)
return nullptr;
118 if (!AI.
hasOneUse() && CastElTyAlign == AllocElTyAlign)
return nullptr;
121 uint64_t AllocElTySize =
DL.getTypeAllocSize(AllocElTy).getKnownMinSize();
122 uint64_t CastElTySize =
DL.getTypeAllocSize(CastElTy).getKnownMinSize();
123 if (CastElTySize == 0 || AllocElTySize == 0)
return nullptr;
127 uint64_t AllocElTyStoreSize =
DL.getTypeStoreSize(AllocElTy).getKnownMinSize();
128 uint64_t CastElTyStoreSize =
DL.getTypeStoreSize(CastElTy).getKnownMinSize();
129 if (!AI.
hasOneUse() && CastElTyStoreSize < AllocElTyStoreSize)
return nullptr;
133 unsigned ArraySizeScale;
140 if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0 ||
141 (AllocElTySize*ArrayOffset ) % CastElTySize != 0)
return nullptr;
144 assert(!AllocIsScalable || (ArrayOffset == 1 && ArraySizeScale == 0));
146 unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
147 Value *Amt =
nullptr;
153 Amt =
Builder.CreateMul(Amt, NumElements);
156 if (
uint64_t Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
159 Amt =
Builder.CreateAdd(Amt, Off);
174 replaceInstUsesWith(AI, NewCast);
175 eraseInstFromFunction(AI);
177 return replaceInstUsesWith(CI, New);
184 if (
Constant *
C = dyn_cast<Constant>(V)) {
193 unsigned Opc =
I->getOpcode();
196 case Instruction::Sub:
198 case Instruction::And:
199 case Instruction::Or:
200 case Instruction::Xor:
201 case Instruction::AShr:
202 case Instruction::LShr:
203 case Instruction::Shl:
204 case Instruction::UDiv:
205 case Instruction::URem: {
206 Value *
LHS = EvaluateInDifferentType(
I->getOperand(0), Ty, isSigned);
207 Value *
RHS = EvaluateInDifferentType(
I->getOperand(1), Ty, isSigned);
211 case Instruction::Trunc:
212 case Instruction::ZExt:
213 case Instruction::SExt:
217 if (
I->getOperand(0)->getType() == Ty)
218 return I->getOperand(0);
223 Opc == Instruction::SExt);
226 Value *True = EvaluateInDifferentType(
I->getOperand(1), Ty, isSigned);
227 Value *False = EvaluateInDifferentType(
I->getOperand(2), Ty, isSigned);
231 case Instruction::PHI: {
248 return InsertNewInstWith(Res, *
I);
252 InstCombinerImpl::isEliminableCastPair(
const CastInst *CI1,
267 DstTy, SrcIntPtrTy, MidIntPtrTy,
272 if ((Res == Instruction::IntToPtr && SrcTy != DstIntPtrTy) ||
273 (Res == Instruction::PtrToInt && DstTy != SrcIntPtrTy))
285 if (
auto *CSrc = dyn_cast<CastInst>(Src)) {
291 if (CSrc->hasOneUse())
297 if (
auto *Sel = dyn_cast<SelectInst>(Src)) {
303 auto *Cmp = dyn_cast<CmpInst>(Sel->getCondition());
304 if (!Cmp || Cmp->getOperand(0)->getType() != Sel->getType() ||
315 if (
auto *PN = dyn_cast<PHINode>(Src)) {
332 auto *SrcTy = dyn_cast<FixedVectorType>(
X->getType());
333 auto *DestTy = dyn_cast<FixedVectorType>(Ty);
334 if (SrcTy && DestTy &&
335 SrcTy->getNumElements() == DestTy->getNumElements() &&
348 if (isa<Constant>(V))
361 assert(!isa<Constant>(V) &&
"Constant should already be handled.");
362 if (!isa<Instruction>(V))
390 auto *
I = cast<Instruction>(V);
392 switch (
I->getOpcode()) {
394 case Instruction::Sub:
396 case Instruction::And:
397 case Instruction::Or:
398 case Instruction::Xor:
403 case Instruction::UDiv:
404 case Instruction::URem: {
417 case Instruction::Shl: {
428 case Instruction::LShr: {
446 case Instruction::AShr: {
456 unsigned ShiftedBits = OrigBitWidth -
BitWidth;
463 case Instruction::Trunc:
466 case Instruction::ZExt:
467 case Instruction::SExt:
476 case Instruction::PHI: {
504 if (!TruncOp->
hasOneUse() || !isa<IntegerType>(DestType))
507 Value *VecInput =
nullptr;
512 !isa<VectorType>(VecInput->
getType()))
516 unsigned VecWidth =
VecType->getPrimitiveSizeInBits();
518 unsigned ShiftAmount = ShiftVal ? ShiftVal->
getZExtValue() : 0;
520 if ((VecWidth % DestWidth != 0) || (ShiftAmount % DestWidth != 0))
525 unsigned NumVecElts = VecWidth / DestWidth;
526 if (
VecType->getElementType() != DestType) {
531 unsigned Elt = ShiftAmount / DestWidth;
533 Elt = NumVecElts - 1 - Elt;
543 "Don't narrow to an illegal scalar type");
559 Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
566 if (Or0->
getOpcode() == BinaryOperator::LShr) {
572 Or1->
getOpcode() == BinaryOperator::LShr &&
573 "Illegal or(shift,shift) pair");
582 unsigned MaxShiftAmountWidth =
Log2_32(NarrowWidth);
583 APInt HiBitMask = ~
APInt::getLowBitsSet(WideWidth, MaxShiftAmountWidth);
590 if (ShVal0 != ShVal1)
609 Value *ShAmt = matchShiftAmount(ShAmt0, ShAmt1, NarrowWidth);
612 ShAmt = matchShiftAmount(ShAmt1, ShAmt0, NarrowWidth);
629 Value *NarrowShAmt =
Builder.CreateTrunc(ShAmt, DestTy);
631 X =
Y =
Builder.CreateTrunc(ShVal0, DestTy);
632 if (ShVal0 != ShVal1)
633 Y =
Builder.CreateTrunc(ShVal1, DestTy);
634 Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr;
647 if (!isa<VectorType>(SrcTy) && !shouldChangeType(SrcTy, DestTy))
657 case Instruction::And:
658 case Instruction::Or:
659 case Instruction::Xor:
661 case Instruction::Sub:
689 case Instruction::LShr:
690 case Instruction::AShr: {
695 unsigned MaxShiftAmt = SrcWidth - DestWidth;
699 APInt(SrcWidth, MaxShiftAmt)))) {
700 auto *OldShift = cast<Instruction>(Trunc.
getOperand(0));
701 bool IsExact = OldShift->isExact();
705 OldShift->getOpcode() == Instruction::AShr
706 ?
Builder.CreateAShr(A, ShAmt, OldShift->getName(), IsExact)
707 :
Builder.CreateLShr(A, ShAmt, OldShift->getName(), IsExact);
716 if (
Instruction *NarrowOr = narrowFunnelShift(Trunc))
727 auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.
getOperand(0));
728 if (Shuf && Shuf->hasOneUse() &&
match(Shuf->getOperand(1),
m_Undef()) &&
730 Shuf->getType() == Shuf->getOperand(0)->getType()) {
748 assert((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
749 "Unexpected instruction for shrinking");
751 auto *InsElt = dyn_cast<InsertElementInst>(Trunc.
getOperand(0));
752 if (!InsElt || !InsElt->hasOneUse())
757 Value *VecOp = InsElt->getOperand(0);
758 Value *ScalarOp = InsElt->getOperand(1);
765 Value *NarrowOp =
Builder.CreateCast(Opcode, ScalarOp, DestScalarTy);
773 if (
Instruction *Result = commonCastTransforms(Trunc))
777 Type *DestTy = Trunc.
getType(), *SrcTy = Src->getType();
785 if ((DestTy->
isVectorTy() || shouldChangeType(SrcTy, DestTy)) &&
791 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
794 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
796 return replaceInstUsesWith(Trunc, Res);
803 if (
auto *DestITy = dyn_cast<IntegerType>(DestTy)) {
804 if (DestWidth * 2 < SrcWidth) {
805 auto *NewDestTy = DestITy->getExtendedType();
806 if (shouldChangeType(SrcTy, NewDestTy) &&
809 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
810 " to reduce the width of operand of"
812 Value *Res = EvaluateInDifferentType(Src, NewDestTy,
false);
823 if (
SelectInst *Sel = dyn_cast<SelectInst>(Src))
829 if (SimplifyDemandedInstructionBits(Trunc))
832 if (DestWidth == 1) {
869 unsigned AWidth = A->getType()->getScalarSizeInBits();
870 unsigned MaxShiftAmt = SrcWidth -
std::max(DestWidth, AWidth);
871 auto *OldSh = cast<Instruction>(Src);
872 bool IsExact = OldSh->isExact();
877 APInt(SrcWidth, MaxShiftAmt)))) {
879 if (A->getType() == DestTy) {
884 return IsExact ? BinaryOperator::CreateExactAShr(A, ShAmt)
885 : BinaryOperator::CreateAShr(A, ShAmt);
889 if (Src->hasOneUse()) {
909 if (Src->hasOneUse() &&
910 (isa<VectorType>(SrcTy) || shouldChangeType(SrcTy, DestTy))) {
917 APInt Threshold =
APInt(
C->getType()->getScalarSizeInBits(), DestWidth);
919 Value *NewTrunc =
Builder.CreateTrunc(A, DestTy, A->getName() +
".tr");
940 auto *VecOpTy = cast<VectorType>(VecOp->
getType());
941 auto VecElts = VecOpTy->getElementCount();
944 if (SrcWidth % DestWidth == 0) {
945 uint64_t TruncRatio = SrcWidth / DestWidth;
946 uint64_t BitCastNumElts = VecElts.getKnownMinValue() * TruncRatio;
948 uint64_t NewIdx =
DL.isBigEndian() ? (VecOpIdx + 1) * TruncRatio - 1
949 : VecOpIdx * TruncRatio;
955 Value *BitCast =
Builder.CreateBitCast(VecOp, BitCastTo);
963 unsigned AWidth = A->getType()->getScalarSizeInBits();
964 if (AWidth == DestWidth && AWidth >
Log2_32(SrcWidth)) {
978 if (
Log2_32(*MaxVScale) < DestWidth) {
980 return replaceInstUsesWith(Trunc, VScale);
1005 Value *
In = Cmp->getOperand(0);
1007 In->getType()->getScalarSizeInBits() - 1);
1009 if (
In->getType() != Zext.getType())
1010 In =
Builder.CreateIntCast(
In, Zext.getType(),
false );
1012 return replaceInstUsesWith(Zext,
In);
1025 Cmp->isEquality()) {
1030 if (KnownZeroMask.isPowerOf2()) {
1032 if (!Op1CV->
isZero() && (*Op1CV != KnownZeroMask)) {
1036 return replaceInstUsesWith(Zext, Res);
1039 uint32_t ShAmt = KnownZeroMask.logBase2();
1045 In->getName() +
".lobit");
1048 if (!Op1CV->
isZero() == isNE) {
1053 if (
Zext.getType() ==
In->getType())
1054 return replaceInstUsesWith(Zext,
In);
1057 return replaceInstUsesWith(Zext, IntCast);
1062 if (
Cmp->isEquality() &&
Zext.getType() ==
Cmp->getOperand(0)->getType()) {
1074 return replaceInstUsesWith(Zext, And1);
1087 if (KnownLHS == KnownRHS) {
1094 if (KnownLHS.
One.
uge(UnknownBit))
1105 return replaceInstUsesWith(Zext, Result);
1140 auto *
I = cast<Instruction>(V);
1142 switch (
I->getOpcode()) {
1143 case Instruction::ZExt:
1144 case Instruction::SExt:
1145 case Instruction::Trunc:
1147 case Instruction::And:
1148 case Instruction::Or:
1149 case Instruction::Xor:
1151 case Instruction::Sub:
1157 if (BitsToClear == 0 && Tmp == 0)
1162 if (Tmp == 0 &&
I->isBitwiseLogicOp()) {
1171 if (
I->getOpcode() == Instruction::And)
1180 case Instruction::Shl: {
1188 BitsToClear = ShiftAmt < BitsToClear ? BitsToClear - ShiftAmt : 0;
1193 case Instruction::LShr: {
1217 case Instruction::PHI: {
1245 if (
Instruction *Result = commonCastTransforms(CI))
1249 Type *SrcTy = Src->getType(), *DestTy = CI.
getType();
1252 unsigned BitsToClear;
1253 if (shouldChangeType(SrcTy, DestTy) &&
1256 "Can't clear more bits than in SrcTy");
1260 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1261 " to avoid zero extend: "
1263 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
1267 if (
auto *
SrcOp = dyn_cast<Instruction>(Src))
1268 if (
SrcOp->hasOneUse())
1278 DestBitSize-SrcBitsKept),
1280 return replaceInstUsesWith(CI, Res);
1285 return BinaryOperator::CreateAnd(Res,
C);
1291 if (
TruncInst *CSrc = dyn_cast<TruncInst>(Src)) {
1296 Value *A = CSrc->getOperand(0);
1297 unsigned SrcSize = A->getType()->getScalarSizeInBits();
1298 unsigned MidSize = CSrc->getType()->getScalarSizeInBits();
1304 if (SrcSize < DstSize) {
1311 if (SrcSize == DstSize) {
1316 if (SrcSize > DstSize) {
1319 return BinaryOperator::CreateAnd(Trunc,
1325 if (
ICmpInst *Cmp = dyn_cast<ICmpInst>(Src))
1326 return transformZExtICmp(Cmp, CI);
1341 return BinaryOperator::CreateXor(
Builder.CreateAnd(
X, ZC), ZC);
1349 unsigned TypeWidth = Src->getType()->getScalarSizeInBits();
1350 if (
Log2_32(*MaxVScale) < TypeWidth) {
1352 return replaceInstUsesWith(CI, VScale);
1368 if (!Op1->getType()->isIntOrIntVectorTy())
1383 return replaceInstUsesWith(CI,
In);
1386 if (
ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
1391 ICI->
isEquality() && (Op1C->isZero() || Op1C->getValue().isPowerOf2())){
1395 if (KnownZeroMask.isPowerOf2()) {
1399 if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) {
1403 return replaceInstUsesWith(CI, V);
1409 unsigned ShiftAmt = KnownZeroMask.countTrailingZeros();
1423 unsigned ShiftAmt = KnownZeroMask.countLeadingZeros();
1431 KnownZeroMask.getBitWidth() - 1),
"sext");
1435 return replaceInstUsesWith(CI,
In);
1453 "Can't sign extend type to a smaller type");
1459 auto *
I = cast<Instruction>(V);
1460 switch (
I->getOpcode()) {
1461 case Instruction::SExt:
1462 case Instruction::ZExt:
1463 case Instruction::Trunc:
1465 case Instruction::And:
1466 case Instruction::Or:
1467 case Instruction::Xor:
1469 case Instruction::Sub:
1482 case Instruction::PHI: {
1509 Type *SrcTy = Src->getType(), *DestTy = CI.
getType();
1521 dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1522 " to avoid sign extend: "
1524 Value *Res = EvaluateInDifferentType(Src, DestTy,
true);
1530 return replaceInstUsesWith(CI, Res);
1534 return BinaryOperator::CreateAShr(
Builder.CreateShl(Res, ShAmt,
"sext"),
1542 unsigned XBitSize =
X->getType()->getScalarSizeInBits();
1547 if (Src->hasOneUse() &&
X->getType() == DestTy) {
1550 return BinaryOperator::CreateAShr(
Builder.CreateShl(
X, ShAmt), ShAmt);
1558 if (Src->hasOneUse() &&
1566 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
1567 return transformSExtICmp(ICI, CI);
1584 Constant *BA =
nullptr, *CA =
nullptr;
1597 return BinaryOperator::CreateAShr(A, NewShAmt);
1605 Type *XTy =
X->getType();
1610 return BinaryOperator::CreateAShr(
Builder.CreateShl(
X, ShlAmtC),
1612 if (cast<BinaryOperator>(Src)->getOperand(0)->
hasOneUse()) {
1623 if (
Log2_32(*MaxVScale) < (SrcBitSize - 1)) {
1625 return replaceInstUsesWith(CI, VScale);
1664 auto *CV = dyn_cast<Constant>(V);
1665 auto *CVVTy = dyn_cast<FixedVectorType>(V->
getType());
1669 Type *MinType =
nullptr;
1671 unsigned NumElts = CVVTy->getNumElements();
1675 for (
unsigned i = 0;
i != NumElts; ++
i) {
1676 auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(
i));
1696 if (
auto *FPExt = dyn_cast<FPExtInst>(V))
1697 return FPExt->getOperand(0)->getType();
1702 if (
auto *CFP = dyn_cast<ConstantFP>(V))
1709 if (
auto *FPCExt = dyn_cast<ConstantExpr>(V))
1710 if (FPCExt->getOpcode() == Instruction::FPExt)
1711 return FPCExt->getOperand(0)->getType();
1725 assert((Opcode == CastInst::SIToFP || Opcode == CastInst::UIToFP) &&
1727 Value *Src =
I.getOperand(0);
1728 Type *SrcTy = Src->getType();
1729 Type *FPTy =
I.getType();
1730 bool IsSigned = Opcode == Instruction::SIToFP;
1736 if (SrcSize <= DestNumSigBits)
1745 int SrcNumSigBits =
F->getType()->getFPMantissaWidth();
1752 if (SrcNumSigBits > 0 && DestNumSigBits > 0 &&
1753 SrcNumSigBits <= DestNumSigBits)
1775 auto *BO = dyn_cast<BinaryOperator>(FPT.
getOperand(0));
1776 if (BO && BO->hasOneUse()) {
1779 unsigned OpWidth = BO->getType()->getFPMantissaWidth();
1782 unsigned SrcWidth =
std::max(LHSWidth, RHSWidth);
1784 switch (BO->getOpcode()) {
1786 case Instruction::FAdd:
1787 case Instruction::FSub:
1806 if (OpWidth >= 2*DstWidth+1 && DstWidth >= SrcWidth) {
1814 case Instruction::FMul:
1820 if (OpWidth >= LHSWidth + RHSWidth && DstWidth >= SrcWidth) {
1826 case Instruction::FDiv:
1833 if (OpWidth >= 2*DstWidth && DstWidth >= SrcWidth) {
1839 case Instruction::FRem: {
1844 if (SrcWidth == OpWidth)
1847 if (LHSWidth == SrcWidth) {
1848 LHS =
Builder.CreateFPTrunc(BO->getOperand(0), LHSMinType);
1849 RHS =
Builder.CreateFPTrunc(BO->getOperand(1), LHSMinType);
1851 LHS =
Builder.CreateFPTrunc(BO->getOperand(0), RHSMinType);
1852 RHS =
Builder.CreateFPTrunc(BO->getOperand(1), RHSMinType);
1864 if (
Op &&
Op->hasOneUse()) {
1867 if (isa<FPMathOperator>(
Op))
1868 Builder.setFastMathFlags(
Op->getFastMathFlags());
1880 X->getType() == Ty) {
1884 return replaceInstUsesWith(FPT, Sel);
1887 X->getType() == Ty) {
1891 return replaceInstUsesWith(FPT, Sel);
1895 if (
auto *II = dyn_cast<IntrinsicInst>(FPT.
getOperand(0))) {
1896 switch (II->getIntrinsicID()) {
1899 case Intrinsic::fabs:
1901 case Intrinsic::nearbyint:
1902 case Intrinsic::rint:
1904 case Intrinsic::roundeven:
1906 Value *Src = II->getArgOperand(0);
1907 if (!Src->hasOneUse())
1913 if (II->getIntrinsicID() != Intrinsic::fabs) {
1914 FPExtInst *FPExtSrc = dyn_cast<FPExtInst>(Src);
1915 if (!FPExtSrc || FPExtSrc->
getSrcTy() != Ty)
1923 II->getIntrinsicID(), Ty);
1925 II->getOperandBundlesAsDefs(OpBundles);
1938 if (isa<SIToFPInst>(Src) || isa<UIToFPInst>(Src)) {
1939 auto *FPCast = cast<CastInst>(Src);
1952 if (isa<SIToFPInst>(Src) || isa<UIToFPInst>(Src)) {
1953 auto *FPCast = cast<CastInst>(Src);
1958 return commonCastTransforms(FPExt);
1969 auto *OpI = cast<CastInst>(FI.
getOperand(0));
1970 Value *
X = OpI->getOperand(0);
1971 Type *XType =
X->getType();
1973 bool IsOutputSigned = isa<FPToSIInst>(FI);
1988 if (OutputSize > OpI->getType()->getFPMantissaWidth())
1993 bool IsInputSigned = isa<SIToFPInst>(OpI);
1994 if (IsInputSigned && IsOutputSigned)
2001 assert(XType == DestType &&
"Unexpected types for int to FP to int casts");
2002 return replaceInstUsesWith(FI,
X);
2009 return commonCastTransforms(FI);
2016 return commonCastTransforms(FI);
2020 return commonCastTransforms(CI);
2024 return commonCastTransforms(CI);
2033 DL.getPointerSizeInBits(AS)) {
2053 if (
GEP->hasAllZeroIndices() &&
2057 (!isa<AddrSpaceCastInst>(CI) ||
2058 GEP->getType() ==
GEP->getPointerOperandType())) {
2062 return replaceOperand(CI, 0,
GEP->getOperand(0));
2066 return commonCastTransforms(CI);
2078 unsigned PtrSize =
DL.getPointerSizeInBits(AS);
2079 if (TySize != PtrSize) {
2086 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(
SrcOp)) {
2091 if (
GEP->hasOneUse() &&
2092 isa<ConstantPointerNull>(
GEP->getPointerOperand())) {
2093 return replaceInstUsesWith(CI,
2110 return commonPointerCastTransforms(CI);
2148 cast<FixedVectorType>(SrcTy)->getNumElements());
2153 unsigned SrcElts = cast<FixedVectorType>(SrcTy)->getNumElements();
2154 unsigned DestElts = cast<FixedVectorType>(DestTy)->getNumElements();
2156 assert(SrcElts != DestElts &&
"Element counts should be different.");
2161 auto ShuffleMaskStorage = llvm::to_vector<16>(llvm::seq<int>(0, SrcElts));
2165 if (SrcElts > DestElts) {
2174 ShuffleMask = ShuffleMaskStorage;
2176 ShuffleMask = ShuffleMask.
take_back(DestElts);
2178 ShuffleMask = ShuffleMask.
take_front(DestElts);
2189 unsigned DeltaElts = DestElts - SrcElts;
2191 ShuffleMaskStorage.insert(ShuffleMaskStorage.begin(), DeltaElts, NullElt);
2193 ShuffleMaskStorage.append(DeltaElts, NullElt);
2194 ShuffleMask = ShuffleMaskStorage;
2222 "Shift should be a multiple of the element type size");
2225 if (isa<UndefValue>(V))
return true;
2229 if (V->
getType() == VecEltTy) {
2231 if (
Constant *
C = dyn_cast<Constant>(V))
2232 if (
C->isNullValue())
2237 ElementIndex = Elements.size() - ElementIndex - 1;
2240 if (Elements[ElementIndex])
2243 Elements[ElementIndex] = V;
2247 if (
Constant *
C = dyn_cast<Constant>(V)) {
2260 if (!isa<IntegerType>(
C->getType()))
2262 C->getType()->getPrimitiveSizeInBits()));
2266 for (
unsigned i = 0;
i != NumElts; ++
i) {
2267 unsigned ShiftI =
Shift+
i*ElementSize;
2281 if (!
I)
return false;
2282 switch (
I->getOpcode()) {
2283 default:
return false;
2284 case Instruction::BitCast:
2285 if (
I->getOperand(0)->getType()->isVectorTy())
2289 case Instruction::ZExt:
2291 I->getOperand(0)->getType()->getPrimitiveSizeInBits(),
2296 case Instruction::Or:
2301 case Instruction::Shl: {
2303 ConstantInt *CI = dyn_cast<ConstantInt>(
I->getOperand(1));
2304 if (!CI)
return false;
2331 auto *DestVecTy = cast<FixedVectorType>(CI.
getType());
2336 DestVecTy->getElementType(),
2344 for (
unsigned i = 0,
e = Elements.size();
i !=
e; ++
i) {
2345 if (!Elements[
i])
continue;
2377 auto *FixedVType = dyn_cast<FixedVectorType>(
VecType);
2378 if (DestType->
isVectorTy() && FixedVType && FixedVType->getNumElements() == 1)
2405 if (
X->getType()->isFPOrFPVectorTy() &&
2406 Y->getType()->isIntOrIntVectorTy()) {
2412 if (
X->getType()->isIntOrIntVectorTy() &&
2413 Y->getType()->isFPOrFPVectorTy()) {
2428 X->getType() == DestTy && !isa<Constant>(
X)) {
2435 X->getType() == DestTy && !isa<Constant>(
X)) {
2467 if (
auto *CondVTy = dyn_cast<VectorType>(CondTy))
2469 CondVTy->getElementCount() !=
2470 cast<VectorType>(DestTy)->getElementCount())
2480 auto *Sel = cast<Instruction>(BitCast.
getOperand(0));
2483 !isa<Constant>(
X)) {
2485 Value *CastedVal =
Builder.CreateBitCast(FVal, DestTy);
2490 !isa<Constant>(
X)) {
2492 Value *CastedVal =
Builder.CreateBitCast(TVal, DestTy);
2502 if (!isa<StoreInst>(U))
2523 Type *SrcTy = Src->getType();
2533 PhiWorklist.push_back(PN);
2535 while (!PhiWorklist.empty()) {
2537 for (
Value *IncValue : OldPN->incoming_values()) {
2538 if (isa<Constant>(IncValue))
2541 if (
auto *LI = dyn_cast<LoadInst>(IncValue)) {
2547 if (
Addr == &CI || isa<LoadInst>(
Addr))
2555 if (LI->hasOneUse() && LI->isSimple())
2562 if (
auto *PNode = dyn_cast<PHINode>(IncValue)) {
2563 if (OldPhiNodes.
insert(PNode))
2564 PhiWorklist.push_back(PNode);
2568 auto *BCI = dyn_cast<BitCastInst>(IncValue);
2574 Type *TyA = BCI->getOperand(0)->getType();
2575 Type *TyB = BCI->getType();
2576 if (TyA != DestTy || TyB != SrcTy)
2583 for (
auto *OldPN : OldPhiNodes) {
2585 if (
auto *
SI = dyn_cast<StoreInst>(V)) {
2586 if (!
SI->isSimple() ||
SI->getOperand(0) != OldPN)
2588 }
else if (
auto *BCI = dyn_cast<BitCastInst>(V)) {
2590 Type *TyB = BCI->getOperand(0)->getType();
2591 Type *TyA = BCI->getType();
2592 if (TyA != DestTy || TyB != SrcTy)
2594 }
else if (
auto *PHI = dyn_cast<PHINode>(V)) {
2598 if (!OldPhiNodes.contains(PHI))
2608 for (
auto *OldPN : OldPhiNodes) {
2609 Builder.SetInsertPoint(OldPN);
2610 PHINode *NewPN =
Builder.CreatePHI(DestTy, OldPN->getNumOperands());
2611 NewPNodes[OldPN] = NewPN;
2615 for (
auto *OldPN : OldPhiNodes) {
2616 PHINode *NewPN = NewPNodes[OldPN];
2617 for (
unsigned j = 0,
e = OldPN->getNumOperands();
j !=
e; ++
j) {
2618 Value *V = OldPN->getOperand(
j);
2619 Value *NewV =
nullptr;
2620 if (
auto *
C = dyn_cast<Constant>(V)) {
2622 }
else if (
auto *LI = dyn_cast<LoadInst>(V)) {
2626 NewV = combineLoadToNewType(*LI, DestTy);
2630 eraseInstFromFunction(*LI);
2631 }
else if (
auto *BCI = dyn_cast<BitCastInst>(V)) {
2632 NewV = BCI->getOperand(0);
2633 }
else if (
auto *PrevPN = dyn_cast<PHINode>(V)) {
2634 NewV = NewPNodes[PrevPN];
2651 for (
auto *OldPN : OldPhiNodes) {
2652 PHINode *NewPN = NewPNodes[OldPN];
2654 if (
auto *
SI = dyn_cast<StoreInst>(V)) {
2655 assert(
SI->isSimple() &&
SI->getOperand(0) == OldPN);
2658 cast<BitCastInst>(
Builder.CreateBitCast(NewPN, SrcTy));
2659 SI->setOperand(0, NewBC);
2663 else if (
auto *BCI = dyn_cast<BitCastInst>(V)) {
2664 Type *TyB = BCI->getOperand(0)->getType();
2665 Type *TyA = BCI->getType();
2666 assert(TyA == DestTy && TyB == SrcTy);
2672 }
else if (
auto *PHI = dyn_cast<PHINode>(V)) {
2673 assert(OldPhiNodes.contains(PHI));
2687 PointerType *SrcPTy = cast<PointerType>(Src->getType());
2705 unsigned NumZeros = 0;
2706 while (SrcElTy && SrcElTy != DstElTy) {
2712 if (SrcElTy == DstElTy) {
2719 bool CanBeNull, CanBeFreed;
2720 if (Src->getPointerDereferenceableBytes(
DL, CanBeNull, CanBeFreed)) {
2728 GEP->setIsInBounds();
2739 Type *SrcTy = Src->getType();
2744 if (DestTy == Src->getType())
2745 return replaceInstUsesWith(CI, Src);
2747 if (isa<PointerType>(SrcTy) && isa<PointerType>(DestTy)) {
2752 if (
AllocaInst *AI = dyn_cast<AllocaInst>(Src))
2753 if (
Instruction *V = PromoteCastOfAllocation(CI, *AI))
2762 if (DestVTy->getNumElements() == 1 && SrcTy->
isX86_MMXTy()) {
2763 Value *Elem =
Builder.CreateBitCast(Src, DestVTy->getElementType());
2768 if (isa<IntegerType>(SrcTy)) {
2772 if (isa<TruncInst>(Src) || isa<ZExtInst>(Src)) {
2773 CastInst *SrcCast = cast<CastInst>(Src);
2775 if (isa<VectorType>(BCIn->getOperand(0)->getType()))
2777 BCIn->getOperand(0), cast<VectorType>(DestTy), *
this))
2785 return replaceInstUsesWith(CI, V);
2790 if (SrcVTy->getNumElements() == 1) {
2795 Builder.CreateExtractElement(Src,
2803 if (
auto *InsElt = dyn_cast<InsertElementInst>(Src))
2804 return new BitCastInst(InsElt->getOperand(1), DestTy);
2814 Y->getType()->isIntegerTy() && isDesirableIntType(
BitWidth)) {
2816 if (
DL.isBigEndian())
2817 IndexC = SrcVTy->getNumElements() - 1 - IndexC;
2823 unsigned EltWidth =
Y->getType()->getScalarSizeInBits();
2827 return BinaryOperator::CreateOr(AndX, ZextY);
2832 if (
auto *Shuf = dyn_cast<ShuffleVectorInst>(Src)) {
2835 Value *ShufOp0 = Shuf->getOperand(0);
2836 Value *ShufOp1 = Shuf->getOperand(1);
2837 auto ShufElts = cast<VectorType>(Shuf->getType())->getElementCount();
2838 auto SrcVecElts = cast<VectorType>(ShufOp0->
getType())->getElementCount();
2839 if (Shuf->hasOneUse() && DestTy->
isVectorTy() &&
2840 cast<VectorType>(DestTy)->getElementCount() == ShufElts &&
2841 ShufElts == SrcVecElts) {
2846 if (((Tmp = dyn_cast<BitCastInst>(ShufOp0)) &&
2848 ((Tmp = dyn_cast<BitCastInst>(ShufOp1)) &&
2865 ShufElts.getKnownMinValue() % 2 == 0 && Shuf->hasOneUse() &&
2866 Shuf->isReverse()) {
2867 assert(ShufOp0->
getType() == SrcTy &&
"Unexpected shuffle mask");
2871 Value *ScalarX =
Builder.CreateBitCast(ShufOp0, DestTy);
2877 if (
PHINode *PN = dyn_cast<PHINode>(Src))
2891 return commonPointerCastTransforms(CI);
2892 return commonCastTransforms(CI);
2900 PointerType *SrcTy = cast<PointerType>(Src->getType()->getScalarType());
2914 return commonPointerCastTransforms(CI);
static Instruction * shrinkInsertElt(CastInst &Trunc, InstCombiner::BuilderTy &Builder)
Try to narrow the width of an insert element.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Instruction * visitFPToSI(FPToSIInst &FI)
This is an optimization pass for GlobalISel generic memory operations.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Returns true if the give value is known to be non-negative.
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if 'V & Mask' is known to be zero.
op_range incoming_values()
A parsed version of the target data layout string in and methods for querying it.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
bool hasOneUse() const
Return true if there is exactly one use of this value.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
bool isPointerTy() const
True if this is an instance of PointerType.
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g ceil
static const fltSemantics & IEEEsingle() LLVM_READNONE
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
static Instruction * convertBitCastToGEP(BitCastInst &CI, IRBuilderBase &Builder, const DataLayout &DL)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static Instruction * canonicalizeBitCastExtElt(BitCastInst &BitCast, InstCombinerImpl &IC)
Canonicalize scalar bitcasts of extracted elements into a bitcast of the vector followed by extract e...
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.
This class represents a no-op cast from one type to another.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
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.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
PointerType * getType() const
Overload to return most specific pointer type.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty)
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
static bool hasStoreUsersOnly(CastInst &CI)
Check if all users of CI are StoreInsts.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine how a pair of casts can be eliminated, if they can be at all.
static Instruction * foldBitCastSelect(BitCastInst &BitCast, InstCombiner::BuilderTy &Builder)
Change the type of a select if we can eliminate a bitcast.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
@ ICMP_SGT
signed greater than
Instruction * visitAddrSpaceCast(AddrSpaceCastInst &CI)
The instances of the Type class are immutable: once they are created, they are never changed.
CastClass_match< OpTy, Instruction::FPToUI > m_FPToUI(const OpTy &Op)
static bool canAlwaysEvaluateInType(Value *V, Type *Ty)
Constants and extensions/truncates from the destination type are always free to be evaluated in that ...
Instruction * visitBitCast(BitCastInst &CI)
static 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...
const APFloat & getValueAPF() const
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
DiagnosticInfoOptimizationBase::Argument NV
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits.
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Type * getElementType() const
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
static Instruction * shrinkSplatShuffle(TruncInst &Trunc, InstCombiner::BuilderTy &Builder)
Try to narrow the width of a splat shuffle.
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
LLVM_NODISCARD T pop_back_val()
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
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.
unsigned getAddressSpace() const
Return the address space for the allocation.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
Class to represent fixed width SIMD vectors.
VScaleVal_match m_VScale(const DataLayout &DL)
Type * getNonOpaquePointerElementType() const
Only use this method in code that is not reachable with opaque pointers, or part of deprecated method...
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
static IntegerType * getInt32Ty(LLVMContext &C)
deferredval_ty< 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()...
Instruction * visitFPExt(CastInst &CI)
Type * getWithNewType(Type *EltTy) const
Given vector type, change the element type, whilst keeping the old number of elements.
Type * getDestTy() const
Return the destination type, as a convenience.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
unsigned countPopulation() const
Count the number of bits set.
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g floor
OneUse_match< T > m_OneUse(const T &SubPattern)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
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.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
This is the shared class of boolean and integer constants.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
static bool canEvaluateSExtd(Value *V, Type *Ty)
Return true if we can take the specified value and return it as type Ty without inserting any new cas...
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
@ And
Bitwise or logical AND of integers.
This class represents a conversion between pointers from one address space to another.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
bool match(Val *V, const Pattern &P)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
static Type * shrinkFPConstantVector(Value *V)
static Type * getPPC_FP128Ty(LLVMContext &C)
static const fltSemantics & IEEEhalf() LLVM_READNONE
specific_intval< true > m_SpecificIntAllowUndef(APInt V)
static Type * getDoubleTy(LLVMContext &C)
(vector float) vec_cmpeq(*A, *B) C
@ ICMP_ULE
unsigned less or equal
Instruction * visitSIToFP(CastInst &CI)
static uint64_t round(uint64_t Acc, uint64_t Input)
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Instruction * commonCastTransforms(CastInst &CI)
Implement the transforms common to all CastInst visitors.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static Value * decomposeSimpleLinearExpr(Value *Val, unsigned &Scale, uint64_t &Offset)
Analyze 'Val', seeing if it is a simple linear expression.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
bool isVectorTy() const
True if this is an instance of VectorType.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Class to represent integer types.
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
static Constant * getAllOnesValue(Type *Ty)
BinaryOps getOpcode() const
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
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.
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...
const Value * getArraySize() const
Get the number of elements allocated.
uint64_t getZExtValue() const
Get zero extended value.
ConstantFP - Floating Point Values [float, double].
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Type * getSrcTy() const
Return the source type, as a convenience.
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...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
ArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
Instruction * visitPtrToInt(PtrToIntInst &CI)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
Value * getPointerOperand()
Gets the pointer operand.
bool isIntegerTy() const
True if this is an instance of IntegerType.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Instruction * visitTrunc(TruncInst &CI)
Base class of all SIMD vector types.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Instruction * visitZExt(ZExtInst &CI)
int getFPMantissaWidth() const
Return the width of the mantissa of this type.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Instruction * PromoteCastOfAllocation(BitCastInst &CI, AllocaInst &AI)
If we find a cast of an allocation instruction, try to eliminate the cast by moving the type informat...
This is an important base class in LLVM.
static UnaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name="", Instruction *InsertBefore=nullptr)
bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
This instruction compares its operands according to the predicate given to the constructor.
static Type * shrinkFPConstant(ConstantFP *CFP)
Optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or None when unknown.
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
This class represents a cast from floating point to signed integer.
const DataLayout & getDataLayout() const
Instruction * visitIntToPtr(IntToPtrInst &CI)
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
This class represents a truncation of integer types.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
Instruction * visitFPToUI(FPToUIInst &FI)
'undef' values are things that do not have specified contents.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
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...
static Constant * getOr(Constant *C1, Constant *C2)
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Class to represent pointers.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Value * EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned)
Given an expression that CanEvaluateTruncated or CanEvaluateSExtd returns true for,...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
StandardInstrumentations SI(Debug, VerifyEach)
This class represents the LLVM 'select' instruction.
bool is_splat(R &&Range)
Wrapper function around std::equal to detect if all elements in a container are same.
This class represents a cast from floating point to unsigned integer.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class represents zero extension of integer types.
Class for arbitrary precision integers.
bool insert(const value_type &X)
Insert a new element into the SetVector.
@ ICMP_SLT
signed less than
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
specific_intval< false > m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
static Instruction * foldBitCastBitwiseLogic(BitCastInst &BitCast, InstCombiner::BuilderTy &Builder)
Change the type of a bitwise logic operation if we can eliminate a bitcast.
unsigned ComputeNumSignBits(const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
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.
SmallVector< MachineOperand, 4 > Cond
static const fltSemantics & IEEEdouble() LLVM_READNONE
auto m_Undef()
Match an arbitrary undef constant.
static Constant * getUMin(Constant *C1, Constant *C2)
@ ICMP_ULT
unsigned less than
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getType() const
All values are typed, get the type of this value.
const Function * getFunction() const
Return the function this instruction belongs to.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
LLVMContext & getContext() const
All values hold a context through their type.
Common base class shared among various IRBuilders.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This class represents a cast from a pointer to an integer.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool IsSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
This class represents an extension of floating point types.
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g trunc
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
This is the base class for all instructions that perform data casts.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
This class represents a sign extension of integer types.
StringRef getName() const
Return a constant reference to the value's name.
Instruction * visitSExt(SExtInst &CI)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
CastClass_match< OpTy, Instruction::FPExt > m_FPExt(const OpTy &Op)
Instruction * commonPointerCastTransforms(CastInst &CI)
Implement the transforms for cast of pointer (bitcast/ptrtoint)
static bool canEvaluateTruncated(Value *V, Type *Ty, InstCombinerImpl &IC, Instruction *CxtI)
Return true if we can evaluate the specified expression tree as type Ty instead of its larger type,...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool hasSameElementTypeAs(PointerType *Other)
Return true if both pointer types have the same element type.
static Type * getHalfTy(LLVMContext &C)
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
static bool canEvaluateZExtd(Value *V, Type *Ty, unsigned &BitsToClear, InstCombinerImpl &IC, Instruction *CxtI)
Determine if the specified value can be computed in the specified wider type and produce the same low...
CastClass_match< OpTy, Instruction::FPToSI > m_FPToSI(const OpTy &Op)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static Type * getTypeAtIndex(Type *Ty, Value *Idx)
Return the type of the element at the given index of an indexable type.
constexpr unsigned BitWidth
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
This class represents a cast from an integer to a pointer.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
static Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
static bool fitsInFPType(ConstantFP *CFP, const fltSemantics &Sem)
Return a Constant* for the specified floating-point constant if it fits in the specified FP type with...
This instruction constructs a fixed permutation of two input vectors.
static constexpr roundingMode rmNearestTiesToEven
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
static Type * getMinimumFPType(Value *V)
Find the minimum FP type we can safely truncate to.
static PointerType * getWithSamePointeeType(PointerType *PT, unsigned AddressSpace)
This constructs a pointer type with the same pointee type as input PointerType (or opaque pointer if ...
This class represents a truncation of floating point types.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Predicate getPredicate() const
Return the predicate for this instruction.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
static unsigned getTypeSizeIndex(unsigned Value, Type *Ty)
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Fold the constant using the specified DataLayout.
CastClass_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
A SetVector that performs no allocations if smaller than a certain size.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This class represents a function call, abstracting a target machine's calling convention.
Instruction * foldItoFPtoI(CastInst &FI)
fpto{s/u}i({u/s}itofp(X)) --> X or zext(X) or sext(X) or trunc(X) This is safe if the intermediate ty...
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
void takeName(Value *V)
Transfer the name from V to this value.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
an instruction to allocate memory on the stack
Value * getOperand(unsigned i) const
static bool canNotEvaluateInType(Value *V, Type *Ty)
Filter out values that we can not evaluate in the destination type for free.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static bool hasOneUse(unsigned Reg, MachineInstr *Def, MachineRegisterInfo &MRI, MachineDominatorTree &MDT, LiveIntervals &LIS)
Instruction * visitFPTrunc(FPTruncInst &CI)
Instruction * visitUIToFP(CastInst &CI)
LLVM Value Representation.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth=0, const Instruction *CxtI=nullptr) const
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
iterator_range< user_iterator > users()
static Type * getFloatTy(LLVMContext &C)
bool isX86_AMXTy() const
Return true if this is X86 AMX.
static bool isKnownExactCastIntToFP(CastInst &I)
Return true if the cast from integer to FP can be proven to be exact for all possible inputs (the con...
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static Instruction * foldVecTruncToExtElt(TruncInst &Trunc, InstCombinerImpl &IC)
Given a vector that is bitcast to an integer, optionally logically right-shifted, and truncated,...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.