28#ifndef LLVM_IR_PATTERNMATCH_H
29#define LLVM_IR_PATTERNMATCH_H
47namespace PatternMatch {
49template <
typename Val,
typename Pattern>
bool match(Val *V,
const Pattern &
P) {
62 template <
typename OpTy>
bool match(OpTy *V) {
76 template <
typename OpTy>
bool match(OpTy *V) {
77 auto *
I = dyn_cast<FPMathOperator>(V);
88 template <
typename ITy>
bool match(ITy *V) {
return isa<Class>(V); }
109 if (isa<UndefValue>(V))
112 const auto *CA = dyn_cast<ConstantAggregate>(V);
123 for (
const Value *
Op : CA->operand_values()) {
124 if (isa<UndefValue>(
Op))
127 const auto *CA = dyn_cast<ConstantAggregate>(
Op);
130 if (Seen.
insert(CA).second)
140 while (!Worklist.
empty()) {
146 template <
typename ITy>
bool match(ITy *V) {
return check(V); }
178 template <
typename ITy>
bool match(ITy *V) {
179 auto *
C = dyn_cast<Constant>(V);
180 return C && (isa<ConstantExpr>(
C) ||
C->containsConstantExpression());
199 template <
typename ITy>
bool match(ITy *V) {
return !
M.match(V); }
214 template <
typename ITy>
bool match(ITy *V) {
229 template <
typename ITy>
bool match(ITy *V) {
238template <
typename LTy,
typename RTy>
244template <
typename LTy,
typename RTy>
256 template <
typename ITy>
bool match(ITy *V) {
257 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
258 Res = &CI->getValue();
261 if (V->getType()->isVectorTy())
262 if (
const auto *
C = dyn_cast<Constant>(V))
264 dyn_cast_or_null<ConstantInt>(
C->getSplatValue(
AllowPoison))) {
265 Res = &CI->getValue();
281 template <
typename ITy>
bool match(ITy *V) {
282 if (
auto *CI = dyn_cast<ConstantFP>(V)) {
283 Res = &CI->getValueAPF();
286 if (V->getType()->isVectorTy())
287 if (
const auto *
C = dyn_cast<Constant>(V))
289 dyn_cast_or_null<ConstantFP>(
C->getSplatValue(
AllowPoison))) {
290 Res = &CI->getValueAPF();
332 template <
typename ITy>
bool match(ITy *V) {
333 if (
const auto *CI = dyn_cast<ConstantInt>(V)) {
334 const APInt &CIV = CI->getValue();
336 return CIV ==
static_cast<uint64_t>(Val);
355template <
typename Predicate,
typename ConstantVal,
bool AllowPoison>
359 if (
const auto *CV = dyn_cast<ConstantVal>(V))
360 return this->isValue(CV->getValue());
361 if (
const auto *VTy = dyn_cast<VectorType>(V->getType())) {
362 if (
const auto *
C = dyn_cast<Constant>(V)) {
363 if (
const auto *CV = dyn_cast_or_null<ConstantVal>(
C->getSplatValue()))
364 return this->isValue(CV->getValue());
367 auto *FVTy = dyn_cast<FixedVectorType>(VTy);
372 unsigned NumElts = FVTy->getNumElements();
373 assert(NumElts != 0 &&
"Constant vector with no elements?");
374 bool HasNonPoisonElements =
false;
375 for (
unsigned i = 0; i != NumElts; ++i) {
376 Constant *Elt =
C->getAggregateElement(i);
379 if (AllowPoison && isa<PoisonValue>(Elt))
381 auto *CV = dyn_cast<ConstantVal>(Elt);
382 if (!CV || !this->isValue(CV->getValue()))
384 HasNonPoisonElements =
true;
386 return HasNonPoisonElements;
392 template <
typename ITy>
bool match(ITy *V) {
395 *
Res = cast<Constant>(V);
403template <
typename Predicate,
bool AllowPoison = true>
407template <
typename Predicate>
413template <
typename Predicate>
struct api_pred_ty :
public Predicate {
418 template <
typename ITy>
bool match(ITy *V) {
419 if (
const auto *CI = dyn_cast<ConstantInt>(V))
420 if (this->isValue(CI->getValue())) {
421 Res = &CI->getValue();
424 if (V->getType()->isVectorTy())
425 if (
const auto *
C = dyn_cast<Constant>(V))
426 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
427 C->getSplatValue(
true)))
428 if (this->isValue(CI->getValue())) {
429 Res = &CI->getValue();
440template <
typename Predicate>
struct apf_pred_ty :
public Predicate {
445 template <
typename ITy>
bool match(ITy *V) {
446 if (
const auto *CI = dyn_cast<ConstantFP>(V))
447 if (this->isValue(CI->getValue())) {
448 Res = &CI->getValue();
451 if (V->getType()->isVectorTy())
452 if (
const auto *
C = dyn_cast<Constant>(V))
453 if (
auto *CI = dyn_cast_or_null<ConstantFP>(
454 C->getSplatValue(
true)))
455 if (this->isValue(CI->getValue())) {
456 Res = &CI->getValue();
604 template <
typename ITy>
bool match(ITy *V) {
605 auto *
C = dyn_cast<Constant>(V);
802 template <
typename ITy>
bool match(ITy *V) {
803 if (
auto *CV = dyn_cast<Class>(V)) {
871 template <
typename ITy>
bool match(ITy *V) {
return V ==
Val; }
884 template <
typename ITy>
bool match(ITy *
const V) {
return V ==
Val; }
905 template <
typename ITy>
bool match(ITy *V) {
906 if (
const auto *CFP = dyn_cast<ConstantFP>(V))
907 return CFP->isExactlyValue(
Val);
908 if (V->getType()->isVectorTy())
909 if (
const auto *
C = dyn_cast<Constant>(V))
910 if (
auto *CFP = dyn_cast_or_null<ConstantFP>(
C->getSplatValue()))
911 return CFP->isExactlyValue(
Val);
928 template <
typename ITy>
bool match(ITy *V) {
929 if (
const auto *CV = dyn_cast<ConstantInt>(V))
931 VR = CV->getZExtValue();
945 template <
typename ITy>
bool match(ITy *V) {
946 const auto *CI = dyn_cast<ConstantInt>(V);
947 if (!CI && V->getType()->isVectorTy())
948 if (
const auto *
C = dyn_cast<Constant>(V))
949 CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue(AllowPoison));
960 template <
typename ITy>
bool match(ITy *V) {
961 const auto *CI = dyn_cast<ConstantInt>(V);
962 if (!CI && V->getType()->isVectorTy())
963 if (
const auto *
C = dyn_cast<Constant>(V))
964 CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue(AllowPoison));
966 return CI && CI->getValue() ==
Val;
998 template <
typename ITy>
bool match(ITy *V) {
999 const auto *BB = dyn_cast<BasicBlock>(V);
1000 return BB && BB ==
Val;
1021template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
1030 template <
typename OpTy>
bool match(OpTy *V) {
1031 if (
auto *
I = dyn_cast<BinaryOperator>(V))
1032 return (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
1033 (Commutable &&
L.match(
I->getOperand(1)) &&
1034 R.match(
I->getOperand(0)));
1039template <
typename LHS,
typename RHS>
1053 template <
typename OpTy>
bool match(OpTy *V) {
1054 if (
auto *
I = dyn_cast<UnaryOperator>(V))
1055 return X.match(
I->getOperand(0));
1068template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
1069 bool Commutable =
false>
1078 template <
typename OpTy>
inline bool match(
unsigned Opc, OpTy *V) {
1079 if (V->getValueID() == Value::InstructionVal + Opc) {
1080 auto *
I = cast<BinaryOperator>(V);
1081 return (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
1082 (Commutable &&
L.match(
I->getOperand(1)) &&
1083 R.match(
I->getOperand(0)));
1088 template <
typename OpTy>
bool match(OpTy *V) {
return match(Opcode, V); }
1091template <
typename LHS,
typename RHS>
1097template <
typename LHS,
typename RHS>
1103template <
typename LHS,
typename RHS>
1109template <
typename LHS,
typename RHS>
1119 template <
typename OpTy>
bool match(OpTy *V) {
1120 auto *FPMO = dyn_cast<FPMathOperator>(V);
1124 if (FPMO->getOpcode() == Instruction::FNeg)
1125 return X.match(FPMO->getOperand(0));
1127 if (FPMO->getOpcode() == Instruction::FSub) {
1128 if (FPMO->hasNoSignedZeros()) {
1138 return X.match(FPMO->getOperand(1));
1151template <
typename RHS>
1157template <
typename LHS,
typename RHS>
1163template <
typename LHS,
typename RHS>
1169template <
typename LHS,
typename RHS>
1175template <
typename LHS,
typename RHS>
1181template <
typename LHS,
typename RHS>
1187template <
typename LHS,
typename RHS>
1193template <
typename LHS,
typename RHS>
1199template <
typename LHS,
typename RHS>
1205template <
typename LHS,
typename RHS>
1211template <
typename LHS,
typename RHS>
1217template <
typename LHS,
typename RHS>
1223template <
typename LHS,
typename RHS>
1229template <
typename LHS,
typename RHS>
1235template <
typename LHS,
typename RHS>
1241template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
1242 unsigned WrapFlags = 0,
bool Commutable =
false>
1250 template <
typename OpTy>
bool match(OpTy *V) {
1251 if (
auto *
Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1252 if (
Op->getOpcode() != Opcode)
1255 !
Op->hasNoUnsignedWrap())
1258 !
Op->hasNoSignedWrap())
1260 return (
L.match(
Op->getOperand(0)) &&
R.match(
Op->getOperand(1))) ||
1261 (Commutable &&
L.match(
Op->getOperand(1)) &&
1262 R.match(
Op->getOperand(0)));
1268template <
typename LHS,
typename RHS>
1276template <
typename LHS,
typename RHS>
1284template <
typename LHS,
typename RHS>
1292template <
typename LHS,
typename RHS>
1301template <
typename LHS,
typename RHS>
1310template <
typename LHS,
typename RHS>
1319template <
typename LHS,
typename RHS>
1327template <
typename LHS,
typename RHS>
1335template <
typename LHS,
typename RHS>
1344template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
1352 template <
typename OpTy>
bool match(OpTy *V) {
1358template <
typename LHS,
typename RHS>
1364template <
typename LHS,
typename RHS,
bool Commutable = false>
1371 template <
typename OpTy>
bool match(OpTy *V) {
1372 if (
auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1373 assert(PDI->getOpcode() == Instruction::Or &&
"Only or can be disjoint");
1374 if (!PDI->isDisjoint())
1376 return (
L.match(PDI->getOperand(0)) &&
R.match(PDI->getOperand(1))) ||
1377 (Commutable &&
L.match(PDI->getOperand(1)) &&
1378 R.match(PDI->getOperand(0)));
1384template <
typename LHS,
typename RHS>
1389template <
typename LHS,
typename RHS>
1396template <
typename LHS,
typename RHS>
1404template <
typename LHS,
typename RHS>
1414template <
typename LHS,
typename RHS>
1426template <
typename LHS_t,
typename RHS_t,
typename Predicate,
1427 bool Commutable =
false>
1434 template <
typename OpTy>
bool match(OpTy *V) {
1435 if (
auto *
I = dyn_cast<Instruction>(V))
1436 return this->isOpType(
I->getOpcode()) &&
1437 ((
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
1438 (Commutable &&
L.match(
I->getOperand(1)) &&
1439 R.match(
I->getOperand(0))));
1450 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1456 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1468 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1474 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1479template <
typename LHS,
typename RHS>
1486template <
typename LHS,
typename RHS>
1493template <
typename LHS,
typename RHS>
1500template <
typename LHS,
typename RHS>
1507template <
typename LHS,
typename RHS>
1514template <
typename LHS,
typename RHS>
1521template <
typename LHS,
typename RHS>
1535 template <
typename OpTy>
bool match(OpTy *V) {
1536 if (
auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1537 return PEO->isExact() &&
SubPattern.match(V);
1550template <
typename LHS_t,
typename RHS_t,
typename Class,
typename PredicateTy,
1551 bool Commutable =
false>
1564 template <
typename OpTy>
bool match(OpTy *V) {
1565 if (
auto *
I = dyn_cast<Class>(V)) {
1566 if (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) {
1570 }
else if (Commutable &&
L.match(
I->getOperand(1)) &&
1571 R.match(
I->getOperand(0))) {
1581template <
typename LHS,
typename RHS>
1587template <
typename LHS,
typename RHS>
1593template <
typename LHS,
typename RHS>
1599template <
typename LHS,
typename RHS>
1605template <
typename LHS,
typename RHS>
1611template <
typename LHS,
typename RHS>
1619template <
typename LHS_t,
typename RHS_t,
typename Class,
typename PredicateTy,
1620 bool Commutable =
false>
1629 template <
typename OpTy>
bool match(OpTy *V) {
1630 if (
auto *
I = dyn_cast<Class>(V)) {
1631 if (
I->getPredicate() ==
Predicate &&
L.match(
I->getOperand(0)) &&
1632 R.match(
I->getOperand(1)))
1634 if constexpr (Commutable) {
1635 if (
I->getPredicate() == Class::getSwappedPredicate(
Predicate) &&
1636 L.match(
I->getOperand(1)) &&
R.match(
I->getOperand(0)))
1645template <
typename LHS,
typename RHS>
1652template <
typename LHS,
typename RHS>
1659template <
typename LHS,
typename RHS>
1666template <
typename LHS,
typename RHS>
1683 template <
typename OpTy>
bool match(OpTy *V) {
1684 if (V->getValueID() == Value::InstructionVal + Opcode) {
1685 auto *
I = cast<Instruction>(V);
1686 return Op1.match(
I->getOperand(0));
1699 template <
typename OpTy>
bool match(OpTy *V) {
1700 if (V->getValueID() == Value::InstructionVal + Opcode) {
1701 auto *
I = cast<Instruction>(V);
1702 return Op1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1));
1709template <
typename T0,
typename T1,
typename T2,
unsigned Opcode>
1718 template <
typename OpTy>
bool match(OpTy *V) {
1719 if (V->getValueID() == Value::InstructionVal + Opcode) {
1720 auto *
I = cast<Instruction>(V);
1721 return Op1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1)) &&
1722 Op3.match(
I->getOperand(2));
1738 template <
int Idx,
int Last>
1740 return match_operands<Idx, Idx>(
I) && match_operands<Idx + 1, Last>(
I);
1743 template <
int Idx,
int Last>
1745 return std::get<Idx>(
Operands).match(
I->getOperand(
Idx));
1748 template <
typename OpTy>
bool match(OpTy *V) {
1749 if (V->getValueID() == Value::InstructionVal + Opcode) {
1750 auto *
I = cast<Instruction>(V);
1751 return I->getNumOperands() ==
sizeof...(OperandTypes) &&
1759template <
typename Cond,
typename LHS,
typename RHS>
1767template <
int64_t L,
int64_t R,
typename Cond>
1769 Instruction::Select>
1771 return m_Select(
C, m_ConstantInt<L>(), m_ConstantInt<R>());
1775template <
typename OpTy>
1781template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1789template <
typename Val_t,
typename Idx_t>
1804 template <
typename OpTy>
bool match(OpTy *V) {
1805 if (
auto *
I = dyn_cast<ShuffleVectorInst>(V)) {
1806 return Op1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1)) &&
1807 Mask.match(
I->getShuffleMask());
1824 return all_of(Mask, [](
int Elem) {
return Elem == 0 || Elem == -1; });
1838 const auto *
First =
find_if(Mask, [](
int Elem) {
return Elem != -1; });
1839 if (
First == Mask.end())
1843 [
First](
int Elem) {
return Elem == *
First || Elem == -1; });
1854 template <
typename OpTy>
bool match(OpTy *V) {
1855 auto *
GEP = dyn_cast<GEPOperator>(V);
1856 return GEP &&
GEP->getSourceElementType()->isIntegerTy(8) &&
1863template <
typename V1_t,
typename V2_t>
1869template <
typename V1_t,
typename V2_t,
typename Mask_t>
1871m_Shuffle(
const V1_t &v1,
const V2_t &v2,
const Mask_t &mask) {
1876template <
typename OpTy>
1882template <
typename ValueOpTy,
typename Po
interOpTy>
1884m_Store(
const ValueOpTy &ValueOp,
const PointerOpTy &PointerOp) {
1890template <
typename... OperandTypes>
1891inline auto m_GEP(
const OperandTypes &...Ops) {
1892 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
1896template <
typename Po
interOpTy,
typename OffsetOpTy>
1898m_PtrAdd(
const PointerOpTy &PointerOp,
const OffsetOpTy &OffsetOp) {
1911 template <
typename OpTy>
bool match(OpTy *V) {
1912 if (
auto *O = dyn_cast<Operator>(V))
1913 return O->getOpcode() == Opcode &&
Op.match(O->getOperand(0));
1923 template <
typename OpTy>
bool match(OpTy *V) {
1924 if (
auto *
I = dyn_cast<Class>(V))
1925 return Op.match(
I->getOperand(0));
1937 template <
typename OpTy>
bool match(OpTy *V) {
1938 if (
auto *O = dyn_cast<Operator>(V))
1939 return O->getOpcode() == Instruction::PtrToInt &&
1942 Op.match(O->getOperand(0));
1952 template <
typename OpTy>
bool match(OpTy *V) {
1953 if (
auto *
I = dyn_cast<ZExtInst>(V))
1954 return I->hasNonNeg() &&
Op.match(
I->getOperand(0));
1964 template <
typename OpTy>
bool match(OpTy *V) {
1965 if (
auto *
I = dyn_cast<TruncInst>(V))
1966 return (
I->getNoWrapKind() & WrapFlags) == WrapFlags &&
1967 Op.match(
I->getOperand(0));
1973template <
typename OpTy>
1984 template <
typename OpTy>
bool match(OpTy *V) {
1985 auto *
I = dyn_cast<BitCastInst>(V);
1988 Type *SrcType =
I->getSrcTy();
1989 Type *DstType =
I->getType();
1994 if (
VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
1996 cast<VectorType>(DstType)->getElementCount())
1998 return Op.match(
I->getOperand(0));
2002template <
typename OpTy>
2008template <
typename OpTy>
2014template <
typename OpTy>
2021template <
typename OpTy>
2028template <
typename OpTy>
2034template <
typename OpTy>
2041template <
typename OpTy>
2047template <
typename OpTy>
2054template <
typename OpTy>
2060template <
typename OpTy>
2065template <
typename OpTy>
2070template <
typename OpTy>
2076template <
typename OpTy>
2083template <
typename OpTy>
2089template <
typename OpTy>
2096template <
typename OpTy>
2104template <
typename OpTy>
2109template <
typename OpTy>
2114template <
typename OpTy>
2119template <
typename OpTy>
2124template <
typename OpTy>
2129template <
typename OpTy>
2143 template <
typename OpTy>
bool match(OpTy *V) {
2144 if (
auto *BI = dyn_cast<BranchInst>(V))
2145 if (BI->isUnconditional()) {
2146 Succ = BI->getSuccessor(0);
2155template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
2161 brc_match(
const Cond_t &
C,
const TrueBlock_t &t,
const FalseBlock_t &f)
2164 template <
typename OpTy>
bool match(OpTy *V) {
2165 if (
auto *BI = dyn_cast<BranchInst>(V))
2166 if (BI->isConditional() &&
Cond.match(BI->getCondition()))
2167 return T.match(BI->getSuccessor(0)) &&
F.match(BI->getSuccessor(1));
2172template <
typename Cond_t>
2179template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
2181m_Br(
const Cond_t &
C,
const TrueBlock_t &
T,
const FalseBlock_t &
F) {
2189template <
typename CmpInst_t,
typename LHS_t,
typename RHS_t,
typename Pred_t,
2190 bool Commutable =
false>
2200 template <
typename OpTy>
bool match(OpTy *V) {
2201 if (
auto *
II = dyn_cast<IntrinsicInst>(V)) {
2208 return (
L.match(
LHS) &&
R.match(
RHS)) ||
2209 (Commutable &&
L.match(
RHS) &&
R.match(
LHS));
2213 auto *SI = dyn_cast<SelectInst>(V);
2216 auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
2221 auto *TrueVal = SI->getTrueValue();
2222 auto *FalseVal = SI->getFalseValue();
2223 auto *
LHS = Cmp->getOperand(0);
2224 auto *
RHS = Cmp->getOperand(1);
2225 if ((TrueVal !=
LHS || FalseVal !=
RHS) &&
2226 (TrueVal !=
RHS || FalseVal !=
LHS))
2228 typename CmpInst_t::Predicate Pred =
2229 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2231 if (!Pred_t::match(Pred))
2234 return (
L.match(
LHS) &&
R.match(
RHS)) ||
2235 (Commutable &&
L.match(
RHS) &&
R.match(
LHS));
2295template <
typename LHS,
typename RHS>
2301template <
typename LHS,
typename RHS>
2307template <
typename LHS,
typename RHS>
2313template <
typename LHS,
typename RHS>
2319template <
typename LHS,
typename RHS>
2339template <
typename LHS,
typename RHS>
2354template <
typename LHS,
typename RHS>
2369template <
typename LHS,
typename RHS>
2384template <
typename LHS,
typename RHS>
2393template <
typename ValTy>
2399template <
typename ValTy>
2411template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
2420 template <
typename OpTy>
bool match(OpTy *V) {
2421 Value *ICmpLHS, *ICmpRHS;
2426 Value *AddLHS, *AddRHS;
2431 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2432 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpLHS);
2436 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2437 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpRHS);
2443 if (XorExpr.match(ICmpLHS))
2444 return L.match(Op1) &&
R.match(ICmpRHS) &&
S.match(ICmpLHS);
2448 if (XorExpr.match(ICmpRHS))
2449 return L.match(Op1) &&
R.match(ICmpLHS) &&
S.match(ICmpRHS);
2458 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpLHS);
2463 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpRHS);
2474template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
2486 template <
typename OpTy>
bool match(OpTy *V) {
2488 if (
const auto *CI = dyn_cast<CallInst>(V))
2489 return Val.match(CI->getArgOperand(
OpI));
2495template <
unsigned OpI,
typename Opnd_t>
2506 template <
typename OpTy>
bool match(OpTy *V) {
2507 if (
const auto *CI = dyn_cast<CallInst>(V))
2508 if (
const auto *
F = CI->getCalledFunction())
2509 return F->getIntrinsicID() ==
ID;
2518template <
typename T0 = void,
typename T1 = void,
typename T2 = void,
2519 typename T3 = void,
typename T4 = void,
typename T5 = void,
2520 typename T6 = void,
typename T7 = void,
typename T8 = void,
2521 typename T9 = void,
typename T10 =
void>
2530template <
typename T0,
typename T1,
typename T2>
2535template <
typename T0,
typename T1,
typename T2,
typename T3>
2541template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4>
2547template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4,
2561template <
typename Opnd0,
typename Opnd1,
typename Opnd2,
typename Opnd3>
2565 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2, Op3);
2569template <
typename Opnd0,
typename Opnd1,
typename Opnd2,
typename Opnd3>
2573 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2, Op3);
2576template <Intrinsic::ID IntrID,
typename T0>
2578 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
2581template <Intrinsic::ID IntrID,
typename T0,
typename T1>
2584 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
2587template <Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2>
2590 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2597 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2601 typename T3,
typename T4>
2605 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2606 m_Argument<4>(Op4));
2610 typename T3,
typename T4,
typename T5>
2613 const T4 &Op4,
const T5 &Op5) {
2614 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2615 m_Argument<5>(Op5));
2619template <
typename Opnd0>
2621 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
2624template <
typename Opnd0>
2626 return m_Intrinsic<Intrinsic::bswap>(Op0);
2629template <
typename Opnd0>
2631 return m_Intrinsic<Intrinsic::fabs>(Op0);
2634template <
typename Opnd0>
2636 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
2639template <
typename Opnd0,
typename Opnd1>
2642 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2645template <
typename Opnd0,
typename Opnd1>
2648 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2651template <
typename Opnd0,
typename Opnd1,
typename Opnd2>
2653m_FShl(
const Opnd0 &Op0,
const Opnd1 &Op1,
const Opnd2 &Op2) {
2654 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2657template <
typename Opnd0,
typename Opnd1,
typename Opnd2>
2659m_FShr(
const Opnd0 &Op0,
const Opnd1 &Op1,
const Opnd2 &Op2) {
2660 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2663template <
typename Opnd0>
2665 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2668template <
typename Opnd0,
typename Opnd1>
2671 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2674template <
typename Opnd0>
2676 return m_Intrinsic<Intrinsic::vector_reverse>(Op0);
2684template <
typename LHS,
typename RHS>
2691template <
typename LHS,
typename RHS>
2698template <
typename LHS,
typename RHS>
2705template <
typename LHS,
typename RHS>
2712template <
typename LHS,
typename RHS>
2719template <
typename LHS,
typename RHS>
2726template <
typename LHS,
typename RHS>
2733template <
typename LHS,
typename RHS>
2740template <
typename LHS,
typename RHS>
2747template <
typename ValTy>
2754template <
typename ValTy>
2763template <
typename LHS,
typename RHS>
2769template <
typename LHS,
typename RHS>
2775template <
typename LHS,
typename RHS>
2781template <
typename LHS,
typename RHS>
2787template <
typename LHS,
typename RHS>
2798template <Intrinsic::ID IntrID,
typename T0,
typename T1>
2803 m_Intrinsic<IntrID>(Op1, Op0));
2807template <
typename LHS,
typename RHS>
2814template <
typename LHS,
typename RHS>
2824 template <
typename OpTy>
bool match(OpTy *V) {
2825 unsigned TypeSize = V->getType()->getScalarSizeInBits();
2829 unsigned ShiftWidth =
TypeSize - 1;
2830 Value *OpL =
nullptr, *OpR =
nullptr;
2846 return Signum.match(V) && OpL == OpR &&
Val.match(OpL);
2864 template <
typename OpTy>
bool match(OpTy *V) {
2865 if (
auto *
I = dyn_cast<ExtractValueInst>(V)) {
2868 !(
I->getNumIndices() == 1 &&
I->getIndices()[0] == (
unsigned)Ind))
2870 return Val.match(
I->getAggregateOperand());
2878template <
int Ind,
typename Val_t>
2885template <
typename Val_t>
2897 template <
typename OpTy>
bool match(OpTy *V) {
2898 if (
auto *
I = dyn_cast<InsertValueInst>(V)) {
2899 return Op0.match(
I->getOperand(0)) &&
Op1.match(
I->getOperand(1)) &&
2900 I->getNumIndices() == 1 && Ind ==
I->getIndices()[0];
2907template <
int Ind,
typename Val_t,
typename Elt_t>
2918 template <
typename ITy>
bool match(ITy *V) {
2919 if (m_Intrinsic<Intrinsic::vscale>().
match(V))
2924 if (
auto *
GEP = dyn_cast<GEPOperator>(
Ptr)) {
2926 dyn_cast<ScalableVectorType>(
GEP->getSourceElementType());
2927 if (
GEP->getNumIndices() == 1 && DerefTy &&
2928 DerefTy->getElementType()->isIntegerTy(8) &&
2943template <
typename Opnd0,
typename Opnd1>
2946 return m_Intrinsic<Intrinsic::vector_interleave2>(Op0, Op1);
2949template <
typename Opnd>
2951 return m_Intrinsic<Intrinsic::vector_deinterleave2>(
Op);
2954template <
typename LHS,
typename RHS,
unsigned Opcode,
bool Commutable = false>
2962 auto *
I = dyn_cast<Instruction>(V);
2963 if (!
I || !
I->getType()->isIntOrIntVectorTy(1))
2966 if (
I->getOpcode() == Opcode) {
2967 auto *Op0 =
I->getOperand(0);
2968 auto *Op1 =
I->getOperand(1);
2969 return (
L.match(Op0) &&
R.match(Op1)) ||
2970 (Commutable &&
L.match(Op1) &&
R.match(Op0));
2973 if (
auto *
Select = dyn_cast<SelectInst>(
I)) {
2975 auto *TVal =
Select->getTrueValue();
2976 auto *FVal =
Select->getFalseValue();
2983 if (Opcode == Instruction::And) {
2984 auto *
C = dyn_cast<Constant>(FVal);
2985 if (
C &&
C->isNullValue())
2986 return (
L.match(
Cond) &&
R.match(TVal)) ||
2987 (Commutable &&
L.match(TVal) &&
R.match(
Cond));
2989 assert(Opcode == Instruction::Or);
2990 auto *
C = dyn_cast<Constant>(TVal);
2991 if (
C &&
C->isOneValue())
2992 return (
L.match(
Cond) &&
R.match(FVal)) ||
2993 (Commutable &&
L.match(FVal) &&
R.match(
Cond));
3003template <
typename LHS,
typename RHS>
3013template <
typename LHS,
typename RHS>
3021template <
typename LHS,
typename RHS>
3031template <
typename LHS,
typename RHS>
3040template <
typename LHS,
typename RHS,
bool Commutable = false>
3051template <
typename LHS,
typename RHS>
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...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
uint64_t IntrinsicInst * II
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
static bool isSameValue(const APInt &I1, const APInt &I2)
Determine if two APInts have the same value, after zero-extending one of them (if needed!...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ 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_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Base class for aggregate constants (with operands).
A constant value that is initialized with an expression using other constant values.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
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.
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
'undef' values are things that do not have specified contents.
LLVM Value Representation.
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.
An efficient, type-erasing, non-owning reference to a callable.
@ C
The default llvm calling convention, compatible with C.
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
class_match< PoisonValue > m_Poison()
Match an arbitrary poison constant.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
apfloat_match m_APFloatForbidPoison(const APFloat *&Res)
Match APFloat while forbidding poison in splat vector constants.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
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_FCanonicalize(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
AllowReassoc_match< T > m_AllowReassoc(const T &SubPattern)
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
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.
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
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)
br_match m_UnconditionalBr(BasicBlock *&Succ)
SpecificCmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_SpecificICmp(ICmpInst::Predicate MatchPred, 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.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
bool match(Val *V, const Pattern &P)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
constantexpr_match m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true > m_c_NUWAdd(const LHS &L, const RHS &R)
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'.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
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.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
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.
match_combine_or< CastInst_match< OpTy, SExtInst >, OpTy > m_SExtOrSelf(const OpTy &Op)
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1)
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
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)
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
CmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R)
CastInst_match< OpTy, FPToUIInst > m_FPToUI(const OpTy &Op)
m_Intrinsic_Ty< Opnd0 >::Ty m_Sqrt(const Opnd0 &Op0)
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
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.
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
match_combine_or< typename m_Intrinsic_Ty< T0, T1 >::Ty, typename m_Intrinsic_Ty< T1, T0 >::Ty > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
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.
NoWrapTrunc_match< OpTy, TruncInst::NoSignedWrap > m_NSWTrunc(const OpTy &Op)
Matches trunc nsw.
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)
NNegZExt_match< OpTy > m_NNegZExt(const OpTy &Op)
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
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.
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true > m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
auto m_GEP(const OperandTypes &...Ops)
Matches GetElementPtrInst.
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
class_match< ConstantFP > m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
cstfp_pred_ty< is_nonnan > m_NonNaN()
Match a non-NaN FP constant.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2, Opnd3 >::Ty m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2, const Opnd3 &Op3)
Matches MaskedLoad Intrinsic.
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
apint_match m_APIntForbidPoison(const APInt *&Res)
Match APInt while forbidding poison in splat vector constants.
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)
cst_pred_ty< is_all_ones, false > m_AllOnesForbidPoison()
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_bitwiselogic_op, true > m_c_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations in either order.
class_match< UndefValue > m_UndefValue()
Match an arbitrary UndefValue constant.
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.
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
cst_pred_ty< is_negated_power2_or_zero > m_NegatedPower2OrZero()
Match a integer or vector negated power-of-2.
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
cst_pred_ty< custom_checkfn< APInt > > m_CheckedInt(function_ref< bool(const APInt &)> CheckFn)
Match an integer or vector where CheckFn(ele) for each element is true.
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
apfloat_match m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)
Match either "add" or "or disjoint".
SpecificCmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_SpecificICmp(ICmpInst::Predicate MatchPred, const LHS &L, const RHS &R)
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true > m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
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)
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
match_combine_or< CastInst_match< OpTy, SExtInst >, NNegZExt_match< OpTy > > m_SExtLike(const OpTy &Op)
Match either "sext" or "zext nneg".
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
class_match< UnaryOperator > m_UnOp()
Match an arbitrary unary operation and ignore it.
VScaleVal_match m_VScale()
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
cstfp_pred_ty< custom_checkfn< APFloat > > m_CheckedFp(function_ref< bool(const APFloat &)> CheckFn)
Match a float or vector where CheckFn(ele) for each element is true.
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.
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
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.
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
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::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
UAddWithOverflow_match< LHS_t, RHS_t, Sum_t > m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Match an icmp instruction checking for unsigned overflow on addition.
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_VecReverse(const Opnd0 &Op0)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
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.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
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)
SpecificCmpClass_match< LHS, RHS, CmpInst, CmpInst::Predicate > m_SpecificCmp(CmpInst::Predicate MatchPred, const LHS &L, const RHS &R)
ThreeOps_match< Cond, constantint_match< L >, constantint_match< R >, Instruction::Select > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.: m_SelectCst<-1, 0>(m_Value(V))
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
CastInst_match< OpTy, FPTruncInst > m_FPTrunc(const OpTy &Op)
class_match< BasicBlock > m_BasicBlock()
Match an arbitrary basic block value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
SpecificCmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_SpecificFCmp(FCmpInst::Predicate MatchPred, const LHS &L, const RHS &R)
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN 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, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
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".
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
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.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
m_Intrinsic_Ty< Opnd >::Ty m_Deinterleave2(const Opnd &Op)
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2, Opnd3 >::Ty m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2, const Opnd3 &Op3)
Matches MaskedGather Intrinsic.
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
AllowReassoc_match(const SubPattern_t &SP)
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Matches instructions with Opcode and any number of operands.
std::enable_if_t< Idx==Last, bool > match_operands(const Instruction *I)
std::enable_if_t< Idx !=Last, bool > match_operands(const Instruction *I)
std::tuple< OperandTypes... > Operands
AnyOps_match(const OperandTypes &...Ops)
AnyUnaryOp_match(const OP_t &X)
Argument_match(unsigned OpIdx, const Opnd_t &V)
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
bool match(unsigned Opc, OpTy *V)
CastInst_match(const Op_t &OpMatch)
CastOperator_match(const Op_t &OpMatch)
CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
DisjointOr_match(const LHS &L, const RHS &R)
ElementWiseBitCast_match(const Op_t &OpMatch)
Exact_match(const SubPattern_t &SP)
FNeg_match(const Op_t &Op)
Matcher for a single index InsertValue instruction.
InsertValue_match(const T0 &Op0, const T1 &Op1)
IntrinsicID_match(Intrinsic::ID IntrID)
LogicalOp_match(const LHS &L, const RHS &R)
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
NNegZExt_match(const Op_t &OpMatch)
NoWrapTrunc_match(const Op_t &OpMatch)
Matches instructions with Opcode and three operands.
OneOps_match(const T0 &Op1)
OneUse_match(const SubPattern_t &SP)
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
Signum_match(const Opnd_t &V)
SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
SpecificCmpClass_match(PredicateTy Pred, const LHS_t &LHS, const RHS_t &RHS)
const PredicateTy Predicate
Matches instructions with Opcode and three operands.
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
Matches instructions with Opcode and three operands.
TwoOps_match(const T0 &Op1, const T1 &Op2)
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Matches patterns for vscale.
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
apf_pred_ty(const APFloat *&R)
apfloat_match(const APFloat *&Res, bool AllowPoison)
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
api_pred_ty(const APInt *&R)
apint_match(const APInt *&Res, bool AllowPoison)
bind_const_intval_ty(uint64_t &V)
br_match(BasicBlock *&Succ)
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
This helper class is used to match constant scalars, vector splats, and fixed width vectors that sati...
bool isValue(const APTy &C)
function_ref< bool(const APTy &)> CheckFn
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers.
deferredval_ty(Class *const &V)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APFloat &C)
bool isOpType(unsigned Opcode)
bool isValue(const APFloat &C)
bool isValue(const APFloat &C)
bool isOpType(unsigned Opcode)
bool isValue(const APFloat &C)
bool isOpType(unsigned Opcode)
bool isOpType(unsigned Opcode)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APFloat &C)
bool isValue(const APFloat &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APFloat &C)
bool isValue(const APFloat &C)
bool isValue(const APFloat &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APFloat &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isOpType(unsigned Opcode)
bool isOpType(unsigned Opcode)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
bool isValue(const APInt &C)
Intrinsic matches are combinations of ID matchers, and argument matchers.
bool match(ArrayRef< int > Mask)
ArrayRef< int > & MaskRef
m_Mask(ArrayRef< int > &MaskRef)
ArrayRef< int > & MaskRef
bool match(ArrayRef< int > Mask)
m_SpecificMask(ArrayRef< int > &MaskRef)
bool match(ArrayRef< int > Mask)
m_SplatOrPoisonMask(int &SplatIndex)
bool match(ArrayRef< int > Mask)
match_combine_and(const LTy &Left, const RTy &Right)
match_combine_or(const LTy &Left, const RTy &Right)
match_unless(const Ty &Matcher)
Helper class for identifying ordered max predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying ordered min predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying signed max predicates.
static bool match(ICmpInst::Predicate Pred)
Helper class for identifying signed min predicates.
static bool match(ICmpInst::Predicate Pred)
Match a specified basic block value.
specific_bbval(BasicBlock *Val)
Match a specified floating point value or vector of all elements of that value.
specific_intval64(uint64_t V)
Match a specified integer value or vector of all elements of that value.
specific_intval(const APInt &V)
Match a specified Value*.
specificval_ty(const Value *V)
Helper class for identifying unordered max predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying unordered min predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying unsigned max predicates.
static bool match(ICmpInst::Predicate Pred)
Helper class for identifying unsigned min predicates.
static bool match(ICmpInst::Predicate Pred)
static bool check(const Value *V)