20 using namespace PatternMatch;
22 #define DEBUG_TYPE "instcombine"
31 Offset = CI->getZExtValue();
45 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(
I->getOperand(1))) {
46 if (
I->getOpcode() == Instruction::Shl) {
48 Scale = UINT64_C(1) << RHS->getZExtValue();
50 return I->getOperand(0);
53 if (
I->getOpcode() == Instruction::Mul) {
55 Scale = RHS->getZExtValue();
57 return I->getOperand(0);
60 if (
I->getOpcode() == Instruction::Add) {
66 Offset += RHS->getZExtValue();
86 AllocaBuilder.SetInsertPoint(AI.
getParent(), &AI);
93 unsigned AllocElTyAlign =
DL.getABITypeAlignment(AllocElTy);
94 unsigned CastElTyAlign =
DL.getABITypeAlignment(CastElTy);
95 if (CastElTyAlign < AllocElTyAlign)
return nullptr;
100 if (!AI.
hasOneUse() && CastElTyAlign == AllocElTyAlign)
return nullptr;
102 uint64_t AllocElTySize =
DL.getTypeAllocSize(AllocElTy);
103 uint64_t CastElTySize =
DL.getTypeAllocSize(CastElTy);
104 if (CastElTySize == 0 || AllocElTySize == 0)
return nullptr;
108 uint64_t AllocElTyStoreSize =
DL.getTypeStoreSize(AllocElTy);
109 uint64_t CastElTyStoreSize =
DL.getTypeStoreSize(CastElTy);
110 if (!AI.
hasOneUse() && CastElTyStoreSize < AllocElTyStoreSize)
return nullptr;
114 unsigned ArraySizeScale;
115 uint64_t ArrayOffset;
121 if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0 ||
122 (AllocElTySize*ArrayOffset ) % CastElTySize != 0)
return nullptr;
124 unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
125 Value *Amt =
nullptr;
131 Amt = AllocaBuilder.CreateMul(Amt, NumElements);
134 if (uint64_t Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
137 Amt = AllocaBuilder.CreateAdd(Amt, Off);
140 AllocaInst *New = AllocaBuilder.CreateAlloca(CastElTy, Amt);
151 Value *NewCast = AllocaBuilder.CreateBitCast(New, AI.
getType(),
"tmpcast");
152 ReplaceInstUsesWith(AI, NewCast);
154 return ReplaceInstUsesWith(CI, New);
162 if (
Constant *C = dyn_cast<Constant>(V)) {
175 case Instruction::Add:
176 case Instruction::Sub:
177 case Instruction::Mul:
181 case Instruction::AShr:
182 case Instruction::LShr:
183 case Instruction::Shl:
184 case Instruction::UDiv:
185 case Instruction::URem: {
191 case Instruction::Trunc:
192 case Instruction::ZExt:
193 case Instruction::SExt:
203 Opc == Instruction::SExt);
207 Value *False = EvaluateInDifferentType(I->
getOperand(2), Ty, isSigned);
228 return InsertNewInstWith(Res, *I);
252 DstTy, SrcIntPtrTy, MidIntPtrTy,
257 if ((Res == Instruction::IntToPtr && SrcTy != DstIntPtrTy) ||
258 (Res == Instruction::PtrToInt && DstTy != SrcIntPtrTy))
271 if (V->
getType() == Ty || isa<Constant>(V))
return false;
275 if (
const CastInst *CI = dyn_cast<CastInst>(V))
281 if (opc == Instruction::SExt && isa<CmpInst>(V) && Ty->
isVectorTy())
294 if (
CastInst *CSrc = dyn_cast<CastInst>(Src)) {
309 if (isa<PHINode>(Src)) {
335 if (isa<Constant>(V))
339 if (!I)
return false;
345 if ((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
355 case Instruction::Add:
356 case Instruction::Sub:
357 case Instruction::Mul:
365 case Instruction::UDiv:
366 case Instruction::URem: {
370 if (BitWidth < OrigBitWidth) {
372 if (IC.MaskedValueIsZero(I->
getOperand(0), Mask, 0, CxtI) &&
373 IC.MaskedValueIsZero(I->
getOperand(1), Mask, 0, CxtI)) {
380 case Instruction::Shl:
385 if (CI->getLimitedValue(BitWidth) < BitWidth)
389 case Instruction::LShr:
398 CI->getLimitedValue(BitWidth) < BitWidth) {
403 case Instruction::Trunc:
406 case Instruction::ZExt:
407 case Instruction::SExt:
435 if (
Instruction *Result = commonCastTransforms(CI))
449 if (SimplifyDemandedInstructionBits(CI))
459 if ((DestTy->
isVectorTy() || ShouldChangeType(SrcTy, DestTy)) &&
464 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
465 " to avoid cast: " << CI <<
'\n');
466 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
467 assert(Res->
getType() == DestTy);
468 return ReplaceInstUsesWith(CI, Res);
474 Src = Builder->CreateAnd(Src, One);
508 return BinaryOperator::CreateAnd(NewTrunc,
523 const APInt &Op1CV = Op1C->getValue();
529 if (!DoXform)
return ICI;
534 In = Builder->CreateLShr(In, Sh, In->
getName()+
".lobit");
535 if (In->getType() != CI.
getType())
536 In = Builder->CreateIntCast(In, CI.
getType(),
false);
540 In = Builder->CreateXor(In, One, In->
getName()+
".not");
543 return ReplaceInstUsesWith(CI, In);
554 if ((Op1CV == 0 || Op1CV.isPowerOf2()) &&
558 uint32_t BitWidth = Op1C->getType()->getBitWidth();
559 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
562 APInt KnownZeroMask(~KnownZero);
563 if (KnownZeroMask.isPowerOf2()) {
564 if (!DoXform)
return ICI;
567 if (Op1CV != 0 && (Op1CV != KnownZeroMask)) {
573 return ReplaceInstUsesWith(CI, Res);
576 uint32_t ShiftAmt = KnownZeroMask.logBase2();
585 if ((Op1CV != 0) == isNE) {
587 In = Builder->CreateXor(In, One);
590 if (CI.
getType() == In->getType())
591 return ReplaceInstUsesWith(CI, In);
602 uint32_t BitWidth = ITy->getBitWidth();
606 APInt KnownZeroLHS(BitWidth, 0), KnownOneLHS(BitWidth, 0);
607 APInt KnownZeroRHS(BitWidth, 0), KnownOneRHS(BitWidth, 0);
611 if (KnownZeroLHS == KnownZeroRHS && KnownOneLHS == KnownOneRHS) {
612 APInt KnownBits = KnownZeroLHS | KnownOneLHS;
613 APInt UnknownBit = ~KnownBits;
615 if (!DoXform)
return ICI;
617 Value *Result = Builder->CreateXor(LHS, RHS);
620 if (KnownOneLHS.uge(UnknownBit))
621 Result = Builder->CreateAnd(Result,
625 Result = Builder->CreateLShr(
631 return ReplaceInstUsesWith(CI, Result);
661 if (isa<Constant>(V))
665 if (!I)
return false;
678 case Instruction::ZExt:
679 case Instruction::SExt:
680 case Instruction::Trunc:
685 case Instruction::Add:
686 case Instruction::Sub:
687 case Instruction::Mul:
692 if (BitsToClear == 0 && Tmp == 0)
712 case Instruction::Shl:
718 uint64_t ShiftAmt = Amt->getZExtValue();
719 BitsToClear = ShiftAmt < BitsToClear ? BitsToClear - ShiftAmt : 0;
723 case Instruction::LShr:
729 BitsToClear += Amt->getZExtValue();
773 if (
Instruction *Result = commonCastTransforms(CI))
778 if (SimplifyDemandedInstructionBits(CI))
788 unsigned BitsToClear;
789 if ((DestTy->isVectorTy() || ShouldChangeType(SrcTy, DestTy)) &&
791 assert(BitsToClear < SrcTy->getScalarSizeInBits() &&
792 "Unreasonable BitsToClear");
795 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
796 " to avoid zero extend: " << CI);
797 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
798 assert(Res->
getType() == DestTy);
801 uint32_t DestBitSize = DestTy->getScalarSizeInBits();
807 DestBitSize-SrcBitsKept),
809 return ReplaceInstUsesWith(CI, Res);
814 return BinaryOperator::CreateAnd(Res, C);
820 if (
TruncInst *CSrc = dyn_cast<TruncInst>(Src)) {
825 Value *
A = CSrc->getOperand(0);
827 unsigned MidSize = CSrc->getType()->getScalarSizeInBits();
833 if (SrcSize < DstSize) {
840 if (SrcSize == DstSize) {
845 if (SrcSize > DstSize) {
848 return BinaryOperator::CreateAnd(Trunc,
854 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
855 return transformZExtICmp(ICI, CI);
863 if (LHS && RHS && LHS->
hasOneUse() && RHS->hasOneUse() &&
864 (transformZExtICmp(LHS, CI,
false) ||
865 transformZExtICmp(RHS, CI,
false))) {
867 Value *RCast = Builder->CreateZExt(RHS, CI.
getType(), RHS->getName());
886 return BinaryOperator::CreateXor(Builder->CreateAnd(X, ZC), ZC);
907 if (!Op1->getType()->isIntOrIntVectorTy())
910 if (
Constant *Op1C = dyn_cast<Constant>(Op1)) {
918 Value *In = Builder->CreateAShr(Op0, Sh, Op0->
getName()+
".lobit");
919 if (In->getType() != CI.
getType())
920 In = Builder->CreateIntCast(In, CI.
getType(),
true);
923 In = Builder->CreateNot(In, In->getName()+
".not");
924 return ReplaceInstUsesWith(CI, In);
928 if (
ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
933 ICI->
isEquality() && (Op1C->isZero() || Op1C->getValue().isPowerOf2())){
934 unsigned BitWidth = Op1C->getType()->getBitWidth();
935 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
938 APInt KnownZeroMask(~KnownZero);
939 if (KnownZeroMask.isPowerOf2()) {
943 if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) {
947 return ReplaceInstUsesWith(CI, V);
953 unsigned ShiftAmt = KnownZeroMask.countTrailingZeros();
956 In = Builder->CreateLShr(In,
961 In = Builder->CreateAdd(In,
967 unsigned ShiftAmt = KnownZeroMask.countLeadingZeros();
970 In = Builder->CreateShl(In,
975 BitWidth - 1),
"sext");
979 return ReplaceInstUsesWith(CI, In);
998 "Can't sign extend type to a smaller type");
1000 if (isa<Constant>(V))
1004 if (!I)
return false;
1015 case Instruction::SExt:
1016 case Instruction::ZExt:
1017 case Instruction::Trunc:
1022 case Instruction::Add:
1023 case Instruction::Sub:
1024 case Instruction::Mul:
1064 if (SimplifyDemandedInstructionBits(CI))
1072 bool KnownZero, KnownOne;
1075 Value *ZExt = Builder->CreateZExt(Src, DestTy);
1076 return ReplaceInstUsesWith(CI, ZExt);
1083 if ((DestTy->isVectorTy() || ShouldChangeType(SrcTy, DestTy)) &&
1086 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1087 " to avoid sign extend: " << CI);
1088 Value *Res = EvaluateInDifferentType(Src, DestTy,
true);
1089 assert(Res->
getType() == DestTy);
1092 uint32_t DestBitSize = DestTy->getScalarSizeInBits();
1097 return ReplaceInstUsesWith(CI, Res);
1101 return BinaryOperator::CreateAShr(Builder->CreateShl(Res, ShAmt,
"sext"),
1107 if (
TruncInst *TI = dyn_cast<TruncInst>(Src))
1108 if (TI->hasOneUse() && TI->getOperand(0)->getType() == DestTy) {
1110 uint32_t DestBitSize = DestTy->getScalarSizeInBits();
1114 Value *Res = Builder->CreateShl(TI->getOperand(0), ShAmt,
"sext");
1115 return BinaryOperator::CreateAShr(Res, ShAmt);
1118 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
1119 return transformSExtICmp(ICI, CI);
1142 unsigned ShAmt = CA->getZExtValue()+SrcDstSize-MidSize;
1144 A = Builder->CreateShl(A, ShAmtV, CI.
getName());
1145 return BinaryOperator::CreateAShr(A, ShAmtV);
1167 if (I->
getOpcode() == Instruction::FPExt)
1173 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
1182 if (CFP->getType()->isDoubleTy())
1208 unsigned RHSWidth = RHSOrig->getType()->getFPMantissaWidth();
1209 unsigned SrcWidth = std::max(LHSWidth, RHSWidth);
1213 case Instruction::FAdd:
1214 case Instruction::FSub:
1233 if (OpWidth >= 2*DstWidth+1 && DstWidth >= SrcWidth) {
1235 LHSOrig = Builder->CreateFPExt(LHSOrig, CI.
getType());
1236 if (RHSOrig->getType() != CI.
getType())
1237 RHSOrig = Builder->CreateFPExt(RHSOrig, CI.
getType());
1244 case Instruction::FMul:
1250 if (OpWidth >= LHSWidth + RHSWidth && DstWidth >= SrcWidth) {
1252 LHSOrig = Builder->CreateFPExt(LHSOrig, CI.
getType());
1253 if (RHSOrig->getType() != CI.
getType())
1254 RHSOrig = Builder->CreateFPExt(RHSOrig, CI.
getType());
1256 BinaryOperator::CreateFMul(LHSOrig, RHSOrig);
1261 case Instruction::FDiv:
1268 if (OpWidth >= 2*DstWidth && DstWidth >= SrcWidth) {
1270 LHSOrig = Builder->CreateFPExt(LHSOrig, CI.
getType());
1271 if (RHSOrig->getType() != CI.
getType())
1272 RHSOrig = Builder->CreateFPExt(RHSOrig, CI.
getType());
1274 BinaryOperator::CreateFDiv(LHSOrig, RHSOrig);
1279 case Instruction::FRem:
1284 if (SrcWidth == OpWidth)
1286 if (LHSWidth < SrcWidth)
1287 LHSOrig = Builder->CreateFPExt(LHSOrig, RHSOrig->
getType());
1288 else if (RHSWidth <= SrcWidth)
1289 RHSOrig = Builder->CreateFPExt(RHSOrig, LHSOrig->
getType());
1291 Value *ExactResult = Builder->CreateFRem(LHSOrig, RHSOrig);
1292 if (
Instruction *RI = dyn_cast<Instruction>(ExactResult))
1293 RI->copyFastMathFlags(OpI);
1325 case Intrinsic::fabs: {
1334 Value *Args[] = { InnerTrunc };
1344 return commonCastTransforms(CI);
1359 Type *SrcTy = SrcI->getType();
1360 bool IsInputSigned = isa<SIToFPInst>(OpI);
1361 bool IsOutputSigned = isa<FPToSIInst>(FI);
1374 int ActualSize =
std::min(InputSize, OutputSize);
1376 if (ActualSize <= OpITy->getFPMantissaWidth()) {
1378 if (IsInputSigned && IsOutputSigned)
1385 return ReplaceInstUsesWith(FI, SrcI);
1394 return commonCastTransforms(FI);
1399 return commonCastTransforms(FI);
1405 return commonCastTransforms(FI);
1410 return commonCastTransforms(FI);
1414 return commonCastTransforms(CI);
1418 return commonCastTransforms(CI);
1427 DL.getPointerSizeInBits(AS)) {
1449 if (
GEP->hasAllZeroIndices() &&
1453 (!isa<AddrSpaceCastInst>(CI) ||
1454 GEP->getType() ==
GEP->getPointerOperand()->getType())) {
1464 return commonCastTransforms(CI);
1476 return commonPointerCastTransforms(CI);
1530 for (
unsigned i = 0, e = SrcElts; i != e; ++i)
1534 for (
unsigned i = 0, e = DestTy->
getNumElements()-SrcElts; i != e; ++i)
1563 Type *VecEltTy,
bool isBigEndian) {
1565 "Shift should be a multiple of the element type size");
1568 if (isa<UndefValue>(V))
return true;
1572 if (V->
getType() == VecEltTy) {
1574 if (
Constant *C = dyn_cast<Constant>(V))
1575 if (C->isNullValue())
1580 ElementIndex = Elements.
size() - ElementIndex - 1;
1583 if (Elements[ElementIndex])
1586 Elements[ElementIndex] = V;
1590 if (
Constant *C = dyn_cast<Constant>(V)) {
1593 unsigned NumElts =
getTypeSizeIndex(C->getType()->getPrimitiveSizeInBits(),
1599 Shift, Elements, VecEltTy, isBigEndian);
1603 if (!isa<IntegerType>(C->getType()))
1605 C->getType()->getPrimitiveSizeInBits()));
1609 for (
unsigned i = 0; i != NumElts; ++i) {
1610 unsigned ShiftI = Shift+i*ElementSize;
1624 if (!I)
return false;
1626 default:
return false;
1627 case Instruction::BitCast:
1630 case Instruction::ZExt:
1642 case Instruction::Shl: {
1645 if (!CI)
return false;
1685 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
1686 if (!Elements[i])
continue;
1705 Value *VecInput =
nullptr;
1708 isa<VectorType>(VecInput->
getType())) {
1732 isa<VectorType>(VecInput->
getType())) {
1764 return ReplaceInstUsesWith(CI, Src);
1766 if (
PointerType *DstPTy = dyn_cast<PointerType>(DestTy)) {
1768 Type *DstElTy = DstPTy->getElementType();
1775 if (
AllocaInst *AI = dyn_cast<AllocaInst>(Src))
1776 if (
Instruction *V = PromoteCastOfAllocation(CI, *AI))
1782 unsigned NumZeros = 0;
1783 while (SrcElTy != DstElTy &&
1784 isa<CompositeType>(SrcElTy) && !SrcElTy->
isPointerTy() &&
1786 SrcElTy = cast<CompositeType>(SrcElTy)->getTypeAtIndex(0U);
1791 if (SrcElTy == DstElTy) {
1802 if (
VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
1803 if (DestVTy->getNumElements() == 1 && !SrcTy->
isVectorTy()) {
1804 Value *Elem = Builder->CreateBitCast(Src, DestVTy->getElementType());
1810 if (isa<IntegerType>(SrcTy)) {
1814 if (isa<TruncInst>(Src) || isa<ZExtInst>(Src)) {
1815 CastInst *SrcCast = cast<CastInst>(Src);
1817 if (isa<VectorType>(BCIn->getOperand(0)->getType()))
1819 cast<VectorType>(DestTy), *
this))
1827 return ReplaceInstUsesWith(CI, V);
1831 if (
VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy)) {
1832 if (SrcVTy->getNumElements() == 1) {
1837 Builder->CreateExtractElement(Src,
1845 dyn_cast<InsertElementInst>(CI.
getOperand(0)))
1854 if (SVI->hasOneUse() && DestTy->
isVectorTy() &&
1856 SVI->getType()->getNumElements() ==
1857 SVI->getOperand(0)->getType()->getVectorNumElements()) {
1862 if (((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(0))) &&
1864 ((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(1))) &&
1866 Value *LHS = Builder->CreateBitCast(SVI->getOperand(0), DestTy);
1867 Value *RHS = Builder->CreateBitCast(SVI->getOperand(1), DestTy);
1876 return commonPointerCastTransforms(CI);
1877 return commonCastTransforms(CI);
1888 Type *DestElemTy = DestTy->getElementType();
1896 Value *NewBitCast = Builder->CreateBitCast(Src, MidTy);
1900 return commonPointerCastTransforms(CI);
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
static bool CanEvaluateSExtd(Value *V, Type *Ty)
CanEvaluateSExtd - Return true if we can take the specified value and return it as type Ty without in...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
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.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static IntegerType * getInt1Ty(LLVMContext &C)
Instruction * visitBitCast(BitCastInst &CI)
static const fltSemantics IEEEdouble
void setAlignment(unsigned Align)
Intrinsic::ID getIntrinsicID() const
getIntrinsicID - Return the intrinsic ID of this intrinsic.
This class represents zero extension of integer types.
Instruction * commonCastTransforms(CastInst &CI)
Implement the transforms common to all CastInst visitors.
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
const DataLayout & getDataLayout() const
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
bool isPtrOrPtrVectorTy() const
isPtrOrPtrVectorTy - Return true if this is a pointer type or a vector of pointer types...
int getFPMantissaWidth() const
getFPMantissaWidth - Return the width of the mantissa of this type.
static bool isEquality(Predicate P)
isEquality - Return true if this predicate is either EQ or NE.
const Function * getParent() const
Return the enclosing method, or null if none.
This class represents a sign extension of integer types.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static Value * LookThroughFPExtensions(Value *V)
LookThroughFPExtensions - If this is an fp extension instruction, look through it until we get the so...
Constant * ConstantFoldConstantExpression(const ConstantExpr *CE, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstantExpression - Attempt to fold the constant expression using the specified DataLayo...
Instruction * visitUIToFP(CastInst &CI)
static Constant * FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem)
FitsInFPType - Return a Constant* for the specified FP constant if it fits in the specified FP type w...
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Return a constant reference to the value's name.
Instruction * visitFPExt(CastInst &CI)
SelectPatternFlavor matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
Instruction * FoldItoFPtoI(Instruction &FI)
bool match(Val *V, const Pattern &P)
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Instruction * visitFPToUI(FPToUIInst &FI)
This class represents a conversion between pointers from one address space to another.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
SelectInst - This class represents the LLVM 'select' instruction.
static bool CanEvaluateZExtd(Value *V, Type *Ty, unsigned &BitsToClear, InstCombiner &IC, Instruction *CxtI)
CanEvaluateZExtd - Determine if the specified value can be computed in the specified wider type and p...
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is the base class for all instructions that perform data casts.
static Instruction::CastOps isEliminableCastPair(const CastInst *CI, unsigned opcode, Type *DstTy, const DataLayout &DL)
This function is a wrapper around CastInst::isEliminableCastPair.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
The core instruction combiner logic.
Instruction * visitIntToPtr(IntToPtrInst &CI)
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
Instruction * visitAddrSpaceCast(AddrSpaceCastInst &CI)
static Type * getPPC_FP128Ty(LLVMContext &C)
static unsigned getTypeSizeIndex(unsigned Value, Type *Ty)
not_match< LHS > m_Not(const LHS &L)
This class represents a cast from a pointer to an integer.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ConstantExpr - a constant value that is initialized with an expression using other constant values...
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
This class represents a no-op cast from one type to another.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
This class represents a cast from floating point to signed integer.
unsigned getNumElements() const
Return the number of elements in the Vector type.
static bool CollectInsertionElements(Value *V, unsigned Shift, SmallVectorImpl< Value * > &Elements, Type *VecEltTy, bool isBigEndian)
CollectInsertionElements - V is a value which is inserted into a vector of VecEltTy.
void takeName(Value *V)
Transfer the name from V to this value.
This class represents a truncation of integer types.
Type * getElementType() const
PointerType - Class to represent pointers.
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
OneUse_match< T > m_OneUse(const T &SubPattern)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
static Value * DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale, uint64_t &Offset)
DecomposeSimpleLinearExpr - Analyze 'Val', seeing if it is a simple linear expression.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
static bool CanEvaluateTruncated(Value *V, Type *Ty, InstCombiner &IC, Instruction *CxtI)
CanEvaluateTruncated - Return true if we can evaluate the specified expression tree as type Ty instea...
This is an important base class in LLVM.
PointerType * getType() const
getType - Overload to return most specific pointer type
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
unsigned getAlignment() const
getAlignment - Return the alignment of the memory that is being allocated by the instruction.
ConstantFP - Floating Point Values [float, double].
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
BasicBlock * getIncomingBlock(unsigned i) const
getIncomingBlock - Return incoming basic block number i.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
Value * getOperand(unsigned i) const
Class to represent integer types.
unsigned countPopulation() const
Count the number of bits set.
Predicate getPredicate() const
Return the predicate for this instruction.
static Instruction * OptimizeVectorResize(Value *InVal, VectorType *DestTy, InstCombiner &IC)
OptimizeVectorResize - This input value (which is known to have vector type) is being zero extended o...
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeSignBit - Determine whether the sign bit is known to be zero or one.
This class represents a cast from an integer to a pointer.
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
Instruction * visitFPToSI(FPToSIInst &FI)
unsigned getNumContainedTypes() const
getNumContainedTypes - Return the number of types in the derived type.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
static const fltSemantics IEEEhalf
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
BinaryOps getOpcode() const
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static Value * OptimizeIntegerToVectorInsertions(BitCastInst &CI, InstCombiner &IC)
OptimizeIntegerToVectorInsertions - If the input is an 'or' instruction, we may be doing shifts and o...
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.
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
unsigned getVectorNumElements() const
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Type * getType() const
All values are typed, get the type of this value.
Instruction * user_back()
user_back - Specialize the methods defined in Value, as we know that an instruction can only be used ...
Instruction * visitSExt(SExtInst &CI)
unsigned ComputeNumSignBits(Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeNumSignBits - Return the number of times the sign bit of the register is replicated into the o...
This class represents a cast from floating point to unsigned integer.
Instruction * visitZExt(ZExtInst &CI)
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
static CastInst * CreateFPCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create an FPExt, BitCast, or FPTrunc for fp -> fp casts.
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 Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
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...
static Constant * get(Type *Ty, double V)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
unsigned getAddressSpace() const
Returns the address space of this instruction's pointer type.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
VectorType - Class to represent vector types.
Class for arbitrary precision integers.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
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.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
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 ...
Instruction * visitTrunc(TruncInst &CI)
static const fltSemantics IEEEsingle
static IntegerType * getInt32Ty(LLVMContext &C)
Instruction * visitSIToFP(CastInst &CI)
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
bool hasOneUse() const
Return true if there is exactly one user of this value.
static Instruction * OptimizeIntToFloatBitCast(BitCastInst &CI, InstCombiner &IC, const DataLayout &DL)
OptimizeIntToFloatBitCast - See if we can optimize an integer->float/double bitcast.
const APFloat & getValueAPF() const
This class represents a truncation of floating point types.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - 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...
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
const Value * getArraySize() const
getArraySize - Get the number of elements allocated.
Instruction * commonPointerCastTransforms(CastInst &CI)
Implement the transforms for cast of pointer (bitcast/ptrtoint)
C - The default llvm calling convention, compatible with C.
const Value * getFalseValue() const
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
Instruction * visitPtrToInt(PtrToIntInst &CI)
Type * getAllocatedType() const
getAllocatedType - Return the type that is being allocated by the instruction.
op_range incoming_values()
const BasicBlock * getParent() const
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
AllocaInst - an instruction to allocate memory on the stack.
Instruction * visitFPTrunc(FPTruncInst &CI)