107 using namespace llvm;
110 #define DEBUG_TYPE "instcombine" 112 STATISTIC(NumCombined ,
"Number of insts combined");
113 STATISTIC(NumConstProp,
"Number of constant folds");
114 STATISTIC(NumDeadInst ,
"Number of dead inst eliminated");
115 STATISTIC(NumSunkInst ,
"Number of instructions sunk");
116 STATISTIC(NumExpand,
"Number of expansions");
117 STATISTIC(NumFactor ,
"Number of factorizations");
118 STATISTIC(NumReassoc ,
"Number of reassociations");
120 "Controls which instructions are visited");
128 cl::desc(
"Enable expensive instruction combines"));
132 cl::desc(
"Maximum array size considered when doing a combine"));
157 bool InstCombiner::shouldChangeType(
unsigned FromWidth,
158 unsigned ToWidth)
const {
159 bool FromLegal = FromWidth == 1 || DL.isLegalInteger(FromWidth);
160 bool ToLegal = ToWidth == 1 || DL.isLegalInteger(ToWidth);
164 if (ToWidth < FromWidth && (ToWidth == 8 || ToWidth == 16 || ToWidth == 32))
169 if (FromLegal && !ToLegal)
174 if (!FromLegal && !ToLegal && ToWidth > FromWidth)
185 bool InstCombiner::shouldChangeType(
Type *
From,
Type *To)
const {
193 return shouldChangeType(FromWidth, ToWidth);
211 const APInt *BVal, *CVal;
215 bool Overflow =
false;
217 (void)BVal->
sadd_ov(*CVal, Overflow);
219 (
void)BVal->
ssub_ov(*CVal, Overflow);
245 if (!Cast || !Cast->hasOneUse())
250 if (CastOpcode != Instruction::ZExt)
259 if (!BinOp2 || !BinOp2->hasOneUse() || BinOp2->getOpcode() != AssocOpcode)
276 Cast->setOperand(0, BinOp2->getOperand(0));
301 bool InstCombiner::SimplifyAssociativeOrCommutative(
BinaryOperator &
I) {
303 bool Changed =
false;
347 if (Op1 && Op1->getOpcode() == Opcode) {
349 Value *
B = Op1->getOperand(0);
395 if (Op1 && Op1->getOpcode() == Opcode) {
397 Value *
B = Op1->getOperand(0);
419 Op0->
getOpcode() == Opcode && Op1->getOpcode() == Opcode &&
423 if (isa<FPMathOperator>(NewBO)) {
426 Flags &= Op1->getFastMathFlags();
429 InsertNewInstWith(NewBO, I);
453 if (LOp == Instruction::And)
454 return ROp == Instruction::Or || ROp == Instruction::Xor;
457 if (LOp == Instruction::Or)
458 return ROp == Instruction::And;
462 if (LOp == Instruction::Mul)
486 if (isa<Constant>(V))
500 assert(Op &&
"Expected a binary operator");
508 return Instruction::Mul;
520 assert(A && B && C && D &&
"All values must be provided");
523 Value *SimplifiedInst =
nullptr;
534 if (A == C || (InnerCommutative && A == D)) {
539 V =
SimplifyBinOp(TopLevelOpcode, B, D, SQ.getWithInstruction(&I));
542 if (!V && LHS->
hasOneUse() && RHS->hasOneUse())
543 V = Builder.CreateBinOp(TopLevelOpcode, B, D, RHS->
getName());
545 SimplifiedInst = Builder.CreateBinOp(InnerOpcode, A, V);
553 if (B == D || (InnerCommutative && B == C)) {
558 V =
SimplifyBinOp(TopLevelOpcode, A, C, SQ.getWithInstruction(&I));
562 if (!V && LHS->
hasOneUse() && RHS->hasOneUse())
563 V = Builder.CreateBinOp(TopLevelOpcode, A, C, LHS->
getName());
565 SimplifiedInst = Builder.CreateBinOp(InnerOpcode, V, B);
569 if (SimplifiedInst) {
575 if (
BinaryOperator *BO = dyn_cast<BinaryOperator>(SimplifiedInst)) {
576 if (isa<OverflowingBinaryOperator>(SimplifiedInst)) {
578 if (isa<OverflowingBinaryOperator>(&I))
581 if (
auto *LOBO = dyn_cast<OverflowingBinaryOperator>(LHS))
582 HasNSW &= LOBO->hasNoSignedWrap();
584 if (
auto *ROBO = dyn_cast<OverflowingBinaryOperator>(RHS))
585 HasNSW &= ROBO->hasNoSignedWrap();
596 InnerOpcode == Instruction::Mul)
598 BO->setHasNoSignedWrap(HasNSW);
602 return SimplifiedInst;
627 if (Op0 && Op1 && LHSOpcode == RHSOpcode)
628 if (
Value *V = tryFactorization(I, LHSOpcode, A, B, C, D))
635 if (
Value *V = tryFactorization(I, LHSOpcode, A, B, RHS, Ident))
642 if (
Value *V = tryFactorization(I, RHSOpcode, LHS, Ident, C, D))
660 C = Builder.CreateBinOp(InnerOpcode, L, R);
669 C = Builder.CreateBinOp(TopLevelOpcode, B, C);
678 C = Builder.CreateBinOp(TopLevelOpcode, A, C);
687 Value *A = LHS, *B = Op1->getOperand(0), *C = Op1->getOperand(1);
697 A = Builder.CreateBinOp(InnerOpcode, L, R);
706 A = Builder.CreateBinOp(TopLevelOpcode, A, C);
715 A = Builder.CreateBinOp(TopLevelOpcode, A, B);
721 return SimplifySelectsFeedingBinaryOp(I, LHS, RHS);
735 if (isa<FPMathOperator>(&I))
741 SI = Builder.CreateSelect(A, V2, V1);
742 else if (V2 && SelectsHaveOneUse)
743 SI = Builder.CreateSelect(A, V2, Builder.CreateBinOp(Opcode, C, E));
744 else if (V1 && SelectsHaveOneUse)
745 SI = Builder.CreateSelect(A, Builder.CreateBinOp(Opcode, B, D), V1);
756 Value *InstCombiner::dyn_castNegVal(
Value *V)
const {
770 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
775 if (isa<UndefValue>(Elt))
778 if (!isa<ConstantInt>(Elt))
789 if (
auto *Cast = dyn_cast<CastInst>(&I))
795 bool ConstIsRHS = isa<Constant>(I.
getOperand(1));
798 if (
auto *SOC = dyn_cast<Constant>(SO)) {
804 Value *Op0 = SO, *Op1 = ConstOperand;
808 auto *BO = cast<BinaryOperator>(&
I);
812 if (FPInst && isa<FPMathOperator>(FPInst))
824 if (!(isa<Constant>(TV) || isa<Constant>(FV)))
833 if (
auto *BC = dyn_cast<BitCastInst>(&Op)) {
838 if ((SrcTy ==
nullptr) != (DestTy ==
nullptr))
854 if (CI->hasOneUse()) {
855 Value *Op0 = CI->getOperand(0), *Op1 = CI->getOperand(1);
869 bool ConstIsRHS = isa<Constant>(I->
getOperand(1));
872 if (
auto *InC = dyn_cast<Constant>(InV)) {
878 Value *Op0 = InV, *Op1 =
C;
884 if (FPInst && isa<FPMathOperator>(FPInst))
891 if (NumPHIValues == 0)
913 for (
unsigned i = 0; i != NumPHIValues; ++i) {
915 if (isa<Constant>(InVal) && !isa<ConstantExpr>(InVal))
918 if (isa<PHINode>(InVal))
return nullptr;
919 if (NonConstBB)
return nullptr;
925 if (
InvokeInst *II = dyn_cast<InvokeInst>(InVal))
926 if (II->getParent() == NonConstBB)
940 if (NonConstBB !=
nullptr) {
947 InsertNewInstBefore(NewPN, *PN);
956 if (
SelectInst *SI = dyn_cast<SelectInst>(&I)) {
962 for (
unsigned i = 0; i != NumPHIValues; ++i) {
966 Value *InV =
nullptr;
974 if (InC && !isa<ConstantExpr>(InC) && isa<ConstantInt>(InC))
975 InV = InC->
isNullValue() ? FalseVInPred : TrueVInPred;
987 FalseVInPred,
"phitmp");
991 }
else if (
CmpInst *CI = dyn_cast<CmpInst>(&I)) {
993 for (
unsigned i = 0; i != NumPHIValues; ++i) {
994 Value *InV =
nullptr;
997 else if (isa<ICmpInst>(CI))
1005 }
else if (
auto *BO = dyn_cast<BinaryOperator>(&I)) {
1006 for (
unsigned i = 0; i != NumPHIValues; ++i) {
1014 for (
unsigned i = 0; i != NumPHIValues; ++i) {
1027 if (User == &I)
continue;
1028 replaceInstUsesWith(*User, NewPN);
1029 eraseInstFromFunction(*User);
1031 return replaceInstUsesWith(I, NewPN);
1038 if (
auto *Sel = dyn_cast<SelectInst>(I.
getOperand(0))) {
1039 if (
Instruction *NewSel = FoldOpIntoSelect(I, Sel))
1041 }
else if (
auto *PN = dyn_cast<PHINode>(I.
getOperand(0))) {
1061 Type *IndexTy = DL.getIndexType(PtrTy);
1062 int64_t FirstIdx = 0;
1063 if (int64_t TySize = DL.getTypeAllocSize(Ty)) {
1064 FirstIdx = Offset/TySize;
1065 Offset -= FirstIdx*TySize;
1073 assert((uint64_t)Offset < (uint64_t)TySize &&
"Out of range offset");
1081 if (uint64_t(Offset * 8) >= DL.getTypeSizeInBits(Ty))
1084 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
1087 "Offset must stay within the indexed type");
1094 Ty = STy->getElementType(Elt);
1095 }
else if (
ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
1096 uint64_t EltSize = DL.getTypeAllocSize(AT->getElementType());
1097 assert(EltSize &&
"Cannot index into a zero-sized array");
1100 Ty = AT->getElementType();
1122 Value *InstCombiner::Descale(
Value *Val,
APInt Scale,
bool &NoSignedWrap) {
1123 assert(isa<IntegerType>(Val->
getType()) &&
"Can only descale integers!");
1125 Scale.
getBitWidth() &&
"Scale not compatible with value!");
1129 NoSignedWrap =
true;
1161 std::pair<Instruction *, unsigned> Parent;
1165 bool RequireNoSignedWrap =
false;
1170 for (;; Op = Parent.first->getOperand(Parent.second)) {
1171 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
1173 APInt Quotient(Scale), Remainder(Scale);
1180 NoSignedWrap =
true;
1185 if (BO->getOpcode() == Instruction::Mul) {
1187 NoSignedWrap = BO->hasNoSignedWrap();
1188 if (RequireNoSignedWrap && !NoSignedWrap)
1194 Value *LHS = BO->getOperand(0);
1195 Value *RHS = BO->getOperand(1);
1197 if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
1199 if (CI->getValue() == Scale) {
1210 Parent = std::make_pair(BO, 1);
1219 Parent = std::make_pair(BO, 0);
1223 if (logScale > 0 && BO->getOpcode() == Instruction::Shl &&
1224 isa<ConstantInt>(BO->getOperand(1))) {
1226 NoSignedWrap = BO->hasNoSignedWrap();
1227 if (RequireNoSignedWrap && !NoSignedWrap)
1230 Value *LHS = BO->getOperand(0);
1231 int32_t Amt = cast<ConstantInt>(BO->getOperand(1))->
1235 if (Amt == logScale) {
1241 if (Amt < logScale || !Op->hasOneUse())
1246 Parent = std::make_pair(BO, 1);
1255 if (
CastInst *Cast = dyn_cast<CastInst>(Op)) {
1256 if (Cast->getOpcode() == Instruction::SExt) {
1258 unsigned SmallSize = Cast->getSrcTy()->getPrimitiveSizeInBits();
1270 RequireNoSignedWrap =
true;
1273 Parent = std::make_pair(Cast, 0);
1278 if (Cast->getOpcode() == Instruction::Trunc) {
1285 if (RequireNoSignedWrap)
1289 unsigned LargeSize = Cast->getSrcTy()->getPrimitiveSizeInBits();
1290 Parent = std::make_pair(Cast, 0);
1291 Scale = Scale.
sext(LargeSize);
1292 if (logScale + 1 == (int32_t)Cast->getType()->getPrimitiveSizeInBits())
1305 NoSignedWrap =
true;
1319 assert(Parent.first->hasOneUse() &&
"Drilled down when more than one use!");
1320 assert(Op != Parent.first->getOperand(Parent.second) &&
1321 "Descaling was a no-op?");
1322 Parent.first->setOperand(Parent.second, Op);
1323 Worklist.Add(Parent.first);
1338 NoSignedWrap &= OpNoSignedWrap;
1339 if (NoSignedWrap != OpNoSignedWrap) {
1340 BO->setHasNoSignedWrap(NoSignedWrap);
1341 Worklist.Add(Ancestor);
1343 }
else if (Ancestor->
getOpcode() == Instruction::Trunc) {
1347 NoSignedWrap =
false;
1349 assert((Ancestor->
getOpcode() != Instruction::SExt || NoSignedWrap) &&
1350 "Failed to keep proper track of nsw flags while drilling down?");
1352 if (Ancestor == Val)
1357 assert(Ancestor->
hasOneUse() &&
"Drilled down when more than one use!");
1366 unsigned NumElts = cast<VectorType>(Inst.
getType())->getNumElements();
1368 assert(cast<VectorType>(LHS->
getType())->getNumElements() == NumElts);
1369 assert(cast<VectorType>(RHS->
getType())->getNumElements() == NumElts);
1374 Value *L0, *L1, *R0, *R1;
1379 cast<ShuffleVectorInst>(LHS)->isConcat() &&
1380 cast<ShuffleVectorInst>(RHS)->isConcat()) {
1386 Value *NewBO0 = Builder.CreateBinOp(Opcode, L0, R0);
1387 if (
auto *BO = dyn_cast<BinaryOperator>(NewBO0))
1388 BO->copyIRFlags(&Inst);
1389 Value *NewBO1 = Builder.CreateBinOp(Opcode, L1, R1);
1390 if (
auto *BO = dyn_cast<BinaryOperator>(NewBO1))
1391 BO->copyIRFlags(&Inst);
1402 Value *XY = Builder.CreateBinOp(Opcode, X, Y);
1403 if (
auto *BO = dyn_cast<BinaryOperator>(XY))
1404 BO->copyIRFlags(&Inst);
1416 return createBinOpShuffle(V1, V2, Mask);
1430 "Shuffle should not change scalar type");
1437 bool ConstOp1 = isa<Constant>(RHS);
1443 bool MayChange =
true;
1444 for (
unsigned I = 0; I < NumElts; ++
I) {
1446 if (ShMask[I] >= 0) {
1447 assert(ShMask[I] < (
int)NumElts &&
"Not expecting narrowing shuffle");
1455 if (!CElt || (!isa<UndefValue>(NewCElt) && NewCElt != CElt) ||
1456 I >= SrcVecNumElts) {
1460 NewVecC[ShMask[
I]] = CElt;
1469 if (I >= SrcVecNumElts) {
1473 if (!isa<UndefValue>(MaybeUndef)) {
1489 Value *NewLHS = ConstOp1 ? V1 : NewC;
1490 Value *NewRHS = ConstOp1 ? NewC : V1;
1491 return createBinOpShuffle(NewLHS, NewRHS, Mask);
1520 cast<Operator>(Op1)->
getOpcode() == CastOpc &&
1521 (Op0->
hasOneUse() || Op1->hasOneUse()))) {
1544 Value *NarrowBO = Builder.CreateBinOp(BO.getOpcode(),
X,
Y,
"narrow");
1545 if (
auto *NewBinOp = dyn_cast<BinaryOperator>(NarrowBO)) {
1547 NewBinOp->setHasNoSignedWrap();
1549 NewBinOp->setHasNoUnsignedWrap();
1559 return replaceInstUsesWith(GEP, V);
1565 bool MadeChange =
false;
1569 Type *NewScalarIndexTy =
1579 Type *IndexTy = (*I)->getType();
1580 Type *NewIndexType =
1588 if (EltTy->isSized() && DL.getTypeAllocSize(EltTy) == 0)
1589 if (!isa<Constant>(*I) || !cast<Constant>(*I)->isNullValue()) {
1594 if (IndexTy != NewIndexType) {
1598 *I = Builder.CreateIntCast(*I, NewIndexType,
true);
1606 if (
auto *PN = dyn_cast<PHINode>(PtrOp)) {
1624 if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands())
1632 Type *CurTy =
nullptr;
1634 for (
unsigned J = 0,
F = Op1->getNumOperands(); J !=
F; ++J) {
1635 if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())
1638 if (Op1->getOperand(J) != Op2->getOperand(J)) {
1664 CurTy = Op1->getSourceElementType();
1665 }
else if (
auto *CT = dyn_cast<CompositeType>(CurTy)) {
1666 CurTy = CT->getTypeAtIndex(Op1->getOperand(J));
1680 auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());
1693 Builder.SetInsertPoint(PN);
1694 NewPN = Builder.CreatePHI(Op1->getOperand(DI)->getType(),
1699 NewPN->
addIncoming(cast<GEPOperator>(I)->getOperand(DI),
1702 NewGEP->setOperand(DI, NewPN);
1705 NewGEP->setOperand(DI, NewPN);
1715 if (
auto *Src = dyn_cast<GEPOperator>(PtrOp)) {
1720 if (LI && Src->getNumOperands() == 2 && GEP.
getNumOperands() == 2 &&
1724 Value *SO1 = Src->getOperand(1);
1728 if (L->isLoopInvariant(GO1) && !L->isLoopInvariant(SO1)) {
1746 auto *SO0 = Src->getOperand(0);
1748 if (!isa<VectorType>(GEPType) ||
1749 isa<VectorType>(SO0Ty)) {
1750 Src->setOperand(1, GO1);
1757 Builder.SetInsertPoint(cast<Instruction>(PtrOp));
1758 auto *NewSrc = cast<GetElementPtrInst>(
1759 Builder.CreateGEP(SO0, GO1, Src->
getName()));
1760 NewSrc->setIsInBounds(Src->isInBounds());
1772 if (
auto *SrcGEP = dyn_cast<GEPOperator>(Src->getOperand(0)))
1779 bool EndsWithSequential =
false;
1782 EndsWithSequential = I.isSequential();
1785 if (EndsWithSequential) {
1788 Value *SO1 = Src->getOperand(Src->getNumOperands()-1);
1806 if (Src->getNumOperands() == 2) {
1811 Indices.
append(Src->op_begin()+1, Src->op_end()-1);
1814 }
else if (isa<Constant>(*GEP.
idx_begin()) &&
1815 cast<Constant>(*GEP.
idx_begin())->isNullValue() &&
1816 Src->getNumOperands() != 1) {
1818 Indices.
append(Src->op_begin()+1, Src->op_end());
1822 if (!Indices.
empty())
1825 Src->getSourceElementType(), Src->getOperand(0), Indices,
1828 Src->getOperand(0), Indices,
1835 DL.getIndexSizeInBits(AS)) {
1836 uint64_t TyAllocSize = DL.getTypeAllocSize(GEPEltType);
1838 bool Matched =
false;
1841 if (TyAllocSize == 1) {
1846 if (TyAllocSize == 1ULL << C)
1850 if (TyAllocSize == C)
1861 Value *PtrToInt = Builder.CreatePtrToInt(PtrOp, Index->
getType());
1876 if (GEPType->isVectorTy())
1883 if (StrippedPtr != PtrOp) {
1884 bool HasZeroPointerIndex =
false;
1885 if (
auto *C = dyn_cast<ConstantInt>(GEP.
getOperand(1)))
1886 HasZeroPointerIndex = C->isZero();
1895 if (HasZeroPointerIndex) {
1896 if (
auto *CATy = dyn_cast<ArrayType>(GEPEltType)) {
1915 if (
auto *XATy = dyn_cast<ArrayType>(StrippedPtrTy->
getElementType())) {
1917 if (CATy->getElementType() == XATy->getElementType()) {
1939 ? Builder.CreateInBoundsGEP(
1940 nullptr, StrippedPtr, Idx, GEP.
getName())
1941 : Builder.CreateGEP(
nullptr, StrippedPtr, Idx,
1954 DL.getTypeAllocSize(GEPEltType)) {
1955 Type *IdxType = DL.getIndexType(GEPType);
1959 ? Builder.CreateInBoundsGEP(
nullptr, StrippedPtr, Idx,
1961 : Builder.CreateGEP(
nullptr, StrippedPtr, Idx, GEP.
getName());
1974 uint64_t ResSize = DL.getTypeAllocSize(GEPEltType);
1975 uint64_t SrcSize = DL.getTypeAllocSize(SrcEltTy);
1976 if (ResSize && SrcSize % ResSize == 0) {
1979 uint64_t Scale = SrcSize / ResSize;
1985 "Index type does not match the Data Layout preferences");
1988 if (
Value *NewIdx = Descale(Idx,
APInt(BitWidth, Scale), NSW)) {
1994 ? Builder.CreateInBoundsGEP(
nullptr, StrippedPtr, NewIdx,
1996 : Builder.CreateGEP(
nullptr, StrippedPtr, NewIdx,
2014 uint64_t ResSize = DL.getTypeAllocSize(GEPEltType);
2015 uint64_t ArrayEltSize =
2017 if (ResSize && ArrayEltSize % ResSize == 0) {
2020 uint64_t Scale = ArrayEltSize / ResSize;
2026 "Index type does not match the Data Layout preferences");
2029 if (
Value *NewIdx = Descale(Idx,
APInt(BitWidth, Scale), NSW)) {
2033 Type *IndTy = DL.getIndexType(GEPType);
2037 ? Builder.CreateInBoundsGEP(
2038 SrcEltTy, StrippedPtr, Off, GEP.
getName())
2039 : Builder.CreateGEP(SrcEltTy, StrippedPtr, Off,
2053 Value *ASCStrippedPtrOp = PtrOp;
2054 if (
auto *ASC = dyn_cast<AddrSpaceCastInst>(PtrOp)) {
2059 if (
auto *BC = dyn_cast<BitCastInst>(ASC->getOperand(0)))
2060 ASCStrippedPtrOp = BC;
2063 if (
auto *BCI = dyn_cast<BitCastInst>(ASCStrippedPtrOp)) {
2065 PointerType *SrcType = cast<PointerType>(BCI->getSrcTy());
2072 auto areMatchingArrayAndVecTypes = [](
Type *ArrTy,
Type *VecTy) {
2077 ((GEPEltType->
isArrayTy() && SrcEltType->isVectorTy() &&
2078 areMatchingArrayAndVecTypes(GEPEltType, SrcEltType)) ||
2079 (GEPEltType->
isVectorTy() && SrcEltType->isArrayTy() &&
2080 areMatchingArrayAndVecTypes(SrcEltType, GEPEltType)))) {
2088 ? Builder.CreateInBoundsGEP(
nullptr, SrcOp, {Ops[1], Ops[2]})
2089 : Builder.CreateGEP(
nullptr, SrcOp, {Ops[1], Ops[2]});
2096 return replaceInstUsesWith(GEP, NGEP);
2104 unsigned OffsetBits = DL.getIndexTypeSizeInBits(GEPType);
2117 BCI->getParent()->getInstList().insert(BCI->getIterator(),
I);
2118 replaceInstUsesWith(*BCI, I);
2133 if (FindElementAtOffset(SrcType, Offset.
getSExtValue(), NewIndices)) {
2136 ? Builder.CreateInBoundsGEP(
nullptr, SrcOp, NewIndices)
2137 : Builder.CreateGEP(
nullptr, SrcOp, NewIndices);
2139 if (NGEP->
getType() == GEPType)
2140 return replaceInstUsesWith(GEP, NGEP);
2153 APInt BasePtrOffset(IdxWidth, 0);
2154 Value *UnderlyingPtrOp =
2157 if (
auto *AI = dyn_cast<AllocaInst>(UnderlyingPtrOp)) {
2160 APInt AllocSize(IdxWidth, DL.getTypeAllocSize(AI->getAllocatedType()));
2161 if (BasePtrOffset.
ule(AllocSize)) {
2174 if (isa<ConstantPointerNull>(V))
2176 if (
auto *LI = dyn_cast<LoadInst>(V))
2177 return isa<GlobalVariable>(LI->getPointerOperand());
2201 case Instruction::AddrSpaceCast:
2202 case Instruction::BitCast:
2203 case Instruction::GetElementPtr:
2208 case Instruction::ICmp: {
2215 unsigned OtherIndex = (ICI->
getOperand(0) == PI) ? 1 : 0;
2225 switch (II->getIntrinsicID()) {
2263 }
while (!Worklist.
empty());
2283 std::unique_ptr<DIBuilder> DIB;
2284 if (isa<AllocaInst>(MI)) {
2290 for (
unsigned i = 0, e = Users.
size(); i != e; ++i) {
2302 replaceInstUsesWith(*I, Result);
2303 eraseInstFromFunction(*I);
2308 for (
unsigned i = 0, e = Users.
size(); i != e; ++i) {
2314 if (
ICmpInst *C = dyn_cast<ICmpInst>(I)) {
2315 replaceInstUsesWith(*C,
2317 C->isFalseWhenEqual()));
2318 }
else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I) ||
2319 isa<AddrSpaceCastInst>(I)) {
2321 }
else if (
auto *SI = dyn_cast<StoreInst>(I)) {
2322 for (
auto *DII : DIIs)
2325 eraseInstFromFunction(*I);
2328 if (
InvokeInst *II = dyn_cast<InvokeInst>(&MI)) {
2330 Module *M = II->getModule();
2333 None,
"", II->getParent());
2336 for (
auto *DII : DIIs)
2337 eraseInstFromFunction(*DII);
2339 return eraseInstFromFunction(MI);
2383 if (FreeInstrBB->
size() != 2) {
2385 if (&Inst == &FI || &Inst == FreeInstrBBTerminator)
2388 if (!Cast || !Cast->isNoopCast(DL))
2409 "Broken CFG: missing edge from predecessor to successor");
2416 if (&Instr == FreeInstrBBTerminator)
2421 "Only the branch instruction should remain");
2429 if (isa<UndefValue>(Op)) {
2433 return eraseInstFromFunction(FI);
2438 if (isa<ConstantPointerNull>(Op))
2439 return eraseInstFromFunction(FI);
2478 !isa<Constant>(X)) {
2515 for (
auto Case : SI.
cases()) {
2517 assert(isa<ConstantInt>(NewCase) &&
2518 "Result of expression should be constant");
2519 Case.setValue(cast<ConstantInt>(NewCase));
2531 for (
auto &C : SI.
cases()) {
2532 LeadingKnownZeros = std::min(
2533 LeadingKnownZeros, C.getCaseValue()->getValue().countLeadingZeros());
2534 LeadingKnownOnes = std::min(
2535 LeadingKnownOnes, C.getCaseValue()->getValue().countLeadingOnes());
2544 if (NewWidth > 0 && NewWidth < Known.
getBitWidth() &&
2545 shouldChangeType(Known.
getBitWidth(), NewWidth)) {
2547 Builder.SetInsertPoint(&SI);
2548 Value *NewCond = Builder.CreateTrunc(Cond, Ty,
"trunc");
2551 for (
auto Case : SI.
cases()) {
2552 APInt TruncatedCase = Case.getCaseValue()->getValue().
trunc(NewWidth);
2565 return replaceInstUsesWith(EV, Agg);
2568 SQ.getWithInstruction(&EV)))
2569 return replaceInstUsesWith(EV, V);
2573 const unsigned *exti, *exte, *insi, *inse;
2574 for (exti = EV.
idx_begin(), insi = IV->idx_begin(),
2575 exte = EV.
idx_end(), inse = IV->idx_end();
2576 exti != exte && insi != inse;
2590 if (exti == exte && insi == inse)
2595 return replaceInstUsesWith(EV, IV->getInsertedValueOperand());
2605 Value *NewEV = Builder.CreateExtractValue(IV->getAggregateOperand(),
2626 if (II->hasOneUse()) {
2630 switch (II->getIntrinsicID()) {
2634 Value *LHS = II->getArgOperand(0), *RHS = II->getArgOperand(1);
2636 eraseInstFromFunction(*II);
2644 if (
ConstantInt *CI = dyn_cast<ConstantInt>(II->getArgOperand(1)))
2651 Value *LHS = II->getArgOperand(0), *RHS = II->getArgOperand(1);
2653 eraseInstFromFunction(*II);
2654 return BinaryOperator::CreateSub(LHS, RHS);
2660 Value *LHS = II->getArgOperand(0), *RHS = II->getArgOperand(1);
2662 eraseInstFromFunction(*II);
2671 if (
LoadInst *L = dyn_cast<LoadInst>(Agg))
2677 if (L->isSimple() && L->hasOneUse()) {
2684 Indices.
push_back(Builder.getInt32(*I));
2688 Builder.SetInsertPoint(L);
2689 Value *
GEP = Builder.CreateInBoundsGEP(L->getType(),
2690 L->getPointerOperand(), Indices);
2695 L->getAAMetadata(Nodes);
2699 return replaceInstUsesWith(EV, NL);
2714 switch (Personality) {
2742 cast<ArrayType>(LHS->
getType())->getNumElements()
2744 cast<ArrayType>(RHS->
getType())->getNumElements();
2756 bool MakeNewInstruction =
false;
2762 bool isLastClause = i + 1 == e;
2770 if (AlreadyCaught.
insert(TypeInfo).second) {
2775 MakeNewInstruction =
true;
2782 MakeNewInstruction =
true;
2783 CleanupFlag =
false;
2796 ArrayType *FilterType = cast<ArrayType>(FilterClause->getType());
2802 if (!NumTypeInfos) {
2805 MakeNewInstruction =
true;
2806 CleanupFlag =
false;
2810 bool MakeNewFilter =
false;
2812 if (isa<ConstantAggregateZero>(FilterClause)) {
2814 assert(NumTypeInfos > 0 &&
"Should have handled empty filter already!");
2820 MakeNewInstruction =
true;
2827 if (NumTypeInfos > 1)
2828 MakeNewFilter =
true;
2832 NewFilterElts.
reserve(NumTypeInfos);
2837 bool SawCatchAll =
false;
2838 for (
unsigned j = 0; j != NumTypeInfos; ++j) {
2866 if (SeenInFilter.insert(TypeInfo).second)
2867 NewFilterElts.
push_back(cast<Constant>(Elt));
2872 MakeNewInstruction =
true;
2877 if (NewFilterElts.
size() < NumTypeInfos)
2878 MakeNewFilter =
true;
2880 if (MakeNewFilter) {
2882 NewFilterElts.
size());
2884 MakeNewInstruction =
true;
2893 if (MakeNewFilter && !NewFilterElts.
size()) {
2894 assert(MakeNewInstruction &&
"New filter but not a new instruction!");
2895 CleanupFlag =
false;
2906 for (
unsigned i = 0, e = NewClauses.
size(); i + 1 < e; ) {
2909 for (j = i; j != e; ++j)
2910 if (!isa<ArrayType>(NewClauses[j]->
getType()))
2916 for (
unsigned k = i; k + 1 < j; ++k)
2920 std::stable_sort(NewClauses.
begin() + i, NewClauses.
begin() + j,
2922 MakeNewInstruction =
true;
2941 for (
unsigned i = 0; i + 1 < NewClauses.
size(); ++i) {
2951 for (
unsigned j = NewClauses.
size() - 1; j != i; --j) {
2952 Value *LFilter = NewClauses[j];
2963 NewClauses.
erase(J);
2964 MakeNewInstruction =
true;
2974 if (isa<ConstantAggregateZero>(LFilter)) {
2977 if (isa<ConstantAggregateZero>(Filter)) {
2978 assert(FElts <= LElts &&
"Should have handled this case earlier!");
2980 NewClauses.
erase(J);
2981 MakeNewInstruction =
true;
2987 if (isa<ConstantAggregateZero>(Filter)) {
2990 assert(FElts > 0 &&
"Should have eliminated the empty filter earlier!");
2991 for (
unsigned l = 0; l != LElts; ++l)
2994 NewClauses.
erase(J);
2995 MakeNewInstruction =
true;
3006 bool AllFound =
true;
3007 for (
unsigned f = 0; f != FElts; ++f) {
3010 for (
unsigned l = 0; l != LElts; ++l) {
3012 if (LTypeInfo == FTypeInfo) {
3022 NewClauses.
erase(J);
3023 MakeNewInstruction =
true;
3031 if (MakeNewInstruction) {
3034 for (
unsigned i = 0, e = NewClauses.
size(); i != e; ++i)
3039 if (NewClauses.
empty())
3048 assert(!CleanupFlag &&
"Adding a cleanup, not removing one?!");
3073 if (isa<AllocaInst>(I))
3081 if (
auto *CI = dyn_cast<CallInst>(I)) {
3082 if (CI->isConvergent())
3091 if (Scan->mayWriteToMemory())
3102 for (
auto *DII : DbgUsers) {
3103 if (DII->getParent() == SrcBlock) {
3104 DII->moveBefore(&*InsertPos);
3112 while (!Worklist.isEmpty()) {
3114 if (I ==
nullptr)
continue;
3119 eraseInstFromFunction(*I);
3121 MadeIRChange =
true;
3132 LLVM_DEBUG(
dbgs() <<
"IC: ConstFold to: " << *C <<
" from: " << *I
3136 replaceInstUsesWith(*I, C);
3139 eraseInstFromFunction(*I);
3140 MadeIRChange =
true;
3153 <<
" from: " << *I <<
'\n');
3156 replaceInstUsesWith(*I, C);
3159 eraseInstFromFunction(*I);
3160 MadeIRChange =
true;
3172 if (
PHINode *PN = dyn_cast<PHINode>(UserInst))
3177 if (UserParent != BB) {
3178 bool UserIsSuccessor =
false;
3181 if (*SI == UserParent) {
3182 UserIsSuccessor =
true;
3189 if (UserIsSuccessor && UserParent->getUniquePredecessor()) {
3193 MadeIRChange =
true;
3198 if (
Instruction *OpI = dyn_cast<Instruction>(U.get()))
3206 Builder.SetInsertPoint(I);
3207 Builder.SetCurrentDebugLocation(I->
getDebugLoc());
3220 <<
" New = " << *Result <<
'\n');
3228 Result->takeName(I);
3231 Worklist.AddUsersToWorkList(*Result);
3232 Worklist.Add(Result);
3240 if (!isa<PHINode>(Result) && isa<PHINode>(InsertPos))
3245 eraseInstFromFunction(*I);
3248 <<
" New = " << *I <<
'\n');
3253 eraseInstFromFunction(*I);
3255 Worklist.AddUsersToWorkList(*I);
3259 MadeIRChange =
true;
3264 return MadeIRChange;
3279 bool MadeIRChange =
false;
3290 if (!Visited.
insert(BB).second)
3302 MadeIRChange =
true;
3310 LLVM_DEBUG(
dbgs() <<
"IC: ConstFold to: " << *C <<
" from: " << *Inst
3316 MadeIRChange =
true;
3322 if (!isa<ConstantVector>(U) && !isa<ConstantExpr>(U))
3325 auto *C = cast<Constant>(U);
3326 Constant *&FoldRes = FoldedConstants[
C];
3334 <<
"\n Old = " << *C
3335 <<
"\n New = " << *FoldRes <<
'\n');
3337 MadeIRChange =
true;
3343 if (!isa<DbgInfoIntrinsic>(Inst))
3344 InstrsForInstCombineWorklist.
push_back(Inst);
3350 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
3351 if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) {
3352 bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue();
3353 BasicBlock *ReachableBB = BI->getSuccessor(!CondVal);
3357 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
3359 Worklist.
push_back(SI->findCaseValue(Cond)->getCaseSuccessor());
3366 }
while (!Worklist.
empty());
3375 return MadeIRChange;
3386 bool MadeIRChange =
false;
3399 if (Visited.count(&BB))
3403 MadeIRChange |= NumDeadInstInBB > 0;
3404 NumDeadInst += NumDeadInstInBB;
3407 return MadeIRChange;
3424 if (
match(I, m_Intrinsic<Intrinsic::assume>()))
3430 bool MadeIRChange =
false;
3438 LLVM_DEBUG(
dbgs() <<
"\n\nINSTCOMBINE ITERATION #" << Iteration <<
" on " 3444 AC, TLI, DT, ORE, DL, LI);
3451 return MadeIRChange || Iteration > 1;
3465 ExpensiveCombines, LI))
3492 if (skipFunction(F))
3496 auto AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
3497 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
3498 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
3499 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
3500 auto &ORE = getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
3503 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
3504 auto *LI = LIWP ? &LIWP->getLoopInfo() :
nullptr;
3507 ExpensiveCombines, LI);
3513 "Combine redundant instructions",
false,
false)
Legacy wrapper pass to provide the GlobalsAAResult object.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Type * getVectorElementType() const
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
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...
Return a value (possibly void), from a function.
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...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
A parsed version of the target data layout string in and methods for querying it. ...
static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL, TargetLibraryInfo *TLI, InstCombineWorklist &ICWorklist)
Populate the IC worklist from a function, and prune any dead basic blocks discovered in the process...
static ConstantInt * getFalse(LLVMContext &Context)
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction, which must be an operator which supports these flags.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class is the base class for the comparison instructions.
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static IntegerType * getInt1Ty(LLVMContext &C)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
APInt sext(unsigned width) const
Sign extend to a new width.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void LLVMInitializeInstCombine(LLVMPassRegistryRef R)
This class represents lattice values for constants.
BinaryOps getOpcode() const
void swapSuccessors()
Swap the successors of this branch instruction.
static bool isAllocSiteRemovable(Instruction *AI, SmallVectorImpl< WeakTrackingVH > &Users, const TargetLibraryInfo *TLI)
This is the interface for a simple mod/ref and alias analysis over globals.
A Module instance is used to store all the information related to an LLVM module. ...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static Value * foldOperationIntoPhiValue(BinaryOperator *I, Value *InV, InstCombiner::BuilderTy &Builder)
static void ClearSubclassDataAfterReassociation(BinaryOperator &I)
Conservatively clears subclassOptionalData after a reassociation or commutation.
void push_back(const T &Elt)
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
br_match m_UnconditionalBr(BasicBlock *&Succ)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
This class represents a function call, abstracting a target machine's calling convention.
An immutable pass that tracks lazily created AssumptionCache objects.
Value * getCondition() const
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
static bool isCanonicalPredicate(CmpInst::Predicate Pred)
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms...
gep_type_iterator gep_type_end(const User *GEP)
const Value * getTrueValue() const
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
A cache of @llvm.assume calls within a function.
bool salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
LLVMContext & getContext() const
All values hold a context through their type.
bool isTerminator() const
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
void Add(Instruction *I)
Add - Add the specified instruction to the worklist if it isn't already in it.
BasicBlock * getSuccessor(unsigned i) const
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
APInt trunc(unsigned width) const
Truncate to new width.
STATISTIC(NumFunctions, "Total number of functions")
Analysis pass which computes a DominatorTree.
ThreeOps_match< V1_t, V2_t, Mask_t, Instruction::ShuffleVector > m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m)
Matches ShuffleVectorInst.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
uint64_t MaxArraySizeForCombine
Maximum size of array considered when transforming.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
Value * getCondition() const
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool isVectorTy() const
True if this is an instance of VectorType.
iv Induction Variable Users
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
This defines the Use class.
void reserve(size_type N)
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
unsigned getBitWidth() const
Get the bit width of this value.
static bool MaintainNoSignedWrap(BinaryOperator &I, Value *B, Value *C)
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
unsigned getBitWidth() const
Return the number of bits in the APInt.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
bool swapOperands()
Exchange the two operands to this instruction.
Value * getArgOperand(unsigned i) const
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
bool match(Val *V, const Pattern &P)
static Instruction * tryToMoveFreeBeforeNullTest(CallInst &FI, const DataLayout &DL)
Move the call to free before a NULL test.
AnalysisUsage & addRequired()
Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an ExtractValueInst, fold the result or return null.
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
#define INITIALIZE_PASS_DEPENDENCY(depName)
This class represents a conversion between pointers from one address space to another.
static unsigned getComplexity(Value *V)
Assign a complexity or rank value to LLVM Values.
This class represents the LLVM 'select' instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Attribute unwrap(LLVMAttributeRef Attr)
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
This is the base class for all instructions that perform data casts.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
'undef' values are things that do not have specified contents.
uint64_t getArrayNumElements() const
Class to represent struct types.
Value * SimplifyGEPInst(Type *SrcTy, ArrayRef< Value *> Ops, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
A Use represents the edge between a Value definition and its users.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
bool isIntegerTy() const
True if this is an instance of IntegerType.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
The core instruction combiner logic.
static cl::opt< bool > EnableExpensiveCombines("expensive-combines", cl::desc("Enable expensive instruction combines"))
Analysis pass that exposes the LoopInfo for a function.
This file provides an implementation of debug counters.
static bool shorter_filter(const Value *LHS, const Value *RHS)
uint64_t getNumElements() const
Type * getSourceElementType() const
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
This file implements a class to represent arbitrary precision integral constant values and operations...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
Instruction * visitReturnInst(ReturnInst &RI)
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Instruction * visitBranchInst(BranchInst &BI)
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
unsigned getNumIndices() const
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
static Value * getIdentityValue(Instruction::BinaryOps Opcode, Value *V)
This function returns identity value for given opcode, which can be used to factor patterns like (X *...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
int64_t getSExtValue() const
Get sign extended value.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getType() const
All values are typed, get the type of this value.
static bool isNeverEqualToUnescapedAlloc(Value *V, const TargetLibraryInfo *TLI, Instruction *AI)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
Class to represent array types.
static Constant * getSafeVectorConstantForBinop(BinaryOperator::BinaryOps Opcode, Constant *In, bool IsRHSConstant)
Some binary operators require special handling to avoid poison and undefined behavior.
int32_t exactLogBase2() const
This class represents a no-op cast from one type to another.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
TargetFolder - Create constants with target dependent folding.
An instruction for storing to memory.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
FunctionPass * createInstructionCombiningPass(bool ExpensiveCombines=true)
void takeName(Value *V)
Transfer the name from V to this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Value * getOperand(unsigned i) const
static Instruction::BinaryOps getBinOpsForFactorization(Instruction::BinaryOps TopOpcode, BinaryOperator *Op, Value *&LHS, Value *&RHS)
This function predicates factorization using distributive laws.
Class to represent pointers.
Interval::succ_iterator succ_end(Interval *I)
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
OneUse_match< T > m_OneUse(const T &SubPattern)
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
initializer< Ty > init(const Ty &Val)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
bool run()
Run the combiner over the entire worklist until it is empty.
void setAAMetadata(const AAMDNodes &N)
Sets the metadata on this instruction from the AAMDNodes structure.
ConstantInt * lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL, const TargetLibraryInfo *TLI, bool MustSucceed)
Try to turn a call to @llvm.objectsize into an integer value of the given Type.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
Conditional or Unconditional Branch instruction.
static bool isCatchAll(EHPersonality Personality, Constant *TypeInfo)
Return 'true' if the given typeinfo will match anything.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const APInt & getConstant() const
Returns the value when all bits have a known value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A manager for alias analyses.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
void AddInitialGroup(ArrayRef< Instruction *> List)
AddInitialGroup - Add the specified batch of stuff in reverse order.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
brc_match< Cond_t > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Represent the analysis usage information of a pass.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool isConstant() const
Returns true if we know the value of all bits.
This instruction compares its operands according to the predicate given to the constructor.
Analysis pass providing a never-invalidated alias analysis result.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl...
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false)
Return the identity constant for a binary opcode.
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
FunctionPass class - This class is used to implement most global optimizations.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static CastInst * CreatePointerBitCastOrAddrSpaceCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast or an AddrSpaceCast cast instruction.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', returning true if uncertain.
self_iterator getIterator()
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
static bool shouldExecute(unsigned CounterName)
Class to represent integer types.
Constant Vector Declarations.
The legacy pass manager's instcombine pass.
static Constant * getNot(Constant *C)
void setSourceElementType(Type *Ty)
static cl::opt< unsigned > MaxArraySize("instcombine-maxarray-size", cl::init(1024), cl::desc("Maximum array size considered when doing a combine"))
const Value * getCondition() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
Type * getIndexedType() const
InstCombineWorklist - This is the worklist management logic for InstCombine.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Constant * stripPointerCasts() const
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
iterator erase(const_iterator CI)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
static wasm::ValType getType(const TargetRegisterClass *RC)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isFilter(unsigned Idx) const
Return 'true' if the clause and index Idx is a filter clause.
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
A function analysis which provides an AssumptionCache.
const InstListType & getInstList() const
Return the underlying instruction list container.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
This is the common base class for memset/memcpy/memmove.
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
This is the shared class of boolean and integer constants.
static bool simplifyAssocCastAssoc(BinaryOperator *BinOp1)
Combine constant operands of associative operations either before or after a cast to eliminate one of...
TinyPtrVector< DbgVariableIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that 'V' points to...
BlockVerifier::State From
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Utility class for floating point operations which can have information about relaxed accuracy require...
This is a utility class that provides an abstraction for the common functionality between Instruction...
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Provides information about what library functions are available for the current target.
static cl::opt< bool > EnableCodeSinking("instcombine-code-sinking", cl::desc("Enable code sinking"), cl::init(true))
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
LLVM_NODISCARD T pop_back_val()
uint64_t getSizeInBytes() const
Instruction * visitFree(CallInst &FI)
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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.
bool isConditional() const
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...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void initializeInstCombine(PassRegistry &)
Initialize all passes linked into the InstCombine library.
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than it's terminator and any present EH pad instruct...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static ConstantInt * getTrue(LLVMContext &Context)
bool isCommutative() const
Return true if the instruction is commutative:
static bool AddReachableCodeToWorklist(BasicBlock *BB, const DataLayout &DL, SmallPtrSetImpl< BasicBlock *> &Visited, InstCombineWorklist &ICWorklist, const TargetLibraryInfo *TLI)
Walk the function in depth-first order, adding all reachable code to the worklist.
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
struct LLVMOpaquePassManager * LLVMPassManagerRef
static Value * foldOperationIntoSelectOperand(Instruction &I, Value *SO, InstCombiner::BuilderTy &Builder)
Class to represent vector types.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
Accumulate offsets from stripInBoundsConstantOffsets().
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
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.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
typename SuperClass::iterator iterator
iterator_range< user_iterator > users()
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property...
Instruction * visitSwitchInst(SwitchInst &SI)
static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock)
Try to move the specified instruction from its current block into the beginning of DestBlock...
Instruction * visitExtractValueInst(ExtractValueInst &EV)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Represents analyses that only rely on functions' control flow.
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
const Value * getFalseValue() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Instruction * visitLandingPadInst(LandingPadInst &LI)
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Analysis pass providing a never-invalidated alias analysis result.
static bool leftDistributesOverRight(Instruction::BinaryOps LOp, Instruction::BinaryOps ROp)
Return whether "X LOp (Y ROp Z)" is always equal to "(X LOp Y) ROp (X LOp Z)".
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 ...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Provides an 'InsertHelper' that calls a user-provided callback after performing the default insertion...
bool isVolatile() const
Return true if this is a store to a volatile memory location.
iterator insert(iterator where, pointer New)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
void registerAssumption(CallInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
static bool combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist, AliasAnalysis *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, bool ExpensiveCombines=true, LoopInfo *LI=nullptr)
uint64_t getElementOffset(unsigned Idx) const
void emplace_back(ArgTypes &&... Args)
static IntegerType * getInt32Ty(LLVMContext &C)
void setCondition(Value *V)
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void preserveSet()
Mark an analysis set as preserved.
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
void preserve()
Mark an analysis as preserved.
DEBUG_COUNTER(VisitCounter, "instcombine-visit", "Controls which instructions are visited")
bool isUnconditional() const
void initializeInstructionCombiningPassPass(PassRegistry &)
static cl::opt< unsigned > ShouldLowerDbgDeclare("instcombine-lower-dbg-declare", cl::Hidden, cl::init(true))
bool isMinValue() const
Determine if this is the smallest unsigned value.
void setCondition(Value *V)
Analysis pass providing the TargetLibraryInfo.
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
INITIALIZE_PASS_BEGIN(InstructionCombiningPass, "instcombine", "Combine redundant instructions", false, false) INITIALIZE_PASS_END(InstructionCombiningPass
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
const BasicBlock & front() const
SmallVector< int, 16 > getShuffleMask() const
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
A raw_ostream that writes to an std::string.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
This file provides internal interfaces used to implement the InstCombine.
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
succ_range successors(Instruction *I)
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
Instruction * visitGetElementPtrInst(GetElementPtrInst &GEP)
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Type * getElementType() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
Convenience struct for specifying and reasoning about fast-math flags.
This is the interface for LLVM's primary stateless and local alias analysis.
inst_range instructions(Function *F)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
A container for analyses that lazily runs them and caches their results.
Type * getArrayElementType() const
Legacy analysis pass which computes a DominatorTree.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
This header defines various interfaces for pass management in LLVM.
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
static bool shouldMergeGEPs(GEPOperator &GEP, GEPOperator &Src)
Value * getPointerOperand()
Instruction * visitAllocSite(Instruction &FI)
Value * getRawDest() const
static Constant * get(ArrayRef< Constant *> V)
Type * getElementType() const
static bool rightDistributesOverLeft(Instruction::BinaryOps LOp, Instruction::BinaryOps ROp)
Return whether "(X LOp Y) ROp Z" is always equal to "(X ROp Z) LOp (Y ROp Z)".
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
bool isStructTy() const
True if this is an instance of StructType.
bool isArrayTy() const
True if this is an instance of ArrayType.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
This instruction inserts a struct field of array element value into an aggregate value.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Legacy wrapper pass to provide the BasicAAResult object.
gep_type_iterator gep_type_begin(const User *GEP)
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.