22 using namespace PatternMatch;
24 #define DEBUG_TYPE "instcombine"
33 Offset = CI->getZExtValue();
47 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(
I->getOperand(1))) {
48 if (
I->getOpcode() == Instruction::Shl) {
50 Scale = UINT64_C(1) << RHS->getZExtValue();
52 return I->getOperand(0);
55 if (
I->getOpcode() == Instruction::Mul) {
57 Scale = RHS->getZExtValue();
59 return I->getOperand(0);
68 Offset += RHS->getZExtValue();
88 AllocaBuilder.SetInsertPoint(&AI);
97 if (CastElTyAlign < AllocElTyAlign)
return nullptr;
102 if (!AI.
hasOneUse() && CastElTyAlign == AllocElTyAlign)
return nullptr;
106 if (CastElTySize == 0 || AllocElTySize == 0)
return nullptr;
112 if (!AI.
hasOneUse() && CastElTyStoreSize < AllocElTyStoreSize)
return nullptr;
116 unsigned ArraySizeScale;
117 uint64_t ArrayOffset;
123 if ((AllocElTySize*ArraySizeScale) % CastElTySize != 0 ||
124 (AllocElTySize*ArrayOffset ) % CastElTySize != 0)
return nullptr;
126 unsigned Scale = (AllocElTySize*ArraySizeScale)/CastElTySize;
127 Value *Amt =
nullptr;
133 Amt = AllocaBuilder.CreateMul(Amt, NumElements);
136 if (uint64_t
Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
139 Amt = AllocaBuilder.CreateAdd(Amt, Off);
142 AllocaInst *New = AllocaBuilder.CreateAlloca(CastElTy, Amt);
153 Value *NewCast = AllocaBuilder.CreateBitCast(New, AI.
getType(),
"tmpcast");
154 replaceInstUsesWith(AI, NewCast);
156 return replaceInstUsesWith(CI, New);
163 if (
Constant *
C = dyn_cast<Constant>(V)) {
177 case Instruction::Sub:
178 case Instruction::Mul:
179 case Instruction::And:
180 case Instruction::Or:
181 case Instruction::Xor:
182 case Instruction::AShr:
183 case Instruction::LShr:
184 case Instruction::Shl:
185 case Instruction::UDiv:
186 case Instruction::URem: {
192 case Instruction::Trunc:
193 case Instruction::ZExt:
194 case Instruction::SExt:
204 Opc == Instruction::SExt);
208 Value *False = EvaluateInDifferentType(I->
getOperand(2), Ty, isSigned);
212 case Instruction::PHI: {
229 return InsertNewInstWith(Res, *I);
247 DstTy, SrcIntPtrTy, MidIntPtrTy,
252 if ((Res == Instruction::IntToPtr && SrcTy != DstIntPtrTy) ||
253 (Res == Instruction::PtrToInt && DstTy != SrcIntPtrTy))
264 if (
auto *CSrc = dyn_cast<CastInst>(Src)) {
273 if (
auto *
SI = dyn_cast<SelectInst>(Src))
278 if (
auto *PN = dyn_cast<PHINode>(Src)) {
304 if (isa<Constant>(V))
308 if (!I)
return false;
314 if ((isa<ZExtInst>(I) || isa<SExtInst>(I)) &&
325 case Instruction::Sub:
326 case Instruction::Mul:
327 case Instruction::And:
328 case Instruction::Or:
329 case Instruction::Xor:
334 case Instruction::UDiv:
335 case Instruction::URem: {
339 if (BitWidth < OrigBitWidth) {
349 case Instruction::Shl:
354 if (CI->getLimitedValue(BitWidth) < BitWidth)
358 case Instruction::LShr:
367 CI->getLimitedValue(BitWidth) < BitWidth) {
372 case Instruction::Trunc:
375 case Instruction::ZExt:
376 case Instruction::SExt:
385 case Instruction::PHI: {
412 if (!TruncOp->
hasOneUse() || !isa<IntegerType>(DestType))
415 Value *VecInput =
nullptr;
420 !isa<VectorType>(VecInput->
getType()))
426 unsigned ShiftAmount = ShiftVal ? ShiftVal->
getZExtValue() : 0;
428 if ((VecWidth % DestWidth != 0) || (ShiftAmount % DestWidth != 0))
433 unsigned NumVecElts = VecWidth / DestWidth;
439 unsigned Elt = ShiftAmount / DestWidth;
441 Elt = NumVecElts - 1 - Elt;
450 if (isa<IntegerType>(SrcTy) && !shouldChangeType(SrcTy, DestTy))
462 Value *NarrowOp0 = Builder.CreateTrunc(LogicOp->
getOperand(0), DestTy);
472 if (Shuf && Shuf->hasOneUse() && isa<UndefValue>(Shuf->getOperand(1)) &&
473 Shuf->getMask()->getSplatValue() &&
474 Shuf->getType() == Shuf->getOperand(0)->getType()) {
492 assert((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
493 "Unexpected instruction for shrinking");
496 if (!InsElt || !InsElt->hasOneUse())
501 Value *VecOp = InsElt->getOperand(0);
502 Value *ScalarOp = InsElt->getOperand(1);
503 Value *Index = InsElt->getOperand(2);
505 if (isa<UndefValue>(VecOp)) {
517 if (
Instruction *Result = commonCastTransforms(CI))
531 if (SimplifyDemandedInstructionBits(CI))
541 if ((DestTy->
isVectorTy() || shouldChangeType(SrcTy, DestTy)) &&
546 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
547 " to avoid cast: " << CI <<
'\n');
548 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
550 return replaceInstUsesWith(CI, Res);
556 Src = Builder.CreateAnd(Src, One);
595 Value *SExt = cast<Instruction>(Src)->getOperand(0);
599 const unsigned MaxAmt = SExtSize -
std::max(CISize, ASize);
607 if (ShiftAmt <= MaxAmt) {
612 Value *Shift = Builder.CreateAShr(A,
std::min(ShiftAmt, ASize - 1));
628 if (Src->
hasOneUse() && isa<IntegerType>(SrcTy) &&
629 shouldChangeType(SrcTy, DestTy)) {
638 Value *NewTrunc = Builder.CreateTrunc(A, DestTy, A->
getName() +
".tr");
641 Instruction::Shl, NewTrunc,
659 const APInt &Op1CV = Op1C->getValue();
665 if (!DoTransform)
return ICI;
670 In = Builder.CreateLShr(In, Sh, In->
getName() +
".lobit");
671 if (In->getType() != CI.
getType())
672 In = Builder.CreateIntCast(In, CI.
getType(),
false );
676 In = Builder.CreateXor(In, One, In->
getName() +
".not");
679 return replaceInstUsesWith(CI, In);
697 if (KnownZeroMask.isPowerOf2()) {
698 if (!DoTransform)
return ICI;
701 if (!Op1CV.
isNullValue() && (Op1CV != KnownZeroMask)) {
707 return replaceInstUsesWith(CI, Res);
710 uint32_t ShAmt = KnownZeroMask.logBase2();
721 In = Builder.CreateXor(In, One);
724 if (CI.
getType() == In->getType())
725 return replaceInstUsesWith(CI, In);
727 Value *IntCast = Builder.CreateIntCast(In, CI.
getType(),
false);
728 return replaceInstUsesWith(CI, IntCast);
744 if (KnownLHS.
Zero == KnownRHS.
Zero && KnownLHS.
One == KnownRHS.
One) {
746 APInt UnknownBit = ~KnownBits;
748 if (!DoTransform)
return ICI;
750 Value *Result = Builder.CreateXor(LHS, RHS);
753 if (KnownLHS.
One.
uge(UnknownBit))
754 Result = Builder.CreateAnd(Result,
758 Result = Builder.CreateLShr(
764 return replaceInstUsesWith(CI, Result);
794 if (isa<Constant>(V))
798 if (!I)
return false;
811 case Instruction::ZExt:
812 case Instruction::SExt:
813 case Instruction::Trunc:
815 case Instruction::And:
816 case Instruction::Or:
817 case Instruction::Xor:
819 case Instruction::Sub:
820 case Instruction::Mul:
825 if (BitsToClear == 0 && Tmp == 0)
843 case Instruction::Shl:
849 uint64_t ShiftAmt = Amt->getZExtValue();
850 BitsToClear = ShiftAmt < BitsToClear ? BitsToClear - ShiftAmt : 0;
854 case Instruction::LShr:
860 BitsToClear += Amt->getZExtValue();
876 case Instruction::PHI: {
904 if (
Instruction *Result = commonCastTransforms(CI))
914 unsigned BitsToClear;
915 if ((DestTy->
isVectorTy() || shouldChangeType(SrcTy, DestTy)) &&
917 assert(BitsToClear <= SrcTy->getScalarSizeInBits() &&
918 "Can't clear more bits than in SrcTy");
921 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
922 " to avoid zero extend: " << CI <<
'\n');
923 Value *Res = EvaluateInDifferentType(Src, DestTy,
false);
933 DestBitSize-SrcBitsKept),
935 return replaceInstUsesWith(CI, Res);
940 return BinaryOperator::CreateAnd(Res, C);
946 if (
TruncInst *CSrc = dyn_cast<TruncInst>(Src)) {
951 Value *
A = CSrc->getOperand(0);
953 unsigned MidSize = CSrc->getType()->getScalarSizeInBits();
959 if (SrcSize < DstSize) {
962 Value *And = Builder.CreateAnd(A, AndConst, CSrc->
getName() +
".mask");
966 if (SrcSize == DstSize) {
971 if (SrcSize > DstSize) {
974 return BinaryOperator::CreateAnd(Trunc,
980 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
981 return transformZExtICmp(ICI, CI);
984 if (SrcI && SrcI->
getOpcode() == Instruction::Or) {
990 if (LHS && RHS && LHS->
hasOneUse() && RHS->hasOneUse() &&
991 (transformZExtICmp(LHS, CI,
false) ||
992 transformZExtICmp(RHS, CI,
false))) {
995 Value *RCast = Builder.CreateZExt(RHS, CI.
getType(), RHS->getName());
999 if (
auto *LZExt = dyn_cast<ZExtInst>(LCast))
1000 transformZExtICmp(LHS, *LZExt);
1001 if (
auto *RZExt = dyn_cast<ZExtInst>(RCast))
1002 transformZExtICmp(RHS, *RZExt);
1022 return BinaryOperator::CreateXor(Builder.CreateAnd(X, ZC), ZC);
1034 if (!Op1->getType()->isIntOrIntVectorTy())
1037 if (
Constant *Op1C = dyn_cast<Constant>(Op1)) {
1045 Value *In = Builder.CreateAShr(Op0, Sh, Op0->
getName() +
".lobit");
1046 if (In->getType() != CI.
getType())
1047 In = Builder.CreateIntCast(In, CI.
getType(),
true );
1050 In = Builder.CreateNot(In, In->getName() +
".not");
1051 return replaceInstUsesWith(CI, In);
1055 if (
ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
1060 ICI->
isEquality() && (Op1C->isZero() || Op1C->getValue().isPowerOf2())){
1064 if (KnownZeroMask.isPowerOf2()) {
1068 if (!Op1C->isZero() && Op1C->getValue() != KnownZeroMask) {
1072 return replaceInstUsesWith(CI, V);
1078 unsigned ShiftAmt = KnownZeroMask.countTrailingZeros();
1081 In = Builder.CreateLShr(In,
1086 In = Builder.CreateAdd(In,
1092 unsigned ShiftAmt = KnownZeroMask.countLeadingZeros();
1095 In = Builder.CreateShl(In,
1100 KnownZeroMask.getBitWidth() - 1),
"sext");
1104 return replaceInstUsesWith(CI, In);
1122 "Can't sign extend type to a smaller type");
1124 if (isa<Constant>(V))
1128 if (!I)
return false;
1139 case Instruction::SExt:
1140 case Instruction::ZExt:
1141 case Instruction::Trunc:
1143 case Instruction::And:
1144 case Instruction::Or:
1145 case Instruction::Xor:
1147 case Instruction::Sub:
1148 case Instruction::Mul:
1160 case Instruction::PHI: {
1193 Value *ZExt = Builder.CreateZExt(Src, DestTy);
1194 return replaceInstUsesWith(CI, ZExt);
1201 if ((DestTy->
isVectorTy() || shouldChangeType(SrcTy, DestTy)) &&
1204 DEBUG(
dbgs() <<
"ICE: EvaluateInDifferentType converting expression type"
1205 " to avoid sign extend: " << CI <<
'\n');
1206 Value *Res = EvaluateInDifferentType(Src, DestTy,
true);
1215 return replaceInstUsesWith(CI, Res);
1219 return BinaryOperator::CreateAShr(Builder.CreateShl(Res, ShAmt,
"sext"),
1231 return BinaryOperator::CreateAShr(Builder.CreateShl(X, ShAmt), ShAmt);
1234 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Src))
1235 return transformSExtICmp(ICI, CI);
1258 unsigned ShAmt = CA->getZExtValue()+SrcDstSize-MidSize;
1260 A = Builder.CreateShl(A, ShAmtV, CI.
getName());
1261 return BinaryOperator::CreateAShr(A, ShAmtV);
1281 while (
auto *FPExt = dyn_cast<FPExtInst>(V))
1282 V = FPExt->getOperand(0);
1287 if (
auto *CFP = dyn_cast<ConstantFP>(V)) {
1296 if (CFP->getType()->isDoubleTy())
1322 unsigned RHSWidth = RHSOrig->getType()->getFPMantissaWidth();
1323 unsigned SrcWidth =
std::max(LHSWidth, RHSWidth);
1327 case Instruction::FAdd:
1328 case Instruction::FSub:
1347 if (OpWidth >= 2*DstWidth+1 && DstWidth >= SrcWidth) {
1349 LHSOrig = Builder.CreateFPExt(LHSOrig, CI.
getType());
1350 if (RHSOrig->getType() != CI.
getType())
1351 RHSOrig = Builder.CreateFPExt(RHSOrig, CI.
getType());
1358 case Instruction::FMul:
1364 if (OpWidth >= LHSWidth + RHSWidth && DstWidth >= SrcWidth) {
1366 LHSOrig = Builder.CreateFPExt(LHSOrig, CI.
getType());
1367 if (RHSOrig->getType() != CI.
getType())
1368 RHSOrig = Builder.CreateFPExt(RHSOrig, CI.
getType());
1370 BinaryOperator::CreateFMul(LHSOrig, RHSOrig);
1375 case Instruction::FDiv:
1382 if (OpWidth >= 2*DstWidth && DstWidth >= SrcWidth) {
1384 LHSOrig = Builder.CreateFPExt(LHSOrig, CI.
getType());
1385 if (RHSOrig->getType() != CI.
getType())
1386 RHSOrig = Builder.CreateFPExt(RHSOrig, CI.
getType());
1388 BinaryOperator::CreateFDiv(LHSOrig, RHSOrig);
1393 case Instruction::FRem:
1398 if (SrcWidth == OpWidth)
1400 if (LHSWidth < SrcWidth)
1401 LHSOrig = Builder.CreateFPExt(LHSOrig, RHSOrig->
getType());
1402 else if (RHSWidth <= SrcWidth)
1403 RHSOrig = Builder.CreateFPExt(RHSOrig, LHSOrig->
getType());
1405 Value *ExactResult = Builder.CreateFRem(LHSOrig, RHSOrig);
1406 if (
Instruction *RI = dyn_cast<Instruction>(ExactResult))
1407 RI->copyFastMathFlags(OpI);
1443 case Intrinsic::fabs:
1444 case Intrinsic::ceil:
1445 case Intrinsic::floor:
1446 case Intrinsic::rint:
1448 case Intrinsic::nearbyint:
1449 case Intrinsic::trunc: {
1465 Value *InnerTrunc = Builder.CreateFPTrunc(Src, CI.
getType());
1489 return commonCastTransforms(CI);
1504 Type *SrcTy = SrcI->getType();
1505 bool IsInputSigned = isa<SIToFPInst>(OpI);
1506 bool IsOutputSigned = isa<FPToSIInst>(FI);
1519 int ActualSize =
std::min(InputSize, OutputSize);
1521 if (ActualSize <= OpITy->getFPMantissaWidth()) {
1523 if (IsInputSigned && IsOutputSigned)
1530 return replaceInstUsesWith(FI, SrcI);
1539 return commonCastTransforms(FI);
1544 return commonCastTransforms(FI);
1550 return commonCastTransforms(FI);
1555 return commonCastTransforms(FI);
1559 return commonCastTransforms(CI);
1563 return commonCastTransforms(CI);
1594 if (
GEP->hasAllZeroIndices() &&
1598 (!isa<AddrSpaceCastInst>(CI) ||
1599 GEP->getType() ==
GEP->getPointerOperandType())) {
1609 return commonCastTransforms(CI);
1621 return commonPointerCastTransforms(CI);
1675 for (
unsigned i = 0, e = SrcElts; i != e; ++i)
1679 for (
unsigned i = 0, e = DestTy->
getNumElements()-SrcElts; i != e; ++i)
1708 Type *VecEltTy,
bool isBigEndian) {
1710 "Shift should be a multiple of the element type size");
1713 if (isa<UndefValue>(V))
return true;
1717 if (V->
getType() == VecEltTy) {
1719 if (
Constant *C = dyn_cast<Constant>(V))
1725 ElementIndex = Elements.
size() - ElementIndex - 1;
1728 if (Elements[ElementIndex])
1731 Elements[ElementIndex] = V;
1735 if (
Constant *C = dyn_cast<Constant>(V)) {
1744 Shift, Elements, VecEltTy, isBigEndian);
1748 if (!isa<IntegerType>(C->
getType()))
1754 for (
unsigned i = 0; i != NumElts; ++i) {
1755 unsigned ShiftI = Shift+i*ElementSize;
1769 if (!I)
return false;
1771 default:
return false;
1772 case Instruction::BitCast:
1775 case Instruction::ZExt:
1782 case Instruction::Or:
1787 case Instruction::Shl: {
1790 if (!CI)
return false;
1830 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
1831 if (!Elements[i])
continue;
1848 if (!ExtElt || !ExtElt->hasOneUse())
1857 unsigned NumElts = ExtElt->getVectorOperandType()->getNumElements();
1882 X->
getType() == DestTy && !isa<Constant>(
X)) {
1889 X->
getType() == DestTy && !isa<Constant>(
X)) {
1913 Value *Cond, *TVal, *FVal;
1935 auto *Sel = cast<Instruction>(BitCast.
getOperand(0));
1938 !isa<Constant>(
X)) {
1945 !isa<Constant>(
X)) {
1957 if (!isa<StoreInst>(U))
1989 while (!PhiWorklist.
empty()) {
1991 for (
Value *IncValue : OldPN->incoming_values()) {
1992 if (isa<Constant>(IncValue))
1995 if (
auto *LI = dyn_cast<LoadInst>(IncValue)) {
2000 Value *Addr = LI->getOperand(0);
2001 if (Addr == &CI || isa<LoadInst>(Addr))
2003 if (LI->hasOneUse() && LI->isSimple())
2010 if (
auto *PNode = dyn_cast<PHINode>(IncValue)) {
2011 if (OldPhiNodes.
insert(PNode))
2022 Type *TyA = BCI->getOperand(0)->getType();
2023 Type *TyB = BCI->getType();
2024 if (TyA != DestTy || TyB != SrcTy)
2031 for (
auto *OldPN : OldPhiNodes) {
2032 Builder.SetInsertPoint(OldPN);
2033 PHINode *NewPN = Builder.CreatePHI(DestTy, OldPN->getNumOperands());
2034 NewPNodes[OldPN] = NewPN;
2038 for (
auto *OldPN : OldPhiNodes) {
2039 PHINode *NewPN = NewPNodes[OldPN];
2040 for (
unsigned j = 0, e = OldPN->getNumOperands(); j != e; ++j) {
2041 Value *V = OldPN->getOperand(j);
2042 Value *NewV =
nullptr;
2043 if (
auto *C = dyn_cast<Constant>(V)) {
2045 }
else if (
auto *LI = dyn_cast<LoadInst>(V)) {
2046 Builder.SetInsertPoint(LI->getNextNode());
2047 NewV = Builder.CreateBitCast(LI, DestTy);
2049 }
else if (
auto *BCI = dyn_cast<BitCastInst>(V)) {
2050 NewV = BCI->getOperand(0);
2051 }
else if (
auto *PrevPN = dyn_cast<PHINode>(V)) {
2052 NewV = NewPNodes[PrevPN];
2055 NewPN->
addIncoming(NewV, OldPN->getIncomingBlock(j));
2062 if (SI &&
SI->isSimple() &&
SI->getOperand(0) == PN) {
2063 Builder.SetInsertPoint(SI);
2065 cast<BitCastInst>(Builder.CreateBitCast(NewPNodes[PN], SrcTy));
2066 SI->setOperand(0, NewBC);
2072 return replaceInstUsesWith(CI, NewPNodes[PN]);
2085 return replaceInstUsesWith(CI, Src);
2087 if (
PointerType *DstPTy = dyn_cast<PointerType>(DestTy)) {
2089 Type *DstElTy = DstPTy->getElementType();
2096 if (
AllocaInst *AI = dyn_cast<AllocaInst>(Src))
2097 if (
Instruction *V = PromoteCastOfAllocation(CI, *AI))
2110 unsigned NumZeros = 0;
2111 while (SrcElTy != DstElTy &&
2112 isa<CompositeType>(SrcElTy) && !SrcElTy->
isPointerTy() &&
2114 SrcElTy = cast<CompositeType>(SrcElTy)->getTypeAtIndex(0U);
2119 if (SrcElTy == DstElTy) {
2125 if (
VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
2126 if (DestVTy->getNumElements() == 1 && !SrcTy->
isVectorTy()) {
2127 Value *Elem = Builder.CreateBitCast(Src, DestVTy->getElementType());
2133 if (isa<IntegerType>(SrcTy)) {
2137 if (isa<TruncInst>(Src) || isa<ZExtInst>(Src)) {
2138 CastInst *SrcCast = cast<CastInst>(Src);
2140 if (isa<VectorType>(BCIn->getOperand(0)->getType()))
2142 cast<VectorType>(DestTy), *
this))
2150 return replaceInstUsesWith(CI, V);
2154 if (
VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy)) {
2155 if (SrcVTy->getNumElements() == 1) {
2160 Builder.CreateExtractElement(Src,
2168 dyn_cast<InsertElementInst>(CI.
getOperand(0)))
2177 if (SVI->hasOneUse() && DestTy->
isVectorTy() &&
2179 SVI->getType()->getNumElements() ==
2180 SVI->getOperand(0)->getType()->getVectorNumElements()) {
2185 if (((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(0))) &&
2187 ((Tmp = dyn_cast<BitCastInst>(SVI->getOperand(1))) &&
2189 Value *LHS = Builder.CreateBitCast(SVI->getOperand(0), DestTy);
2190 Value *RHS = Builder.CreateBitCast(SVI->getOperand(1), DestTy);
2199 if (
PHINode *PN = dyn_cast<PHINode>(Src))
2200 if (
Instruction *I = optimizeBitCastFromPhi(CI, PN))
2213 return commonPointerCastTransforms(CI);
2214 return commonCastTransforms(CI);
2225 Type *DestElemTy = DestTy->getElementType();
2233 Value *NewBitCast = Builder.CreateBitCast(Src, MidTy);
2237 return commonPointerCastTransforms(CI);
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
void push_back(const T &Elt)
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)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
DiagnosticInfoOptimizationBase::Argument NV
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Instruction * visitBitCast(BitCastInst &CI)
void setAlignment(unsigned Align)
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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...
This class represents a function call, abstracting a target machine's calling convention.
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.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
static uint64_t round(uint64_t Acc, uint64_t Input)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
const DataLayout & getDataLayout() const
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)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
int getFPMantissaWidth() const
Return the width of the mantissa of this type.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
static Value * lookThroughFPExtensions(Value *V)
Look through floating-point extensions until we get the source value.
This class represents a sign extension of integer types.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Type * getElementType() const
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
Instruction * visitUIToFP(CastInst &CI)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
Instruction * visitFPExt(CastInst &CI)
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)
bool isNonNegative() const
Returns true if this value is known to be non-negative.
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)
This class represents the LLVM 'select' instruction.
static bool hasStoreUsersOnly(CastInst &CI)
Check if all users of CI are StoreInsts.
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
'undef' values are things that do not have specified contents.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static bool canEvaluateZExtd(Value *V, Type *Ty, unsigned &BitsToClear, InstCombiner &IC, Instruction *CxtI)
Determine if the specified value can be computed in the specified wider type and produce the same low...
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
The core instruction combiner logic.
static bool canEvaluateTruncated(Value *V, Type *Ty, InstCombiner &IC, Instruction *CxtI)
Return true if we can evaluate the specified expression tree as type Ty instead of its larger type...
static Instruction * canonicalizeBitCastExtElt(BitCastInst &BitCast, InstCombiner &IC)
Canonicalize scalar bitcasts of extracted elements into a bitcast of the vector followed by extract e...
Instruction * visitIntToPtr(IntToPtrInst &CI)
static Instruction * optimizeVectorResize(Value *InVal, VectorType *DestTy, InstCombiner &IC)
This input value (which is known to have vector type) is being zero extended or truncated to the spec...
Instruction * visitAddrSpaceCast(AddrSpaceCastInst &CI)
static Type * getPPC_FP128Ty(LLVMContext &C)
static unsigned getTypeSizeIndex(unsigned Value, Type *Ty)
This class represents a cast from a pointer to an integer.
LLVM_NODISCARD bool empty() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty)
bool insert(const value_type &X)
Insert a new element into the SetVector.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
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.
An instruction for storing to memory.
This class represents a cast from floating point to signed integer.
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
static Value * optimizeIntegerToVectorInsertions(BitCastInst &CI, InstCombiner &IC)
If the input is an 'or' instruction, we may be doing shifts and ors to assemble the elements of the v...
static const fltSemantics & IEEEdouble() LLVM_READNONE
void takeName(Value *V)
Transfer the name from V to this value.
static Instruction * foldBitCastSelect(BitCastInst &BitCast, InstCombiner::BuilderTy &Builder)
Change the type of a select if we can eliminate a bitcast.
Type * getElementType() const
This class represents a truncation of integer types.
Class to represent pointers.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
SelectPatternResult 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...
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
static Instruction * foldBitCastBitwiseLogic(BitCastInst &BitCast, InstCombiner::BuilderTy &Builder)
Change the type of a bitwise logic operation if we can eliminate a bitcast.
This instruction inserts a single (scalar) element into a VectorType value.
APInt trunc(unsigned width) const
Truncate to new width.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
True if this is an instance of VectorType.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
This is an important base class in LLVM.
PointerType * getType() const
Overload to return most specific pointer type.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if 'V & Mask' is known to be zero.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
ConstantFP - Floating Point Values [float, double].
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
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 Value * decomposeSimpleLinearExpr(Value *Val, unsigned &Scale, uint64_t &Offset)
Analyze 'Val', seeing if it is a simple linear expression.
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.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
uint64_t getNumElements() const
Value * getOperand(unsigned i) const
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Class to represent integer types.
Type * getSrcTy() const
Return the source type, as a convenience.
unsigned countPopulation() const
Count the number of bits set.
Predicate getPredicate() const
Return the predicate for this instruction.
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
Return the number of types in the derived type.
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
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)
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static const fltSemantics & IEEEsingle() LLVM_READNONE
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.
A SetVector that performs no allocations if smaller than a certain size.
This is the shared class of boolean and integer constants.
static const fltSemantics & IEEEhalf() LLVM_READNONE
SelectPatternFlavor Flavor
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return the number of times the sign bit of the register is replicated into the other bits...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static Instruction * shrinkInsertElt(CastInst &Trunc, InstCombiner::BuilderTy &Builder)
Try to narrow the width of an insert element.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
static Instruction * shrinkSplatShuffle(TruncInst &Trunc, InstCombiner::BuilderTy &Builder)
Try to narrow the width of a splat shuffle.
Instruction * visitSExt(SExtInst &CI)
This class represents a cast from floating point to unsigned integer.
Type * getDestTy() const
Return the destination type, as a convenience.
LLVM_NODISCARD T pop_back_val()
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)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
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.
Class to represent vector types.
Class for arbitrary precision integers.
bool isIntegerTy() const
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.
iterator_range< user_iterator > users()
unsigned getVectorNumElements() const
llvm_unreachable("Unknown RegBank!")
bool isAllOnesValue() const
Determine if all bits are set.
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 bool collectInsertionElements(Value *V, unsigned Shift, SmallVectorImpl< Value * > &Elements, Type *VecEltTy, bool isBigEndian)
V is a value which is inserted into a vector of VecEltTy.
static IntegerType * getInt32Ty(LLVMContext &C)
Instruction * visitSIToFP(CastInst &CI)
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
static Instruction * foldVecTruncToExtElt(TruncInst &Trunc, InstCombiner &IC)
Given a vector that is bitcast to an integer, optionally logically right-shifted, and truncated...
static Constant * fitsInFPType(ConstantFP *CFP, const fltSemantics &Sem)
Return a Constant* for the specified floating-point constant if it fits in the specified FP type with...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
const APFloat & getValueAPF() const
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents a truncation of floating point types.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
static bool canEvaluateSExtd(Value *V, Type *Ty)
Return true if we can take the specified value and return it as type Ty without inserting any new cas...
const Value * getArraySize() const
Get the number of elements allocated.
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.
Instruction * commonPointerCastTransforms(CastInst &CI)
Implement the transforms for cast of pointer (bitcast/ptrtoint)
const Value * getFalseValue() const
bool isNullValue() const
Determine if all bits are clear.
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
Return the type that is being allocated by the instruction.
op_range incoming_values()
This class represents an extension of floating point types.
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)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
A wrapper class for inspecting calls to intrinsic functions.
an instruction to allocate memory on the stack
Instruction * visitFPTrunc(FPTruncInst &CI)