Go to the documentation of this file.
28 #ifndef LLVM_IR_PATTERNMATCH_H
29 #define LLVM_IR_PATTERNMATCH_H
47 namespace PatternMatch {
49 template <
typename Val,
typename Pattern>
bool match(Val *V,
const Pattern &
P) {
62 template <
typename OpTy>
bool match(OpTy *V) {
72 template <
typename ITy>
bool match(ITy *V) {
return isa<Class>(V); }
93 if (isa<UndefValue>(V))
96 const auto *CA = dyn_cast<ConstantAggregate>(V);
107 for (
const Value *
Op : CA->operand_values()) {
108 if (isa<UndefValue>(
Op))
111 const auto *CA = dyn_cast<ConstantAggregate>(
Op);
114 if (Seen.
insert(CA).second)
124 while (!Worklist.empty()) {
130 template <
typename ITy>
bool match(ITy *V) {
return check(V); }
172 template <
typename ITy>
bool match(ITy *V) {
return !
M.match(V); }
187 template <
typename ITy>
bool match(ITy *V) {
202 template <
typename ITy>
bool match(ITy *V) {
211 template <
typename LTy,
typename RTy>
217 template <
typename LTy,
typename RTy>
229 template <
typename ITy>
bool match(ITy *V) {
230 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
231 Res = &CI->getValue();
234 if (V->getType()->isVectorTy())
235 if (
const auto *
C = dyn_cast<Constant>(V))
237 dyn_cast_or_null<ConstantInt>(
C->getSplatValue(
AllowUndef))) {
238 Res = &CI->getValue();
254 template <
typename ITy>
bool match(ITy *V) {
255 if (
auto *CI = dyn_cast<ConstantFP>(V)) {
256 Res = &CI->getValueAPF();
259 if (V->getType()->isVectorTy())
260 if (
const auto *
C = dyn_cast<Constant>(V))
262 dyn_cast_or_null<ConstantFP>(
C->getSplatValue(
AllowUndef))) {
263 Res = &CI->getValueAPF();
305 template <
typename ITy>
bool match(ITy *V) {
306 if (
const auto *CI = dyn_cast<ConstantInt>(V)) {
307 const APInt &CIV = CI->getValue();
309 return CIV ==
static_cast<uint64_t>(Val);
327 template <
typename Predicate,
typename ConstantVal>
329 template <
typename ITy>
bool match(ITy *V) {
330 if (
const auto *CV = dyn_cast<ConstantVal>(V))
331 return this->isValue(CV->getValue());
332 if (
const auto *VTy = dyn_cast<VectorType>(V->getType())) {
333 if (
const auto *
C = dyn_cast<Constant>(V)) {
334 if (
const auto *CV = dyn_cast_or_null<ConstantVal>(
C->getSplatValue()))
335 return this->isValue(CV->getValue());
338 auto *FVTy = dyn_cast<FixedVectorType>(VTy);
343 unsigned NumElts = FVTy->getNumElements();
344 assert(NumElts != 0 &&
"Constant vector with no elements?");
345 bool HasNonUndefElements =
false;
346 for (
unsigned i = 0;
i != NumElts; ++
i) {
350 if (isa<UndefValue>(Elt))
352 auto *CV = dyn_cast<ConstantVal>(Elt);
353 if (!CV || !this->isValue(CV->getValue()))
355 HasNonUndefElements =
true;
357 return HasNonUndefElements;
365 template <
typename Predicate>
369 template <
typename Predicate>
379 template <
typename ITy>
bool match(ITy *V) {
380 if (
const auto *CI = dyn_cast<ConstantInt>(V))
381 if (this->isValue(CI->getValue())) {
382 Res = &CI->getValue();
385 if (V->getType()->isVectorTy())
386 if (
const auto *
C = dyn_cast<Constant>(V))
387 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
388 if (this->isValue(CI->getValue())) {
389 Res = &CI->getValue();
405 template <
typename ITy>
bool match(ITy *V) {
406 if (
const auto *CI = dyn_cast<ConstantFP>(V))
407 if (this->isValue(CI->getValue())) {
408 Res = &CI->getValue();
411 if (V->getType()->isVectorTy())
412 if (
const auto *
C = dyn_cast<Constant>(V))
413 if (
auto *CI = dyn_cast_or_null<ConstantFP>(
414 C->getSplatValue(
true)))
415 if (this->isValue(CI->getValue())) {
416 Res = &CI->getValue();
523 template <
typename ITy>
bool match(ITy *V) {
524 auto *
C = dyn_cast<Constant>(V);
696 template <
typename ITy>
bool match(ITy *V) {
697 if (
auto *CV = dyn_cast<Class>(V)) {
762 template <
typename ITy>
bool match(ITy *V) {
return V ==
Val; }
775 template <
typename ITy>
bool match(ITy *
const V) {
return V ==
Val; }
796 template <
typename ITy>
bool match(ITy *V) {
797 if (
const auto *CFP = dyn_cast<ConstantFP>(V))
798 return CFP->isExactlyValue(
Val);
799 if (V->getType()->isVectorTy())
800 if (
const auto *
C = dyn_cast<Constant>(V))
801 if (
auto *CFP = dyn_cast_or_null<ConstantFP>(
C->getSplatValue()))
802 return CFP->isExactlyValue(
Val);
819 template <
typename ITy>
bool match(ITy *V) {
820 if (
const auto *CV = dyn_cast<ConstantInt>(V))
822 VR = CV->getZExtValue();
836 template <
typename ITy>
bool match(ITy *V) {
837 const auto *CI = dyn_cast<ConstantInt>(V);
838 if (!CI && V->getType()->isVectorTy())
839 if (
const auto *
C = dyn_cast<Constant>(V))
840 CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue(AllowUndefs));
874 template <
typename ITy>
bool match(ITy *V) {
875 const auto *
BB = dyn_cast<BasicBlock>(V);
897 template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
906 template <
typename OpTy>
bool match(OpTy *V) {
907 if (
auto *
I = dyn_cast<BinaryOperator>(V))
908 return (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
910 R.match(
I->getOperand(0)));
915 template <
typename LHS,
typename RHS>
929 template <
typename OpTy>
bool match(OpTy *V) {
930 if (
auto *
I = dyn_cast<UnaryOperator>(V))
931 return X.match(
I->getOperand(0));
944 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
954 template <
typename OpTy>
inline bool match(
unsigned Opc, OpTy *V) {
955 if (V->getValueID() == Value::InstructionVal + Opc) {
956 auto *
I = cast<BinaryOperator>(V);
957 return (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
959 R.match(
I->getOperand(0)));
961 if (
auto *CE = dyn_cast<ConstantExpr>(V))
962 return CE->getOpcode() == Opc &&
963 ((
L.match(CE->getOperand(0)) &&
R.match(CE->getOperand(1))) ||
965 R.match(CE->getOperand(0))));
969 template <
typename OpTy>
bool match(OpTy *V) {
return match(Opcode, V); }
972 template <
typename LHS,
typename RHS>
978 template <
typename LHS,
typename RHS>
984 template <
typename LHS,
typename RHS>
990 template <
typename LHS,
typename RHS>
1000 template <
typename OpTy>
bool match(OpTy *V) {
1001 auto *FPMO = dyn_cast<FPMathOperator>(V);
1005 if (FPMO->getOpcode() == Instruction::FNeg)
1006 return X.match(FPMO->getOperand(0));
1008 if (FPMO->getOpcode() == Instruction::FSub) {
1009 if (FPMO->hasNoSignedZeros()) {
1019 return X.match(FPMO->getOperand(1));
1032 template <
typename RHS>
1038 template <
typename LHS,
typename RHS>
1044 template <
typename LHS,
typename RHS>
1050 template <
typename LHS,
typename RHS>
1056 template <
typename LHS,
typename RHS>
1062 template <
typename LHS,
typename RHS>
1068 template <
typename LHS,
typename RHS>
1074 template <
typename LHS,
typename RHS>
1080 template <
typename LHS,
typename RHS>
1086 template <
typename LHS,
typename RHS>
1092 template <
typename LHS,
typename RHS>
1098 template <
typename LHS,
typename RHS>
1104 template <
typename LHS,
typename RHS>
1110 template <
typename LHS,
typename RHS>
1116 template <
typename LHS,
typename RHS>
1122 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
1123 unsigned WrapFlags = 0>
1131 template <
typename OpTy>
bool match(OpTy *V) {
1132 if (
auto *
Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1133 if (
Op->getOpcode() != Opcode)
1136 !
Op->hasNoUnsignedWrap())
1139 !
Op->hasNoSignedWrap())
1141 return L.match(
Op->getOperand(0)) &&
R.match(
Op->getOperand(1));
1147 template <
typename LHS,
typename RHS>
1155 template <
typename LHS,
typename RHS>
1163 template <
typename LHS,
typename RHS>
1171 template <
typename LHS,
typename RHS>
1180 template <
typename LHS,
typename RHS>
1188 template <
typename LHS,
typename RHS>
1196 template <
typename LHS,
typename RHS>
1204 template <
typename LHS,
typename RHS>
1213 template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
1221 template <
typename OpTy>
bool match(OpTy *V) {
1227 template <
typename LHS,
typename RHS>
1236 template <
typename LHS_t,
typename RHS_t,
typename Predicate>
1243 template <
typename OpTy>
bool match(OpTy *V) {
1244 if (
auto *
I = dyn_cast<Instruction>(V))
1245 return this->isOpType(
I->getOpcode()) &&
L.match(
I->getOperand(0)) &&
1246 R.match(
I->getOperand(1));
1247 if (
auto *CE = dyn_cast<ConstantExpr>(V))
1248 return this->isOpType(CE->getOpcode()) &&
L.match(CE->getOperand(0)) &&
1249 R.match(CE->getOperand(1));
1260 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1266 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1278 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1284 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1289 template <
typename LHS,
typename RHS>
1296 template <
typename LHS,
typename RHS>
1303 template <
typename LHS,
typename RHS>
1310 template <
typename LHS,
typename RHS>
1317 template <
typename LHS,
typename RHS>
1324 template <
typename LHS,
typename RHS>
1338 template <
typename OpTy>
bool match(OpTy *V) {
1339 if (
auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1340 return PEO->isExact() &&
SubPattern.match(V);
1353 template <
typename LHS_t,
typename RHS_t,
typename Class,
typename PredicateTy,
1365 template <
typename OpTy>
bool match(OpTy *V) {
1366 if (
auto *
I = dyn_cast<Class>(V)) {
1367 if (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) {
1371 R.match(
I->getOperand(0))) {
1380 template <
typename LHS,
typename RHS>
1386 template <
typename LHS,
typename RHS>
1392 template <
typename LHS,
typename RHS>
1408 template <
typename OpTy>
bool match(OpTy *V) {
1409 if (V->getValueID() == Value::InstructionVal + Opcode) {
1410 auto *
I = cast<Instruction>(V);
1411 return Op1.match(
I->getOperand(0));
1424 template <
typename OpTy>
bool match(OpTy *V) {
1425 if (V->getValueID() == Value::InstructionVal + Opcode) {
1426 auto *
I = cast<Instruction>(V);
1427 return Op1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1));
1434 template <
typename T0,
typename T1,
typename T2,
unsigned Opcode>
1443 template <
typename OpTy>
bool match(OpTy *V) {
1444 if (V->getValueID() == Value::InstructionVal + Opcode) {
1445 auto *
I = cast<Instruction>(V);
1446 return Op1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1)) &&
1447 Op3.match(
I->getOperand(2));
1454 template <
typename Cond,
typename LHS,
typename RHS>
1462 template <
int64_t L,
int64_t R,
typename Cond>
1466 return m_Select(
C, m_ConstantInt<L>(), m_ConstantInt<R>());
1470 template <
typename OpTy>
1476 template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1484 template <
typename Val_t,
typename Idx_t>
1499 template <
typename OpTy>
bool match(OpTy *V) {
1500 if (
auto *
I = dyn_cast<ShuffleVectorInst>(V)) {
1501 return Op1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1)) &&
1502 Mask.match(
I->getShuffleMask());
1519 return all_of(
Mask, [](
int Elem) {
return Elem == 0 || Elem == -1; });
1538 [
First](
int Elem) {
return Elem == *
First || Elem == -1; });
1543 template <
typename V1_t,
typename V2_t>
1549 template <
typename V1_t,
typename V2_t,
typename Mask_t>
1556 template <
typename OpTy>
1562 template <
typename ValueOpTy,
typename Po
interOpTy>
1564 m_Store(
const ValueOpTy &ValueOp,
const PointerOpTy &PointerOp) {
1578 template <
typename OpTy>
bool match(OpTy *V) {
1579 if (
auto *
O = dyn_cast<Operator>(V))
1580 return O->getOpcode() == Opcode &&
Op.match(
O->getOperand(0));
1586 template <
typename OpTy>
1592 template <
typename OpTy>
1598 template <
typename OpTy>
1604 template <
typename OpTy>
1609 template <
typename OpTy>
1616 template <
typename OpTy>
1622 template <
typename OpTy>
1627 template <
typename OpTy>
1633 template <
typename OpTy>
1639 template <
typename OpTy>
1646 template <
typename OpTy>
1655 template <
typename OpTy>
1660 template <
typename OpTy>
1665 template <
typename OpTy>
1670 template <
typename OpTy>
1675 template <
typename OpTy>
1680 template <
typename OpTy>
1694 template <
typename OpTy>
bool match(OpTy *V) {
1695 if (
auto *BI = dyn_cast<BranchInst>(V))
1696 if (BI->isUnconditional()) {
1697 Succ = BI->getSuccessor(0);
1706 template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
1715 template <
typename OpTy>
bool match(OpTy *V) {
1716 if (
auto *BI = dyn_cast<BranchInst>(V))
1717 if (BI->isConditional() &&
Cond.match(BI->getCondition()))
1718 return T.match(BI->getSuccessor(0)) &&
F.match(BI->getSuccessor(1));
1723 template <
typename Cond_t>
1730 template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
1732 m_Br(
const Cond_t &
C,
const TrueBlock_t &T,
const FalseBlock_t &
F) {
1740 template <
typename CmpInst_t,
typename LHS_t,
typename RHS_t,
typename Pred_t,
1751 template <
typename OpTy>
bool match(OpTy *V) {
1752 if (
auto *II = dyn_cast<IntrinsicInst>(V)) {
1758 Value *
LHS = II->getOperand(0), *
RHS = II->getOperand(1);
1759 return (
L.match(
LHS) &&
R.match(
RHS)) ||
1764 auto *
SI = dyn_cast<SelectInst>(V);
1767 auto *Cmp = dyn_cast<CmpInst_t>(
SI->getCondition());
1774 auto *
LHS = Cmp->getOperand(0);
1775 auto *
RHS = Cmp->getOperand(1);
1780 LHS ==
TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1785 return (
L.match(
LHS) &&
R.match(
RHS)) ||
1846 template <
typename LHS,
typename RHS>
1852 template <
typename LHS,
typename RHS>
1858 template <
typename LHS,
typename RHS>
1864 template <
typename LHS,
typename RHS>
1870 template <
typename LHS,
typename RHS>
1890 template <
typename LHS,
typename RHS>
1905 template <
typename LHS,
typename RHS>
1920 template <
typename LHS,
typename RHS>
1935 template <
typename LHS,
typename RHS>
1946 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1955 template <
typename OpTy>
bool match(OpTy *V) {
1956 Value *ICmpLHS, *ICmpRHS;
1961 Value *AddLHS, *AddRHS;
1966 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1967 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpLHS);
1971 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1972 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpRHS);
1978 if (XorExpr.match(ICmpLHS))
1979 return L.match(Op1) &&
R.match(ICmpRHS) &&
S.match(ICmpLHS);
1983 if (XorExpr.match(ICmpRHS))
1984 return L.match(Op1) &&
R.match(ICmpLHS) &&
S.match(ICmpRHS);
1993 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpLHS);
1998 return L.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpRHS);
2009 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
2021 template <
typename OpTy>
bool match(OpTy *V) {
2023 if (
const auto *CI = dyn_cast<CallInst>(V))
2024 return Val.match(CI->getArgOperand(
OpI));
2030 template <
unsigned OpI,
typename Opnd_t>
2041 template <
typename OpTy>
bool match(OpTy *V) {
2042 if (
const auto *CI = dyn_cast<CallInst>(V))
2043 if (
const auto *
F = CI->getCalledFunction())
2044 return F->getIntrinsicID() ==
ID;
2053 template <
typename T0 = void,
typename T1 = void,
typename T2 = void,
2054 typename T3 = void,
typename T4 = void,
typename T5 = void,
2055 typename T6 = void,
typename T7 = void,
typename T8 = void,
2056 typename T9 = void,
typename T10 =
void>
2065 template <
typename T0,
typename T1,
typename T2>
2070 template <
typename T0,
typename T1,
typename T2,
typename T3>
2076 template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4>
2082 template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4,
2096 template <
typename Opnd0,
typename Opnd1,
typename Opnd2,
typename Opnd3>
2100 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2, Op3);
2104 template <
typename Opnd0,
typename Opnd1,
typename Opnd2,
typename Opnd3>
2108 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2, Op3);
2111 template <Intrinsic::ID IntrID,
typename T0>
2113 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
2116 template <Intrinsic::ID IntrID,
typename T0,
typename T1>
2119 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
2122 template <Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2>
2125 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2128 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
2132 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2135 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
2136 typename T3,
typename T4>
2140 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2141 m_Argument<4>(Op4));
2144 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
2145 typename T3,
typename T4,
typename T5>
2148 const T4 &Op4,
const T5 &Op5) {
2149 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2150 m_Argument<5>(Op5));
2154 template <
typename Opnd0>
2156 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
2159 template <
typename Opnd0>
2161 return m_Intrinsic<Intrinsic::bswap>(Op0);
2164 template <
typename Opnd0>
2166 return m_Intrinsic<Intrinsic::fabs>(Op0);
2169 template <
typename Opnd0>
2171 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
2174 template <
typename Opnd0,
typename Opnd1>
2177 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2180 template <
typename Opnd0,
typename Opnd1>
2183 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2186 template <
typename Opnd0,
typename Opnd1,
typename Opnd2>
2188 m_FShl(
const Opnd0 &Op0,
const Opnd1 &Op1,
const Opnd2 &Op2) {
2189 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2192 template <
typename Opnd0,
typename Opnd1,
typename Opnd2>
2194 m_FShr(
const Opnd0 &Op0,
const Opnd1 &Op1,
const Opnd2 &Op2) {
2195 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2198 template <
typename Opnd0>
2200 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2208 template <
typename LHS,
typename RHS>
2215 template <
typename LHS,
typename RHS>
2223 template <
typename LHS,
typename RHS>
2230 template <
typename LHS,
typename RHS>
2237 template <
typename LHS,
typename RHS>
2244 template <
typename LHS,
typename RHS>
2251 template <
typename LHS,
typename RHS>
2258 template <
typename LHS,
typename RHS>
2265 template <
typename ValTy>
2272 template <
typename ValTy>
2281 template <
typename ValTy>
2291 template <
typename OpTy>
bool match(OpTy *V) {
2298 return Val.match(
X);
2300 return Val.match(
X);
2307 template <
typename ValTy>
2313 template <
typename LHS,
typename RHS>
2319 template <
typename LHS,
typename RHS>
2325 template <
typename LHS,
typename RHS>
2331 template <
typename LHS,
typename RHS>
2337 template <
typename LHS,
typename RHS>
2349 template <
typename LHS,
typename RHS>
2356 template <
typename LHS,
typename RHS>
2366 template <
typename OpTy>
bool match(OpTy *V) {
2367 unsigned TypeSize = V->getType()->getScalarSizeInBits();
2371 unsigned ShiftWidth =
TypeSize - 1;
2372 Value *OpL =
nullptr, *OpR =
nullptr;
2388 return Signum.match(V) && OpL == OpR &&
Val.match(OpL);
2406 template <
typename OpTy>
bool match(OpTy *V) {
2407 if (
auto *
I = dyn_cast<ExtractValueInst>(V)) {
2410 !(
I->getNumIndices() == 1 &&
I->getIndices()[0] == (
unsigned)Ind))
2412 return Val.match(
I->getAggregateOperand());
2420 template <
int Ind,
typename Val_t>
2427 template <
typename Val_t>
2439 template <
typename OpTy>
bool match(OpTy *V) {
2440 if (
auto *
I = dyn_cast<InsertValueInst>(V)) {
2441 return Op0.match(
I->getOperand(0)) &&
Op1.match(
I->getOperand(1)) &&
2442 I->getNumIndices() == 1 && Ind ==
I->getIndices()[0];
2449 template <
int Ind,
typename Val_t,
typename Elt_t>
2463 template <
typename ITy>
bool match(ITy *V) {
2464 if (m_Intrinsic<Intrinsic::vscale>().
match(V))
2469 if (
auto *
GEP = dyn_cast<GEPOperator>(Ptr)) {
2470 auto *DerefTy =
GEP->getSourceElementType();
2471 if (
GEP->getNumIndices() == 1 && isa<ScalableVectorType>(DerefTy) &&
2487 template <
typename LHS,
typename RHS,
unsigned Opcode,
bool Commutable = false>
2494 template <
typename T>
bool match(T *V) {
2495 auto *
I = dyn_cast<Instruction>(V);
2496 if (!
I || !
I->getType()->isIntOrIntVectorTy(1))
2499 if (
I->getOpcode() == Opcode) {
2500 auto *Op0 =
I->getOperand(0);
2501 auto *Op1 =
I->getOperand(1);
2502 return (
L.match(Op0) &&
R.match(Op1)) ||
2506 if (
auto *
Select = dyn_cast<SelectInst>(
I)) {
2508 auto *TVal =
Select->getTrueValue();
2509 auto *FVal =
Select->getFalseValue();
2510 if (Opcode == Instruction::And) {
2511 auto *
C = dyn_cast<Constant>(FVal);
2512 if (
C &&
C->isNullValue())
2513 return (
L.match(
Cond) &&
R.match(TVal)) ||
2516 assert(Opcode == Instruction::Or);
2517 auto *
C = dyn_cast<Constant>(TVal);
2518 if (
C &&
C->isOneValue())
2519 return (
L.match(
Cond) &&
R.match(FVal)) ||
2530 template <
typename LHS,
typename RHS>
2540 template <
typename LHS,
typename RHS>
2548 template <
typename LHS,
typename RHS>
2558 template <
typename LHS,
typename RHS>
2567 #endif // LLVM_IR_PATTERNMATCH_H
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
bind_const_intval_ty(uint64_t &V)
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
apfloat_match m_APFloatForbidUndef(const APFloat *&Res)
Match APFloat while forbidding undefs in splat vector constants.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
bool isValue(const APFloat &C)
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.
bool isValue(const APFloat &C)
CastClass_match< OpTy, Instruction::SIToFP > m_SIToFP(const OpTy &Op)
SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
bool isValue(const APInt &C)
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
bool isValue(const APInt &C)
This is an optimization pass for GlobalISel generic memory operations.
static bool match(FCmpInst::Predicate Pred)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
match_combine_or< CastClass_match< OpTy, Instruction::Trunc >, OpTy > m_TruncOrSelf(const OpTy &Op)
A parsed version of the target data layout string in and methods for querying it.
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.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
bool isValue(const APInt &C)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Matches instructions with Opcode and three operands.
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
match_combine_and(const LTy &Left, const RTy &Right)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
bool isValue(const APInt &C)
m_Mask(ArrayRef< int > &MaskRef)
specificval_ty(const Value *V)
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
br_match(BasicBlock *&Succ)
m_SplatOrUndefMask(int &SplatIndex)
Base class for aggregate constants (with operands).
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
apf_pred_ty(const APFloat *&R)
m_Intrinsic_Ty< Opnd0 >::Ty m_FCanonicalize(const Opnd0 &Op0)
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
@ ICMP_SGT
signed greater than
Match a specified integer value or vector of all elements of that value.
static bool match(ICmpInst::Predicate Pred)
CastClass_match< OpTy, Instruction::FPToUI > m_FPToUI(const OpTy &Op)
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
Matches instructions with Opcode and three operands.
bool isValue(const APInt &C)
CastClass_match(const Op_t &OpMatch)
match_combine_or< match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
bool match(ArrayRef< int > Mask)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
Matcher for a single index InsertValue instruction.
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
@ ICMP_SLE
signed less or equal
LogicalOp_match(const LHS &L, const RHS &R)
IntrinsicID_match(Intrinsic::ID IntrID)
OneOps_match(const T0 &Op1)
LLVM_NODISCARD T pop_back_val()
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
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.
bool match(ArrayRef< int > Mask)
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
VScaleVal_match m_VScale(const DataLayout &DL)
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
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()...
class_match< ConstantFP > m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
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)
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
static bool match(ICmpInst::Predicate Pred)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
LLVM Basic Block Representation.
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
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.
OneUse_match< T > m_OneUse(const T &SubPattern)
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
@ FCMP_ULT
1 1 0 0 True if unordered or less than
This helper class is used to match constant scalars, vector splats, and fixed width vectors that sati...
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.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
bool isValue(const APInt &C)
This is the shared class of boolean and integer constants.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
CastClass_match< OpTy, Instruction::UIToFP > m_UIToFP(const OpTy &Op)
bool isValue(const APFloat &C)
bool isOpType(unsigned Opcode)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
static bool match(ICmpInst::Predicate Pred)
Helper class for identifying signed min predicates.
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
bool match(Val *V, const Pattern &P)
Matches instructions with Opcode and three operands.
NotForbidUndef_match(const ValTy &V)
Helper class for identifying unordered max predicates.
bool isValue(const APInt &C)
Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
Match a specified basic block value.
Exact_match< T > m_Exact(const T &SubPattern)
AnyUnaryOp_match(const OP_t &X)
class_match< UnaryOperator > m_UnOp()
Match an arbitrary unary operation and ignore it.
specific_intval< true > m_SpecificIntAllowUndef(APInt V)
(vector float) vec_cmpeq(*A, *B) C
@ ICMP_ULE
unsigned less or equal
apfloat_match(const APFloat *&Res, bool AllowUndef)
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
cstfp_pred_ty< is_nonnan > m_NonNaN()
Match a non-NaN FP constant.
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
bitcast float %x to i32 %s=and i32 %t, 2147483647 %d=bitcast i32 %s to float ret float %d } declare float @fabsf(float %n) define float @bar(float %x) nounwind { %d=call float @fabsf(float %x) ret float %d } This IR(from PR6194):target datalayout="e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple="x86_64-apple-darwin10.0.0" %0=type { double, double } %struct.float3=type { float, float, float } define void @test(%0, %struct.float3 *nocapture %res) nounwind noinline ssp { entry:%tmp18=extractvalue %0 %0, 0 t
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
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.
into llvm powi allowing the code generator to produce balanced multiplication trees First
bool isValue(const APInt &C)
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)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
Helper class for identifying unordered min predicates.
deferredval_ty(Class *const &V)
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
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.
ConstantFP - Floating Point Values [float, double].
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(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.
bool isValue(const APFloat &C)
@ FCMP_OLT
0 1 0 0 True if ordered and less than
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
bool isOpType(unsigned Opcode)
apint_match m_APIntAllowUndef(const APInt *&Res)
Match APInt while allowing undefs in splat vector constants.
Matches patterns for vscale.
Match a specified Value*.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
bool isValue(const APInt &C)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
FNeg_match(const Op_t &Op)
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
static bool match(FCmpInst::Predicate Pred)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
api_pred_ty(const APInt *&R)
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
CastClass_match< OpTy, Instruction::FPTrunc > m_FPTrunc(const OpTy &Op)
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, OpTy > m_ZExtOrSelf(const OpTy &Op)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
TwoOps_match(const T0 &Op1, const T1 &Op2)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
This is an important base class in LLVM.
br_match m_UnconditionalBr(BasicBlock *&Succ)
match_combine_and< class_match< Constant >, match_unless< class_match< ConstantExpr > > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
Helper class for identifying signed max predicates.
LogicalOp_match< LHS, RHS, Instruction::Or > m_LogicalOr(const LHS &L, const RHS &R)
Matches L || R either in the form of L | R or L ? true : R.
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
bool match(ArrayRef< int > Mask)
Argument_match(unsigned OpIdx, const Opnd_t &V)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
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.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
OneUse_match(const SubPattern_t &SP)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
StandardInstrumentations SI(Debug, VerifyEach)
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
bool isValue(const APFloat &C)
Helper class for identifying unsigned min predicates.
@ ICMP_UGE
unsigned greater or equal
NotForbidUndef_match< ValTy > m_NotForbidUndef(const ValTy &V)
Matches a bitwise 'not' as 'xor V, -1' or 'xor -1, V'.
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
bool isValue(const APInt &C)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Class for arbitrary precision integers.
@ ICMP_SLT
signed less than
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Match a specified floating point value or vector of all elements of that value.
m_SpecificMask(ArrayRef< int > &MaskRef)
specific_intval< false > m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
bool isValue(const APFloat &C)
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.
bool match(ArrayRef< int > Mask, const Pattern &P)
SmallVector< MachineOperand, 4 > Cond
auto m_Undef()
Match an arbitrary undef constant.
@ ICMP_ULT
unsigned less than
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
bool isValue(const APInt &C)
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
llvm lib Support Unix the directory structure underneath this directory could look like only those directories actually needing to be created should be created further subdirectories could be created to reflect versions of the various standards For under SUS there could be v2
Represents an op.with.overflow intrinsic.
bool isOpType(unsigned Opcode)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
VScaleVal_match(const DataLayout &DL)
class_match< PoisonValue > m_Poison()
Match an arbitrary poison constant.
bool isValue(const APInt &C)
ArrayRef< int > & MaskRef
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
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.
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
CastClass_match< OpTy, Instruction::FPExt > m_FPExt(const OpTy &Op)
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
match_combine_or< CastClass_match< OpTy, Instruction::SExt >, OpTy > m_SExtOrSelf(const OpTy &Op)
InsertValue_match(const T0 &Op0, const T1 &Op1)
A constant value that is initialized with an expression using other constant values.
bool isOpType(unsigned Opcode)
bool isValue(const APFloat &C)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isValue(const APInt &C)
m_Intrinsic_Ty< Opnd0 >::Ty m_Sqrt(const Opnd0 &Op0)
llvm lib Support Unix the directory structure underneath this directory could look like only those directories actually needing to be created should be created further subdirectories could be created to reflect versions of the various standards For under SUS there could be v1
CastClass_match< OpTy, Instruction::FPToSI > m_FPToSI(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.
bool match(ArrayRef< int > Mask)
static bool check(const Value *V)
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
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!...
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
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.
Helper class for identifying unsigned max predicates.
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
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.
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
@ ICMP_SGE
signed greater or equal
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
bool isValue(const APFloat &C)
apfloat_match m_APFloatAllowUndef(const APFloat *&Res)
Match APFloat while allowing undefs in splat vector constants.
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.
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
ArrayRef< int > & MaskRef
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
Helper class for identifying ordered max predicates.
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
class_match< ConstantExpr > m_ConstantExpr()
Match an arbitrary ConstantExpr and ignore it.
Intrinsic matches are combinations of ID matchers, and argument matchers.
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.
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.
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
apint_match(const APInt *&Res, bool AllowUndef)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
@ ICMP_UGT
unsigned greater than
Signum_match(const Opnd_t &V)
bool isOpType(unsigned Opcode)
bool isValue(const APInt &C)
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'.
bool match(unsigned Opc, OpTy *V)
ScalarTy getKnownMinSize() const
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
CmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Helper class for identifying ordered min predicates.
CastClass_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
bool isValue(const APFloat &C)
specific_bbval(BasicBlock *Val)
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
bool isValue(const APInt &C)
match_combine_or(const LTy &Left, const RTy &Right)
apint_match m_APIntForbidUndef(const APInt *&Res)
Match APInt while forbidding undefs in splat vector constants.
class_match< BasicBlock > m_BasicBlock()
Match an arbitrary basic block value and ignore it.
static bool match(ICmpInst::Predicate Pred)
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
match_unless(const Ty &Matcher)
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
static bool match(FCmpInst::Predicate Pred)
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.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool isValue(const APFloat &C)
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.
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
bool isOpType(unsigned Opcode)
LLVM Value Representation.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
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'.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
LogicalOp_match< LHS, RHS, Instruction::And > m_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R either in the form of L & R or L ? R : false.
Exact_match(const SubPattern_t &SP)
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::Mul > m_Mul(const LHS &L, const RHS &R)
static bool match(FCmpInst::Predicate Pred)
reference emplace_back(ArgTypes &&... Args)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.