46#include "llvm/IR/IntrinsicsAArch64.h"
47#include "llvm/IR/IntrinsicsAMDGPU.h"
48#include "llvm/IR/IntrinsicsARM.h"
49#include "llvm/IR/IntrinsicsHexagon.h"
78#define DEBUG_TYPE "instcombine"
82using namespace PatternMatch;
84STATISTIC(NumSimplified,
"Number of library calls simplified");
87 "instcombine-guard-widening-window",
89 cl::desc(
"How wide an instruction window to bypass looking for "
96 if (ITy->getBitWidth() < 32)
106 auto *Src =
MI->getRawSource();
107 while (isa<GetElementPtrInst>(Src) || isa<BitCastInst>(Src)) {
108 if (!Src->hasOneUse())
110 Src = cast<Instruction>(Src)->getOperand(0);
112 return isa<AllocaInst>(Src) && Src->hasOneUse();
118 if (!CopyDstAlign || *CopyDstAlign < DstAlign) {
119 MI->setDestAlignment(DstAlign);
125 if (!CopySrcAlign || *CopySrcAlign < SrcAlign) {
126 MI->setSourceAlignment(SrcAlign);
149 ConstantInt *MemOpLength = dyn_cast<ConstantInt>(
MI->getLength());
150 if (!MemOpLength)
return nullptr;
157 assert(
Size &&
"0-sized memory transferring should be removed already.");
166 if (isa<AtomicMemTransferInst>(
MI))
167 if (*CopyDstAlign <
Size || *CopySrcAlign <
Size)
177 Value *Src =
MI->getArgOperand(1);
178 Value *Dest =
MI->getArgOperand(0);
181 L->setAlignment(*CopySrcAlign);
182 L->setAAMetadata(AACopyMD);
183 MDNode *LoopMemParallelMD =
184 MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
185 if (LoopMemParallelMD)
186 L->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
187 MDNode *AccessGroupMD =
MI->getMetadata(LLVMContext::MD_access_group);
189 L->setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
195 if (LoopMemParallelMD)
196 S->
setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
198 S->
setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
201 if (
auto *MT = dyn_cast<MemTransferInst>(
MI)) {
203 L->setVolatile(MT->isVolatile());
206 if (isa<AtomicMemTransferInst>(
MI)) {
218 const Align KnownAlignment =
221 if (!MemSetAlign || *MemSetAlign < KnownAlignment) {
222 MI->setDestAlignment(KnownAlignment);
238 if (isa<UndefValue>(
MI->getValue())) {
250 assert(Len &&
"0-sized memory setting should be removed already.");
251 const Align Alignment =
MI->getDestAlign().valueOrOne();
257 if (isa<AtomicMemSetInst>(
MI))
269 Constant *FillVal = ConstantInt::get(ITy, Fill);
272 auto replaceOpForAssignmentMarkers = [FillC, FillVal](
auto *DbgAssign) {
274 DbgAssign->replaceVariableLocationOp(FillC, FillVal);
280 if (isa<AtomicMemSetInst>(
MI))
294 Value *LoadPtr =
II.getArgOperand(0);
295 const Align Alignment =
296 cast<ConstantInt>(
II.getArgOperand(1))->getAlignValue();
310 II.getDataLayout(), &
II, &
AC)) {
313 LI->copyMetadata(
II);
324 auto *ConstMask = dyn_cast<Constant>(
II.getArgOperand(3));
329 if (ConstMask->isNullValue())
333 if (ConstMask->isAllOnesValue()) {
334 Value *StorePtr =
II.getArgOperand(1);
335 Align Alignment = cast<ConstantInt>(
II.getArgOperand(2))->getAlignValue();
337 new StoreInst(
II.getArgOperand(0), StorePtr,
false, Alignment);
342 if (isa<ScalableVectorType>(ConstMask->getType()))
362 auto *ConstMask = dyn_cast<Constant>(
II.getArgOperand(2));
369 if (ConstMask->isAllOnesValue())
371 auto *VecTy = cast<VectorType>(
II.getType());
372 const Align Alignment =
373 cast<ConstantInt>(
II.getArgOperand(1))->getAlignValue();
375 Alignment,
"load.scalar");
390 auto *ConstMask = dyn_cast<Constant>(
II.getArgOperand(3));
395 if (ConstMask->isNullValue())
404 cast<ConstantInt>(
II.getArgOperand(2))->getAlignValue();
413 if (ConstMask->isAllOnesValue()) {
414 Align Alignment = cast<ConstantInt>(
II.getArgOperand(2))->getAlignValue();
415 VectorType *WideLoadTy = cast<VectorType>(
II.getArgOperand(1)->getType());
422 new StoreInst(Extract, SplatPtr,
false, Alignment);
427 if (isa<ScalableVectorType>(ConstMask->getType()))
453 auto *Arg =
II.getArgOperand(0);
454 auto *StrippedArg = Arg->stripPointerCasts();
455 auto *StrippedInvariantGroupsArg = StrippedArg;
456 while (
auto *
Intr = dyn_cast<IntrinsicInst>(StrippedInvariantGroupsArg)) {
457 if (
Intr->getIntrinsicID() != Intrinsic::launder_invariant_group &&
458 Intr->getIntrinsicID() != Intrinsic::strip_invariant_group)
460 StrippedInvariantGroupsArg =
Intr->getArgOperand(0)->stripPointerCasts();
462 if (StrippedArg == StrippedInvariantGroupsArg)
465 Value *Result =
nullptr;
467 if (
II.getIntrinsicID() == Intrinsic::launder_invariant_group)
469 else if (
II.getIntrinsicID() == Intrinsic::strip_invariant_group)
473 "simplifyInvariantGroupIntrinsic only handles launder and strip");
474 if (Result->getType()->getPointerAddressSpace() !=
475 II.getType()->getPointerAddressSpace())
478 return cast<Instruction>(Result);
482 assert((
II.getIntrinsicID() == Intrinsic::cttz ||
483 II.getIntrinsicID() == Intrinsic::ctlz) &&
484 "Expected cttz or ctlz intrinsic");
485 bool IsTZ =
II.getIntrinsicID() == Intrinsic::cttz;
486 Value *Op0 =
II.getArgOperand(0);
487 Value *Op1 =
II.getArgOperand(1);
497 if (
II.getType()->isIntOrIntVectorTy(1)) {
555 return BinaryOperator::CreateAdd(ConstCttz,
X);
563 return BinaryOperator::CreateSub(ConstCttz,
X);
569 ConstantInt::get(
II.getType(),
II.getType()->getScalarSizeInBits());
570 return BinaryOperator::CreateSub(Width,
X);
578 return BinaryOperator::CreateAdd(ConstCtlz,
X);
586 return BinaryOperator::CreateSub(ConstCtlz,
X);
602 if (PossibleZeros == DefiniteZeros) {
603 auto *
C = ConstantInt::get(Op0->
getType(), DefiniteZeros);
618 if (
BitWidth != 1 && !
II.hasRetAttr(Attribute::Range) &&
619 !
II.getMetadata(LLVMContext::MD_range)) {
630 assert(
II.getIntrinsicID() == Intrinsic::ctpop &&
631 "Expected ctpop intrinsic");
634 Value *Op0 =
II.getArgOperand(0);
681 if ((~Known.
Zero).isPowerOf2())
682 return BinaryOperator::CreateLShr(
683 Op0, ConstantInt::get(Ty, (~Known.
Zero).exactLogBase2()));
695 if (
BitWidth != 1 && !
II.hasRetAttr(Attribute::Range) &&
696 !
II.getMetadata(LLVMContext::MD_range)) {
713 auto *
C = dyn_cast<Constant>(
II.getArgOperand(1));
717 auto *VecTy = cast<FixedVectorType>(
II.getType());
718 unsigned NumElts = VecTy->getNumElements();
721 if (!VecTy->getElementType()->isIntegerTy(8) || NumElts != 8)
726 for (
unsigned I = 0;
I < NumElts; ++
I) {
729 if (!COp || !isa<ConstantInt>(COp))
732 Indexes[
I] = cast<ConstantInt>(COp)->getLimitedValue();
735 if ((
unsigned)Indexes[
I] >= NumElts)
739 auto *V1 =
II.getArgOperand(0);
747 unsigned NumOperands) {
748 assert(
I.arg_size() >= NumOperands &&
"Not enough operands");
750 for (
unsigned i = 0; i < NumOperands; i++)
772 for (; BI != BE; ++BI) {
773 if (
auto *
I = dyn_cast<IntrinsicInst>(&*BI)) {
774 if (
I->isDebugOrPseudoInst() ||
795 return I.getIntrinsicID() == Intrinsic::vastart ||
796 I.getIntrinsicID() == Intrinsic::vacopy;
802 assert(Call.arg_size() > 1 &&
"Need at least 2 args to swap");
803 Value *Arg0 = Call.getArgOperand(0), *Arg1 = Call.getArgOperand(1);
804 if (isa<Constant>(Arg0) && !isa<Constant>(Arg1)) {
805 Call.setArgOperand(0, Arg1);
806 Call.setArgOperand(1, Arg0);
825 Value *OperationResult =
nullptr;
848 switch (
static_cast<unsigned>(Mask)) {
889 case ~fcZero & ~fcNan:
905 Value *Src0 =
II.getArgOperand(0);
906 Value *Src1 =
II.getArgOperand(1);
907 const ConstantInt *CMask = cast<ConstantInt>(Src1);
912 const FPClassTest OrderedInvertedMask = ~OrderedMask & ~fcNan;
914 const bool IsStrict =
915 II.getFunction()->getAttributes().hasFnAttr(Attribute::StrictFP);
921 II.setArgOperand(1, ConstantInt::get(Src1->
getType(),
fneg(Mask)));
931 if ((OrderedMask ==
fcInf || OrderedInvertedMask ==
fcInf) &&
932 (IsOrdered || IsUnordered) && !IsStrict) {
940 if (OrderedInvertedMask ==
fcInf)
950 (IsOrdered || IsUnordered) && !IsStrict) {
965 (IsOrdered || IsUnordered) && !IsStrict) {
978 if (Mask ==
fcNan && !IsStrict) {
1010 if (!IsStrict && (IsOrdered || IsUnordered) &&
1055 return std::nullopt;
1067 return std::nullopt;
1079 return *Known0 == *Known1;
1087 assert((MinMaxID == Intrinsic::smax || MinMaxID == Intrinsic::smin ||
1088 MinMaxID == Intrinsic::umax || MinMaxID == Intrinsic::umin) &&
1089 "Expected a min or max intrinsic");
1092 Value *Op0 =
II->getArgOperand(0), *Op1 =
II->getArgOperand(1);
1094 const APInt *C0, *C1;
1100 bool IsSigned = MinMaxID == Intrinsic::smax || MinMaxID == Intrinsic::smin;
1101 auto *
Add = cast<BinaryOperator>(Op0);
1102 if ((IsSigned && !
Add->hasNoSignedWrap()) ||
1103 (!IsSigned && !
Add->hasNoUnsignedWrap()))
1110 IsSigned ? C1->
ssub_ov(*C0, Overflow) : C1->
usub_ov(*C0, Overflow);
1111 assert(!Overflow &&
"Expected simplify of min/max");
1115 Constant *NewMinMaxC = ConstantInt::get(
II->getType(), CDiff);
1117 return IsSigned ? BinaryOperator::CreateNSWAdd(NewMinMax,
Add->getOperand(1))
1118 : BinaryOperator::CreateNUWAdd(NewMinMax,
Add->getOperand(1));
1129 const APInt *MinValue, *MaxValue;
1133 }
else if (
match(&MinMax1,
1142 if (!(*MaxValue + 1).isPowerOf2() || -*MinValue != *MaxValue + 1)
1145 unsigned NewBitWidth = (*MaxValue + 1).logBase2() + 1;
1159 if (
AddSub->getOpcode() == Instruction::Add)
1160 IntrinsicID = Intrinsic::sadd_sat;
1161 else if (
AddSub->getOpcode() == Instruction::Sub)
1162 IntrinsicID = Intrinsic::ssub_sat;
1187 Value *I0 =
II->getArgOperand(0), *I1 =
II->getArgOperand(1);
1189 const APInt *C0, *C1;
1194 switch (
II->getIntrinsicID()) {
1195 case Intrinsic::smax:
1199 case Intrinsic::smin:
1203 case Intrinsic::umax:
1207 case Intrinsic::umin:
1229 auto *
LHS = dyn_cast<MinMaxIntrinsic>(
II->getArgOperand(0));
1243 if (InnerMinMaxID != MinMaxID &&
1244 !(((MinMaxID == Intrinsic::umax && InnerMinMaxID == Intrinsic::smax) ||
1245 (MinMaxID == Intrinsic::smin && InnerMinMaxID == Intrinsic::umin)) &&
1253 {LHS->getArgOperand(0), NewC});
1273 auto *InnerMM = dyn_cast<IntrinsicInst>(Inner);
1274 if (!InnerMM || InnerMM->getIntrinsicID() != MinMaxID ||
1289 auto *
LHS = dyn_cast<IntrinsicInst>(
II->getArgOperand(0));
1290 auto *
RHS = dyn_cast<IntrinsicInst>(
II->getArgOperand(1));
1292 if (!
LHS || !
RHS ||
LHS->getIntrinsicID() != MinMaxID ||
1293 RHS->getIntrinsicID() != MinMaxID ||
1303 Value *MinMaxOp =
nullptr;
1304 Value *ThirdOp =
nullptr;
1308 if (
D ==
A ||
C ==
A) {
1313 }
else if (
D ==
B ||
C ==
B) {
1322 if (
D ==
A ||
D ==
B) {
1327 }
else if (
C ==
A ||
C ==
B) {
1335 if (!MinMaxOp || !ThirdOp)
1351 switch (
II->getIntrinsicID()) {
1352 case Intrinsic::smax:
1353 case Intrinsic::smin:
1354 case Intrinsic::umax:
1355 case Intrinsic::umin:
1356 case Intrinsic::fma:
1357 case Intrinsic::fshl:
1358 case Intrinsic::fshr:
1366 if (!
match(
II->getArgOperand(0),
1371 if (
none_of(
II->args(), [](
Value *V) { return V->hasOneUse(); }))
1377 Type *SrcTy =
X->getType();
1378 for (
unsigned i = 1, e =
II->arg_size(); i != e; ++i) {
1379 if (!
match(
II->getArgOperand(i),
1381 X->getType() != SrcTy)
1388 Value *NewIntrinsic =
1396template <Intrinsic::ID IntrID>
1399 static_assert(IntrID == Intrinsic::bswap || IntrID == Intrinsic::bitreverse,
1400 "This helper only supports BSWAP and BITREVERSE intrinsics");
1406 isa<BinaryOperator>(V)) {
1407 Value *OldReorderX, *OldReorderY;
1433 if (!CanReorderLanes)
1441 if (!isa<FixedVectorType>(Arg->
getType()) ||
1443 !cast<ShuffleVectorInst>(Arg)->isSingleSource())
1446 int Sz = Mask.size();
1448 for (
int Idx : Mask) {
1456 return UsedIndices.
all() ? V :
nullptr;
1486 if (!
II)
return visitCallBase(CI);
1490 if (
auto *AMI = dyn_cast<AtomicMemIntrinsic>(
II))
1491 if (
ConstantInt *NumBytes = dyn_cast<ConstantInt>(AMI->getLength()))
1492 if (NumBytes->isNegative() ||
1493 (NumBytes->getZExtValue() % AMI->getElementSizeInBytes() != 0)) {
1495 assert(AMI->getType()->isVoidTy() &&
1496 "non void atomic unordered mem intrinsic");
1502 if (
auto *
MI = dyn_cast<AnyMemIntrinsic>(
II)) {
1503 bool Changed =
false;
1506 if (
Constant *NumBytes = dyn_cast<Constant>(
MI->getLength())) {
1507 if (NumBytes->isNullValue())
1512 if (
auto *M = dyn_cast<MemIntrinsic>(
MI))
1513 if (M->isVolatile())
1519 if (
auto *MMI = dyn_cast<AnyMemMoveInst>(
MI)) {
1520 if (
GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
1521 if (GVSrc->isConstant()) {
1524 isa<AtomicMemMoveInst>(MMI)
1525 ? Intrinsic::memcpy_element_unordered_atomic
1526 : Intrinsic::memcpy;
1537 if (MTI->getSource() == MTI->getDest())
1543 if (
auto *MTI = dyn_cast<AnyMemTransferInst>(
MI)) {
1546 }
else if (
auto *MSI = dyn_cast<AnyMemSetInst>(
MI)) {
1551 if (Changed)
return II;
1556 if (
auto *IIFVTy = dyn_cast<FixedVectorType>(
II->getType())) {
1557 auto VWidth = IIFVTy->getNumElements();
1558 APInt PoisonElts(VWidth, 0);
1567 if (
II->isCommutative()) {
1568 if (
auto Pair = matchSymmetricPair(
II->getOperand(0),
II->getOperand(1))) {
1582 if (CI.
use_empty() && isa<ConstrainedFPIntrinsic>(CI)) {
1589 case Intrinsic::objectsize: {
1592 &InsertedInstructions)) {
1593 for (
Instruction *Inserted : InsertedInstructions)
1599 case Intrinsic::abs: {
1600 Value *IIOperand =
II->getArgOperand(0);
1601 bool IntMinIsPoison = cast<Constant>(
II->getArgOperand(1))->isOneValue();
1615 if (
match(IIOperand,
1617 m_Intrinsic<Intrinsic::abs>(
m_Value(
Y)))))) {
1619 cast<Instruction>(IIOperand)->hasNoSignedWrap() && IntMinIsPoison;
1624 if (std::optional<bool> Known =
1650 return BinaryOperator::CreateAnd(
X, ConstantInt::get(
II->getType(), 1));
1654 case Intrinsic::umin: {
1655 Value *I0 =
II->getArgOperand(0), *I1 =
II->getArgOperand(1);
1658 assert(
II->getType()->getScalarSizeInBits() != 1 &&
1659 "Expected simplify of umin with max constant");
1666 case Intrinsic::umax: {
1667 Value *I0 =
II->getArgOperand(0), *I1 =
II->getArgOperand(1);
1670 (I0->
hasOneUse() || I1->hasOneUse()) &&
X->getType() ==
Y->getType()) {
1686 case Intrinsic::smax:
1687 case Intrinsic::smin: {
1688 Value *I0 =
II->getArgOperand(0), *I1 =
II->getArgOperand(1);
1691 (I0->
hasOneUse() || I1->hasOneUse()) &&
X->getType() ==
Y->getType()) {
1707 if ((IID == Intrinsic::umin || IID == Intrinsic::smax) &&
1708 II->getType()->isIntOrIntVectorTy(1)) {
1709 return BinaryOperator::CreateAnd(I0, I1);
1714 if ((IID == Intrinsic::umax || IID == Intrinsic::smin) &&
1715 II->getType()->isIntOrIntVectorTy(1)) {
1716 return BinaryOperator::CreateOr(I0, I1);
1719 if (IID == Intrinsic::smax || IID == Intrinsic::smin) {
1746 bool UseOr = IID == Intrinsic::smax || IID == Intrinsic::umax;
1747 bool UseAndN = IID == Intrinsic::smin || IID == Intrinsic::umin;
1749 if (IID == Intrinsic::smax || IID == Intrinsic::smin) {
1751 if (KnownSign == std::nullopt) {
1754 }
else if (*KnownSign ) {
1766 return BinaryOperator::CreateOr(I0,
X);
1804 ConstantInt::get(
II->getType(), *RHSC));
1814 if (I0->
hasOneUse() && !I1->hasOneUse())
1826 if (IID == Intrinsic::smin || IID == Intrinsic::umax)
1854 if (LHS_CR.
icmp(Pred, *RHSC))
1858 ConstantInt::get(
II->getType(), *RHSC));
1864 case Intrinsic::bitreverse: {
1865 Value *IIOperand =
II->getArgOperand(0);
1869 X->getType()->isIntOrIntVectorTy(1)) {
1870 Type *Ty =
II->getType();
1877 foldBitOrderCrossLogicOp<Intrinsic::bitreverse>(IIOperand,
Builder))
1878 return crossLogicOpFold;
1882 case Intrinsic::bswap: {
1883 Value *IIOperand =
II->getArgOperand(0);
1895 cast<BinaryOperator>(IIOperand)->
getOpcode() == Instruction::Shl
1908 if (BW - LZ - TZ == 8) {
1909 assert(LZ != TZ &&
"active byte cannot be in the middle");
1911 return BinaryOperator::CreateNUWShl(
1912 IIOperand, ConstantInt::get(IIOperand->
getType(), LZ - TZ));
1914 return BinaryOperator::CreateExactLShr(
1915 IIOperand, ConstantInt::get(IIOperand->
getType(), TZ - LZ));
1920 unsigned C =
X->getType()->getScalarSizeInBits() - BW;
1921 Value *CV = ConstantInt::get(
X->getType(),
C);
1927 foldBitOrderCrossLogicOp<Intrinsic::bswap>(IIOperand,
Builder)) {
1928 return crossLogicOpFold;
1937 case Intrinsic::masked_load:
1938 if (
Value *SimplifiedMaskedOp = simplifyMaskedLoad(*
II))
1941 case Intrinsic::masked_store:
1942 return simplifyMaskedStore(*
II);
1943 case Intrinsic::masked_gather:
1944 return simplifyMaskedGather(*
II);
1945 case Intrinsic::masked_scatter:
1946 return simplifyMaskedScatter(*
II);
1947 case Intrinsic::launder_invariant_group:
1948 case Intrinsic::strip_invariant_group:
1952 case Intrinsic::powi:
1953 if (
ConstantInt *Power = dyn_cast<ConstantInt>(
II->getArgOperand(1))) {
1956 if (Power->isMinusOne())
1958 II->getArgOperand(0),
II);
1960 if (Power->equalsInt(2))
1962 II->getArgOperand(0),
II);
1964 if (!Power->getValue()[0]) {
1979 case Intrinsic::cttz:
1980 case Intrinsic::ctlz:
1985 case Intrinsic::ctpop:
1990 case Intrinsic::fshl:
1991 case Intrinsic::fshr: {
1992 Value *Op0 =
II->getArgOperand(0), *Op1 =
II->getArgOperand(1);
1993 Type *Ty =
II->getType();
2003 if (ModuloC != ShAmtC)
2009 "Shift amount expected to be modulo bitwidth");
2014 if (IID == Intrinsic::fshr) {
2024 assert(IID == Intrinsic::fshl &&
2025 "All funnel shifts by simple constants should go left");
2030 return BinaryOperator::CreateShl(Op0, ShAmtC);
2035 return BinaryOperator::CreateLShr(Op1,
2065 case Intrinsic::ptrmask: {
2071 Value *InnerPtr, *InnerMask;
2072 bool Changed =
false;
2076 if (
match(
II->getArgOperand(0),
2080 "Mask types must match");
2097 unsigned NewAlignmentLog =
2111 case Intrinsic::uadd_with_overflow:
2112 case Intrinsic::sadd_with_overflow: {
2120 const APInt *C0, *C1;
2121 Value *Arg0 =
II->getArgOperand(0);
2122 Value *Arg1 =
II->getArgOperand(1);
2123 bool IsSigned = IID == Intrinsic::sadd_with_overflow;
2124 bool HasNWAdd = IsSigned
2130 IsSigned ? C1->
sadd_ov(*C0, Overflow) : C1->
uadd_ov(*C0, Overflow);
2134 IID,
X, ConstantInt::get(Arg1->
getType(), NewC)));
2139 case Intrinsic::umul_with_overflow:
2140 case Intrinsic::smul_with_overflow:
2141 case Intrinsic::usub_with_overflow:
2146 case Intrinsic::ssub_with_overflow: {
2151 Value *Arg0 =
II->getArgOperand(0);
2152 Value *Arg1 =
II->getArgOperand(1);
2169 case Intrinsic::uadd_sat:
2170 case Intrinsic::sadd_sat:
2171 case Intrinsic::usub_sat:
2172 case Intrinsic::ssub_sat: {
2174 Type *Ty = SI->getType();
2175 Value *Arg0 = SI->getLHS();
2176 Value *Arg1 = SI->getRHS();
2207 if (IID == Intrinsic::usub_sat &&
2218 C->isNotMinSignedValue()) {
2222 Intrinsic::sadd_sat, Arg0, NegVal));
2228 if (
auto *
Other = dyn_cast<IntrinsicInst>(Arg0)) {
2230 const APInt *Val, *Val2;
2233 IID == Intrinsic::uadd_sat || IID == Intrinsic::usub_sat;
2234 if (
Other->getIntrinsicID() == IID &&
2242 NewVal = Val->
sadd_ov(*Val2, Overflow);
2255 IID,
X, ConstantInt::get(
II->getType(), NewVal)));
2261 case Intrinsic::minnum:
2262 case Intrinsic::maxnum:
2263 case Intrinsic::minimum:
2264 case Intrinsic::maximum: {
2265 Value *Arg0 =
II->getArgOperand(0);
2266 Value *Arg1 =
II->getArgOperand(1);
2275 case Intrinsic::maxnum:
2276 NewIID = Intrinsic::minnum;
2278 case Intrinsic::minnum:
2279 NewIID = Intrinsic::maxnum;
2281 case Intrinsic::maximum:
2282 NewIID = Intrinsic::minimum;
2284 case Intrinsic::minimum:
2285 NewIID = Intrinsic::maximum;
2291 Instruction *FNeg = UnaryOperator::CreateFNeg(NewCall);
2298 if (
auto *M = dyn_cast<IntrinsicInst>(Arg0)) {
2306 case Intrinsic::maxnum:
2309 case Intrinsic::minnum:
2312 case Intrinsic::maximum:
2315 case Intrinsic::minimum:
2322 IID,
X, ConstantFP::get(Arg0->
getType(), Res),
II);
2326 if (
auto *CI = dyn_cast<CallInst>(V))
2335 X->getType() ==
Y->getType()) {
2347 auto IsMinMaxOrXNegX = [IID, &
X](
Value *Op0,
Value *Op1) {
2349 return Op0->hasOneUse() ||
2350 (IID != Intrinsic::minimum && IID != Intrinsic::minnum);
2354 if (IsMinMaxOrXNegX(Arg0, Arg1) || IsMinMaxOrXNegX(Arg1, Arg0)) {
2356 if (IID == Intrinsic::minimum || IID == Intrinsic::minnum)
2363 case Intrinsic::matrix_multiply: {
2375 Value *Op0 =
II->getOperand(0);
2376 Value *Op1 =
II->getOperand(1);
2377 Value *OpNotNeg, *NegatedOp;
2378 unsigned NegatedOpArg, OtherOpArg;
2395 Value *OtherOp =
II->getOperand(OtherOpArg);
2413 NewArgs[NegatedOpArg] = OpNotNeg;
2420 case Intrinsic::fmuladd: {
2423 II->getFastMathFlags(),
2425 auto *
FAdd = BinaryOperator::CreateFAdd(V,
II->getArgOperand(2));
2426 FAdd->copyFastMathFlags(
II);
2432 case Intrinsic::fma: {
2434 Value *Src0 =
II->getArgOperand(0);
2435 Value *Src1 =
II->getArgOperand(1);
2454 II->getFastMathFlags(),
2456 auto *
FAdd = BinaryOperator::CreateFAdd(V,
II->getArgOperand(2));
2457 FAdd->copyFastMathFlags(
II);
2466 II->getFastMathFlags().noSignedZeros()))
2471 case Intrinsic::copysign: {
2472 Value *Mag =
II->getArgOperand(0), *Sign =
II->getArgOperand(1);
2475 if (*KnownSignBit) {
2512 case Intrinsic::fabs: {
2514 Value *Arg =
II->getArgOperand(0);
2524 if (isa<Constant>(TVal) || isa<Constant>(FVal)) {
2529 FastMathFlags FMF2 = cast<SelectInst>(Arg)->getFastMathFlags();
2531 SI->setFastMathFlags(FMF1 | FMF2);
2542 Value *Magnitude, *Sign;
2543 if (
match(
II->getArgOperand(0),
2554 case Intrinsic::ceil:
2555 case Intrinsic::floor:
2556 case Intrinsic::round:
2557 case Intrinsic::roundeven:
2558 case Intrinsic::nearbyint:
2559 case Intrinsic::rint:
2560 case Intrinsic::trunc: {
2569 case Intrinsic::cos:
2570 case Intrinsic::amdgcn_cos: {
2572 Value *Src =
II->getArgOperand(0);
2582 case Intrinsic::sin: {
2587 Instruction *FNeg = UnaryOperator::CreateFNeg(NewSin);
2593 case Intrinsic::ldexp: {
2606 Value *Src =
II->getArgOperand(0);
2607 Value *Exp =
II->getArgOperand(1);
2612 Exp->getType() == InnerExp->
getType()) {
2614 FastMathFlags InnerFlags = cast<FPMathOperator>(Src)->getFastMathFlags();
2621 II->setArgOperand(1, NewExp);
2622 II->setFastMathFlags(InnerFlags);
2634 ConstantFP::get(
II->getType(), 1.0));
2641 ConstantFP::get(
II->getType(), 1.0));
2647 case Intrinsic::ptrauth_auth:
2648 case Intrinsic::ptrauth_resign: {
2651 bool NeedSign =
II->getIntrinsicID() == Intrinsic::ptrauth_resign;
2653 Value *Key =
II->getArgOperand(1);
2654 Value *Disc =
II->getArgOperand(2);
2658 Value *AuthKey =
nullptr, *AuthDisc =
nullptr, *BasePtr;
2659 if (
const auto *CI = dyn_cast<CallBase>(
Ptr)) {
2671 }
else if (
const auto *PtrToInt = dyn_cast<PtrToIntOperator>(
Ptr)) {
2674 const auto *CPA = dyn_cast<ConstantPtrAuth>(PtrToInt->getOperand(0));
2675 if (!CPA || !CPA->isKnownCompatibleWith(Key, Disc,
DL))
2679 if (NeedSign && isa<ConstantInt>(
II->getArgOperand(4))) {
2680 auto *SignKey = cast<ConstantInt>(
II->getArgOperand(3));
2681 auto *SignDisc = cast<ConstantInt>(
II->getArgOperand(4));
2684 SignDisc, SignAddrDisc);
2696 if (AuthKey && NeedSign) {
2698 NewIntrin = Intrinsic::ptrauth_resign;
2699 }
else if (AuthKey) {
2701 NewIntrin = Intrinsic::ptrauth_auth;
2702 }
else if (NeedSign) {
2704 NewIntrin = Intrinsic::ptrauth_sign;
2726 case Intrinsic::arm_neon_vtbl1:
2727 case Intrinsic::aarch64_neon_tbl1:
2732 case Intrinsic::arm_neon_vmulls:
2733 case Intrinsic::arm_neon_vmullu:
2734 case Intrinsic::aarch64_neon_smull:
2735 case Intrinsic::aarch64_neon_umull: {
2736 Value *Arg0 =
II->getArgOperand(0);
2737 Value *Arg1 =
II->getArgOperand(1);
2740 if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) {
2745 bool Zext = (IID == Intrinsic::arm_neon_vmullu ||
2746 IID == Intrinsic::aarch64_neon_umull);
2748 if (
Constant *CV0 = dyn_cast<Constant>(Arg0)) {
2749 if (
Constant *CV1 = dyn_cast<Constant>(Arg1)) {
2760 if (
Constant *CV1 = dyn_cast<Constant>(Arg1))
2762 dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
2769 case Intrinsic::arm_neon_aesd:
2770 case Intrinsic::arm_neon_aese:
2771 case Intrinsic::aarch64_crypto_aesd:
2772 case Intrinsic::aarch64_crypto_aese: {
2773 Value *DataArg =
II->getArgOperand(0);
2774 Value *KeyArg =
II->getArgOperand(1);
2786 case Intrinsic::hexagon_V6_vandvrt:
2787 case Intrinsic::hexagon_V6_vandvrt_128B: {
2789 if (
auto Op0 = dyn_cast<IntrinsicInst>(
II->getArgOperand(0))) {
2791 if (ID0 != Intrinsic::hexagon_V6_vandqrt &&
2792 ID0 != Intrinsic::hexagon_V6_vandqrt_128B)
2794 Value *Bytes = Op0->getArgOperand(1), *Mask =
II->getArgOperand(1);
2799 if ((
C & 0xFF) && (
C & 0xFF00) && (
C & 0xFF0000) && (
C & 0xFF000000))
2804 case Intrinsic::stackrestore: {
2805 enum class ClassifyResult {
2809 CallWithSideEffects,
2812 if (isa<AllocaInst>(
I))
2813 return ClassifyResult::Alloca;
2815 if (
auto *CI = dyn_cast<CallInst>(
I)) {
2816 if (
auto *
II = dyn_cast<IntrinsicInst>(CI)) {
2817 if (
II->getIntrinsicID() == Intrinsic::stackrestore)
2818 return ClassifyResult::StackRestore;
2820 if (
II->mayHaveSideEffects())
2821 return ClassifyResult::CallWithSideEffects;
2824 return ClassifyResult::CallWithSideEffects;
2828 return ClassifyResult::None;
2834 if (
IntrinsicInst *SS = dyn_cast<IntrinsicInst>(
II->getArgOperand(0))) {
2835 if (SS->getIntrinsicID() == Intrinsic::stacksave &&
2836 SS->getParent() ==
II->getParent()) {
2838 bool CannotRemove =
false;
2839 for (++BI; &*BI !=
II; ++BI) {
2840 switch (Classify(&*BI)) {
2841 case ClassifyResult::None:
2845 case ClassifyResult::StackRestore:
2848 if (cast<IntrinsicInst>(*BI).getArgOperand(0) != SS)
2849 CannotRemove =
true;
2852 case ClassifyResult::Alloca:
2853 case ClassifyResult::CallWithSideEffects:
2856 CannotRemove =
true;
2872 bool CannotRemove =
false;
2873 for (++BI; &*BI != TI; ++BI) {
2874 switch (Classify(&*BI)) {
2875 case ClassifyResult::None:
2879 case ClassifyResult::StackRestore:
2883 case ClassifyResult::Alloca:
2884 case ClassifyResult::CallWithSideEffects:
2888 CannotRemove =
true;
2898 if (!CannotRemove && (isa<ReturnInst>(TI) || isa<ResumeInst>(TI)))
2902 case Intrinsic::lifetime_end:
2905 if (
II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
2906 II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory) ||
2907 II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
2911 return I.getIntrinsicID() == Intrinsic::lifetime_start;
2915 case Intrinsic::assume: {
2916 Value *IIOperand =
II->getArgOperand(0);
2918 II->getOperandBundlesAsDefs(OpBundles);
2924 assert(isa<AssumeInst>(Assume));
2934 if (
match(Next, m_Intrinsic<Intrinsic::assume>(
m_Specific(IIOperand))))
2935 return RemoveConditionFromAssume(Next);
2941 Value *AssumeIntrinsic =
II->getCalledOperand();
2969 return RemoveConditionFromAssume(
II);
2979 for (
unsigned Idx = 0;
Idx <
II->getNumOperandBundles();
Idx++) {
2981 if (OBU.
getTagName() ==
"separate_storage") {
2983 auto MaybeSimplifyHint = [&](
const Use &U) {
2984 Value *Hint = U.get();
2991 MaybeSimplifyHint(OBU.
Inputs[0]);
2992 MaybeSimplifyHint(OBU.
Inputs[1]);
3007 Replacement->insertBefore(Next);
3009 return RemoveConditionFromAssume(
II);
3036 if (
auto *Replacement =
3039 Replacement->insertAfter(
II);
3042 return RemoveConditionFromAssume(
II);
3049 for (
unsigned Idx = 0;
Idx <
II->getNumOperandBundles();
Idx++) {
3050 auto &BOI =
II->bundle_op_info_begin()[
Idx];
3053 if (BOI.End - BOI.Begin > 2)
3064 if (BOI.End - BOI.Begin > 0) {
3071 if (BOI.End - BOI.Begin > 0)
3072 II->op_begin()[BOI.Begin].set(CanonRK.
WasOn);
3073 if (BOI.End - BOI.Begin > 1)
3074 II->op_begin()[BOI.Begin + 1].set(ConstantInt::get(
3100 case Intrinsic::experimental_guard: {
3111 Value *NextCond =
nullptr;
3113 m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(NextCond)))) {
3114 Value *CurrCond =
II->getArgOperand(0);
3118 if (CurrCond != NextCond) {
3120 while (MoveI != NextInst) {
3132 case Intrinsic::vector_insert: {
3133 Value *Vec =
II->getArgOperand(0);
3134 Value *SubVec =
II->getArgOperand(1);
3136 auto *DstTy = dyn_cast<FixedVectorType>(
II->getType());
3137 auto *VecTy = dyn_cast<FixedVectorType>(Vec->
getType());
3138 auto *SubVecTy = dyn_cast<FixedVectorType>(SubVec->
getType());
3142 if (DstTy && VecTy && SubVecTy) {
3143 unsigned DstNumElts = DstTy->getNumElements();
3144 unsigned VecNumElts = VecTy->getNumElements();
3145 unsigned SubVecNumElts = SubVecTy->getNumElements();
3146 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
3149 if (VecNumElts == SubVecNumElts)
3158 for (i = 0; i != SubVecNumElts; ++i)
3160 for (; i != VecNumElts; ++i)
3166 for (
unsigned i = 0; i != IdxN; ++i)
3168 for (
unsigned i = DstNumElts; i != DstNumElts + SubVecNumElts; ++i)
3170 for (
unsigned i = IdxN + SubVecNumElts; i != DstNumElts; ++i)
3178 case Intrinsic::vector_extract: {
3179 Value *Vec =
II->getArgOperand(0);
3182 Type *ReturnType =
II->getType();
3185 unsigned ExtractIdx = cast<ConstantInt>(
Idx)->getZExtValue();
3186 Value *InsertTuple, *InsertIdx, *InsertValue;
3187 if (
match(Vec, m_Intrinsic<Intrinsic::vector_insert>(
m_Value(InsertTuple),
3190 InsertValue->
getType() == ReturnType) {
3191 unsigned Index = cast<ConstantInt>(InsertIdx)->getZExtValue();
3195 if (ExtractIdx ==
Index)
3206 auto *DstTy = dyn_cast<VectorType>(ReturnType);
3207 auto *VecTy = dyn_cast<VectorType>(Vec->
getType());
3209 if (DstTy && VecTy) {
3210 auto DstEltCnt = DstTy->getElementCount();
3211 auto VecEltCnt = VecTy->getElementCount();
3212 unsigned IdxN = cast<ConstantInt>(
Idx)->getZExtValue();
3215 if (DstEltCnt == VecTy->getElementCount()) {
3222 if (VecEltCnt.isScalable() || DstEltCnt.isScalable())
3226 for (
unsigned i = 0; i != DstEltCnt.getKnownMinValue(); ++i)
3227 Mask.push_back(IdxN + i);
3234 case Intrinsic::vector_reverse: {
3236 Value *Vec =
II->getArgOperand(0);
3238 auto *OldBinOp = cast<BinaryOperator>(Vec);
3243 OldBinOp->getOpcode(),
X,
Y,
3244 OldBinOp, OldBinOp->getName(),
3245 II->getIterator()));
3249 OldBinOp->getOpcode(),
X, BO1,
3250 OldBinOp, OldBinOp->
getName(),
3251 II->getIterator()));
3257 OldBinOp->getOpcode(), BO0,
Y, OldBinOp,
3258 OldBinOp->getName(),
II->getIterator()));
3262 auto *OldUnOp = cast<UnaryOperator>(Vec);
3264 OldUnOp->getOpcode(),
X, OldUnOp, OldUnOp->getName(),
3270 case Intrinsic::vector_reduce_or:
3271 case Intrinsic::vector_reduce_and: {
3279 Value *Arg =
II->getArgOperand(0);
3289 if (
auto *FTy = dyn_cast<FixedVectorType>(Vect->
getType()))
3293 if (IID == Intrinsic::vector_reduce_and) {
3297 assert(IID == Intrinsic::vector_reduce_or &&
3298 "Expected or reduction.");
3309 case Intrinsic::vector_reduce_add: {
3310 if (IID == Intrinsic::vector_reduce_add) {
3317 Value *Arg =
II->getArgOperand(0);
3327 if (
auto *FTy = dyn_cast<FixedVectorType>(Vect->
getType()))
3335 cast<Instruction>(Arg)->
getOpcode() == Instruction::SExt)
3343 case Intrinsic::vector_reduce_xor: {
3344 if (IID == Intrinsic::vector_reduce_xor) {
3352 Value *Arg =
II->getArgOperand(0);
3362 if (
auto *FTy = dyn_cast<FixedVectorType>(Vect->
getType()))
3374 case Intrinsic::vector_reduce_mul: {
3375 if (IID == Intrinsic::vector_reduce_mul) {
3382 Value *Arg =
II->getArgOperand(0);
3392 if (
auto *FTy = dyn_cast<FixedVectorType>(Vect->
getType()))
3403 case Intrinsic::vector_reduce_umin:
3404 case Intrinsic::vector_reduce_umax: {
3405 if (IID == Intrinsic::vector_reduce_umin ||
3406 IID == Intrinsic::vector_reduce_umax) {
3413 Value *Arg =
II->getArgOperand(0);
3423 if (
auto *FTy = dyn_cast<FixedVectorType>(Vect->
getType()))
3425 Value *Res = IID == Intrinsic::vector_reduce_umin
3437 case Intrinsic::vector_reduce_smin:
3438 case Intrinsic::vector_reduce_smax: {
3439 if (IID == Intrinsic::vector_reduce_smin ||
3440 IID == Intrinsic::vector_reduce_smax) {
3455 Value *Arg =
II->getArgOperand(0);
3465 if (
auto *FTy = dyn_cast<FixedVectorType>(Vect->
getType()))
3469 ExtOpc = cast<CastInst>(Arg)->getOpcode();
3470 Value *Res = ((IID == Intrinsic::vector_reduce_smin) ==
3471 (ExtOpc == Instruction::CastOps::ZExt))
3482 case Intrinsic::vector_reduce_fmax:
3483 case Intrinsic::vector_reduce_fmin:
3484 case Intrinsic::vector_reduce_fadd:
3485 case Intrinsic::vector_reduce_fmul: {
3486 bool CanReorderLanes = (IID != Intrinsic::vector_reduce_fadd &&
3487 IID != Intrinsic::vector_reduce_fmul) ||
3488 II->hasAllowReassoc();
3489 const unsigned ArgIdx = (IID == Intrinsic::vector_reduce_fadd ||
3490 IID == Intrinsic::vector_reduce_fmul)
3493 Value *Arg =
II->getArgOperand(ArgIdx);
3500 case Intrinsic::is_fpclass: {
3505 case Intrinsic::threadlocal_address: {
3528 case Intrinsic::ctlz:
3529 case Intrinsic::cttz:
3530 case Intrinsic::ctpop:
3531 case Intrinsic::umin:
3532 case Intrinsic::umax:
3533 case Intrinsic::smin:
3534 case Intrinsic::smax:
3535 case Intrinsic::usub_sat:
3536 case Intrinsic::uadd_sat:
3537 case Intrinsic::ssub_sat:
3538 case Intrinsic::sadd_sat:
3540 if (
auto *Sel = dyn_cast<SelectInst>(
Op))
3553 return visitCallBase(*
II);
3568 if (FI1SyncScope != FI2->getSyncScopeID() ||
3575 if (NFI && isIdenticalOrStrongerFence(NFI, &FI))
3579 if (isIdenticalOrStrongerFence(PFI, &FI))
3586 return visitCallBase(
II);
3591 return visitCallBase(CBI);
3611 if (
Value *With = Simplifier.optimizeCall(CI,
Builder)) {
3623 if (Underlying != TrampMem &&
3624 (!Underlying->hasOneUse() || Underlying->user_back() != TrampMem))
3626 if (!isa<AllocaInst>(Underlying))
3634 if (
II->getIntrinsicID() == Intrinsic::init_trampoline) {
3638 InitTrampoline =
II;
3641 if (
II->getIntrinsicID() == Intrinsic::adjust_trampoline)
3648 if (!InitTrampoline)
3652 if (InitTrampoline->
getOperand(0) != TrampMem)
3655 return InitTrampoline;
3667 if (
II->getIntrinsicID() == Intrinsic::init_trampoline &&
3668 II->getOperand(0) == TrampMem)
3680 Callee = Callee->stripPointerCasts();
3681 IntrinsicInst *AdjustTramp = dyn_cast<IntrinsicInst>(Callee);
3695bool InstCombinerImpl::annotateAnyAllocSite(
CallBase &Call,
3701 bool Changed =
false;
3703 if (!
Call.getType()->isPointerTy())
3710 if (
Call.hasRetAttr(Attribute::NonNull)) {
3711 Changed = !
Call.hasRetAttr(Attribute::Dereferenceable);
3713 Call.getContext(),
Size->getLimitedValue()));
3715 Changed = !
Call.hasRetAttr(Attribute::DereferenceableOrNull);
3717 Call.getContext(),
Size->getLimitedValue()));
3726 ConstantInt *AlignOpC = dyn_cast<ConstantInt>(Alignment);
3730 Align ExistingAlign =
Call.getRetAlign().valueOrOne();
3732 if (NewAlign > ExistingAlign) {
3744 bool Changed = annotateAnyAllocSite(Call, &
TLI);
3753 if (
V->getType()->isPointerTy() &&
3754 !
Call.paramHasAttr(ArgNo, Attribute::NonNull) &&
3760 assert(ArgNo ==
Call.arg_size() &&
"Call arguments not processed correctly.");
3762 if (!ArgNos.
empty()) {
3767 Call.setAttributes(AS);
3774 Function *CalleeF = dyn_cast<Function>(Callee);
3776 transformConstExprCastCall(Call))
3783 LLVM_DEBUG(
dbgs() <<
"Removing convergent attr from instr " << Call
3785 Call.setNotConvergent();
3807 if (isa<CallInst>(OldCall))
3812 cast<CallBase>(OldCall)->setCalledFunction(
3821 if ((isa<ConstantPointerNull>(Callee) &&
3823 isa<UndefValue>(Callee)) {
3826 if (!
Call.getType()->isVoidTy())
3829 if (
Call.isTerminator()) {
3840 return transformCallThroughTrampoline(Call, *
II);
3842 if (isa<InlineAsm>(Callee) && !
Call.doesNotThrow()) {
3844 if (!
IA->canThrow()) {
3847 Call.setDoesNotThrow();
3855 if (
CallInst *CI = dyn_cast<CallInst>(&Call)) {
3862 if (!
Call.use_empty() && !
Call.isMustTailCall())
3863 if (
Value *ReturnedArg =
Call.getReturnedArgOperand()) {
3865 Type *RetArgTy = ReturnedArg->getType();
3874 if (Bundle && !
Call.isIndirectCall()) {
3878 ConstantInt *ExpectedType = cast<ConstantInt>(Bundle->Inputs[0]);
3881 FunctionType = mdconst::extract<ConstantInt>(MD->getOperand(0));
3885 dbgs() <<
Call.getModule()->getName()
3886 <<
": warning: kcfi: " <<
Call.getCaller()->getName()
3887 <<
": call to " << CalleeF->
getName()
3888 <<
" using a mismatching function pointer type\n";
3899 switch (
Call.getIntrinsicID()) {
3900 case Intrinsic::experimental_gc_statepoint: {
3916 if (isa<UndefValue>(DerivedPtr) || isa<UndefValue>(BasePtr)) {
3922 if (
auto *PT = dyn_cast<PointerType>(GCR.
getType())) {
3926 if (isa<ConstantPointerNull>(DerivedPtr)) {
3955 LiveGcValues.
insert(BasePtr);
3956 LiveGcValues.
insert(DerivedPtr);
3958 std::optional<OperandBundleUse> Bundle =
3960 unsigned NumOfGCLives = LiveGcValues.
size();
3961 if (!Bundle || NumOfGCLives == Bundle->Inputs.size())
3965 std::vector<Value *> NewLiveGc;
3966 for (
Value *V : Bundle->Inputs) {
3967 if (Val2Idx.
count(V))
3969 if (LiveGcValues.
count(V)) {
3970 Val2Idx[
V] = NewLiveGc.
size();
3971 NewLiveGc.push_back(V);
3973 Val2Idx[
V] = NumOfGCLives;
3979 assert(Val2Idx.
count(BasePtr) && Val2Idx[BasePtr] != NumOfGCLives &&
3980 "Missed live gc for base pointer");
3982 GCR.
setOperand(1, ConstantInt::get(OpIntTy1, Val2Idx[BasePtr]));
3984 assert(Val2Idx.
count(DerivedPtr) && Val2Idx[DerivedPtr] != NumOfGCLives &&
3985 "Missed live gc for derived pointer");
3987 GCR.
setOperand(2, ConstantInt::get(OpIntTy2, Val2Idx[DerivedPtr]));
3996 return Changed ? &
Call :
nullptr;
4002bool InstCombinerImpl::transformConstExprCastCall(
CallBase &Call) {
4004 dyn_cast<Function>(
Call.getCalledOperand()->stripPointerCasts());
4008 assert(!isa<CallBrInst>(Call) &&
4009 "CallBr's don't have a single point after a def to insert at");
4014 if (
Callee->hasFnAttribute(
"thunk"))
4020 if (
Callee->hasFnAttribute(Attribute::Naked))
4027 if (
Call.isMustTailCall())
4038 Type *NewRetTy = FT->getReturnType();
4041 if (OldRetTy != NewRetTy) {
4047 if (
Callee->isDeclaration())
4050 if (!
Caller->use_empty() &&
4066 if (!
Caller->use_empty()) {
4068 if (
auto *
II = dyn_cast<InvokeInst>(Caller))
4069 PhisNotSupportedBlock =
II->getNormalDest();
4070 if (PhisNotSupportedBlock)
4072 if (
PHINode *PN = dyn_cast<PHINode>(U))
4073 if (PN->getParent() == PhisNotSupportedBlock)
4078 unsigned NumActualArgs =
Call.arg_size();
4079 unsigned NumCommonArgs = std::min(FT->getNumParams(), NumActualArgs);
4089 if (
Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) ||
4090 Callee->getAttributes().hasAttrSomewhere(Attribute::Preallocated))
4093 auto AI =
Call.arg_begin();
4094 for (
unsigned i = 0, e = NumCommonArgs; i !=
e; ++i, ++AI) {
4095 Type *ParamTy = FT->getParamType(i);
4096 Type *ActTy = (*AI)->getType();
4107 if (
Call.isInAllocaArgument(i) ||
4115 Callee->getAttributes().hasParamAttr(i, Attribute::ByVal))
4119 if (
Callee->isDeclaration()) {
4121 if (FT->getNumParams() < NumActualArgs && !FT->isVarArg())
4127 if (FT->isVarArg() !=
Call.getFunctionType()->isVarArg())
4133 if (FT->isVarArg() &&
Call.getFunctionType()->isVarArg() &&
4134 FT->getNumParams() !=
Call.getFunctionType()->getNumParams())
4138 if (FT->getNumParams() < NumActualArgs && FT->isVarArg() &&
4153 Args.reserve(NumActualArgs);
4154 ArgAttrs.
reserve(NumActualArgs);
4164 AI =
Call.arg_begin();
4165 for (
unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
4166 Type *ParamTy = FT->getParamType(i);
4168 Value *NewArg = *AI;
4169 if ((*AI)->getType() != ParamTy)
4171 Args.push_back(NewArg);
4183 for (
unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i) {
4189 if (FT->getNumParams() < NumActualArgs) {
4191 if (FT->isVarArg()) {
4193 for (
unsigned i = FT->getNumParams(); i != NumActualArgs; ++i, ++AI) {
4195 Value *NewArg = *AI;
4196 if (PTy != (*AI)->getType()) {
4202 Args.push_back(NewArg);
4215 assert((ArgAttrs.
size() == FT->getNumParams() || FT->isVarArg()) &&
4216 "missing argument attributes");
4221 Call.getOperandBundlesAsDefs(OpBundles);
4226 II->getUnwindDest(), Args, OpBundles);
4230 cast<CallInst>(Caller)->getTailCallKind());
4237 NewCall->
copyMetadata(*Caller, {LLVMContext::MD_prof});
4242 if (OldRetTy !=
NV->getType() && !
Caller->use_empty()) {
4243 if (!
NV->getType()->isVoidTy()) {
4245 NC->setDebugLoc(
Caller->getDebugLoc());
4248 assert(OptInsertPt &&
"No place to insert cast");
4256 if (!
Caller->use_empty())
4258 else if (
Caller->hasValueHandle()) {
4259 if (OldRetTy ==
NV->getType())
4274InstCombinerImpl::transformCallThroughTrampoline(
CallBase &Call,
4281 if (
Attrs.hasAttrSomewhere(Attribute::Nest))
4289 unsigned NestArgNo = 0;
4290 Type *NestTy =
nullptr;
4295 E = NestFTy->param_end();
4296 I != E; ++NestArgNo, ++
I) {
4307 std::vector<Value*> NewArgs;
4308 std::vector<AttributeSet> NewArgAttrs;
4309 NewArgs.reserve(
Call.arg_size() + 1);
4310 NewArgAttrs.reserve(
Call.arg_size());
4317 auto I =
Call.arg_begin(), E =
Call.arg_end();
4319 if (ArgNo == NestArgNo) {
4322 if (NestVal->
getType() != NestTy)
4324 NewArgs.push_back(NestVal);
4325 NewArgAttrs.push_back(NestAttr);
4332 NewArgs.push_back(*
I);
4333 NewArgAttrs.push_back(
Attrs.getParamAttrs(ArgNo));
4344 std::vector<Type*> NewTypes;
4345 NewTypes.reserve(FTy->getNumParams()+1);
4352 E = FTy->param_end();
4355 if (ArgNo == NestArgNo)
4357 NewTypes.push_back(NestTy);
4363 NewTypes.push_back(*
I);
4376 Attrs.getRetAttrs(), NewArgAttrs);
4379 Call.getOperandBundlesAsDefs(OpBundles);
4384 II->getUnwindDest(), NewArgs, OpBundles);
4385 cast<InvokeInst>(NewCaller)->setCallingConv(
II->getCallingConv());
4386 cast<InvokeInst>(NewCaller)->setAttributes(NewPAL);
4387 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(&Call)) {
4390 CBI->getIndirectDests(), NewArgs, OpBundles);
4391 cast<CallBrInst>(NewCaller)->setCallingConv(CBI->getCallingConv());
4392 cast<CallBrInst>(NewCaller)->setAttributes(NewPAL);
4395 cast<CallInst>(NewCaller)->setTailCallKind(
4396 cast<CallInst>(Call).getTailCallKind());
4397 cast<CallInst>(NewCaller)->setCallingConv(
4398 cast<CallInst>(Call).getCallingConv());
4399 cast<CallInst>(NewCaller)->setAttributes(NewPAL);
4410 Call.setCalledFunction(FTy, NestF);
amdgpu AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static SDValue foldBitOrderCrossLogicOp(SDNode *N, SelectionDAG &DAG)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static Type * getPromotedType(Type *Ty)
Return the specified type promoted as it would be to pass though a va_arg area.
static Instruction * createOverflowTuple(IntrinsicInst *II, Value *Result, Constant *Overflow)
Creates a result tuple for an overflow intrinsic II with a given Result and a constant Overflow value...
static IntrinsicInst * findInitTrampolineFromAlloca(Value *TrampMem)
static bool removeTriviallyEmptyRange(IntrinsicInst &EndI, InstCombinerImpl &IC, std::function< bool(const IntrinsicInst &)> IsStart)
static bool inputDenormalIsDAZ(const Function &F, const Type *Ty)
static Instruction * reassociateMinMaxWithConstantInOperand(IntrinsicInst *II, InstCombiner::BuilderTy &Builder)
If this min/max has a matching min/max operand with a constant, try to push the constant operand into...
static bool signBitMustBeTheSame(Value *Op0, Value *Op1, const SimplifyQuery &SQ)
Return true if two values Op0 and Op1 are known to have the same sign.
static Instruction * moveAddAfterMinMax(IntrinsicInst *II, InstCombiner::BuilderTy &Builder)
Try to canonicalize min/max(X + C0, C1) as min/max(X, C1 - C0) + C0.
static Instruction * simplifyInvariantGroupIntrinsic(IntrinsicInst &II, InstCombinerImpl &IC)
This function transforms launder.invariant.group and strip.invariant.group like: launder(launder(x)) ...
static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E, unsigned NumOperands)
static std::optional< bool > getKnownSign(Value *Op, const SimplifyQuery &SQ)
static cl::opt< unsigned > GuardWideningWindow("instcombine-guard-widening-window", cl::init(3), cl::desc("How wide an instruction window to bypass looking for " "another guard"))
static bool hasUndefSource(AnyMemTransferInst *MI)
Recognize a memcpy/memmove from a trivially otherwise unused alloca.
static Instruction * foldShuffledIntrinsicOperands(IntrinsicInst *II, InstCombiner::BuilderTy &Builder)
If all arguments of the intrinsic are unary shuffles with the same mask, try to shuffle after the int...
static Instruction * factorizeMinMaxTree(IntrinsicInst *II)
Reduce a sequence of min/max intrinsics with a common operand.
static Value * simplifyNeonTbl1(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Convert a table lookup to shufflevector if the mask is constant.
static Instruction * foldClampRangeOfTwo(IntrinsicInst *II, InstCombiner::BuilderTy &Builder)
If we have a clamp pattern like max (min X, 42), 41 – where the output can only be one of two possibl...
static Value * simplifyReductionOperand(Value *Arg, bool CanReorderLanes)
static IntrinsicInst * findInitTrampolineFromBB(IntrinsicInst *AdjustTramp, Value *TrampMem)
static std::optional< bool > getKnownSignOrZero(Value *Op, const SimplifyQuery &SQ)
static Instruction * foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC)
static Instruction * foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC)
static IntrinsicInst * findInitTrampoline(Value *Callee)
static FCmpInst::Predicate fpclassTestIsFCmp0(FPClassTest Mask, const Function &F, Type *Ty)
static Value * reassociateMinMaxWithConstants(IntrinsicInst *II, IRBuilderBase &Builder, const SimplifyQuery &SQ)
If this min/max has a constant operand and an operand that is a matching min/max with a constant oper...
static CallInst * canonicalizeConstantArg0ToArg1(CallInst &Call)
This file provides internal interfaces used to implement the InstCombine.
This file provides the interface for the instcombine pass implementation.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the SmallBitVector class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
static bool inputDenormalIsIEEE(const Function &F, const Type *Ty)
Return true if it's possible to assume IEEE treatment of input denormals in F for Val.
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, bool IgnoreLocals=false)
Returns a bitmask that should be unconditionally applied to the ModRef info of a memory location.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
APInt usub_ov(const APInt &RHS, bool &Overflow) const
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
APInt uadd_sat(const APInt &RHS) const
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
static APSInt getMaxValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
This class represents any memset intrinsic.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
void updateAffectedValues(AssumeInst *CI)
Update the cache of values being affected by this assumption (i.e.
bool overlaps(const AttributeMask &AM) const
Return true if the builder has any attribute that's in the specified builder.
AttributeSet getFnAttrs() const
The function attributes are returned.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
bool isEmpty() const
Return true if there are no attributes.
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the attribute exists for the given argument.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
AttributeSet removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attributes from this set.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM Basic Block Representation.
InstListType::reverse_iterator reverse_iterator
InstListType::iterator iterator
Instruction iterators...
bool isSigned() const
Whether the intrinsic is signed or unsigned.
Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
static BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, FastMathFlags FMF, const Twine &Name="")
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO, const Twine &Name="", InsertPosition InsertBefore=nullptr)
static BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setCallingConv(CallingConv::ID CC)
MaybeAlign getRetAlign() const
Extract the alignment of the return value.
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
bool doesNotThrow() const
Determine if the call cannot unwind.
void addRetAttr(Attribute::AttrKind Kind)
Adds the attribute to the return value.
Value * getArgOperand(unsigned i) const
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
static CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, InsertPosition InsertPt=nullptr)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
static CallBase * removeOperandBundle(CallBase *CB, uint32_t ID, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle ID removed.
unsigned arg_size() const
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
void setTailCallKind(TailCallKind TCK)
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
bool isMustTailCall() const
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op.
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Predicate getUnorderedPredicate() const
static ConstantAggregateZero * get(Type *Ty)
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getNeg(Constant *C, bool HasNSW=false)
static Constant * getInfinity(Type *Ty, bool Negative=false)
static Constant * getZero(Type *Ty, bool Negative=false)
This is the shared class of boolean and integer constants.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
static ConstantInt * getTrue(LLVMContext &Context)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
static ConstantInt * getBool(LLVMContext &Context, bool V)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
This class represents a range of values.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other? NOTE: false does not mean that inverse pr...
static Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
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...
static Constant * getAllOnesValue(Type *Ty)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
This class represents an Operation in the Expression.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
This class represents an extension of floating point types.
Convenience struct for specifying and reasoning about fast-math flags.
void setNoSignedZeros(bool B=true)
bool allowReassoc() const
Flag queries.
An instruction for ordering other memory operations.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this fence instruction.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this fence instruction.
Class to represent function types.
Type::subtype_iterator param_iterator
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
bool isConvergent() const
Determine if the call is convergent.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
AttributeList getAttributes() const
Return the attribute list for this Function.
bool doesNotThrow() const
Determine if the function cannot unwind.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Represents calls to the gc.relocate intrinsic.
Value * getBasePtr() const
unsigned getBasePtrIndex() const
The index into the associate statepoint's argument list which contains the base pointer of the pointe...
Value * getDerivedPtr() const
unsigned getDerivedPtrIndex() const
The index into the associate statepoint's argument list which contains the pointer whose relocation t...
Represents a gc.statepoint intrinsic call.
std::vector< const GCRelocateInst * > getGCRelocates() const
Get list of all gc reloactes linked to this statepoint May contain several relocations for the same b...
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
PointerType * getType() const
Global values are always pointers.
Common base class shared among various IRBuilders.
Value * CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
Value * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Value * CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
CallInst * CreateAndReduce(Value *Src)
Create a vector int AND reduction intrinsic of the source vector.
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
ConstantInt * getTrue()
Get the constant value for i1 true.
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Value * CreateFNegFMF(Value *V, Instruction *FMFSource, const Twine &Name="")
Copy fast-math-flags from an instruction rather than using the builder's default FMF.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
InvokeInst * CreateInvoke(FunctionType *Ty, Value *Callee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > OpBundles, const Twine &Name="")
Create an invoke instruction.
Value * CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
CallInst * CreateAddReduce(Value *Src)
Create a vector int add reduction intrinsic of the source vector.
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Value * CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
CallInst * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateBitOrPointerCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateNot(Value *V, const Twine &Name="")
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
ConstantInt * getFalse()
Get the constant value for i1 false.
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Value * CreateElementCount(Type *DstType, ElementCount EC)
Create an expression which evaluates to the number of elements in EC at runtime.
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Value * CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Instruction * FoldOpIntoSelect(Instruction &Op, SelectInst *SI, bool FoldWithMultiUse=false)
Given an instruction with a select as one operand and a constant as the other operand,...
KnownFPClass computeKnownFPClass(Value *Val, FastMathFlags FMF, FPClassTest Interested=fcAllFlags, const Instruction *CtxI=nullptr, unsigned Depth=0) const
bool SimplifyDemandedBits(Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, unsigned Depth=0) override
This form of SimplifyDemandedBits simplifies the specified instruction operand if possible,...
Value * SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &PoisonElts, unsigned Depth=0, bool AllowMultipleUsers=false) override
The specified value produces a vector with any number of elements.
Instruction * SimplifyAnyMemSet(AnyMemSetInst *MI)
Constant * getLosslessUnsignedTrunc(Constant *C, Type *TruncTy)
Instruction * visitFree(CallInst &FI, Value *FreedOp)
Instruction * visitCallBrInst(CallBrInst &CBI)
Instruction * eraseInstFromFunction(Instruction &I) override
Combiner aware instruction erasure.
Instruction * visitFenceInst(FenceInst &FI)
Instruction * visitInvokeInst(InvokeInst &II)
Constant * getLosslessSignedTrunc(Constant *C, Type *TruncTy)
bool SimplifyDemandedInstructionBits(Instruction &Inst)
Tries to simplify operands to an integer instruction based on its demanded bits.
void CreateNonTerminatorUnreachable(Instruction *InsertAt)
Create and insert the idiom we use to indicate a block is unreachable without having to rewrite the C...
Instruction * visitVAEndInst(VAEndInst &I)
Instruction * matchBSwapOrBitReverse(Instruction &I, bool MatchBSwaps, bool MatchBitReversals)
Given an initial instruction, check to see if it is the root of a bswap/bitreverse idiom.
Instruction * visitAllocSite(Instruction &FI)
Instruction * SimplifyAnyMemTransfer(AnyMemTransferInst *MI)
OverflowResult computeOverflow(Instruction::BinaryOps BinaryOp, bool IsSigned, Value *LHS, Value *RHS, Instruction *CxtI) const
Instruction * visitCallInst(CallInst &CI)
CallInst simplification.
bool isFreeToInvert(Value *V, bool WillInvertAllUses, bool &DoesConsume)
Return true if the specified value is free to invert (apply ~ to).
DominatorTree & getDominatorTree() const
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, unsigned Depth=0, const Instruction *CxtI=nullptr)
Instruction * InsertNewInstBefore(Instruction *New, BasicBlock::iterator Old)
Inserts an instruction New before instruction Old.
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
void replaceUse(Use &U, Value *NewValue)
Replace use and add the previously used value to the worklist.
InstructionWorklist & Worklist
A worklist of the instructions that need to be simplified.
std::optional< Instruction * > targetInstCombineIntrinsic(IntrinsicInst &II)
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
AssumptionCache & getAssumptionCache() const
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth=0, const Instruction *CxtI=nullptr) const
OptimizationRemarkEmitter & ORE
Value * getFreelyInverted(Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume)
const SimplifyQuery & getSimplifyQuery() const
unsigned ComputeMaxSignificantBits(const Value *Op, unsigned Depth=0, const Instruction *CxtI=nullptr) const
void pushUsersToWorkList(Instruction &I)
When an instruction is simplified, add all users of the instruction to the work lists because they mi...
void add(Instruction *I)
Add instruction to the worklist.
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction,...
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
const Instruction * getPrevNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the previous non-debug instruction in the same basic block as 'this',...
const Function * getFunction() const
Return the function this instruction belongs to.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
std::optional< InstListType::iterator > getInsertionPointAfterDef()
Get the first insertion point at which the result of this instruction is defined.
bool isIdenticalTo(const Instruction *I) const LLVM_READONLY
Return true if the specified instruction is exactly identical to the current one.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
LibCallSimplifier - This class implements a collection of optimizations that replace well formed call...
An instruction for reading from memory.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
ICmpInst::Predicate getPredicate() const
Returns the comparison predicate underlying the intrinsic.
bool isSigned() const
Whether the intrinsic is signed or unsigned.
A Module instance is used to store all the information related to an LLVM module.
A container for an operand bundle being viewed as a set of values rather than a set of uses.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Represents a saturating add/sub intrinsic.
This class represents the LLVM 'select' instruction.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, Instruction *MDFrom=nullptr)
This instruction constructs a fixed permutation of two input vectors.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
bool test(unsigned Idx) const
bool all() const
Returns true if all bits are set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
void setVolatile(bool V)
Specify whether this is a volatile store or not.
void setAlignment(Align Align)
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this store instruction.
Class to represent struct types.
static bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
Provides information about what library functions are available for the current target.
This class represents a truncation of integer types.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
const fltSemantics & getFltSemantics() const
bool isPointerTy() const
True if this is an instance of PointerType.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isStructTy() const
True if this is an instance of StructType.
Type * getWithNewBitWidth(unsigned NewBitWidth) const
Given an integer or vector type, change the lane bitwidth to NewBitwidth, whilst keeping the old numb...
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isVoidTy() const
Return true if this is 'void'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static UnaryOperator * CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO, const Twine &Name="", InsertPosition InsertBefore=nullptr)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
This represents the llvm.va_end intrinsic.
static void ValueIsDeleted(Value *V)
static void ValueIsRAUWd(Value *Old, Value *New)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
static constexpr uint64_t MaximumAlignment
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
bool hasOneUse() const
Return true if there is exactly one use of this value.
iterator_range< user_iterator > users()
static void dropDroppableUse(Use &U)
Remove the droppable use U.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVMContext & getContext() const
All values hold a context through their type.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Represents an op.with.overflow intrinsic.
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ C
The default llvm calling convention, compatible with C.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
OverflowingBinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWNeg(const ValTy &V)
Matches a 'Neg' as 'sub nsw 0, V'.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
apint_match m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
OneUse_match< T > m_OneUse(const T &SubPattern)
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
match_combine_and< class_match< Constant >, match_unless< constantexpr_match > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
match_combine_or< match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true >, MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > >, match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true >, MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > > > m_c_MaxOrMin(const LHS &L, const RHS &R)
class_match< UnaryOperator > m_UnOp()
Match an arbitrary unary operation and ignore it.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap >, DisjointOr_match< LHS, RHS > > m_NSWAddLike(const LHS &L, const RHS &R)
Match either "add nsw" or "or disjoint".
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Exact_match< T > m_Exact(const T &SubPattern)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_VecReverse(const Opnd0 &Op0)
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
match_combine_or< match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty >, MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > >, match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty >, MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > > > m_MaxOrMin(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap >, DisjointOr_match< LHS, RHS > > m_NUWAddLike(const LHS &L, const RHS &R)
Match either "add nuw" or "or disjoint".
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
@ System
Synchronized with respect to all concurrently executing threads.
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
SmallVector< DbgVariableRecord * > getDVRAssignmentMarkers(const Instruction *Inst)
initializer< Ty > init(const Ty &Val)
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
cl::opt< bool > EnableKnowledgeRetention
Intrinsic::ID getInverseMinMaxIntrinsic(Intrinsic::ID MinMaxID)
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
@ NeverOverflows
Never overflows.
@ AlwaysOverflowsHigh
Always overflows in the direction of signed/unsigned max value.
@ AlwaysOverflowsLow
Always overflows in the direction of signed/unsigned min value.
@ MayOverflow
May or may not overflow.
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
Value * simplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FMul, fold the result or return null.
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
APInt possiblyDemandedEltsInMask(Value *Mask)
Given a mask vector of the form <Y x i1>, return an APInt (of bitwidth Y) for each lane which may be ...
RetainedKnowledge simplifyRetainedKnowledge(AssumeInst *Assume, RetainedKnowledge RK, AssumptionCache *AC, DominatorTree *DT)
canonicalize the RetainedKnowledge RK.
bool isRemovableAlloc(const CallBase *V, const TargetLibraryInfo *TLI)
Return true if this is a call to an allocation function that does not have side effects that we are r...
Value * 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.
Value * getAllocAlignment(const CallBase *V, const TargetLibraryInfo *TLI)
Gets the alignment argument for an aligned_alloc-like function, using either built-in knowledge based...
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
Value * simplifyCall(CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q)
Given a callsite, callee, and arguments, fold the result or return null.
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Instruction *I=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
bool isAssumeWithEmptyBundle(const AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
RetainedKnowledge getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI)
This extracts the Knowledge from an element of an operand bundle.
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
bool isSplatValue(const Value *V, int Index=-1, unsigned Depth=0)
Return true if each element of the vector value V is poisoned or equal to every other non-poisoned el...
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2019 maximumNumber semantics.
FPClassTest fneg(FPClassTest Mask)
Return the test mask which returns true if the value's sign bit is flipped.
SelectPatternFlavor
Specific patterns of select instructions we can match.
@ SPF_ABS
Floating point maxnum.
@ SPF_NABS
Absolute value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool isModSet(const ModRefInfo MRI)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
bool isAtLeastOrStrongerThan(AtomicOrdering AO, AtomicOrdering Other)
AssumeInst * buildAssumeFromKnowledge(ArrayRef< RetainedKnowledge > Knowledge, Instruction *CtxI, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Build and return a new assume created from the provided knowledge if the knowledge in the assume is f...
FPClassTest inverse_fabs(FPClassTest Mask)
Return the test mask which returns true after fabs is applied to the value.
bool maskIsAllOneOrUndef(Value *Mask)
Given a mask vector of i1, Return true if all of the elements of this predicate mask are known to be ...
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.
bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
constexpr int PoisonMaskElem
@ Mod
The access may modify the value stored in memory.
Value * simplifyFMAFMul(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for the multiplication of a FMA, fold the result or return null.
Value * simplifyConstrainedFPCall(CallBase *Call, const SimplifyQuery &Q)
Given a constrained FP intrinsic call, tries to compute its simplified version.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE-754 2019 minimumNumber semantics.
ConstantRange computeConstantRangeIncludingKnownBits(const WithCache< const Value * > &V, bool ForSigned, const SimplifyQuery &SQ)
Combine constant ranges from computeConstantRange() and computeKnownBits().
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Value * getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI)
If this if a call to a free function, return the freed operand.
bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
constexpr unsigned BitWidth
bool isDereferenceablePointer(const Value *V, Type *Ty, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Return true if this is always a dereferenceable pointer.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
std::optional< APInt > getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, function_ref< const Value *(const Value *)> Mapper=[](const Value *V) { return V;})
Return the size of the requested allocation.
std::optional< bool > computeKnownFPSignBit(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return false if we can prove that the specified FP value's sign bit is 0.
unsigned Log2(Align A)
Returns the log2 of the alignment.
bool maskContainsAllOneOrUndef(Value *Mask)
Given a mask vector of i1, Return true if any of the elements of this predicate mask are known to be ...
uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the largest uint64_t less than or equal to Value and is Skew mod Align.
std::optional< bool > isImpliedByDomCondition(const Value *Cond, const Instruction *ContextI, const DataLayout &DL)
Return the boolean condition value in the context of the given instruction if it is known based on do...
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 minimum semantics.
bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW=false, bool AllowPoison=true)
Return true if the two given values are negation.
bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the give value is known to be non-negative.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
This struct is a compact representation of a valid (non-zero power of two) alignment.
@ IEEE
IEEE-754 denormal numbers preserved.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
unsigned getBitWidth() const
Get the bit width of this value.
bool isNonZero() const
Returns true if this value is known to be non-zero.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
bool isNegative() const
Returns true if this value is known to be negative.
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
unsigned countMinPopulation() const
Returns the number of bits known to be one.
bool isAllOnes() const
Returns true if value is all one bits.
FPClassTest KnownFPClasses
Floating-point classes the value could be one of.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
A lightweight accessor for an operand bundle meant to be passed around by value.
StringRef getTagName() const
Return the tag of this operand bundle as a string.
Represent one information held inside an operand bundle of an llvm.assume.
Attribute::AttrKind AttrKind
SelectPatternFlavor Flavor
SimplifyQuery getWithInstruction(const Instruction *I) const