1//===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file provides a simple and efficient mechanism for performing general 10// tree-based pattern matches on the LLVM IR. The power of these routines is 11// that it allows you to write concise patterns that are expressive and easy to 12// understand. The other major advantage of this is that it allows you to 13// trivially capture/bind elements in the pattern to variables. For example, 14// you can do something like this: 17// Value *X, *Y; ConstantInt *C1, *C2; // (X & C1) | (Y & C2) 18// if (match(Exp, m_Or(m_And(m_Value(X), m_ConstantInt(C1)), 19// m_And(m_Value(Y), m_ConstantInt(C2))))) { 20// ... Pattern is matched and variables are bound ... 23// This is primarily useful to things like the instruction combiner, but can 24// also be useful for static analysis tools or code generators. 26//===----------------------------------------------------------------------===// 28#ifndef LLVM_IR_PATTERNMATCH_H 29#define LLVM_IR_PATTERNMATCH_H 47namespacePatternMatch {
49template <
typename Val,
typename Pattern>
boolmatch(Val *V,
constPattern &
P) {
62template <
typename OpTy>
boolmatch(OpTy *V) {
76template <
typename OpTy>
boolmatch(OpTy *V) {
77auto *
I = dyn_cast<FPMathOperator>(V);
88template <
typename ITy>
boolmatch(ITy *V) {
return isa<Class>(V); }
91/// Match an arbitrary value and ignore it. 94/// Match an arbitrary unary operation and ignore it. 99/// Match an arbitrary binary operation and ignore it. 104/// Matches any compare instruction and ignore it. 109if (isa<UndefValue>(V))
112constauto *CA = dyn_cast<ConstantAggregate>(V);
119// Either UndefValue, PoisonValue, or an aggregate that only contains 120// these is accepted by matcher. 121// CheckValue returns false if CA cannot satisfy this constraint. 123for (
constValue *
Op : CA->operand_values()) {
124if (isa<UndefValue>(
Op))
127constauto *CA = dyn_cast<ConstantAggregate>(
Op);
130if (Seen.
insert(CA).second)
140while (!Worklist.
empty()) {
149/// Match an arbitrary undef constant. This matches poison as well. 150/// If this is an aggregate and contains a non-aggregate element that is 151/// neither undef nor poison, the aggregate is not matched. 154/// Match an arbitrary UndefValue constant. 159/// Match an arbitrary poison constant. 164/// Match an arbitrary Constant and ignore it. 167/// Match an arbitrary ConstantInt and ignore it. 172/// Match an arbitrary ConstantFP and ignore it. 178template <
typename ITy>
boolmatch(ITy *V) {
179auto *
C = dyn_cast<Constant>(V);
180returnC && (isa<ConstantExpr>(
C) ||
C->containsConstantExpression());
184/// Match a constant expression or a constant that contains a constant 188/// Match an arbitrary basic block value and ignore it. 199template <
typename ITy>
boolmatch(ITy *V) {
return !
M.match(V); }
202/// Match if the inner matcher does *NOT* match. 207/// Matching combinators 214template <
typename ITy>
boolmatch(ITy *V) {
229template <
typename ITy>
boolmatch(ITy *V) {
237/// Combine two pattern matchers matching L || R 238template <
typename LTy,
typename RTy>
243/// Combine two pattern matchers matching L && R 244template <
typename LTy,
typename RTy>
256template <
typename ITy>
boolmatch(ITy *V) {
257if (
auto *CI = dyn_cast<ConstantInt>(V)) {
258Res = &CI->getValue();
261if (V->getType()->isVectorTy())
262if (
constauto *
C = dyn_cast<Constant>(V))
264 dyn_cast_or_null<ConstantInt>(
C->getSplatValue(
AllowPoison))) {
265Res = &CI->getValue();
271// Either constexpr if or renaming ConstantFP::getValueAPF to 272// ConstantFP::getValue is needed to do it via single template 273// function for both apint/apfloat. 281template <
typename ITy>
boolmatch(ITy *V) {
282if (
auto *CI = dyn_cast<ConstantFP>(V)) {
283Res = &CI->getValueAPF();
286if (V->getType()->isVectorTy())
287if (
constauto *
C = dyn_cast<Constant>(V))
289 dyn_cast_or_null<ConstantFP>(
C->getSplatValue(
AllowPoison))) {
290Res = &CI->getValueAPF();
297/// Match a ConstantInt or splatted ConstantVector, binding the 298/// specified pointer to the contained APInt. 300// Forbid poison by default to maintain previous behavior. 304/// Match APInt while allowing poison in splat vector constants. 309/// Match APInt while forbidding poison in splat vector constants. 314/// Match a ConstantFP or splatted ConstantVector, binding the 315/// specified pointer to the contained APFloat. 317// Forbid undefs by default to maintain previous behavior. 321/// Match APFloat while allowing poison in splat vector constants. 326/// Match APFloat while forbidding poison in splat vector constants. 332template <
typename ITy>
boolmatch(ITy *V) {
333if (
constauto *CI = dyn_cast<ConstantInt>(V)) {
334constAPInt &CIV = CI->getValue();
336return CIV ==
static_cast<uint64_t>(Val);
337// If Val is negative, and CI is shorter than it, truncate to the right 338// number of bits. If it is larger, then we have to sign extend. Just 339// compare their negated values. 346/// Match a ConstantInt with a specific value. 351/// This helper class is used to match constant scalars, vector splats, 352/// and fixed width vectors that satisfy a specified predicate. 353/// For fixed width vector constants, poison elements are ignored if AllowPoison 355template <
typename Predicate,
typename ConstantVal,
bool AllowPoison>
359if (
constauto *CV = dyn_cast<ConstantVal>(V))
360return this->isValue(CV->getValue());
361if (
constauto *VTy = dyn_cast<VectorType>(V->getType())) {
362if (
constauto *
C = dyn_cast<Constant>(V)) {
363if (
constauto *CV = dyn_cast_or_null<ConstantVal>(
C->getSplatValue()))
364return this->isValue(CV->getValue());
366// Number of elements of a scalable vector unknown at compile time 367auto *FVTy = dyn_cast<FixedVectorType>(VTy);
371// Non-splat vector constant: check each element for a match. 372unsigned NumElts = FVTy->getNumElements();
373assert(NumElts != 0 &&
"Constant vector with no elements?");
374bool HasNonPoisonElements =
false;
375for (
unsigned i = 0; i != NumElts; ++i) {
379if (AllowPoison && isa<PoisonValue>(Elt))
381auto *CV = dyn_cast<ConstantVal>(Elt);
382if (!CV || !this->isValue(CV->getValue()))
384 HasNonPoisonElements =
true;
386return HasNonPoisonElements;
392template <
typename ITy>
boolmatch(ITy *V) {
395 *
Res = cast<Constant>(V);
402/// specialization of cstval_pred_ty for ConstantInt 403template <
typename Predicate,
bool AllowPoison = true>
406/// specialization of cstval_pred_ty for ConstantFP 407template <
typename Predicate>
409/*AllowPoison=*/true>;
411/// This helper class is used to match scalar and vector constants that 412/// satisfy a specified predicate, and bind them to an APInt. 418template <
typename ITy>
boolmatch(ITy *V) {
419if (
constauto *CI = dyn_cast<ConstantInt>(V))
420if (this->isValue(CI->getValue())) {
421Res = &CI->getValue();
424if (V->getType()->isVectorTy())
425if (
constauto *
C = dyn_cast<Constant>(V))
426if (
auto *CI = dyn_cast_or_null<ConstantInt>(
427C->getSplatValue(
/*AllowPoison=*/true)))
428if (this->isValue(CI->getValue())) {
429Res = &CI->getValue();
437/// This helper class is used to match scalar and vector constants that 438/// satisfy a specified predicate, and bind them to an APFloat. 439/// Poison is allowed in splat vector constants. 445template <
typename ITy>
boolmatch(ITy *V) {
446if (
constauto *CI = dyn_cast<ConstantFP>(V))
447if (this->isValue(CI->getValue())) {
448Res = &CI->getValue();
451if (V->getType()->isVectorTy())
452if (
constauto *
C = dyn_cast<Constant>(V))
453if (
auto *CI = dyn_cast_or_null<ConstantFP>(
454C->getSplatValue(
/* AllowPoison */true)))
455if (this->isValue(CI->getValue())) {
456Res = &CI->getValue();
464/////////////////////////////////////////////////////////////////////////////// 466// Encapsulate constant value queries for use in templated predicate matchers. 467// This allows checking if constants match using compound predicates and works 468// with vector constants, possibly with relaxed constraints. For example, ignore 471/////////////////////////////////////////////////////////////////////////////// 478/// Match an integer or vector where CheckFn(ele) for each element is true. 479/// For vectors, poison elements are assumed to match. 490/// Match a float or vector where CheckFn(ele) for each element is true. 491/// For vectors, poison elements are assumed to match. 505/// Match an integer or vector with any integral constant. 506/// For vectors, this includes constants with undefined elements. 522/// Match an integer or vector with all bits set. 523/// For vectors, this includes constants with undefined elements. 535/// Match an integer or vector with values having all bits except for the high 536/// bit set (0x7f...). 537/// For vectors, this includes constants with undefined elements. 548/// Match an integer or vector of negative values. 549/// For vectors, this includes constants with undefined elements. 558/// Match an integer or vector of non-negative values. 559/// For vectors, this includes constants with undefined elements. 568/// Match an integer or vector of strictly positive values. 569/// For vectors, this includes constants with undefined elements. 580/// Match an integer or vector of non-positive values. 581/// For vectors, this includes constants with undefined elements. 590/// Match an integer 1 or a vector with all elements equal to 1. 591/// For vectors, this includes constants with undefined elements. 597/// Match an integer 0 or a vector with all elements equal to 0. 598/// For vectors, this includes constants with undefined elements. 604template <
typename ITy>
boolmatch(ITy *V) {
605auto *
C = dyn_cast<Constant>(V);
606// FIXME: this should be able to do something for scalable vectors 610/// Match any null constant or a vector with all elements equal to 0. 611/// For vectors, this includes constants with undefined elements. 617/// Match an integer or vector power-of-2. 618/// For vectors, this includes constants with undefined elements. 625/// Match a integer or vector negated power-of-2. 626/// For vectors, this includes constants with undefined elements. 637/// Match a integer or vector negated power-of-2. 638/// For vectors, this includes constants with undefined elements. 650/// Match an integer or vector of 0 or power-of-2 values. 651/// For vectors, this includes constants with undefined elements. 662/// Match an integer or vector with only the sign bit(s) set. 663/// For vectors, this includes constants with undefined elements. 671/// Match an integer or vector with only the low bit(s) set. 672/// For vectors, this includes constants with undefined elements. 681/// Match an integer or vector with only the low bit(s) set. 682/// For vectors, this includes constants with undefined elements. 695/// Match an integer or vector with every element comparing 'pred' (eg/ne/...) 696/// to Threshold. For vectors, this includes constants with undefined elements. 708/// Match an arbitrary NaN constant. This includes quiet and signalling nans. 709/// For vectors, this includes constants with undefined elements. 715/// Match a non-NaN FP constant. 716/// For vectors, this includes constants with undefined elements. 724/// Match a positive or negative infinity FP constant. 725/// For vectors, this includes constants with undefined elements. 731/// Match a non-infinity FP constant, i.e. finite or NaN. 732/// For vectors, this includes constants with undefined elements. 740/// Match a finite FP constant, i.e. not infinity or NaN. 741/// For vectors, this includes constants with undefined elements. 750/// Match a finite non-zero FP constant. 751/// For vectors, this includes constants with undefined elements. 762/// Match a floating-point negative zero or positive zero. 763/// For vectors, this includes constants with undefined elements. 771/// Match a floating-point positive zero. 772/// For vectors, this includes constants with undefined elements. 780/// Match a floating-point negative zero. 781/// For vectors, this includes constants with undefined elements. 789/// Match a floating-point non-zero. 790/// For vectors, this includes constants with undefined elements. 799/// Match a floating-point non-zero that is not a denormal. 800/// For vectors, this includes constants with undefined elements. 805/////////////////////////////////////////////////////////////////////////////// 812template <
typename ITy>
boolmatch(ITy *V) {
813if (
auto *CV = dyn_cast<Class>(V)) {
821/// Match a value, capturing it if we match. 825/// Match an instruction, capturing it if we match. 827/// Match a unary operator, capturing it if we match. 829/// Match a binary operator, capturing it if we match. 831/// Match a with overflow intrinsic, capturing it if we match. 840/// Match an UndefValue, capturing the value if we match. 843/// Match a Constant, capturing the value if we match. 846/// Match a ConstantInt, capturing the value if we match. 849/// Match a ConstantFP, capturing the value if we match. 852/// Match a ConstantExpr, capturing the value if we match. 855/// Match a basic block value, capturing it if we match. 861/// Match an arbitrary immediate Constant and ignore it. 868/// Match an immediate Constant, capturing the value if we match. 875/// Match a specified Value*. 881template <
typename ITy>
boolmatch(ITy *V) {
return V ==
Val; }
884/// Match if we have a specific specified value. 887/// Stores a reference to the Value *, not the Value * itself, 888/// thus can be used in commutative matchers. 894template <
typename ITy>
boolmatch(ITy *
const V) {
return V ==
Val; }
897/// Like m_Specific(), but works if the specific value to match is determined 898/// as part of the same match() expression. For example: 899/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will 900/// bind X before the pattern match starts. 901/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against 902/// whichever value m_Value(X) populated. 908/// Match a specified floating point value or vector of all elements of 915template <
typename ITy>
boolmatch(ITy *V) {
916if (
constauto *CFP = dyn_cast<ConstantFP>(V))
917return CFP->isExactlyValue(
Val);
918if (V->getType()->isVectorTy())
919if (
constauto *
C = dyn_cast<Constant>(V))
920if (
auto *CFP = dyn_cast_or_null<ConstantFP>(
C->getSplatValue()))
921return CFP->isExactlyValue(
Val);
926/// Match a specific floating point value or vector with all elements 927/// equal to the value. 930/// Match a float 1.0 or vector with all elements equal to 1.0. 938template <
typename ITy>
boolmatch(ITy *V) {
939if (
constauto *CV = dyn_cast<ConstantInt>(V))
941VR = CV->getZExtValue();
948/// Match a specified integer value or vector of all elements of that 955template <
typename ITy>
boolmatch(ITy *V) {
956constauto *CI = dyn_cast<ConstantInt>(V);
957if (!CI && V->getType()->isVectorTy())
958if (
constauto *
C = dyn_cast<Constant>(V))
959 CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue(AllowPoison));
970template <
typename ITy>
boolmatch(ITy *V) {
971constauto *CI = dyn_cast<ConstantInt>(V);
972if (!CI && V->getType()->isVectorTy())
973if (
constauto *
C = dyn_cast<Constant>(V))
974 CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue(AllowPoison));
976return CI && CI->getValue() ==
Val;
980/// Match a specific integer value or vector with all elements equal to 998/// Match a ConstantInt and bind to its value. This does not match 999/// ConstantInts wider than 64-bits. 1002/// Match a specified basic block value. 1008template <
typename ITy>
boolmatch(ITy *V) {
1009constauto *BB = dyn_cast<BasicBlock>(V);
1010return BB && BB ==
Val;
1014/// Match a specific basic block value. 1019/// A commutative-friendly version of m_Specific(). 1028//===----------------------------------------------------------------------===// 1029// Matcher for any binary operator. 1031template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
1036// The evaluation order is always stable, regardless of Commutability. 1037// The LHS is always matched first. 1040template <
typename OpTy>
boolmatch(OpTy *V) {
1041if (
auto *
I = dyn_cast<BinaryOperator>(V))
1042return (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
1043 (Commutable &&
L.match(
I->getOperand(1)) &&
1044R.match(
I->getOperand(0)));
1049template <
typename LHS,
typename RHS>
1054//===----------------------------------------------------------------------===// 1055// Matcher for any unary operator. 1056// TODO fuse unary, binary matcher into n-ary matcher 1063template <
typename OpTy>
boolmatch(OpTy *V) {
1064if (
auto *
I = dyn_cast<UnaryOperator>(V))
1065returnX.match(
I->getOperand(0));
1074//===----------------------------------------------------------------------===// 1075// Matchers for specific binary operators. 1078template <
typenameLHS_t,
typenameRHS_t,
unsigned Opcode,
1079bool Commutable =
false>
1084// The evaluation order is always stable, regardless of Commutability. 1085// The LHS is always matched first. 1088template <
typename OpTy>
inlineboolmatch(
unsigned Opc, OpTy *V) {
1089if (V->getValueID() == Value::InstructionVal + Opc) {
1090auto *
I = cast<BinaryOperator>(V);
1091return (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
1092 (Commutable &&
L.match(
I->getOperand(1)) &&
1093R.match(
I->getOperand(0)));
1098template <
typename OpTy>
boolmatch(OpTy *V) {
returnmatch(Opcode, V); }
1101template <
typename LHS,
typename RHS>
1107template <
typename LHS,
typename RHS>
1113template <
typename LHS,
typename RHS>
1119template <
typename LHS,
typename RHS>
1129template <
typename OpTy>
boolmatch(OpTy *V) {
1130auto *FPMO = dyn_cast<FPMathOperator>(V);
1134if (FPMO->getOpcode() == Instruction::FNeg)
1135returnX.match(FPMO->getOperand(0));
1137if (FPMO->getOpcode() == Instruction::FSub) {
1138if (FPMO->hasNoSignedZeros()) {
1139// With 'nsz', any zero goes. 1143// Without 'nsz', we need fsub -0.0, X exactly. 1148returnX.match(FPMO->getOperand(1));
1155/// Match 'fneg X' as 'fsub -0.0, X'. 1160/// Match 'fneg X' as 'fsub +-0.0, X'. 1161template <
typename RHS>
1167template <
typename LHS,
typename RHS>
1173template <
typename LHS,
typename RHS>
1179template <
typename LHS,
typename RHS>
1185template <
typename LHS,
typename RHS>
1191template <
typename LHS,
typename RHS>
1197template <
typename LHS,
typename RHS>
1203template <
typename LHS,
typename RHS>
1209template <
typename LHS,
typename RHS>
1215template <
typename LHS,
typename RHS>
1221template <
typename LHS,
typename RHS>
1227template <
typename LHS,
typename RHS>
1233template <
typename LHS,
typename RHS>
1239template <
typename LHS,
typename RHS>
1245template <
typename LHS,
typename RHS>
1251template <
typenameLHS_t,
typenameRHS_t,
unsigned Opcode,
1252unsigned WrapFlags = 0,
bool Commutable =
false>
1260template <
typename OpTy>
boolmatch(OpTy *V) {
1261if (
auto *
Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1262if (
Op->getOpcode() != Opcode)
1265 !
Op->hasNoUnsignedWrap())
1268 !
Op->hasNoSignedWrap())
1270return (
L.match(
Op->getOperand(0)) &&
R.match(
Op->getOperand(1))) ||
1271 (Commutable &&
L.match(
Op->getOperand(1)) &&
1272R.match(
Op->getOperand(0)));
1278template <
typename LHS,
typename RHS>
1286template <
typename LHS,
typename RHS>
1294template <
typename LHS,
typename RHS>
1302template <
typename LHS,
typename RHS>
1311template <
typename LHS,
typename RHS>
1320template <
typename LHS,
typename RHS>
1329template <
typename LHS,
typename RHS>
1337template <
typename LHS,
typename RHS>
1345template <
typename LHS,
typename RHS>
1354template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
1362template <
typename OpTy>
boolmatch(OpTy *V) {
1367/// Matches a specific opcode. 1368template <
typename LHS,
typename RHS>
1374template <
typename LHS,
typename RHS,
bool Commutable = false>
1381template <
typename OpTy>
boolmatch(OpTy *V) {
1382if (
auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1383assert(PDI->getOpcode() == Instruction::Or &&
"Only or can be disjoint");
1384if (!PDI->isDisjoint())
1386return (
L.match(PDI->getOperand(0)) &&
R.match(PDI->getOperand(1))) ||
1387 (Commutable &&
L.match(PDI->getOperand(1)) &&
1388R.match(PDI->getOperand(0)));
1394template <
typename LHS,
typename RHS>
1399template <
typename LHS,
typename RHS>
1405/// Match either "add" or "or disjoint". 1406template <
typename LHS,
typename RHS>
1413/// Match either "add nsw" or "or disjoint" 1414template <
typename LHS,
typename RHS>
1423/// Match either "add nuw" or "or disjoint" 1424template <
typename LHS,
typename RHS>
1433template <
typename LHS,
typename RHS>
1440template <
typename OpTy>
boolmatch(OpTy *V) {
1441if (
auto *
Op = dyn_cast<BinaryOperator>(V)) {
1442if (
Op->getOpcode() == Instruction::Sub &&
Op->hasNoUnsignedWrap() &&
1445elseif (
Op->getOpcode() != Instruction::Xor)
1447return (
L.match(
Op->getOperand(0)) &&
R.match(
Op->getOperand(1))) ||
1448 (
L.match(
Op->getOperand(1)) &&
R.match(
Op->getOperand(0)));
1454/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()` 1455/// Only commutative matcher as the `sub` will need to swap the L and R. 1456template <
typename LHS,
typename RHS>
1461//===----------------------------------------------------------------------===// 1462// Class that matches a group of binary opcodes. 1465bool Commutable =
false>
1472template <
typename OpTy>
boolmatch(OpTy *V) {
1473if (
auto *
I = dyn_cast<Instruction>(V))
1474return this->isOpType(
I->getOpcode()) &&
1475 ((
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) ||
1476 (Commutable &&
L.match(
I->getOperand(1)) &&
1477R.match(
I->getOperand(0))));
1488return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1494return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1506return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1512return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1516/// Matches shift operations. 1517template <
typename LHS,
typename RHS>
1523/// Matches logical shift operations. 1524template <
typename LHS,
typename RHS>
1530/// Matches logical shift operations. 1531template <
typename LHS,
typename RHS>
1537/// Matches bitwise logic operations. 1538template <
typename LHS,
typename RHS>
1544/// Matches bitwise logic operations in either order. 1545template <
typename LHS,
typename RHS>
1551/// Matches integer division operations. 1552template <
typename LHS,
typename RHS>
1558/// Matches integer remainder operations. 1559template <
typename LHS,
typename RHS>
1565//===----------------------------------------------------------------------===// 1566// Class that matches exact binary ops. 1573template <
typename OpTy>
boolmatch(OpTy *V) {
1574if (
auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1584//===----------------------------------------------------------------------===// 1585// Matchers for CmpInst classes 1588template <
typenameLHS_t,
typenameRHS_t,
typename Class,
1589bool Commutable =
false>
1595// The evaluation order is always stable, regardless of Commutability. 1596// The LHS is always matched first. 1602template <
typename OpTy>
boolmatch(OpTy *V) {
1603if (
auto *
I = dyn_cast<Class>(V)) {
1604if (
L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1))) {
1609if (Commutable &&
L.match(
I->getOperand(1)) &&
1610R.match(
I->getOperand(0))) {
1620template <
typename LHS,
typename RHS>
1626template <
typename LHS,
typename RHS>
1628constLHS &L,
constRHS &R) {
1632template <
typename LHS,
typename RHS>
1634constLHS &L,
constRHS &R) {
1638template <
typename LHS,
typename RHS>
1643template <
typename LHS,
typename RHS>
1648template <
typename LHS,
typename RHS>
1653// Same as CmpClass, but instead of saving Pred as out output variable, match a 1654// specific input pred for equality. 1655template <
typenameLHS_t,
typenameRHS_t,
typename Class,
1656bool Commutable =
false>
1665template <
typename OpTy>
boolmatch(OpTy *V) {
1666if (
auto *
I = dyn_cast<Class>(V)) {
1668L.match(
I->getOperand(0)) &&
R.match(
I->getOperand(1)))
1670ifconstexpr (Commutable) {
1673L.match(
I->getOperand(1)) &&
R.match(
I->getOperand(0)))
1682template <
typename LHS,
typename RHS>
1688template <
typename LHS,
typename RHS>
1694template <
typename LHS,
typename RHS>
1700template <
typename LHS,
typename RHS>
1706//===----------------------------------------------------------------------===// 1707// Matchers for instructions with a given opcode and number of operands. 1710/// Matches instructions with Opcode and three operands. 1716template <
typename OpTy>
boolmatch(OpTy *V) {
1717if (V->getValueID() == Value::InstructionVal + Opcode) {
1718auto *
I = cast<Instruction>(V);
1719returnOp1.match(
I->getOperand(0));
1725/// Matches instructions with Opcode and three operands. 1732template <
typename OpTy>
boolmatch(OpTy *V) {
1733if (V->getValueID() == Value::InstructionVal + Opcode) {
1734auto *
I = cast<Instruction>(V);
1735returnOp1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1));
1741/// Matches instructions with Opcode and three operands. 1742template <
typename T0,
typenameT1,
typename T2,
unsigned Opcode,
1743bool CommutableOp2Op3 =
false>
1752template <
typename OpTy>
boolmatch(OpTy *V) {
1753if (V->getValueID() == Value::InstructionVal + Opcode) {
1754auto *
I = cast<Instruction>(V);
1755if (!
Op1.match(
I->getOperand(0)))
1757if (
Op2.match(
I->getOperand(1)) &&
Op3.match(
I->getOperand(2)))
1759return CommutableOp2Op3 &&
Op2.match(
I->getOperand(2)) &&
1760Op3.match(
I->getOperand(1));
1766/// Matches instructions with Opcode and any number of operands 1772// Operand matching works by recursively calling match_operands, matching the 1773// operands left to right. The first version is called for each operand but 1774// the last, for which the second version is called. The second version of 1775// match_operands is also used to match each individual operand. 1776template <
int Idx,
int Last>
1778return match_operands<Idx, Idx>(
I) && match_operands<Idx + 1, Last>(
I);
1781template <
int Idx,
int Last>
1783return std::get<Idx>(
Operands).match(
I->getOperand(
Idx));
1786template <
typename OpTy>
boolmatch(OpTy *V) {
1787if (V->getValueID() == Value::InstructionVal + Opcode) {
1788auto *
I = cast<Instruction>(V);
1789returnI->getNumOperands() ==
sizeof...(OperandTypes) &&
1796/// Matches SelectInst. 1797template <
typename Cond,
typename LHS,
typename RHS>
1803/// This matches a select of two constants, e.g.: 1804/// m_SelectCst<-1, 0>(m_Value(V)) 1805template <
int64_t L,
int64_t R,
typename Cond>
1807 Instruction::Select>
1809returnm_Select(
C, m_ConstantInt<L>(), m_ConstantInt<R>());
1812/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS) 1813template <
typename LHS,
typename RHS>
1820/// Matches FreezeInst. 1821template <
typename OpTy>
1826/// Matches InsertElementInst. 1827template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1834/// Matches ExtractElementInst. 1835template <
typename Val_t,
typename Idx_t>
1850template <
typename OpTy>
boolmatch(OpTy *V) {
1851if (
auto *
I = dyn_cast<ShuffleVectorInst>(V)) {
1852returnOp1.match(
I->getOperand(0)) &&
Op2.match(
I->getOperand(1)) &&
1853Mask.match(
I->getShuffleMask());
1870returnall_of(Mask, [](
int Elem) {
return Elem == 0 || Elem == -1; });
1884constauto *
First =
find_if(Mask, [](
int Elem) {
return Elem != -1; });
1885if (
First == Mask.end())
1889 [
First](
int Elem) {
return Elem == *
First || Elem == -1; });
1900template <
typename OpTy>
boolmatch(OpTy *V) {
1901auto *
GEP = dyn_cast<GEPOperator>(V);
1902returnGEP &&
GEP->getSourceElementType()->isIntegerTy(8) &&
1908/// Matches ShuffleVectorInst independently of mask value. 1909template <
typename V1_t,
typename V2_t>
1915template <
typename V1_t,
typename V2_t,
typename Mask_t>
1917m_Shuffle(
const V1_t &v1,
const V2_t &v2,
const Mask_t &mask) {
1921/// Matches LoadInst. 1922template <
typename OpTy>
1927/// Matches StoreInst. 1928template <
typename ValueOpTy,
typename Po
interOpTy>
1930m_Store(
const ValueOpTy &ValueOp,
const PointerOpTy &PointerOp) {
1935/// Matches GetElementPtrInst. 1936template <
typename... OperandTypes>
1937inlineautom_GEP(
const OperandTypes &...Ops) {
1938returnAnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
1941/// Matches GEP with i8 source element type 1942template <
typename Po
interOpTy,
typename OffsetOpTy>
1944m_PtrAdd(
const PointerOpTy &PointerOp,
const OffsetOpTy &OffsetOp) {
1948//===----------------------------------------------------------------------===// 1949// Matchers for CastInst classes 1957template <
typename OpTy>
boolmatch(OpTy *V) {
1958if (
auto *O = dyn_cast<Operator>(V))
1959return O->getOpcode() == Opcode &&
Op.match(O->getOperand(0));
1969template <
typename OpTy>
boolmatch(OpTy *V) {
1970if (
auto *
I = dyn_cast<Class>(V))
1971returnOp.match(
I->getOperand(0));
1983template <
typename OpTy>
boolmatch(OpTy *V) {
1984if (
auto *O = dyn_cast<Operator>(V))
1985return O->getOpcode() == Instruction::PtrToInt &&
1988Op.match(O->getOperand(0));
1998template <
typename OpTy>
boolmatch(OpTy *V) {
1999if (
auto *
I = dyn_cast<ZExtInst>(V))
2000returnI->hasNonNeg() &&
Op.match(
I->getOperand(0));
2010template <
typename OpTy>
boolmatch(OpTy *V) {
2011if (
auto *
I = dyn_cast<TruncInst>(V))
2012return (
I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2013Op.match(
I->getOperand(0));
2019template <
typename OpTy>
2030template <
typename OpTy>
boolmatch(OpTy *V) {
2031auto *
I = dyn_cast<BitCastInst>(V);
2034Type *SrcType =
I->getSrcTy();
2035Type *DstType =
I->getType();
2036// Make sure the bitcast doesn't change between scalar and vector and 2037// doesn't change the number of vector elements. 2040if (
VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2042 cast<VectorType>(DstType)->getElementCount())
2044returnOp.match(
I->getOperand(0));
2048template <
typename OpTy>
2053/// Matches PtrToInt. 2054template <
typename OpTy>
2060template <
typename OpTy>
2066/// Matches IntToPtr. 2067template <
typename OpTy>
2074template <
typename OpTy>
2079/// Matches trunc nuw. 2080template <
typename OpTy>
2086/// Matches trunc nsw. 2087template <
typename OpTy>
2093template <
typename OpTy>
2100template <
typename OpTy>
2106template <
typename OpTy>
2111template <
typename OpTy>
2116template <
typename OpTy>
2122template <
typename OpTy>
2128/// Match either "sext" or "zext nneg". 2129template <
typename OpTy>
2135template <
typename OpTy>
2142template <
typename OpTy>
2150template <
typename OpTy>
2155template <
typename OpTy>
2160template <
typename OpTy>
2165template <
typename OpTy>
2170template <
typename OpTy>
2175template <
typename OpTy>
2180//===----------------------------------------------------------------------===// 2181// Matchers for control flow. 2189template <
typename OpTy>
boolmatch(OpTy *V) {
2190if (
auto *BI = dyn_cast<BranchInst>(V))
2191if (BI->isUnconditional()) {
2192Succ = BI->getSuccessor(0);
2201template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
2207brc_match(
const Cond_t &
C,
const TrueBlock_t &t,
const FalseBlock_t &f)
2210template <
typename OpTy>
boolmatch(OpTy *V) {
2211if (
auto *BI = dyn_cast<BranchInst>(V))
2212if (BI->isConditional() &&
Cond.match(BI->getCondition()))
2213returnT.match(BI->getSuccessor(0)) &&
F.match(BI->getSuccessor(1));
2218template <
typename Cond_t>
2225template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
2227m_Br(
const Cond_t &
C,
const TrueBlock_t &
T,
const FalseBlock_t &
F) {
2231//===----------------------------------------------------------------------===// 2232// Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y). 2235template <
typename CmpInst_t,
typenameLHS_t,
typenameRHS_t,
typename Pred_t,
2236bool Commutable =
false>
2242// The evaluation order is always stable, regardless of Commutability. 2243// The LHS is always matched first. 2246template <
typename OpTy>
boolmatch(OpTy *V) {
2247if (
auto *
II = dyn_cast<IntrinsicInst>(V)) {
2254return (
L.match(
LHS) &&
R.match(
RHS)) ||
2255 (Commutable &&
L.match(
RHS) &&
R.match(
LHS));
2258// Look for "(x pred y) ? x : y" or "(x pred y) ? y : x". 2259auto *SI = dyn_cast<SelectInst>(V);
2262auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
2265// At this point we have a select conditioned on a comparison. Check that 2266// it is the values returned by the select that are being compared. 2267auto *TrueVal = SI->getTrueValue();
2268auto *FalseVal = SI->getFalseValue();
2269auto *
LHS = Cmp->getOperand(0);
2270auto *
RHS = Cmp->getOperand(1);
2271if ((TrueVal !=
LHS || FalseVal !=
RHS) &&
2272 (TrueVal !=
RHS || FalseVal !=
LHS))
2274typename CmpInst_t::Predicate Pred =
2275LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2276// Does "(x pred y) ? x : y" represent the desired max/min operation? 2277if (!Pred_t::match(Pred))
2279// It does! Bind the operands. 2280return (
L.match(
LHS) &&
R.match(
RHS)) ||
2281 (Commutable &&
L.match(
RHS) &&
R.match(
LHS));
2285/// Helper class for identifying signed max predicates. 2292/// Helper class for identifying signed min predicates. 2299/// Helper class for identifying unsigned max predicates. 2306/// Helper class for identifying unsigned min predicates. 2313/// Helper class for identifying ordered max predicates. 2320/// Helper class for identifying ordered min predicates. 2327/// Helper class for identifying unordered max predicates. 2334/// Helper class for identifying unordered min predicates. 2341template <
typename LHS,
typename RHS>
2347template <
typename LHS,
typename RHS>
2353template <
typename LHS,
typename RHS>
2359template <
typename LHS,
typename RHS>
2365template <
typename LHS,
typename RHS>
2376/// Match an 'ordered' floating point maximum function. 2377/// Floating point has one special value 'NaN'. Therefore, there is no total 2378/// order. However, if we can ignore the 'NaN' value (for example, because of a 2379/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum' 2380/// semantics. In the presence of 'NaN' we have to preserve the original 2381/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate. 2383/// max(L, R) iff L and R are not NaN 2384/// m_OrdFMax(L, R) = R iff L or R are NaN 2385template <
typename LHS,
typename RHS>
2391/// Match an 'ordered' floating point minimum function. 2392/// Floating point has one special value 'NaN'. Therefore, there is no total 2393/// order. However, if we can ignore the 'NaN' value (for example, because of a 2394/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum' 2395/// semantics. In the presence of 'NaN' we have to preserve the original 2396/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate. 2398/// min(L, R) iff L and R are not NaN 2399/// m_OrdFMin(L, R) = R iff L or R are NaN 2400template <
typename LHS,
typename RHS>
2406/// Match an 'unordered' floating point maximum function. 2407/// Floating point has one special value 'NaN'. Therefore, there is no total 2408/// order. However, if we can ignore the 'NaN' value (for example, because of a 2409/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum' 2410/// semantics. In the presence of 'NaN' we have to preserve the original 2411/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate. 2413/// max(L, R) iff L and R are not NaN 2414/// m_UnordFMax(L, R) = L iff L or R are NaN 2415template <
typename LHS,
typename RHS>
2421/// Match an 'unordered' floating point minimum function. 2422/// Floating point has one special value 'NaN'. Therefore, there is no total 2423/// order. However, if we can ignore the 'NaN' value (for example, because of a 2424/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum' 2425/// semantics. In the presence of 'NaN' we have to preserve the original 2426/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate. 2428/// min(L, R) iff L and R are not NaN 2429/// m_UnordFMin(L, R) = L iff L or R are NaN 2430template <
typename LHS,
typename RHS>
2436/// Match an 'ordered' or 'unordered' floating point maximum function. 2437/// Floating point has one special value 'NaN'. Therefore, there is no total 2438/// order. However, if we can ignore the 'NaN' value (for example, because of a 2439/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum' 2441template <
typename LHS,
typename RHS>
2449/// Match an 'ordered' or 'unordered' floating point minimum function. 2450/// Floating point has one special value 'NaN'. Therefore, there is no total 2451/// order. However, if we can ignore the 'NaN' value (for example, because of a 2452/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum' 2454template <
typename LHS,
typename RHS>
2462/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'. 2463/// NOTE: we first match the 'Not' (by matching '-1'), 2464/// and only then match the inner matcher! 2465template <
typename ValTy>
2471template <
typename ValTy>
2478//===----------------------------------------------------------------------===// 2479// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b 2480// Note that S might be matched to other instructions than AddInst. 2483template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
2492template <
typename OpTy>
boolmatch(OpTy *V) {
2493Value *ICmpLHS, *ICmpRHS;
2498Value *AddLHS, *AddRHS;
2501// (a + b) u< a, (a + b) u< b 2503if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2504returnL.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpLHS);
2506// a >u (a + b), b >u (a + b) 2508if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2509returnL.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpRHS);
2515if (XorExpr.match(ICmpLHS))
2516returnL.match(Op1) &&
R.match(ICmpRHS) &&
S.match(ICmpLHS);
2520if (XorExpr.match(ICmpRHS))
2521returnL.match(Op1) &&
R.match(ICmpLHS) &&
S.match(ICmpRHS);
2524// Match special-case for increment-by-1. 2530returnL.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpLHS);
2535returnL.match(AddLHS) &&
R.match(AddRHS) &&
S.match(ICmpRHS);
2542/// Match an icmp instruction checking for unsigned overflow on addition. 2544/// S is matched to the addition whose result is being checked for overflow, and 2545/// L and R are matched to the LHS and RHS of S. 2546template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
2558template <
typename OpTy>
boolmatch(OpTy *V) {
2559// FIXME: Should likely be switched to use `CallBase`. 2560if (
constauto *CI = dyn_cast<CallInst>(V))
2561returnVal.match(CI->getArgOperand(
OpI));
2566/// Match an argument. 2567template <
unsigned OpI,
typename Opnd_t>
2572/// Intrinsic matchers. 2578template <
typename OpTy>
boolmatch(OpTy *V) {
2579if (
constauto *CI = dyn_cast<CallInst>(V))
2580if (
constauto *
F = CI->getCalledFunction())
2581returnF->getIntrinsicID() ==
ID;
2586/// Intrinsic matches are combinations of ID matchers, and argument 2587/// matchers. Higher arity matcher are defined recursively in terms of and-ing 2588/// them with lower arity matchers. Here's some convenient typedefs for up to 2589/// several arguments, and more can be added as needed 2590template <
typename T0 = void,
typenameT1 = void,
typename T2 = void,
2591typename T3 = void,
typename T4 = void,
typename T5 = void,
2592typename T6 = void,
typename T7 = void,
typename T8 = void,
2593typename T9 = void,
typename T10 =
void>
2602template <
typename T0,
typename T1,
typename T2>
2607template <
typename T0,
typename T1,
typename T2,
typename T3>
2613template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4>
2619template <
typename T0,
typenameT1,
typename T2,
typename T3,
typename T4,
2626/// Match intrinsic calls like this: 2627/// m_Intrinsic<Intrinsic::fabs>(m_Value(X)) 2632/// Matches MaskedLoad Intrinsic. 2633template <
typename Opnd0,
typename Opnd1,
typename Opnd2,
typename Opnd3>
2637return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2, Op3);
2640/// Matches MaskedGather Intrinsic. 2641template <
typename Opnd0,
typename Opnd1,
typename Opnd2,
typename Opnd3>
2645return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2, Op3);
2648template <Intrinsic::ID IntrID,
typename T0>
2650returnm_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
2653template <Intrinsic::ID IntrID,
typename T0,
typename T1>
2656returnm_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
2659template <Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2>
2662returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2669returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2673typename T3,
typename T4>
2677returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2678 m_Argument<4>(Op4));
2682typename T3,
typename T4,
typename T5>
2685const T4 &Op4,
const T5 &Op5) {
2686returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2687 m_Argument<5>(Op5));
2690// Helper intrinsic matching specializations. 2691template <
typename Opnd0>
2693return m_Intrinsic<Intrinsic::bitreverse>(Op0);
2696template <
typename Opnd0>
2698return m_Intrinsic<Intrinsic::bswap>(Op0);
2701template <
typename Opnd0>
2703return m_Intrinsic<Intrinsic::fabs>(Op0);
2706template <
typename Opnd0>
2708return m_Intrinsic<Intrinsic::canonicalize>(Op0);
2711template <
typename Opnd0,
typename Opnd1>
2714return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2717template <
typename Opnd0,
typename Opnd1>
2720return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2723template <
typename Opnd0,
typename Opnd1,
typename Opnd2>
2725m_FShl(
const Opnd0 &Op0,
const Opnd1 &Op1,
const Opnd2 &Op2) {
2726return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2729template <
typename Opnd0,
typename Opnd1,
typename Opnd2>
2731m_FShr(
const Opnd0 &Op0,
const Opnd1 &Op1,
const Opnd2 &Op2) {
2732return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2735template <
typename Opnd0>
2737return m_Intrinsic<Intrinsic::sqrt>(Op0);
2740template <
typename Opnd0,
typename Opnd1>
2743return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2746template <
typename Opnd0>
2748return m_Intrinsic<Intrinsic::vector_reverse>(Op0);
2751//===----------------------------------------------------------------------===// 2752// Matchers for two-operands operators with the operators in either order 2755/// Matches a BinaryOperator with LHS and RHS in either order. 2756template <
typename LHS,
typename RHS>
2761/// Matches an ICmp with a predicate over LHS and RHS in either order. 2762/// Swaps the predicate if operands are commuted. 2763template <
typename LHS,
typename RHS>
2769template <
typename LHS,
typename RHS>
2775/// Matches a specific opcode with LHS and RHS in either order. 2776template <
typename LHS,
typename RHS>
2782/// Matches a Add with LHS and RHS in either order. 2783template <
typename LHS,
typename RHS>
2789/// Matches a Mul with LHS and RHS in either order. 2790template <
typename LHS,
typename RHS>
2796/// Matches an And with LHS and RHS in either order. 2797template <
typename LHS,
typename RHS>
2803/// Matches an Or with LHS and RHS in either order. 2804template <
typename LHS,
typename RHS>
2810/// Matches an Xor with LHS and RHS in either order. 2811template <
typename LHS,
typename RHS>
2817/// Matches a 'Neg' as 'sub 0, V'. 2818template <
typename ValTy>
2824/// Matches a 'Neg' as 'sub nsw 0, V'. 2825template <
typename ValTy>
2833/// Matches an SMin with LHS and RHS in either order. 2834template <
typename LHS,
typename RHS>
2839/// Matches an SMax with LHS and RHS in either order. 2840template <
typename LHS,
typename RHS>
2845/// Matches a UMin with LHS and RHS in either order. 2846template <
typename LHS,
typename RHS>
2851/// Matches a UMax with LHS and RHS in either order. 2852template <
typename LHS,
typename RHS>
2858template <
typename LHS,
typename RHS>
2869template <Intrinsic::ID IntrID,
typename T0,
typename T1>
2874 m_Intrinsic<IntrID>(Op1, Op0));
2877/// Matches FAdd with LHS and RHS in either order. 2878template <
typename LHS,
typename RHS>
2884/// Matches FMul with LHS and RHS in either order. 2885template <
typename LHS,
typename RHS>
2895template <
typename OpTy>
boolmatch(OpTy *V) {
2896unsignedTypeSize = V->getType()->getScalarSizeInBits();
2903// This is the representation of signum we match: 2905// signum(x) == (x >> 63) | (-x >>u 63) 2907// An i1 value is its own signum, so it's correct to match 2909// signum(x) == (x >> 0) | (-x >>u 0) 2917return Signum.match(V) &&
Val.match(
Op);
2921/// Matches a signum pattern. 2935template <
typename OpTy>
boolmatch(OpTy *V) {
2936if (
auto *
I = dyn_cast<ExtractValueInst>(V)) {
2937// If Ind is -1, don't inspect indices 2939 !(
I->getNumIndices() == 1 &&
I->getIndices()[0] == (
unsigned)Ind))
2941returnVal.match(
I->getAggregateOperand());
2947/// Match a single index ExtractValue instruction. 2948/// For example m_ExtractValue<1>(...) 2949template <
int Ind,
typename Val_t>
2954/// Match an ExtractValue instruction with any index. 2955/// For example m_ExtractValue(...) 2956template <
typename Val_t>
2961/// Matcher for a single index InsertValue instruction. 2968template <
typename OpTy>
boolmatch(OpTy *V) {
2969if (
auto *
I = dyn_cast<InsertValueInst>(V)) {
2970returnOp0.match(
I->getOperand(0)) &&
Op1.match(
I->getOperand(1)) &&
2971I->getNumIndices() == 1 && Ind ==
I->getIndices()[0];
2977/// Matches a single index InsertValue instruction. 2978template <
int Ind,
typename Val_t,
typename Elt_t>
2984/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or 2985/// the constant expression 2986/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>` 2987/// under the right conditions determined by DataLayout. 2989template <
typename ITy>
boolmatch(ITy *V) {
2990if (m_Intrinsic<Intrinsic::vscale>().
match(V))
2995if (
auto *
GEP = dyn_cast<GEPOperator>(
Ptr)) {
2997 dyn_cast<ScalableVectorType>(
GEP->getSourceElementType());
2998if (
GEP->getNumIndices() == 1 && DerefTy &&
2999 DerefTy->getElementType()->isIntegerTy(8) &&
3014template <
typename Opnd0,
typename Opnd1>
3017return m_Intrinsic<Intrinsic::vector_interleave2>(Op0, Op1);
3020template <
typename Opnd>
3022return m_Intrinsic<Intrinsic::vector_deinterleave2>(
Op);
3025template <
typename LHS,
typename RHS,
unsigned Opcode,
bool Commutable = false>
3033auto *
I = dyn_cast<Instruction>(V);
3034if (!
I || !
I->getType()->isIntOrIntVectorTy(1))
3037if (
I->getOpcode() == Opcode) {
3038auto *Op0 =
I->getOperand(0);
3039auto *Op1 =
I->getOperand(1);
3040return (
L.match(Op0) &&
R.match(Op1)) ||
3041 (Commutable &&
L.match(Op1) &&
R.match(Op0));
3044if (
auto *
Select = dyn_cast<SelectInst>(
I)) {
3046auto *TVal =
Select->getTrueValue();
3047auto *FVal =
Select->getFalseValue();
3049// Don't match a scalar select of bool vectors. 3050// Transforms expect a single type for operands if this matches. 3054if (Opcode == Instruction::And) {
3055auto *
C = dyn_cast<Constant>(FVal);
3056if (
C &&
C->isNullValue())
3057return (
L.match(
Cond) &&
R.match(TVal)) ||
3058 (Commutable &&
L.match(TVal) &&
R.match(
Cond));
3060assert(Opcode == Instruction::Or);
3061auto *
C = dyn_cast<Constant>(TVal);
3062if (
C &&
C->isOneValue())
3063return (
L.match(
Cond) &&
R.match(FVal)) ||
3064 (Commutable &&
L.match(FVal) &&
R.match(
Cond));
3072/// Matches L && R either in the form of L & R or L ? R : false. 3073/// Note that the latter form is poison-blocking. 3074template <
typename LHS,
typename RHS>
3080/// Matches L && R where L and R are arbitrary values. 3083/// Matches L && R with LHS and RHS in either order. 3084template <
typename LHS,
typename RHS>
3090/// Matches L || R either in the form of L | R or L ? true : R. 3091/// Note that the latter form is poison-blocking. 3092template <
typename LHS,
typename RHS>
3098/// Matches L || R where L and R are arbitrary values. 3101/// Matches L || R with LHS and RHS in either order. 3102template <
typename LHS,
typename RHS>
3108/// Matches either L && R or L || R, 3109/// either one being in the either binary or logical form. 3110/// Note that the latter form is poison-blocking. 3111template <
typename LHS,
typename RHS,
bool Commutable = false>
3118/// Matches either L && R or L || R where L and R are arbitrary values. 3121/// Matches either L && R or L || R with LHS and RHS in either order. 3122template <
typename LHS,
typename RHS>
3127}
// end namespace PatternMatch 3128}
// end namespace llvm 3130#endif// LLVM_IR_PATTERNMATCH_H 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
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
static CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
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)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
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)
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.
auto m_c_XorLike(const LHS &L, const RHS &R)
Match either (xor L, R), (xor R, L) or (sub nuw R, L) iff R.isMask() Only commutative matcher as the ...
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
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.
match_combine_or< MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty >, MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > > m_OrdOrUnordFMin(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point minimum function.
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.
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)
SpecificCmpClass_match< LHS, RHS, CmpInst > m_SpecificCmp(CmpPredicate MatchPred, 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.
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.
ThreeOps_match< decltype(m_Value()), LHS, RHS, Instruction::Select, true > m_c_Select(const LHS &L, const RHS &R)
Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
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.
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
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)
cstfp_pred_ty< is_non_zero_not_denormal_fp > m_NonZeroNotDenormalFP()
Match a floating-point non-zero that is not a denormal.
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.
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.
SpecificCmpClass_match< LHS, RHS, FCmpInst > m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
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".
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
match_combine_or< MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty >, MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
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)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, 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)
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.
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.
SpecificCmpClass_match< LHS, RHS, ICmpInst, true > m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
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.
DWARFExpression::Operation Op
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(CmpPredicate &Pred, const LHS_t &LHS, const RHS_t &RHS)
CmpClass_match(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)
ExtractValue_match(const Opnd_t &V)
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(CmpPredicate Pred, const LHS_t &LHS, const RHS_t &RHS)
const CmpPredicate 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.
XorLike_match(const LHS &L, const RHS &R)
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 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)
bool match(ArrayRef< int > Mask)
m_SpecificMask(ArrayRef< int > Val)
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)