Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
PatternMatch.h
Go to the documentation of this file.
1//===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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:
15//
16// Value *Exp = ...
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 ...
21// }
22//
23// This is primarily useful to things like the instruction combiner, but can
24// also be useful for static analysis tools or code generators.
25//
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_IR_PATTERNMATCH_H
29#define LLVM_IR_PATTERNMATCH_H
30
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/APInt.h"
33#include "llvm/IR/Constant.h"
34#include "llvm/IR/Constants.h"
35#include "llvm/IR/DataLayout.h"
36#include "llvm/IR/InstrTypes.h"
37#include "llvm/IR/Instruction.h"
38#include "llvm/IR/Instructions.h"
39#include "llvm/IR/IntrinsicInst.h"
40#include "llvm/IR/Intrinsics.h"
41#include "llvm/IR/Operator.h"
42#include "llvm/IR/Value.h"
43#include "llvm/Support/Casting.h"
44#include <cstdint>
45
46namespacellvm {
47namespacePatternMatch {
48
49template <typename Val,typename Pattern>boolmatch(Val *V,constPattern &P) {
50returnconst_cast<Pattern &>(P).match(V);
51}
52
53template <typename Pattern>boolmatch(ArrayRef<int> Mask,constPattern &P) {
54returnconst_cast<Pattern &>(P).match(Mask);
55}
56
57template <typename SubPattern_t>structOneUse_match {
58 SubPattern_tSubPattern;
59
60OneUse_match(const SubPattern_t &SP) :SubPattern(SP) {}
61
62template <typename OpTy>boolmatch(OpTy *V) {
63return V->hasOneUse() &&SubPattern.match(V);
64 }
65};
66
67template <typename T>inlineOneUse_match<T>m_OneUse(constT &SubPattern) {
68return SubPattern;
69}
70
71template <typename SubPattern_t>structAllowReassoc_match {
72 SubPattern_tSubPattern;
73
74AllowReassoc_match(const SubPattern_t &SP) :SubPattern(SP) {}
75
76template <typename OpTy>boolmatch(OpTy *V) {
77auto *I = dyn_cast<FPMathOperator>(V);
78returnI &&I->hasAllowReassoc() &&SubPattern.match(I);
79 }
80};
81
82template <typename T>
83inlineAllowReassoc_match<T>m_AllowReassoc(constT &SubPattern) {
84return SubPattern;
85}
86
87template <typename Class>structclass_match {
88template <typename ITy>boolmatch(ITy *V) {return isa<Class>(V); }
89};
90
91/// Match an arbitrary value and ignore it.
92inlineclass_match<Value>m_Value() {returnclass_match<Value>(); }
93
94/// Match an arbitrary unary operation and ignore it.
95inlineclass_match<UnaryOperator>m_UnOp() {
96returnclass_match<UnaryOperator>();
97}
98
99/// Match an arbitrary binary operation and ignore it.
100inlineclass_match<BinaryOperator>m_BinOp() {
101returnclass_match<BinaryOperator>();
102}
103
104/// Matches any compare instruction and ignore it.
105inlineclass_match<CmpInst>m_Cmp() {returnclass_match<CmpInst>(); }
106
107structundef_match {
108staticboolcheck(constValue *V) {
109if (isa<UndefValue>(V))
110returntrue;
111
112constauto *CA = dyn_cast<ConstantAggregate>(V);
113if (!CA)
114returnfalse;
115
116SmallPtrSet<const ConstantAggregate *, 8> Seen;
117SmallVector<const ConstantAggregate *, 8> Worklist;
118
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.
122auto CheckValue = [&](constConstantAggregate *CA) {
123for (constValue *Op : CA->operand_values()) {
124if (isa<UndefValue>(Op))
125continue;
126
127constauto *CA = dyn_cast<ConstantAggregate>(Op);
128if (!CA)
129returnfalse;
130if (Seen.insert(CA).second)
131 Worklist.emplace_back(CA);
132 }
133
134returntrue;
135 };
136
137if (!CheckValue(CA))
138returnfalse;
139
140while (!Worklist.empty()) {
141if (!CheckValue(Worklist.pop_back_val()))
142returnfalse;
143 }
144returntrue;
145 }
146template <typename ITy>boolmatch(ITy *V) {returncheck(V); }
147};
148
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.
152inlineautom_Undef() {returnundef_match(); }
153
154/// Match an arbitrary UndefValue constant.
155inlineclass_match<UndefValue>m_UndefValue() {
156returnclass_match<UndefValue>();
157}
158
159/// Match an arbitrary poison constant.
160inlineclass_match<PoisonValue>m_Poison() {
161returnclass_match<PoisonValue>();
162}
163
164/// Match an arbitrary Constant and ignore it.
165inlineclass_match<Constant>m_Constant() {returnclass_match<Constant>(); }
166
167/// Match an arbitrary ConstantInt and ignore it.
168inlineclass_match<ConstantInt>m_ConstantInt() {
169returnclass_match<ConstantInt>();
170}
171
172/// Match an arbitrary ConstantFP and ignore it.
173inlineclass_match<ConstantFP>m_ConstantFP() {
174returnclass_match<ConstantFP>();
175}
176
177structconstantexpr_match {
178template <typename ITy>boolmatch(ITy *V) {
179auto *C = dyn_cast<Constant>(V);
180returnC && (isa<ConstantExpr>(C) ||C->containsConstantExpression());
181 }
182};
183
184/// Match a constant expression or a constant that contains a constant
185/// expression.
186inlineconstantexpr_matchm_ConstantExpr() {returnconstantexpr_match(); }
187
188/// Match an arbitrary basic block value and ignore it.
189inlineclass_match<BasicBlock>m_BasicBlock() {
190returnclass_match<BasicBlock>();
191}
192
193/// Inverting matcher
194template <typename Ty>structmatch_unless {
195 TyM;
196
197match_unless(const Ty &Matcher) :M(Matcher) {}
198
199template <typename ITy>boolmatch(ITy *V) {return !M.match(V); }
200};
201
202/// Match if the inner matcher does *NOT* match.
203template <typename Ty>inlinematch_unless<Ty>m_Unless(const Ty &M) {
204returnmatch_unless<Ty>(M);
205}
206
207/// Matching combinators
208template <typename LTy,typename RTy>structmatch_combine_or {
209 LTyL;
210 RTyR;
211
212match_combine_or(const LTy &Left,const RTy &Right) :L(Left),R(Right) {}
213
214template <typename ITy>boolmatch(ITy *V) {
215if (L.match(V))
216returntrue;
217if (R.match(V))
218returntrue;
219returnfalse;
220 }
221};
222
223template <typename LTy,typename RTy>structmatch_combine_and {
224 LTyL;
225 RTyR;
226
227match_combine_and(const LTy &Left,const RTy &Right) :L(Left),R(Right) {}
228
229template <typename ITy>boolmatch(ITy *V) {
230if (L.match(V))
231if (R.match(V))
232returntrue;
233returnfalse;
234 }
235};
236
237/// Combine two pattern matchers matching L || R
238template <typename LTy,typename RTy>
239inlinematch_combine_or<LTy, RTy>m_CombineOr(const LTy &L,const RTy &R) {
240returnmatch_combine_or<LTy, RTy>(L, R);
241}
242
243/// Combine two pattern matchers matching L && R
244template <typename LTy,typename RTy>
245inlinematch_combine_and<LTy, RTy>m_CombineAnd(const LTy &L,const RTy &R) {
246returnmatch_combine_and<LTy, RTy>(L, R);
247}
248
249structapint_match {
250constAPInt *&Res;
251boolAllowPoison;
252
253apint_match(constAPInt *&Res,boolAllowPoison)
254 :Res(Res),AllowPoison(AllowPoison) {}
255
256template <typename ITy>boolmatch(ITy *V) {
257if (auto *CI = dyn_cast<ConstantInt>(V)) {
258Res = &CI->getValue();
259returntrue;
260 }
261if (V->getType()->isVectorTy())
262if (constauto *C = dyn_cast<Constant>(V))
263if (auto *CI =
264 dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison))) {
265Res = &CI->getValue();
266returntrue;
267 }
268returnfalse;
269 }
270};
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.
274structapfloat_match {
275constAPFloat *&Res;
276boolAllowPoison;
277
278apfloat_match(constAPFloat *&Res,boolAllowPoison)
279 :Res(Res),AllowPoison(AllowPoison) {}
280
281template <typename ITy>boolmatch(ITy *V) {
282if (auto *CI = dyn_cast<ConstantFP>(V)) {
283Res = &CI->getValueAPF();
284returntrue;
285 }
286if (V->getType()->isVectorTy())
287if (constauto *C = dyn_cast<Constant>(V))
288if (auto *CI =
289 dyn_cast_or_null<ConstantFP>(C->getSplatValue(AllowPoison))) {
290Res = &CI->getValueAPF();
291returntrue;
292 }
293returnfalse;
294 }
295};
296
297/// Match a ConstantInt or splatted ConstantVector, binding the
298/// specified pointer to the contained APInt.
299inlineapint_matchm_APInt(constAPInt *&Res) {
300// Forbid poison by default to maintain previous behavior.
301returnapint_match(Res,/* AllowPoison */false);
302}
303
304/// Match APInt while allowing poison in splat vector constants.
305inlineapint_matchm_APIntAllowPoison(constAPInt *&Res) {
306returnapint_match(Res,/* AllowPoison */true);
307}
308
309/// Match APInt while forbidding poison in splat vector constants.
310inlineapint_matchm_APIntForbidPoison(constAPInt *&Res) {
311returnapint_match(Res,/* AllowPoison */false);
312}
313
314/// Match a ConstantFP or splatted ConstantVector, binding the
315/// specified pointer to the contained APFloat.
316inlineapfloat_matchm_APFloat(constAPFloat *&Res) {
317// Forbid undefs by default to maintain previous behavior.
318returnapfloat_match(Res,/* AllowPoison */false);
319}
320
321/// Match APFloat while allowing poison in splat vector constants.
322inlineapfloat_matchm_APFloatAllowPoison(constAPFloat *&Res) {
323returnapfloat_match(Res,/* AllowPoison */true);
324}
325
326/// Match APFloat while forbidding poison in splat vector constants.
327inlineapfloat_matchm_APFloatForbidPoison(constAPFloat *&Res) {
328returnapfloat_match(Res,/* AllowPoison */false);
329}
330
331template <int64_t Val>structconstantint_match {
332template <typename ITy>boolmatch(ITy *V) {
333if (constauto *CI = dyn_cast<ConstantInt>(V)) {
334constAPInt &CIV = CI->getValue();
335if (Val >= 0)
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.
340return -CIV == -Val;
341 }
342returnfalse;
343 }
344};
345
346/// Match a ConstantInt with a specific value.
347template <int64_t Val>inlineconstantint_match<Val>m_ConstantInt() {
348returnconstantint_match<Val>();
349}
350
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
354/// is true.
355template <typename Predicate,typename ConstantVal,bool AllowPoison>
356structcstval_pred_ty :publicPredicate {
357constConstant **Res =nullptr;
358template <typename ITy>boolmatch_impl(ITy *V) {
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());
365
366// Number of elements of a scalable vector unknown at compile time
367auto *FVTy = dyn_cast<FixedVectorType>(VTy);
368if (!FVTy)
369returnfalse;
370
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) {
376Constant *Elt =C->getAggregateElement(i);
377if (!Elt)
378returnfalse;
379if (AllowPoison && isa<PoisonValue>(Elt))
380continue;
381auto *CV = dyn_cast<ConstantVal>(Elt);
382if (!CV || !this->isValue(CV->getValue()))
383returnfalse;
384 HasNonPoisonElements =true;
385 }
386return HasNonPoisonElements;
387 }
388 }
389returnfalse;
390 }
391
392template <typename ITy>boolmatch(ITy *V) {
393if (this->match_impl(V)) {
394if (Res)
395 *Res = cast<Constant>(V);
396returntrue;
397 }
398returnfalse;
399 }
400};
401
402/// specialization of cstval_pred_ty for ConstantInt
403template <typename Predicate,bool AllowPoison = true>
404usingcst_pred_ty =cstval_pred_ty<Predicate, ConstantInt, AllowPoison>;
405
406/// specialization of cstval_pred_ty for ConstantFP
407template <typename Predicate>
408usingcstfp_pred_ty =cstval_pred_ty<Predicate,ConstantFP,
409/*AllowPoison=*/true>;
410
411/// This helper class is used to match scalar and vector constants that
412/// satisfy a specified predicate, and bind them to an APInt.
413template <typename Predicate>structapi_pred_ty :publicPredicate {
414constAPInt *&Res;
415
416api_pred_ty(constAPInt *&R) :Res(R) {}
417
418template <typename ITy>boolmatch(ITy *V) {
419if (constauto *CI = dyn_cast<ConstantInt>(V))
420if (this->isValue(CI->getValue())) {
421Res = &CI->getValue();
422returntrue;
423 }
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();
430returntrue;
431 }
432
433returnfalse;
434 }
435};
436
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.
440template <typename Predicate>structapf_pred_ty :publicPredicate {
441constAPFloat *&Res;
442
443apf_pred_ty(constAPFloat *&R) :Res(R) {}
444
445template <typename ITy>boolmatch(ITy *V) {
446if (constauto *CI = dyn_cast<ConstantFP>(V))
447if (this->isValue(CI->getValue())) {
448Res = &CI->getValue();
449returntrue;
450 }
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();
457returntrue;
458 }
459
460returnfalse;
461 }
462};
463
464///////////////////////////////////////////////////////////////////////////////
465//
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
469// undef values.
470//
471///////////////////////////////////////////////////////////////////////////////
472
473template <typename APTy>structcustom_checkfn {
474function_ref<bool(const APTy &)>CheckFn;
475boolisValue(const APTy &C) {returnCheckFn(C); }
476};
477
478/// Match an integer or vector where CheckFn(ele) for each element is true.
479/// For vectors, poison elements are assumed to match.
480inlinecst_pred_ty<custom_checkfn<APInt>>
481m_CheckedInt(function_ref<bool(constAPInt &)> CheckFn) {
482returncst_pred_ty<custom_checkfn<APInt>>{{CheckFn}};
483}
484
485inlinecst_pred_ty<custom_checkfn<APInt>>
486m_CheckedInt(constConstant *&V,function_ref<bool(constAPInt &)> CheckFn) {
487returncst_pred_ty<custom_checkfn<APInt>>{{CheckFn}, &V};
488}
489
490/// Match a float or vector where CheckFn(ele) for each element is true.
491/// For vectors, poison elements are assumed to match.
492inlinecstfp_pred_ty<custom_checkfn<APFloat>>
493m_CheckedFp(function_ref<bool(constAPFloat &)> CheckFn) {
494returncstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}};
495}
496
497inlinecstfp_pred_ty<custom_checkfn<APFloat>>
498m_CheckedFp(constConstant *&V,function_ref<bool(constAPFloat &)> CheckFn) {
499returncstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}, &V};
500}
501
502structis_any_apint {
503boolisValue(constAPInt &C) {returntrue; }
504};
505/// Match an integer or vector with any integral constant.
506/// For vectors, this includes constants with undefined elements.
507inlinecst_pred_ty<is_any_apint>m_AnyIntegralConstant() {
508returncst_pred_ty<is_any_apint>();
509}
510
511structis_shifted_mask {
512boolisValue(constAPInt &C) {returnC.isShiftedMask(); }
513};
514
515inlinecst_pred_ty<is_shifted_mask>m_ShiftedMask() {
516returncst_pred_ty<is_shifted_mask>();
517}
518
519structis_all_ones {
520boolisValue(constAPInt &C) {returnC.isAllOnes(); }
521};
522/// Match an integer or vector with all bits set.
523/// For vectors, this includes constants with undefined elements.
524inlinecst_pred_ty<is_all_ones>m_AllOnes() {
525returncst_pred_ty<is_all_ones>();
526}
527
528inlinecst_pred_ty<is_all_ones, false>m_AllOnesForbidPoison() {
529returncst_pred_ty<is_all_ones, false>();
530}
531
532structis_maxsignedvalue {
533boolisValue(constAPInt &C) {returnC.isMaxSignedValue(); }
534};
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.
538inlinecst_pred_ty<is_maxsignedvalue>m_MaxSignedValue() {
539returncst_pred_ty<is_maxsignedvalue>();
540}
541inlineapi_pred_ty<is_maxsignedvalue>m_MaxSignedValue(constAPInt *&V) {
542return V;
543}
544
545structis_negative {
546boolisValue(constAPInt &C) {returnC.isNegative(); }
547};
548/// Match an integer or vector of negative values.
549/// For vectors, this includes constants with undefined elements.
550inlinecst_pred_ty<is_negative>m_Negative() {
551returncst_pred_ty<is_negative>();
552}
553inlineapi_pred_ty<is_negative>m_Negative(constAPInt *&V) {return V; }
554
555structis_nonnegative {
556boolisValue(constAPInt &C) {returnC.isNonNegative(); }
557};
558/// Match an integer or vector of non-negative values.
559/// For vectors, this includes constants with undefined elements.
560inlinecst_pred_ty<is_nonnegative>m_NonNegative() {
561returncst_pred_ty<is_nonnegative>();
562}
563inlineapi_pred_ty<is_nonnegative>m_NonNegative(constAPInt *&V) {return V; }
564
565structis_strictlypositive {
566boolisValue(constAPInt &C) {returnC.isStrictlyPositive(); }
567};
568/// Match an integer or vector of strictly positive values.
569/// For vectors, this includes constants with undefined elements.
570inlinecst_pred_ty<is_strictlypositive>m_StrictlyPositive() {
571returncst_pred_ty<is_strictlypositive>();
572}
573inlineapi_pred_ty<is_strictlypositive>m_StrictlyPositive(constAPInt *&V) {
574return V;
575}
576
577structis_nonpositive {
578boolisValue(constAPInt &C) {returnC.isNonPositive(); }
579};
580/// Match an integer or vector of non-positive values.
581/// For vectors, this includes constants with undefined elements.
582inlinecst_pred_ty<is_nonpositive>m_NonPositive() {
583returncst_pred_ty<is_nonpositive>();
584}
585inlineapi_pred_ty<is_nonpositive>m_NonPositive(constAPInt *&V) {return V; }
586
587structis_one {
588boolisValue(constAPInt &C) {returnC.isOne(); }
589};
590/// Match an integer 1 or a vector with all elements equal to 1.
591/// For vectors, this includes constants with undefined elements.
592inlinecst_pred_ty<is_one>m_One() {returncst_pred_ty<is_one>(); }
593
594structis_zero_int {
595boolisValue(constAPInt &C) {returnC.isZero(); }
596};
597/// Match an integer 0 or a vector with all elements equal to 0.
598/// For vectors, this includes constants with undefined elements.
599inlinecst_pred_ty<is_zero_int>m_ZeroInt() {
600returncst_pred_ty<is_zero_int>();
601}
602
603structis_zero {
604template <typename ITy>boolmatch(ITy *V) {
605auto *C = dyn_cast<Constant>(V);
606// FIXME: this should be able to do something for scalable vectors
607returnC && (C->isNullValue() ||cst_pred_ty<is_zero_int>().match(C));
608 }
609};
610/// Match any null constant or a vector with all elements equal to 0.
611/// For vectors, this includes constants with undefined elements.
612inlineis_zerom_Zero() {returnis_zero(); }
613
614structis_power2 {
615boolisValue(constAPInt &C) {returnC.isPowerOf2(); }
616};
617/// Match an integer or vector power-of-2.
618/// For vectors, this includes constants with undefined elements.
619inlinecst_pred_ty<is_power2>m_Power2() {returncst_pred_ty<is_power2>(); }
620inlineapi_pred_ty<is_power2>m_Power2(constAPInt *&V) {return V; }
621
622structis_negated_power2 {
623boolisValue(constAPInt &C) {returnC.isNegatedPowerOf2(); }
624};
625/// Match a integer or vector negated power-of-2.
626/// For vectors, this includes constants with undefined elements.
627inlinecst_pred_ty<is_negated_power2>m_NegatedPower2() {
628returncst_pred_ty<is_negated_power2>();
629}
630inlineapi_pred_ty<is_negated_power2>m_NegatedPower2(constAPInt *&V) {
631return V;
632}
633
634structis_negated_power2_or_zero {
635boolisValue(constAPInt &C) {return !C ||C.isNegatedPowerOf2(); }
636};
637/// Match a integer or vector negated power-of-2.
638/// For vectors, this includes constants with undefined elements.
639inlinecst_pred_ty<is_negated_power2_or_zero>m_NegatedPower2OrZero() {
640returncst_pred_ty<is_negated_power2_or_zero>();
641}
642inlineapi_pred_ty<is_negated_power2_or_zero>
643m_NegatedPower2OrZero(constAPInt *&V) {
644return V;
645}
646
647structis_power2_or_zero {
648boolisValue(constAPInt &C) {return !C ||C.isPowerOf2(); }
649};
650/// Match an integer or vector of 0 or power-of-2 values.
651/// For vectors, this includes constants with undefined elements.
652inlinecst_pred_ty<is_power2_or_zero>m_Power2OrZero() {
653returncst_pred_ty<is_power2_or_zero>();
654}
655inlineapi_pred_ty<is_power2_or_zero>m_Power2OrZero(constAPInt *&V) {
656return V;
657}
658
659structis_sign_mask {
660boolisValue(constAPInt &C) {returnC.isSignMask(); }
661};
662/// Match an integer or vector with only the sign bit(s) set.
663/// For vectors, this includes constants with undefined elements.
664inlinecst_pred_ty<is_sign_mask>m_SignMask() {
665returncst_pred_ty<is_sign_mask>();
666}
667
668structis_lowbit_mask {
669boolisValue(constAPInt &C) {returnC.isMask(); }
670};
671/// Match an integer or vector with only the low bit(s) set.
672/// For vectors, this includes constants with undefined elements.
673inlinecst_pred_ty<is_lowbit_mask>m_LowBitMask() {
674returncst_pred_ty<is_lowbit_mask>();
675}
676inlineapi_pred_ty<is_lowbit_mask>m_LowBitMask(constAPInt *&V) {return V; }
677
678structis_lowbit_mask_or_zero {
679boolisValue(constAPInt &C) {return !C ||C.isMask(); }
680};
681/// Match an integer or vector with only the low bit(s) set.
682/// For vectors, this includes constants with undefined elements.
683inlinecst_pred_ty<is_lowbit_mask_or_zero>m_LowBitMaskOrZero() {
684returncst_pred_ty<is_lowbit_mask_or_zero>();
685}
686inlineapi_pred_ty<is_lowbit_mask_or_zero>m_LowBitMaskOrZero(constAPInt *&V) {
687return V;
688}
689
690structicmp_pred_with_threshold {
691CmpPredicatePred;
692constAPInt *Thr;
693boolisValue(constAPInt &C) {returnICmpInst::compare(C, *Thr,Pred); }
694};
695/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
696/// to Threshold. For vectors, this includes constants with undefined elements.
697inlinecst_pred_ty<icmp_pred_with_threshold>
698m_SpecificInt_ICMP(ICmpInst::PredicatePredicate,constAPInt &Threshold) {
699cst_pred_ty<icmp_pred_with_threshold>P;
700P.Pred =Predicate;
701P.Thr = &Threshold;
702returnP;
703}
704
705structis_nan {
706boolisValue(constAPFloat &C) {returnC.isNaN(); }
707};
708/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
709/// For vectors, this includes constants with undefined elements.
710inlinecstfp_pred_ty<is_nan>m_NaN() {returncstfp_pred_ty<is_nan>(); }
711
712structis_nonnan {
713boolisValue(constAPFloat &C) {return !C.isNaN(); }
714};
715/// Match a non-NaN FP constant.
716/// For vectors, this includes constants with undefined elements.
717inlinecstfp_pred_ty<is_nonnan>m_NonNaN() {
718returncstfp_pred_ty<is_nonnan>();
719}
720
721structis_inf {
722boolisValue(constAPFloat &C) {returnC.isInfinity(); }
723};
724/// Match a positive or negative infinity FP constant.
725/// For vectors, this includes constants with undefined elements.
726inlinecstfp_pred_ty<is_inf>m_Inf() {returncstfp_pred_ty<is_inf>(); }
727
728structis_noninf {
729boolisValue(constAPFloat &C) {return !C.isInfinity(); }
730};
731/// Match a non-infinity FP constant, i.e. finite or NaN.
732/// For vectors, this includes constants with undefined elements.
733inlinecstfp_pred_ty<is_noninf>m_NonInf() {
734returncstfp_pred_ty<is_noninf>();
735}
736
737structis_finite {
738boolisValue(constAPFloat &C) {returnC.isFinite(); }
739};
740/// Match a finite FP constant, i.e. not infinity or NaN.
741/// For vectors, this includes constants with undefined elements.
742inlinecstfp_pred_ty<is_finite>m_Finite() {
743returncstfp_pred_ty<is_finite>();
744}
745inlineapf_pred_ty<is_finite>m_Finite(constAPFloat *&V) {return V; }
746
747structis_finitenonzero {
748boolisValue(constAPFloat &C) {returnC.isFiniteNonZero(); }
749};
750/// Match a finite non-zero FP constant.
751/// For vectors, this includes constants with undefined elements.
752inlinecstfp_pred_ty<is_finitenonzero>m_FiniteNonZero() {
753returncstfp_pred_ty<is_finitenonzero>();
754}
755inlineapf_pred_ty<is_finitenonzero>m_FiniteNonZero(constAPFloat *&V) {
756return V;
757}
758
759structis_any_zero_fp {
760boolisValue(constAPFloat &C) {returnC.isZero(); }
761};
762/// Match a floating-point negative zero or positive zero.
763/// For vectors, this includes constants with undefined elements.
764inlinecstfp_pred_ty<is_any_zero_fp>m_AnyZeroFP() {
765returncstfp_pred_ty<is_any_zero_fp>();
766}
767
768structis_pos_zero_fp {
769boolisValue(constAPFloat &C) {returnC.isPosZero(); }
770};
771/// Match a floating-point positive zero.
772/// For vectors, this includes constants with undefined elements.
773inlinecstfp_pred_ty<is_pos_zero_fp>m_PosZeroFP() {
774returncstfp_pred_ty<is_pos_zero_fp>();
775}
776
777structis_neg_zero_fp {
778boolisValue(constAPFloat &C) {returnC.isNegZero(); }
779};
780/// Match a floating-point negative zero.
781/// For vectors, this includes constants with undefined elements.
782inlinecstfp_pred_ty<is_neg_zero_fp>m_NegZeroFP() {
783returncstfp_pred_ty<is_neg_zero_fp>();
784}
785
786structis_non_zero_fp {
787boolisValue(constAPFloat &C) {returnC.isNonZero(); }
788};
789/// Match a floating-point non-zero.
790/// For vectors, this includes constants with undefined elements.
791inlinecstfp_pred_ty<is_non_zero_fp>m_NonZeroFP() {
792returncstfp_pred_ty<is_non_zero_fp>();
793}
794
795structis_non_zero_not_denormal_fp {
796boolisValue(constAPFloat &C) {return !C.isDenormal() &&C.isNonZero(); }
797};
798
799/// Match a floating-point non-zero that is not a denormal.
800/// For vectors, this includes constants with undefined elements.
801inlinecstfp_pred_ty<is_non_zero_not_denormal_fp>m_NonZeroNotDenormalFP() {
802returncstfp_pred_ty<is_non_zero_not_denormal_fp>();
803}
804
805///////////////////////////////////////////////////////////////////////////////
806
807template <typename Class>structbind_ty {
808 Class *&VR;
809
810bind_ty(Class *&V) :VR(V) {}
811
812template <typename ITy>boolmatch(ITy *V) {
813if (auto *CV = dyn_cast<Class>(V)) {
814VR = CV;
815returntrue;
816 }
817returnfalse;
818 }
819};
820
821/// Match a value, capturing it if we match.
822inlinebind_ty<Value>m_Value(Value *&V) {return V; }
823inlinebind_ty<const Value>m_Value(constValue *&V) {return V; }
824
825/// Match an instruction, capturing it if we match.
826inlinebind_ty<Instruction>m_Instruction(Instruction *&I) {returnI; }
827/// Match a unary operator, capturing it if we match.
828inlinebind_ty<UnaryOperator>m_UnOp(UnaryOperator *&I) {returnI; }
829/// Match a binary operator, capturing it if we match.
830inlinebind_ty<BinaryOperator>m_BinOp(BinaryOperator *&I) {returnI; }
831/// Match a with overflow intrinsic, capturing it if we match.
832inlinebind_ty<WithOverflowInst>m_WithOverflowInst(WithOverflowInst *&I) {
833returnI;
834}
835inlinebind_ty<const WithOverflowInst>
836m_WithOverflowInst(constWithOverflowInst *&I) {
837returnI;
838}
839
840/// Match an UndefValue, capturing the value if we match.
841inlinebind_ty<UndefValue>m_UndefValue(UndefValue *&U) {return U; }
842
843/// Match a Constant, capturing the value if we match.
844inlinebind_ty<Constant>m_Constant(Constant *&C) {returnC; }
845
846/// Match a ConstantInt, capturing the value if we match.
847inlinebind_ty<ConstantInt>m_ConstantInt(ConstantInt *&CI) {return CI; }
848
849/// Match a ConstantFP, capturing the value if we match.
850inlinebind_ty<ConstantFP>m_ConstantFP(ConstantFP *&C) {returnC; }
851
852/// Match a ConstantExpr, capturing the value if we match.
853inlinebind_ty<ConstantExpr>m_ConstantExpr(ConstantExpr *&C) {returnC; }
854
855/// Match a basic block value, capturing it if we match.
856inlinebind_ty<BasicBlock>m_BasicBlock(BasicBlock *&V) {return V; }
857inlinebind_ty<const BasicBlock>m_BasicBlock(constBasicBlock *&V) {
858return V;
859}
860
861/// Match an arbitrary immediate Constant and ignore it.
862inlinematch_combine_and<class_match<Constant>,
863match_unless<constantexpr_match>>
864m_ImmConstant() {
865returnm_CombineAnd(m_Constant(),m_Unless(m_ConstantExpr()));
866}
867
868/// Match an immediate Constant, capturing the value if we match.
869inlinematch_combine_and<bind_ty<Constant>,
870match_unless<constantexpr_match>>
871m_ImmConstant(Constant *&C) {
872returnm_CombineAnd(m_Constant(C),m_Unless(m_ConstantExpr()));
873}
874
875/// Match a specified Value*.
876structspecificval_ty {
877constValue *Val;
878
879specificval_ty(constValue *V) :Val(V) {}
880
881template <typename ITy>boolmatch(ITy *V) {return V ==Val; }
882};
883
884/// Match if we have a specific specified value.
885inlinespecificval_tym_Specific(constValue *V) {return V; }
886
887/// Stores a reference to the Value *, not the Value * itself,
888/// thus can be used in commutative matchers.
889template <typename Class>structdeferredval_ty {
890 Class *const &Val;
891
892deferredval_ty(Class *const &V) :Val(V) {}
893
894template <typename ITy>boolmatch(ITy *const V) {return V ==Val; }
895};
896
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.
903inlinedeferredval_ty<Value>m_Deferred(Value *const &V) {return V; }
904inlinedeferredval_ty<const Value>m_Deferred(constValue *const &V) {
905return V;
906}
907
908/// Match a specified floating point value or vector of all elements of
909/// that value.
910structspecific_fpval {
911doubleVal;
912
913specific_fpval(double V) :Val(V) {}
914
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);
922returnfalse;
923 }
924};
925
926/// Match a specific floating point value or vector with all elements
927/// equal to the value.
928inlinespecific_fpvalm_SpecificFP(double V) {returnspecific_fpval(V); }
929
930/// Match a float 1.0 or vector with all elements equal to 1.0.
931inlinespecific_fpvalm_FPOne() {returnm_SpecificFP(1.0); }
932
933structbind_const_intval_ty {
934uint64_t &VR;
935
936bind_const_intval_ty(uint64_t &V) :VR(V) {}
937
938template <typename ITy>boolmatch(ITy *V) {
939if (constauto *CV = dyn_cast<ConstantInt>(V))
940if (CV->getValue().ule(UINT64_MAX)) {
941VR = CV->getZExtValue();
942returntrue;
943 }
944returnfalse;
945 }
946};
947
948/// Match a specified integer value or vector of all elements of that
949/// value.
950template <bool AllowPoison>structspecific_intval {
951constAPInt &Val;
952
953specific_intval(constAPInt &V) :Val(V) {}
954
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));
960
961return CI &&APInt::isSameValue(CI->getValue(),Val);
962 }
963};
964
965template <bool AllowPoison>structspecific_intval64 {
966uint64_tVal;
967
968specific_intval64(uint64_t V) :Val(V) {}
969
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));
975
976return CI && CI->getValue() ==Val;
977 }
978};
979
980/// Match a specific integer value or vector with all elements equal to
981/// the value.
982inlinespecific_intval<false>m_SpecificInt(constAPInt &V) {
983returnspecific_intval<false>(V);
984}
985
986inlinespecific_intval64<false>m_SpecificInt(uint64_t V) {
987returnspecific_intval64<false>(V);
988}
989
990inlinespecific_intval<true>m_SpecificIntAllowPoison(constAPInt &V) {
991returnspecific_intval<true>(V);
992}
993
994inlinespecific_intval64<true>m_SpecificIntAllowPoison(uint64_t V) {
995returnspecific_intval64<true>(V);
996}
997
998/// Match a ConstantInt and bind to its value. This does not match
999/// ConstantInts wider than 64-bits.
1000inlinebind_const_intval_tym_ConstantInt(uint64_t &V) {return V; }
1001
1002/// Match a specified basic block value.
1003structspecific_bbval {
1004BasicBlock *Val;
1005
1006specific_bbval(BasicBlock *Val) :Val(Val) {}
1007
1008template <typename ITy>boolmatch(ITy *V) {
1009constauto *BB = dyn_cast<BasicBlock>(V);
1010return BB && BB ==Val;
1011 }
1012};
1013
1014/// Match a specific basic block value.
1015inlinespecific_bbvalm_SpecificBB(BasicBlock *BB) {
1016returnspecific_bbval(BB);
1017}
1018
1019/// A commutative-friendly version of m_Specific().
1020inlinedeferredval_ty<BasicBlock>m_Deferred(BasicBlock *const &BB) {
1021return BB;
1022}
1023inlinedeferredval_ty<const BasicBlock>
1024m_Deferred(constBasicBlock *const &BB) {
1025return BB;
1026}
1027
1028//===----------------------------------------------------------------------===//
1029// Matcher for any binary operator.
1030//
1031template <typename LHS_t,typename RHS_t,bool Commutable = false>
1032structAnyBinaryOp_match {
1033LHS_tL;
1034RHS_tR;
1035
1036// The evaluation order is always stable, regardless of Commutability.
1037// The LHS is always matched first.
1038AnyBinaryOp_match(constLHS_t &LHS,constRHS_t &RHS) :L(LHS),R(RHS) {}
1039
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)));
1045returnfalse;
1046 }
1047};
1048
1049template <typename LHS,typename RHS>
1050inlineAnyBinaryOp_match<LHS, RHS>m_BinOp(constLHS &L,constRHS &R) {
1051returnAnyBinaryOp_match<LHS, RHS>(L, R);
1052}
1053
1054//===----------------------------------------------------------------------===//
1055// Matcher for any unary operator.
1056// TODO fuse unary, binary matcher into n-ary matcher
1057//
1058template <typename OP_t>structAnyUnaryOp_match {
1059 OP_tX;
1060
1061AnyUnaryOp_match(const OP_t &X) :X(X) {}
1062
1063template <typename OpTy>boolmatch(OpTy *V) {
1064if (auto *I = dyn_cast<UnaryOperator>(V))
1065returnX.match(I->getOperand(0));
1066returnfalse;
1067 }
1068};
1069
1070template <typename OP_t>inlineAnyUnaryOp_match<OP_t>m_UnOp(const OP_t &X) {
1071returnAnyUnaryOp_match<OP_t>(X);
1072}
1073
1074//===----------------------------------------------------------------------===//
1075// Matchers for specific binary operators.
1076//
1077
1078template <typenameLHS_t,typenameRHS_t,unsigned Opcode,
1079bool Commutable =false>
1080structBinaryOp_match {
1081LHS_tL;
1082RHS_tR;
1083
1084// The evaluation order is always stable, regardless of Commutability.
1085// The LHS is always matched first.
1086BinaryOp_match(constLHS_t &LHS,constRHS_t &RHS) :L(LHS),R(RHS) {}
1087
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)));
1094 }
1095returnfalse;
1096 }
1097
1098template <typename OpTy>boolmatch(OpTy *V) {returnmatch(Opcode, V); }
1099};
1100
1101template <typename LHS,typename RHS>
1102inlineBinaryOp_match<LHS, RHS, Instruction::Add>m_Add(constLHS &L,
1103constRHS &R) {
1104returnBinaryOp_match<LHS, RHS, Instruction::Add>(L, R);
1105}
1106
1107template <typename LHS,typename RHS>
1108inlineBinaryOp_match<LHS, RHS, Instruction::FAdd>m_FAdd(constLHS &L,
1109constRHS &R) {
1110returnBinaryOp_match<LHS, RHS, Instruction::FAdd>(L, R);
1111}
1112
1113template <typename LHS,typename RHS>
1114inlineBinaryOp_match<LHS, RHS, Instruction::Sub>m_Sub(constLHS &L,
1115constRHS &R) {
1116returnBinaryOp_match<LHS, RHS, Instruction::Sub>(L, R);
1117}
1118
1119template <typename LHS,typename RHS>
1120inlineBinaryOp_match<LHS, RHS, Instruction::FSub>m_FSub(constLHS &L,
1121constRHS &R) {
1122returnBinaryOp_match<LHS, RHS, Instruction::FSub>(L, R);
1123}
1124
1125template <typename Op_t>structFNeg_match {
1126 Op_tX;
1127
1128FNeg_match(const Op_t &Op) :X(Op) {}
1129template <typename OpTy>boolmatch(OpTy *V) {
1130auto *FPMO = dyn_cast<FPMathOperator>(V);
1131if (!FPMO)
1132returnfalse;
1133
1134if (FPMO->getOpcode() == Instruction::FNeg)
1135returnX.match(FPMO->getOperand(0));
1136
1137if (FPMO->getOpcode() == Instruction::FSub) {
1138if (FPMO->hasNoSignedZeros()) {
1139// With 'nsz', any zero goes.
1140if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1141returnfalse;
1142 }else {
1143// Without 'nsz', we need fsub -0.0, X exactly.
1144if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1145returnfalse;
1146 }
1147
1148returnX.match(FPMO->getOperand(1));
1149 }
1150
1151returnfalse;
1152 }
1153};
1154
1155/// Match 'fneg X' as 'fsub -0.0, X'.
1156template <typename OpTy>inlineFNeg_match<OpTy>m_FNeg(const OpTy &X) {
1157returnFNeg_match<OpTy>(X);
1158}
1159
1160/// Match 'fneg X' as 'fsub +-0.0, X'.
1161template <typename RHS>
1162inlineBinaryOp_match<cstfp_pred_ty<is_any_zero_fp>,RHS, Instruction::FSub>
1163m_FNegNSZ(constRHS &X) {
1164returnm_FSub(m_AnyZeroFP(),X);
1165}
1166
1167template <typename LHS,typename RHS>
1168inlineBinaryOp_match<LHS, RHS, Instruction::Mul>m_Mul(constLHS &L,
1169constRHS &R) {
1170returnBinaryOp_match<LHS, RHS, Instruction::Mul>(L, R);
1171}
1172
1173template <typename LHS,typename RHS>
1174inlineBinaryOp_match<LHS, RHS, Instruction::FMul>m_FMul(constLHS &L,
1175constRHS &R) {
1176returnBinaryOp_match<LHS, RHS, Instruction::FMul>(L, R);
1177}
1178
1179template <typename LHS,typename RHS>
1180inlineBinaryOp_match<LHS, RHS, Instruction::UDiv>m_UDiv(constLHS &L,
1181constRHS &R) {
1182returnBinaryOp_match<LHS, RHS, Instruction::UDiv>(L, R);
1183}
1184
1185template <typename LHS,typename RHS>
1186inlineBinaryOp_match<LHS, RHS, Instruction::SDiv>m_SDiv(constLHS &L,
1187constRHS &R) {
1188returnBinaryOp_match<LHS, RHS, Instruction::SDiv>(L, R);
1189}
1190
1191template <typename LHS,typename RHS>
1192inlineBinaryOp_match<LHS, RHS, Instruction::FDiv>m_FDiv(constLHS &L,
1193constRHS &R) {
1194returnBinaryOp_match<LHS, RHS, Instruction::FDiv>(L, R);
1195}
1196
1197template <typename LHS,typename RHS>
1198inlineBinaryOp_match<LHS, RHS, Instruction::URem>m_URem(constLHS &L,
1199constRHS &R) {
1200returnBinaryOp_match<LHS, RHS, Instruction::URem>(L, R);
1201}
1202
1203template <typename LHS,typename RHS>
1204inlineBinaryOp_match<LHS, RHS, Instruction::SRem>m_SRem(constLHS &L,
1205constRHS &R) {
1206returnBinaryOp_match<LHS, RHS, Instruction::SRem>(L, R);
1207}
1208
1209template <typename LHS,typename RHS>
1210inlineBinaryOp_match<LHS, RHS, Instruction::FRem>m_FRem(constLHS &L,
1211constRHS &R) {
1212returnBinaryOp_match<LHS, RHS, Instruction::FRem>(L, R);
1213}
1214
1215template <typename LHS,typename RHS>
1216inlineBinaryOp_match<LHS, RHS, Instruction::And>m_And(constLHS &L,
1217constRHS &R) {
1218returnBinaryOp_match<LHS, RHS, Instruction::And>(L, R);
1219}
1220
1221template <typename LHS,typename RHS>
1222inlineBinaryOp_match<LHS, RHS, Instruction::Or>m_Or(constLHS &L,
1223constRHS &R) {
1224returnBinaryOp_match<LHS, RHS, Instruction::Or>(L, R);
1225}
1226
1227template <typename LHS,typename RHS>
1228inlineBinaryOp_match<LHS, RHS, Instruction::Xor>m_Xor(constLHS &L,
1229constRHS &R) {
1230returnBinaryOp_match<LHS, RHS, Instruction::Xor>(L, R);
1231}
1232
1233template <typename LHS,typename RHS>
1234inlineBinaryOp_match<LHS, RHS, Instruction::Shl>m_Shl(constLHS &L,
1235constRHS &R) {
1236returnBinaryOp_match<LHS, RHS, Instruction::Shl>(L, R);
1237}
1238
1239template <typename LHS,typename RHS>
1240inlineBinaryOp_match<LHS, RHS, Instruction::LShr>m_LShr(constLHS &L,
1241constRHS &R) {
1242returnBinaryOp_match<LHS, RHS, Instruction::LShr>(L, R);
1243}
1244
1245template <typename LHS,typename RHS>
1246inlineBinaryOp_match<LHS, RHS, Instruction::AShr>m_AShr(constLHS &L,
1247constRHS &R) {
1248returnBinaryOp_match<LHS, RHS, Instruction::AShr>(L, R);
1249}
1250
1251template <typenameLHS_t,typenameRHS_t,unsigned Opcode,
1252unsigned WrapFlags = 0,bool Commutable =false>
1253structOverflowingBinaryOp_match {
1254LHS_tL;
1255RHS_tR;
1256
1257OverflowingBinaryOp_match(constLHS_t &LHS,constRHS_t &RHS)
1258 :L(LHS),R(RHS) {}
1259
1260template <typename OpTy>boolmatch(OpTy *V) {
1261if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1262if (Op->getOpcode() != Opcode)
1263returnfalse;
1264if ((WrapFlags &OverflowingBinaryOperator::NoUnsignedWrap) &&
1265 !Op->hasNoUnsignedWrap())
1266returnfalse;
1267if ((WrapFlags &OverflowingBinaryOperator::NoSignedWrap) &&
1268 !Op->hasNoSignedWrap())
1269returnfalse;
1270return (L.match(Op->getOperand(0)) &&R.match(Op->getOperand(1))) ||
1271 (Commutable &&L.match(Op->getOperand(1)) &&
1272R.match(Op->getOperand(0)));
1273 }
1274returnfalse;
1275 }
1276};
1277
1278template <typename LHS,typename RHS>
1279inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1280OverflowingBinaryOperator::NoSignedWrap>
1281m_NSWAdd(constLHS &L,constRHS &R) {
1282returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1283OverflowingBinaryOperator::NoSignedWrap>(L,
1284 R);
1285}
1286template <typename LHS,typename RHS>
1287inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Sub,
1288OverflowingBinaryOperator::NoSignedWrap>
1289m_NSWSub(constLHS &L,constRHS &R) {
1290returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Sub,
1291OverflowingBinaryOperator::NoSignedWrap>(L,
1292 R);
1293}
1294template <typename LHS,typename RHS>
1295inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Mul,
1296OverflowingBinaryOperator::NoSignedWrap>
1297m_NSWMul(constLHS &L,constRHS &R) {
1298returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Mul,
1299OverflowingBinaryOperator::NoSignedWrap>(L,
1300 R);
1301}
1302template <typename LHS,typename RHS>
1303inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Shl,
1304OverflowingBinaryOperator::NoSignedWrap>
1305m_NSWShl(constLHS &L,constRHS &R) {
1306returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Shl,
1307OverflowingBinaryOperator::NoSignedWrap>(L,
1308 R);
1309}
1310
1311template <typename LHS,typename RHS>
1312inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1313OverflowingBinaryOperator::NoUnsignedWrap>
1314m_NUWAdd(constLHS &L,constRHS &R) {
1315returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1316OverflowingBinaryOperator::NoUnsignedWrap>(
1317 L, R);
1318}
1319
1320template <typename LHS,typename RHS>
1321inlineOverflowingBinaryOp_match<
1322LHS,RHS, Instruction::Add,OverflowingBinaryOperator::NoUnsignedWrap,true>
1323m_c_NUWAdd(constLHS &L,constRHS &R) {
1324returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1325OverflowingBinaryOperator::NoUnsignedWrap,
1326true>(L, R);
1327}
1328
1329template <typename LHS,typename RHS>
1330inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Sub,
1331OverflowingBinaryOperator::NoUnsignedWrap>
1332m_NUWSub(constLHS &L,constRHS &R) {
1333returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Sub,
1334OverflowingBinaryOperator::NoUnsignedWrap>(
1335 L, R);
1336}
1337template <typename LHS,typename RHS>
1338inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Mul,
1339OverflowingBinaryOperator::NoUnsignedWrap>
1340m_NUWMul(constLHS &L,constRHS &R) {
1341returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Mul,
1342OverflowingBinaryOperator::NoUnsignedWrap>(
1343 L, R);
1344}
1345template <typename LHS,typename RHS>
1346inlineOverflowingBinaryOp_match<LHS,RHS, Instruction::Shl,
1347OverflowingBinaryOperator::NoUnsignedWrap>
1348m_NUWShl(constLHS &L,constRHS &R) {
1349returnOverflowingBinaryOp_match<LHS,RHS, Instruction::Shl,
1350OverflowingBinaryOperator::NoUnsignedWrap>(
1351 L, R);
1352}
1353
1354template <typename LHS_t,typename RHS_t,bool Commutable = false>
1355structSpecificBinaryOp_match
1356 :publicBinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1357unsignedOpcode;
1358
1359SpecificBinaryOp_match(unsignedOpcode,constLHS_t &LHS,constRHS_t &RHS)
1360 :BinaryOp_match<LHS_t,RHS_t, 0, Commutable>(LHS,RHS),Opcode(Opcode) {}
1361
1362template <typename OpTy>boolmatch(OpTy *V) {
1363returnBinaryOp_match<LHS_t, RHS_t, 0, Commutable>::match(Opcode, V);
1364 }
1365};
1366
1367/// Matches a specific opcode.
1368template <typename LHS,typename RHS>
1369inlineSpecificBinaryOp_match<LHS, RHS>m_BinOp(unsigned Opcode,constLHS &L,
1370constRHS &R) {
1371returnSpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1372}
1373
1374template <typename LHS,typename RHS,bool Commutable = false>
1375structDisjointOr_match {
1376LHSL;
1377RHSR;
1378
1379DisjointOr_match(constLHS &L,constRHS &R) :L(L),R(R) {}
1380
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())
1385returnfalse;
1386return (L.match(PDI->getOperand(0)) &&R.match(PDI->getOperand(1))) ||
1387 (Commutable &&L.match(PDI->getOperand(1)) &&
1388R.match(PDI->getOperand(0)));
1389 }
1390returnfalse;
1391 }
1392};
1393
1394template <typename LHS,typename RHS>
1395inlineDisjointOr_match<LHS, RHS>m_DisjointOr(constLHS &L,constRHS &R) {
1396returnDisjointOr_match<LHS, RHS>(L, R);
1397}
1398
1399template <typename LHS,typename RHS>
1400inlineDisjointOr_match<LHS, RHS, true>m_c_DisjointOr(constLHS &L,
1401constRHS &R) {
1402returnDisjointOr_match<LHS, RHS, true>(L, R);
1403}
1404
1405/// Match either "add" or "or disjoint".
1406template <typename LHS,typename RHS>
1407inlinematch_combine_or<BinaryOp_match<LHS, RHS, Instruction::Add>,
1408DisjointOr_match<LHS, RHS>>
1409m_AddLike(constLHS &L,constRHS &R) {
1410returnm_CombineOr(m_Add(L, R),m_DisjointOr(L, R));
1411}
1412
1413/// Match either "add nsw" or "or disjoint"
1414template <typename LHS,typename RHS>
1415inlinematch_combine_or<
1416OverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1417OverflowingBinaryOperator::NoSignedWrap>,
1418DisjointOr_match<LHS, RHS>>
1419m_NSWAddLike(constLHS &L,constRHS &R) {
1420returnm_CombineOr(m_NSWAdd(L, R),m_DisjointOr(L, R));
1421}
1422
1423/// Match either "add nuw" or "or disjoint"
1424template <typename LHS,typename RHS>
1425inlinematch_combine_or<
1426OverflowingBinaryOp_match<LHS,RHS, Instruction::Add,
1427OverflowingBinaryOperator::NoUnsignedWrap>,
1428DisjointOr_match<LHS, RHS>>
1429m_NUWAddLike(constLHS &L,constRHS &R) {
1430returnm_CombineOr(m_NUWAdd(L, R),m_DisjointOr(L, R));
1431}
1432
1433template <typename LHS,typename RHS>
1434structXorLike_match {
1435LHSL;
1436RHSR;
1437
1438XorLike_match(constLHS &L,constRHS &R) :L(L),R(R) {}
1439
1440template <typename OpTy>boolmatch(OpTy *V) {
1441if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1442if (Op->getOpcode() == Instruction::Sub &&Op->hasNoUnsignedWrap() &&
1443PatternMatch::match(Op->getOperand(0),m_LowBitMask()))
1444 ;// Pass
1445elseif (Op->getOpcode() != Instruction::Xor)
1446returnfalse;
1447return (L.match(Op->getOperand(0)) &&R.match(Op->getOperand(1))) ||
1448 (L.match(Op->getOperand(1)) &&R.match(Op->getOperand(0)));
1449 }
1450returnfalse;
1451 }
1452};
1453
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>
1457inlineautom_c_XorLike(constLHS &L,constRHS &R) {
1458returnXorLike_match<LHS, RHS>(L, R);
1459}
1460
1461//===----------------------------------------------------------------------===//
1462// Class that matches a group of binary opcodes.
1463//
1464template <typenameLHS_t,typenameRHS_t,typenamePredicate,
1465bool Commutable =false>
1466structBinOpPred_match :Predicate {
1467LHS_tL;
1468RHS_tR;
1469
1470BinOpPred_match(constLHS_t &LHS,constRHS_t &RHS) :L(LHS),R(RHS) {}
1471
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))));
1478returnfalse;
1479 }
1480};
1481
1482structis_shift_op {
1483boolisOpType(unsigned Opcode) {returnInstruction::isShift(Opcode); }
1484};
1485
1486structis_right_shift_op {
1487boolisOpType(unsigned Opcode) {
1488return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1489 }
1490};
1491
1492structis_logical_shift_op {
1493boolisOpType(unsigned Opcode) {
1494return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1495 }
1496};
1497
1498structis_bitwiselogic_op {
1499boolisOpType(unsigned Opcode) {
1500returnInstruction::isBitwiseLogicOp(Opcode);
1501 }
1502};
1503
1504structis_idiv_op {
1505boolisOpType(unsigned Opcode) {
1506return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1507 }
1508};
1509
1510structis_irem_op {
1511boolisOpType(unsigned Opcode) {
1512return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1513 }
1514};
1515
1516/// Matches shift operations.
1517template <typename LHS,typename RHS>
1518inlineBinOpPred_match<LHS, RHS, is_shift_op>m_Shift(constLHS &L,
1519constRHS &R) {
1520returnBinOpPred_match<LHS, RHS, is_shift_op>(L, R);
1521}
1522
1523/// Matches logical shift operations.
1524template <typename LHS,typename RHS>
1525inlineBinOpPred_match<LHS, RHS, is_right_shift_op>m_Shr(constLHS &L,
1526constRHS &R) {
1527returnBinOpPred_match<LHS, RHS, is_right_shift_op>(L, R);
1528}
1529
1530/// Matches logical shift operations.
1531template <typename LHS,typename RHS>
1532inlineBinOpPred_match<LHS, RHS, is_logical_shift_op>
1533m_LogicalShift(constLHS &L,constRHS &R) {
1534returnBinOpPred_match<LHS, RHS, is_logical_shift_op>(L, R);
1535}
1536
1537/// Matches bitwise logic operations.
1538template <typename LHS,typename RHS>
1539inlineBinOpPred_match<LHS, RHS, is_bitwiselogic_op>
1540m_BitwiseLogic(constLHS &L,constRHS &R) {
1541returnBinOpPred_match<LHS, RHS, is_bitwiselogic_op>(L, R);
1542}
1543
1544/// Matches bitwise logic operations in either order.
1545template <typename LHS,typename RHS>
1546inlineBinOpPred_match<LHS, RHS, is_bitwiselogic_op, true>
1547m_c_BitwiseLogic(constLHS &L,constRHS &R) {
1548returnBinOpPred_match<LHS, RHS, is_bitwiselogic_op, true>(L, R);
1549}
1550
1551/// Matches integer division operations.
1552template <typename LHS,typename RHS>
1553inlineBinOpPred_match<LHS, RHS, is_idiv_op>m_IDiv(constLHS &L,
1554constRHS &R) {
1555returnBinOpPred_match<LHS, RHS, is_idiv_op>(L, R);
1556}
1557
1558/// Matches integer remainder operations.
1559template <typename LHS,typename RHS>
1560inlineBinOpPred_match<LHS, RHS, is_irem_op>m_IRem(constLHS &L,
1561constRHS &R) {
1562returnBinOpPred_match<LHS, RHS, is_irem_op>(L, R);
1563}
1564
1565//===----------------------------------------------------------------------===//
1566// Class that matches exact binary ops.
1567//
1568template <typename SubPattern_t>structExact_match {
1569 SubPattern_tSubPattern;
1570
1571Exact_match(const SubPattern_t &SP) :SubPattern(SP) {}
1572
1573template <typename OpTy>boolmatch(OpTy *V) {
1574if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1575return PEO->isExact() &&SubPattern.match(V);
1576returnfalse;
1577 }
1578};
1579
1580template <typename T>inlineExact_match<T>m_Exact(constT &SubPattern) {
1581return SubPattern;
1582}
1583
1584//===----------------------------------------------------------------------===//
1585// Matchers for CmpInst classes
1586//
1587
1588template <typenameLHS_t,typenameRHS_t,typename Class,
1589bool Commutable =false>
1590structCmpClass_match {
1591CmpPredicate *Predicate;
1592LHS_tL;
1593RHS_tR;
1594
1595// The evaluation order is always stable, regardless of Commutability.
1596// The LHS is always matched first.
1597CmpClass_match(CmpPredicate &Pred,constLHS_t &LHS,constRHS_t &RHS)
1598 :Predicate(&Pred),L(LHS),R(RHS) {}
1599CmpClass_match(constLHS_t &LHS,constRHS_t &RHS)
1600 :Predicate(nullptr),L(LHS),R(RHS) {}
1601
1602template <typename OpTy>boolmatch(OpTy *V) {
1603if (auto *I = dyn_cast<Class>(V)) {
1604if (L.match(I->getOperand(0)) &&R.match(I->getOperand(1))) {
1605if (Predicate)
1606 *Predicate =CmpPredicate::get(I);
1607returntrue;
1608 }
1609if (Commutable &&L.match(I->getOperand(1)) &&
1610R.match(I->getOperand(0))) {
1611if (Predicate)
1612 *Predicate =CmpPredicate::getSwapped(I);
1613returntrue;
1614 }
1615 }
1616returnfalse;
1617 }
1618};
1619
1620template <typename LHS,typename RHS>
1621inlineCmpClass_match<LHS, RHS, CmpInst>m_Cmp(CmpPredicate &Pred,constLHS &L,
1622constRHS &R) {
1623returnCmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1624}
1625
1626template <typename LHS,typename RHS>
1627inlineCmpClass_match<LHS, RHS, ICmpInst>m_ICmp(CmpPredicate &Pred,
1628constLHS &L,constRHS &R) {
1629returnCmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1630}
1631
1632template <typename LHS,typename RHS>
1633inlineCmpClass_match<LHS, RHS, FCmpInst>m_FCmp(CmpPredicate &Pred,
1634constLHS &L,constRHS &R) {
1635returnCmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1636}
1637
1638template <typename LHS,typename RHS>
1639inlineCmpClass_match<LHS, RHS, CmpInst>m_Cmp(constLHS &L,constRHS &R) {
1640returnCmpClass_match<LHS, RHS, CmpInst>(L, R);
1641}
1642
1643template <typename LHS,typename RHS>
1644inlineCmpClass_match<LHS, RHS, ICmpInst>m_ICmp(constLHS &L,constRHS &R) {
1645returnCmpClass_match<LHS, RHS, ICmpInst>(L, R);
1646}
1647
1648template <typename LHS,typename RHS>
1649inlineCmpClass_match<LHS, RHS, FCmpInst>m_FCmp(constLHS &L,constRHS &R) {
1650returnCmpClass_match<LHS, RHS, FCmpInst>(L, R);
1651}
1652
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>
1657structSpecificCmpClass_match {
1658constCmpPredicatePredicate;
1659LHS_tL;
1660RHS_tR;
1661
1662SpecificCmpClass_match(CmpPredicate Pred,constLHS_t &LHS,constRHS_t &RHS)
1663 :Predicate(Pred),L(LHS),R(RHS) {}
1664
1665template <typename OpTy>boolmatch(OpTy *V) {
1666if (auto *I = dyn_cast<Class>(V)) {
1667if (CmpPredicate::getMatching(CmpPredicate::get(I),Predicate) &&
1668L.match(I->getOperand(0)) &&R.match(I->getOperand(1)))
1669returntrue;
1670ifconstexpr (Commutable) {
1671if (CmpPredicate::getMatching(CmpPredicate::get(I),
1672CmpPredicate::getSwapped(Predicate)) &&
1673L.match(I->getOperand(1)) &&R.match(I->getOperand(0)))
1674returntrue;
1675 }
1676 }
1677
1678returnfalse;
1679 }
1680};
1681
1682template <typename LHS,typename RHS>
1683inlineSpecificCmpClass_match<LHS, RHS, CmpInst>
1684m_SpecificCmp(CmpPredicate MatchPred,constLHS &L,constRHS &R) {
1685returnSpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1686}
1687
1688template <typename LHS,typename RHS>
1689inlineSpecificCmpClass_match<LHS, RHS, ICmpInst>
1690m_SpecificICmp(CmpPredicate MatchPred,constLHS &L,constRHS &R) {
1691returnSpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1692}
1693
1694template <typename LHS,typename RHS>
1695inlineSpecificCmpClass_match<LHS, RHS, ICmpInst, true>
1696m_c_SpecificICmp(CmpPredicate MatchPred,constLHS &L,constRHS &R) {
1697returnSpecificCmpClass_match<LHS, RHS, ICmpInst, true>(MatchPred, L, R);
1698}
1699
1700template <typename LHS,typename RHS>
1701inlineSpecificCmpClass_match<LHS, RHS, FCmpInst>
1702m_SpecificFCmp(CmpPredicate MatchPred,constLHS &L,constRHS &R) {
1703returnSpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1704}
1705
1706//===----------------------------------------------------------------------===//
1707// Matchers for instructions with a given opcode and number of operands.
1708//
1709
1710/// Matches instructions with Opcode and three operands.
1711template <typename T0,unsigned Opcode>structOneOps_match {
1712 T0Op1;
1713
1714OneOps_match(const T0 &Op1) :Op1(Op1) {}
1715
1716template <typename OpTy>boolmatch(OpTy *V) {
1717if (V->getValueID() == Value::InstructionVal + Opcode) {
1718auto *I = cast<Instruction>(V);
1719returnOp1.match(I->getOperand(0));
1720 }
1721returnfalse;
1722 }
1723};
1724
1725/// Matches instructions with Opcode and three operands.
1726template <typename T0,typename T1,unsigned Opcode>structTwoOps_match {
1727 T0Op1;
1728T1Op2;
1729
1730TwoOps_match(const T0 &Op1,constT1 &Op2) :Op1(Op1),Op2(Op2) {}
1731
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));
1736 }
1737returnfalse;
1738 }
1739};
1740
1741/// Matches instructions with Opcode and three operands.
1742template <typename T0,typenameT1,typename T2,unsigned Opcode,
1743bool CommutableOp2Op3 =false>
1744structThreeOps_match {
1745 T0Op1;
1746T1Op2;
1747 T2Op3;
1748
1749ThreeOps_match(const T0 &Op1,constT1 &Op2,const T2 &Op3)
1750 :Op1(Op1),Op2(Op2),Op3(Op3) {}
1751
1752template <typename OpTy>boolmatch(OpTy *V) {
1753if (V->getValueID() == Value::InstructionVal + Opcode) {
1754auto *I = cast<Instruction>(V);
1755if (!Op1.match(I->getOperand(0)))
1756returnfalse;
1757if (Op2.match(I->getOperand(1)) &&Op3.match(I->getOperand(2)))
1758returntrue;
1759return CommutableOp2Op3 &&Op2.match(I->getOperand(2)) &&
1760Op3.match(I->getOperand(1));
1761 }
1762returnfalse;
1763 }
1764};
1765
1766/// Matches instructions with Opcode and any number of operands
1767template <unsigned Opcode,typename... OperandTypes>structAnyOps_match {
1768 std::tuple<OperandTypes...>Operands;
1769
1770AnyOps_match(const OperandTypes &...Ops) :Operands(Ops...) {}
1771
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>
1777 std::enable_if_t<Idx != Last, bool>match_operands(constInstruction *I) {
1778return match_operands<Idx, Idx>(I) && match_operands<Idx + 1, Last>(I);
1779 }
1780
1781template <int Idx,int Last>
1782 std::enable_if_t<Idx == Last, bool>match_operands(constInstruction *I) {
1783return std::get<Idx>(Operands).match(I->getOperand(Idx));
1784 }
1785
1786template <typename OpTy>boolmatch(OpTy *V) {
1787if (V->getValueID() == Value::InstructionVal + Opcode) {
1788auto *I = cast<Instruction>(V);
1789returnI->getNumOperands() ==sizeof...(OperandTypes) &&
1790match_operands<0,sizeof...(OperandTypes) - 1>(I);
1791 }
1792returnfalse;
1793 }
1794};
1795
1796/// Matches SelectInst.
1797template <typename Cond,typename LHS,typename RHS>
1798inlineThreeOps_match<Cond, LHS, RHS, Instruction::Select>
1799m_Select(constCond &C,constLHS &L,constRHS &R) {
1800returnThreeOps_match<Cond, LHS, RHS, Instruction::Select>(C, L, R);
1801}
1802
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>
1806inlineThreeOps_match<Cond, constantint_match<L>,constantint_match<R>,
1807 Instruction::Select>
1808m_SelectCst(constCond &C) {
1809returnm_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1810}
1811
1812/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1813template <typename LHS,typename RHS>
1814inlineThreeOps_match<decltype(m_Value()),LHS,RHS, Instruction::Select,true>
1815m_c_Select(constLHS &L,constRHS &R) {
1816returnThreeOps_match<decltype(m_Value()),LHS,RHS, Instruction::Select,
1817true>(m_Value(), L, R);
1818}
1819
1820/// Matches FreezeInst.
1821template <typename OpTy>
1822inlineOneOps_match<OpTy, Instruction::Freeze>m_Freeze(const OpTy &Op) {
1823returnOneOps_match<OpTy, Instruction::Freeze>(Op);
1824}
1825
1826/// Matches InsertElementInst.
1827template <typename Val_t,typename Elt_t,typename Idx_t>
1828inlineThreeOps_match<Val_t, Elt_t, Idx_t, Instruction::InsertElement>
1829m_InsertElt(const Val_t &Val,const Elt_t &Elt,const Idx_t &Idx) {
1830returnThreeOps_match<Val_t, Elt_t, Idx_t, Instruction::InsertElement>(
1831 Val, Elt,Idx);
1832}
1833
1834/// Matches ExtractElementInst.
1835template <typename Val_t,typename Idx_t>
1836inlineTwoOps_match<Val_t, Idx_t, Instruction::ExtractElement>
1837m_ExtractElt(const Val_t &Val,const Idx_t &Idx) {
1838returnTwoOps_match<Val_t, Idx_t, Instruction::ExtractElement>(Val,Idx);
1839}
1840
1841/// Matches shuffle.
1842template <typename T0,typename T1,typename T2>structShuffle_match {
1843 T0Op1;
1844T1Op2;
1845 T2Mask;
1846
1847Shuffle_match(const T0 &Op1,constT1 &Op2,const T2 &Mask)
1848 :Op1(Op1),Op2(Op2),Mask(Mask) {}
1849
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());
1854 }
1855returnfalse;
1856 }
1857};
1858
1859structm_Mask {
1860ArrayRef<int> &MaskRef;
1861m_Mask(ArrayRef<int> &MaskRef) :MaskRef(MaskRef) {}
1862boolmatch(ArrayRef<int> Mask) {
1863MaskRef = Mask;
1864returntrue;
1865 }
1866};
1867
1868structm_ZeroMask {
1869boolmatch(ArrayRef<int> Mask) {
1870returnall_of(Mask, [](int Elem) {return Elem == 0 || Elem == -1; });
1871 }
1872};
1873
1874structm_SpecificMask {
1875ArrayRef<int>Val;
1876m_SpecificMask(ArrayRef<int>Val) :Val(Val) {}
1877boolmatch(ArrayRef<int> Mask) {returnVal == Mask; }
1878};
1879
1880structm_SplatOrPoisonMask {
1881int &SplatIndex;
1882m_SplatOrPoisonMask(int &SplatIndex) :SplatIndex(SplatIndex) {}
1883boolmatch(ArrayRef<int> Mask) {
1884constauto *First =find_if(Mask, [](int Elem) {return Elem != -1; });
1885if (First == Mask.end())
1886returnfalse;
1887SplatIndex = *First;
1888returnall_of(Mask,
1889 [First](int Elem) {return Elem == *First || Elem == -1; });
1890 }
1891};
1892
1893template <typename PointerOpTy,typename OffsetOpTy>structPtrAdd_match {
1894 PointerOpTyPointerOp;
1895 OffsetOpTyOffsetOp;
1896
1897PtrAdd_match(const PointerOpTy &PointerOp,const OffsetOpTy &OffsetOp)
1898 :PointerOp(PointerOp),OffsetOp(OffsetOp) {}
1899
1900template <typename OpTy>boolmatch(OpTy *V) {
1901auto *GEP = dyn_cast<GEPOperator>(V);
1902returnGEP &&GEP->getSourceElementType()->isIntegerTy(8) &&
1903PointerOp.match(GEP->getPointerOperand()) &&
1904OffsetOp.match(GEP->idx_begin()->get());
1905 }
1906};
1907
1908/// Matches ShuffleVectorInst independently of mask value.
1909template <typename V1_t,typename V2_t>
1910inlineTwoOps_match<V1_t, V2_t, Instruction::ShuffleVector>
1911m_Shuffle(const V1_t &v1,const V2_t &v2) {
1912returnTwoOps_match<V1_t, V2_t, Instruction::ShuffleVector>(v1, v2);
1913}
1914
1915template <typename V1_t,typename V2_t,typename Mask_t>
1916inlineShuffle_match<V1_t, V2_t, Mask_t>
1917m_Shuffle(const V1_t &v1,const V2_t &v2,const Mask_t &mask) {
1918returnShuffle_match<V1_t, V2_t, Mask_t>(v1, v2, mask);
1919}
1920
1921/// Matches LoadInst.
1922template <typename OpTy>
1923inlineOneOps_match<OpTy, Instruction::Load>m_Load(const OpTy &Op) {
1924returnOneOps_match<OpTy, Instruction::Load>(Op);
1925}
1926
1927/// Matches StoreInst.
1928template <typename ValueOpTy,typename PointerOpTy>
1929inlineTwoOps_match<ValueOpTy, PointerOpTy, Instruction::Store>
1930m_Store(const ValueOpTy &ValueOp,const PointerOpTy &PointerOp) {
1931returnTwoOps_match<ValueOpTy, PointerOpTy, Instruction::Store>(ValueOp,
1932 PointerOp);
1933}
1934
1935/// Matches GetElementPtrInst.
1936template <typename... OperandTypes>
1937inlineautom_GEP(const OperandTypes &...Ops) {
1938returnAnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
1939}
1940
1941/// Matches GEP with i8 source element type
1942template <typename PointerOpTy,typename OffsetOpTy>
1943inlinePtrAdd_match<PointerOpTy, OffsetOpTy>
1944m_PtrAdd(const PointerOpTy &PointerOp,const OffsetOpTy &OffsetOp) {
1945returnPtrAdd_match<PointerOpTy, OffsetOpTy>(PointerOp, OffsetOp);
1946}
1947
1948//===----------------------------------------------------------------------===//
1949// Matchers for CastInst classes
1950//
1951
1952template <typename Op_t,unsigned Opcode>structCastOperator_match {
1953 Op_tOp;
1954
1955CastOperator_match(const Op_t &OpMatch) :Op(OpMatch) {}
1956
1957template <typename OpTy>boolmatch(OpTy *V) {
1958if (auto *O = dyn_cast<Operator>(V))
1959return O->getOpcode() == Opcode &&Op.match(O->getOperand(0));
1960returnfalse;
1961 }
1962};
1963
1964template <typename Op_t,typename Class>structCastInst_match {
1965 Op_tOp;
1966
1967CastInst_match(const Op_t &OpMatch) :Op(OpMatch) {}
1968
1969template <typename OpTy>boolmatch(OpTy *V) {
1970if (auto *I = dyn_cast<Class>(V))
1971returnOp.match(I->getOperand(0));
1972returnfalse;
1973 }
1974};
1975
1976template <typename Op_t>structPtrToIntSameSize_match {
1977constDataLayout &DL;
1978 Op_tOp;
1979
1980PtrToIntSameSize_match(constDataLayout &DL,const Op_t &OpMatch)
1981 :DL(DL),Op(OpMatch) {}
1982
1983template <typename OpTy>boolmatch(OpTy *V) {
1984if (auto *O = dyn_cast<Operator>(V))
1985return O->getOpcode() == Instruction::PtrToInt &&
1986DL.getTypeSizeInBits(O->getType()) ==
1987DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
1988Op.match(O->getOperand(0));
1989returnfalse;
1990 }
1991};
1992
1993template <typename Op_t>structNNegZExt_match {
1994 Op_tOp;
1995
1996NNegZExt_match(const Op_t &OpMatch) :Op(OpMatch) {}
1997
1998template <typename OpTy>boolmatch(OpTy *V) {
1999if (auto *I = dyn_cast<ZExtInst>(V))
2000returnI->hasNonNeg() &&Op.match(I->getOperand(0));
2001returnfalse;
2002 }
2003};
2004
2005template <typename Op_t,unsigned WrapFlags = 0>structNoWrapTrunc_match {
2006 Op_tOp;
2007
2008NoWrapTrunc_match(const Op_t &OpMatch) :Op(OpMatch) {}
2009
2010template <typename OpTy>boolmatch(OpTy *V) {
2011if (auto *I = dyn_cast<TruncInst>(V))
2012return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2013Op.match(I->getOperand(0));
2014returnfalse;
2015 }
2016};
2017
2018/// Matches BitCast.
2019template <typename OpTy>
2020inlineCastOperator_match<OpTy, Instruction::BitCast>
2021m_BitCast(const OpTy &Op) {
2022returnCastOperator_match<OpTy, Instruction::BitCast>(Op);
2023}
2024
2025template <typename Op_t>structElementWiseBitCast_match {
2026 Op_tOp;
2027
2028ElementWiseBitCast_match(const Op_t &OpMatch) :Op(OpMatch) {}
2029
2030template <typename OpTy>boolmatch(OpTy *V) {
2031auto *I = dyn_cast<BitCastInst>(V);
2032if (!I)
2033returnfalse;
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.
2038if (SrcType->isVectorTy() != DstType->isVectorTy())
2039returnfalse;
2040if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2041 SrcVecTy && SrcVecTy->getElementCount() !=
2042 cast<VectorType>(DstType)->getElementCount())
2043returnfalse;
2044returnOp.match(I->getOperand(0));
2045 }
2046};
2047
2048template <typename OpTy>
2049inlineElementWiseBitCast_match<OpTy>m_ElementWiseBitCast(const OpTy &Op) {
2050returnElementWiseBitCast_match<OpTy>(Op);
2051}
2052
2053/// Matches PtrToInt.
2054template <typename OpTy>
2055inlineCastOperator_match<OpTy, Instruction::PtrToInt>
2056m_PtrToInt(const OpTy &Op) {
2057returnCastOperator_match<OpTy, Instruction::PtrToInt>(Op);
2058}
2059
2060template <typename OpTy>
2061inlinePtrToIntSameSize_match<OpTy>m_PtrToIntSameSize(constDataLayout &DL,
2062const OpTy &Op) {
2063returnPtrToIntSameSize_match<OpTy>(DL,Op);
2064}
2065
2066/// Matches IntToPtr.
2067template <typename OpTy>
2068inlineCastOperator_match<OpTy, Instruction::IntToPtr>
2069m_IntToPtr(const OpTy &Op) {
2070returnCastOperator_match<OpTy, Instruction::IntToPtr>(Op);
2071}
2072
2073/// Matches Trunc.
2074template <typename OpTy>
2075inlineCastInst_match<OpTy, TruncInst>m_Trunc(const OpTy &Op) {
2076returnCastInst_match<OpTy, TruncInst>(Op);
2077}
2078
2079/// Matches trunc nuw.
2080template <typename OpTy>
2081inlineNoWrapTrunc_match<OpTy, TruncInst::NoUnsignedWrap>
2082m_NUWTrunc(const OpTy &Op) {
2083returnNoWrapTrunc_match<OpTy, TruncInst::NoUnsignedWrap>(Op);
2084}
2085
2086/// Matches trunc nsw.
2087template <typename OpTy>
2088inlineNoWrapTrunc_match<OpTy, TruncInst::NoSignedWrap>
2089m_NSWTrunc(const OpTy &Op) {
2090returnNoWrapTrunc_match<OpTy, TruncInst::NoSignedWrap>(Op);
2091}
2092
2093template <typename OpTy>
2094inlinematch_combine_or<CastInst_match<OpTy, TruncInst>, OpTy>
2095m_TruncOrSelf(const OpTy &Op) {
2096returnm_CombineOr(m_Trunc(Op),Op);
2097}
2098
2099/// Matches SExt.
2100template <typename OpTy>
2101inlineCastInst_match<OpTy, SExtInst>m_SExt(const OpTy &Op) {
2102returnCastInst_match<OpTy, SExtInst>(Op);
2103}
2104
2105/// Matches ZExt.
2106template <typename OpTy>
2107inlineCastInst_match<OpTy, ZExtInst>m_ZExt(const OpTy &Op) {
2108returnCastInst_match<OpTy, ZExtInst>(Op);
2109}
2110
2111template <typename OpTy>
2112inlineNNegZExt_match<OpTy>m_NNegZExt(const OpTy &Op) {
2113returnNNegZExt_match<OpTy>(Op);
2114}
2115
2116template <typename OpTy>
2117inlinematch_combine_or<CastInst_match<OpTy, ZExtInst>, OpTy>
2118m_ZExtOrSelf(const OpTy &Op) {
2119returnm_CombineOr(m_ZExt(Op),Op);
2120}
2121
2122template <typename OpTy>
2123inlinematch_combine_or<CastInst_match<OpTy, SExtInst>, OpTy>
2124m_SExtOrSelf(const OpTy &Op) {
2125returnm_CombineOr(m_SExt(Op),Op);
2126}
2127
2128/// Match either "sext" or "zext nneg".
2129template <typename OpTy>
2130inlinematch_combine_or<CastInst_match<OpTy, SExtInst>,NNegZExt_match<OpTy>>
2131m_SExtLike(const OpTy &Op) {
2132returnm_CombineOr(m_SExt(Op),m_NNegZExt(Op));
2133}
2134
2135template <typename OpTy>
2136inlinematch_combine_or<CastInst_match<OpTy, ZExtInst>,
2137CastInst_match<OpTy, SExtInst>>
2138m_ZExtOrSExt(const OpTy &Op) {
2139returnm_CombineOr(m_ZExt(Op),m_SExt(Op));
2140}
2141
2142template <typename OpTy>
2143inlinematch_combine_or<match_combine_or<CastInst_match<OpTy, ZExtInst>,
2144CastInst_match<OpTy, SExtInst>>,
2145 OpTy>
2146m_ZExtOrSExtOrSelf(const OpTy &Op) {
2147returnm_CombineOr(m_ZExtOrSExt(Op),Op);
2148}
2149
2150template <typename OpTy>
2151inlineCastInst_match<OpTy, UIToFPInst>m_UIToFP(const OpTy &Op) {
2152returnCastInst_match<OpTy, UIToFPInst>(Op);
2153}
2154
2155template <typename OpTy>
2156inlineCastInst_match<OpTy, SIToFPInst>m_SIToFP(const OpTy &Op) {
2157returnCastInst_match<OpTy, SIToFPInst>(Op);
2158}
2159
2160template <typename OpTy>
2161inlineCastInst_match<OpTy, FPToUIInst>m_FPToUI(const OpTy &Op) {
2162returnCastInst_match<OpTy, FPToUIInst>(Op);
2163}
2164
2165template <typename OpTy>
2166inlineCastInst_match<OpTy, FPToSIInst>m_FPToSI(const OpTy &Op) {
2167returnCastInst_match<OpTy, FPToSIInst>(Op);
2168}
2169
2170template <typename OpTy>
2171inlineCastInst_match<OpTy, FPTruncInst>m_FPTrunc(const OpTy &Op) {
2172returnCastInst_match<OpTy, FPTruncInst>(Op);
2173}
2174
2175template <typename OpTy>
2176inlineCastInst_match<OpTy, FPExtInst>m_FPExt(const OpTy &Op) {
2177returnCastInst_match<OpTy, FPExtInst>(Op);
2178}
2179
2180//===----------------------------------------------------------------------===//
2181// Matchers for control flow.
2182//
2183
2184structbr_match {
2185BasicBlock *&Succ;
2186
2187br_match(BasicBlock *&Succ) :Succ(Succ) {}
2188
2189template <typename OpTy>boolmatch(OpTy *V) {
2190if (auto *BI = dyn_cast<BranchInst>(V))
2191if (BI->isUnconditional()) {
2192Succ = BI->getSuccessor(0);
2193returntrue;
2194 }
2195returnfalse;
2196 }
2197};
2198
2199inlinebr_matchm_UnconditionalBr(BasicBlock *&Succ) {returnbr_match(Succ); }
2200
2201template <typename Cond_t,typename TrueBlock_t,typename FalseBlock_t>
2202structbrc_match {
2203 Cond_tCond;
2204 TrueBlock_tT;
2205 FalseBlock_tF;
2206
2207brc_match(const Cond_t &C,const TrueBlock_t &t,const FalseBlock_t &f)
2208 :Cond(C),T(t),F(f) {}
2209
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));
2214returnfalse;
2215 }
2216};
2217
2218template <typename Cond_t>
2219inlinebrc_match<Cond_t, bind_ty<BasicBlock>,bind_ty<BasicBlock>>
2220m_Br(const Cond_t &C,BasicBlock *&T,BasicBlock *&F) {
2221returnbrc_match<Cond_t, bind_ty<BasicBlock>,bind_ty<BasicBlock>>(
2222C,m_BasicBlock(T),m_BasicBlock(F));
2223}
2224
2225template <typename Cond_t,typename TrueBlock_t,typename FalseBlock_t>
2226inlinebrc_match<Cond_t, TrueBlock_t, FalseBlock_t>
2227m_Br(const Cond_t &C,const TrueBlock_t &T,const FalseBlock_t &F) {
2228returnbrc_match<Cond_t, TrueBlock_t, FalseBlock_t>(C,T,F);
2229}
2230
2231//===----------------------------------------------------------------------===//
2232// Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2233//
2234
2235template <typename CmpInst_t,typenameLHS_t,typenameRHS_t,typename Pred_t,
2236bool Commutable =false>
2237structMaxMin_match {
2238usingPredType = Pred_t;
2239LHS_tL;
2240RHS_tR;
2241
2242// The evaluation order is always stable, regardless of Commutability.
2243// The LHS is always matched first.
2244MaxMin_match(constLHS_t &LHS,constRHS_t &RHS) :L(LHS),R(RHS) {}
2245
2246template <typename OpTy>boolmatch(OpTy *V) {
2247if (auto *II = dyn_cast<IntrinsicInst>(V)) {
2248Intrinsic::ID IID =II->getIntrinsicID();
2249if ((IID == Intrinsic::smax && Pred_t::match(ICmpInst::ICMP_SGT)) ||
2250 (IID == Intrinsic::smin && Pred_t::match(ICmpInst::ICMP_SLT)) ||
2251 (IID == Intrinsic::umax && Pred_t::match(ICmpInst::ICMP_UGT)) ||
2252 (IID == Intrinsic::umin && Pred_t::match(ICmpInst::ICMP_ULT))) {
2253Value *LHS =II->getOperand(0), *RHS =II->getOperand(1);
2254return (L.match(LHS) &&R.match(RHS)) ||
2255 (Commutable &&L.match(RHS) &&R.match(LHS));
2256 }
2257 }
2258// Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2259auto *SI = dyn_cast<SelectInst>(V);
2260if (!SI)
2261returnfalse;
2262auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
2263if (!Cmp)
2264returnfalse;
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))
2273returnfalse;
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))
2278returnfalse;
2279// It does! Bind the operands.
2280return (L.match(LHS) &&R.match(RHS)) ||
2281 (Commutable &&L.match(RHS) &&R.match(LHS));
2282 }
2283};
2284
2285/// Helper class for identifying signed max predicates.
2286structsmax_pred_ty {
2287staticboolmatch(ICmpInst::Predicate Pred) {
2288return Pred ==CmpInst::ICMP_SGT || Pred ==CmpInst::ICMP_SGE;
2289 }
2290};
2291
2292/// Helper class for identifying signed min predicates.
2293structsmin_pred_ty {
2294staticboolmatch(ICmpInst::Predicate Pred) {
2295return Pred ==CmpInst::ICMP_SLT || Pred ==CmpInst::ICMP_SLE;
2296 }
2297};
2298
2299/// Helper class for identifying unsigned max predicates.
2300structumax_pred_ty {
2301staticboolmatch(ICmpInst::Predicate Pred) {
2302return Pred ==CmpInst::ICMP_UGT || Pred ==CmpInst::ICMP_UGE;
2303 }
2304};
2305
2306/// Helper class for identifying unsigned min predicates.
2307structumin_pred_ty {
2308staticboolmatch(ICmpInst::Predicate Pred) {
2309return Pred ==CmpInst::ICMP_ULT || Pred ==CmpInst::ICMP_ULE;
2310 }
2311};
2312
2313/// Helper class for identifying ordered max predicates.
2314structofmax_pred_ty {
2315staticboolmatch(FCmpInst::Predicate Pred) {
2316return Pred ==CmpInst::FCMP_OGT || Pred ==CmpInst::FCMP_OGE;
2317 }
2318};
2319
2320/// Helper class for identifying ordered min predicates.
2321structofmin_pred_ty {
2322staticboolmatch(FCmpInst::Predicate Pred) {
2323return Pred ==CmpInst::FCMP_OLT || Pred ==CmpInst::FCMP_OLE;
2324 }
2325};
2326
2327/// Helper class for identifying unordered max predicates.
2328structufmax_pred_ty {
2329staticboolmatch(FCmpInst::Predicate Pred) {
2330return Pred ==CmpInst::FCMP_UGT || Pred ==CmpInst::FCMP_UGE;
2331 }
2332};
2333
2334/// Helper class for identifying unordered min predicates.
2335structufmin_pred_ty {
2336staticboolmatch(FCmpInst::Predicate Pred) {
2337return Pred ==CmpInst::FCMP_ULT || Pred ==CmpInst::FCMP_ULE;
2338 }
2339};
2340
2341template <typename LHS,typename RHS>
2342inlineMaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty>m_SMax(constLHS &L,
2343constRHS &R) {
2344returnMaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty>(L, R);
2345}
2346
2347template <typename LHS,typename RHS>
2348inlineMaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty>m_SMin(constLHS &L,
2349constRHS &R) {
2350returnMaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty>(L, R);
2351}
2352
2353template <typename LHS,typename RHS>
2354inlineMaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty>m_UMax(constLHS &L,
2355constRHS &R) {
2356returnMaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty>(L, R);
2357}
2358
2359template <typename LHS,typename RHS>
2360inlineMaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty>m_UMin(constLHS &L,
2361constRHS &R) {
2362returnMaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty>(L, R);
2363}
2364
2365template <typename LHS,typename RHS>
2366inlinematch_combine_or<
2367match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty>,
2368MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty>>,
2369match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty>,
2370MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty>>>
2371m_MaxOrMin(constLHS &L,constRHS &R) {
2372returnm_CombineOr(m_CombineOr(m_SMax(L, R),m_SMin(L, R)),
2373m_CombineOr(m_UMax(L, R),m_UMin(L, R)));
2374}
2375
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.
2382///
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>
2386inlineMaxMin_match<FCmpInst, LHS, RHS, ofmax_pred_ty>m_OrdFMax(constLHS &L,
2387constRHS &R) {
2388returnMaxMin_match<FCmpInst, LHS, RHS, ofmax_pred_ty>(L, R);
2389}
2390
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.
2397///
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>
2401inlineMaxMin_match<FCmpInst, LHS, RHS, ofmin_pred_ty>m_OrdFMin(constLHS &L,
2402constRHS &R) {
2403returnMaxMin_match<FCmpInst, LHS, RHS, ofmin_pred_ty>(L, R);
2404}
2405
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.
2412///
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>
2416inlineMaxMin_match<FCmpInst, LHS, RHS, ufmax_pred_ty>
2417m_UnordFMax(constLHS &L,constRHS &R) {
2418returnMaxMin_match<FCmpInst, LHS, RHS, ufmax_pred_ty>(L, R);
2419}
2420
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.
2427///
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>
2431inlineMaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>
2432m_UnordFMin(constLHS &L,constRHS &R) {
2433returnMaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>(L, R);
2434}
2435
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'
2440/// semantics.
2441template <typename LHS,typename RHS>
2442inlinematch_combine_or<MaxMin_match<FCmpInst, LHS, RHS, ofmax_pred_ty>,
2443MaxMin_match<FCmpInst, LHS, RHS, ufmax_pred_ty>>
2444m_OrdOrUnordFMax(constLHS &L,constRHS &R) {
2445returnm_CombineOr(MaxMin_match<FCmpInst, LHS, RHS, ofmax_pred_ty>(L, R),
2446MaxMin_match<FCmpInst, LHS, RHS, ufmax_pred_ty>(L, R));
2447}
2448
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'
2453/// semantics.
2454template <typename LHS,typename RHS>
2455inlinematch_combine_or<MaxMin_match<FCmpInst, LHS, RHS, ofmin_pred_ty>,
2456MaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>>
2457m_OrdOrUnordFMin(constLHS &L,constRHS &R) {
2458returnm_CombineOr(MaxMin_match<FCmpInst, LHS, RHS, ofmin_pred_ty>(L, R),
2459MaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>(L, R));
2460}
2461
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>
2466inlineBinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor,true>
2467m_Not(const ValTy &V) {
2468returnm_c_Xor(m_AllOnes(), V);
2469}
2470
2471template <typename ValTy>
2472inlineBinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2473true>
2474m_NotForbidPoison(const ValTy &V) {
2475returnm_c_Xor(m_AllOnesForbidPoison(), V);
2476}
2477
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.
2481//
2482
2483template <typename LHS_t,typename RHS_t,typename Sum_t>
2484structUAddWithOverflow_match {
2485LHS_tL;
2486RHS_tR;
2487 Sum_tS;
2488
2489UAddWithOverflow_match(constLHS_t &L,constRHS_t &R,const Sum_t &S)
2490 :L(L),R(R),S(S) {}
2491
2492template <typename OpTy>boolmatch(OpTy *V) {
2493Value *ICmpLHS, *ICmpRHS;
2494CmpPredicate Pred;
2495if (!m_ICmp(Pred,m_Value(ICmpLHS),m_Value(ICmpRHS)).match(V))
2496returnfalse;
2497
2498Value *AddLHS, *AddRHS;
2499auto AddExpr =m_Add(m_Value(AddLHS),m_Value(AddRHS));
2500
2501// (a + b) u< a, (a + b) u< b
2502if (Pred ==ICmpInst::ICMP_ULT)
2503if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2504returnL.match(AddLHS) &&R.match(AddRHS) &&S.match(ICmpLHS);
2505
2506// a >u (a + b), b >u (a + b)
2507if (Pred ==ICmpInst::ICMP_UGT)
2508if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2509returnL.match(AddLHS) &&R.match(AddRHS) &&S.match(ICmpRHS);
2510
2511Value *Op1;
2512auto XorExpr =m_OneUse(m_Not(m_Value(Op1)));
2513// (~a) <u b
2514if (Pred ==ICmpInst::ICMP_ULT) {
2515if (XorExpr.match(ICmpLHS))
2516returnL.match(Op1) &&R.match(ICmpRHS) &&S.match(ICmpLHS);
2517 }
2518// b > u (~a)
2519if (Pred ==ICmpInst::ICMP_UGT) {
2520if (XorExpr.match(ICmpRHS))
2521returnL.match(Op1) &&R.match(ICmpLHS) &&S.match(ICmpRHS);
2522 }
2523
2524// Match special-case for increment-by-1.
2525if (Pred ==ICmpInst::ICMP_EQ) {
2526// (a + 1) == 0
2527// (1 + a) == 0
2528if (AddExpr.match(ICmpLHS) &&m_ZeroInt().match(ICmpRHS) &&
2529 (m_One().match(AddLHS) ||m_One().match(AddRHS)))
2530returnL.match(AddLHS) &&R.match(AddRHS) &&S.match(ICmpLHS);
2531// 0 == (a + 1)
2532// 0 == (1 + a)
2533if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2534 (m_One().match(AddLHS) ||m_One().match(AddRHS)))
2535returnL.match(AddLHS) &&R.match(AddRHS) &&S.match(ICmpRHS);
2536 }
2537
2538returnfalse;
2539 }
2540};
2541
2542/// Match an icmp instruction checking for unsigned overflow on addition.
2543///
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>
2547UAddWithOverflow_match<LHS_t, RHS_t, Sum_t>
2548m_UAddWithOverflow(constLHS_t &L,constRHS_t &R,const Sum_t &S) {
2549returnUAddWithOverflow_match<LHS_t, RHS_t, Sum_t>(L, R, S);
2550}
2551
2552template <typename Opnd_t>structArgument_match {
2553unsignedOpI;
2554 Opnd_tVal;
2555
2556Argument_match(unsigned OpIdx,const Opnd_t &V) :OpI(OpIdx),Val(V) {}
2557
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));
2562returnfalse;
2563 }
2564};
2565
2566/// Match an argument.
2567template <unsigned OpI,typename Opnd_t>
2568inlineArgument_match<Opnd_t>m_Argument(const Opnd_t &Op) {
2569returnArgument_match<Opnd_t>(OpI,Op);
2570}
2571
2572/// Intrinsic matchers.
2573structIntrinsicID_match {
2574unsignedID;
2575
2576IntrinsicID_match(Intrinsic::ID IntrID) :ID(IntrID) {}
2577
2578template <typename OpTy>boolmatch(OpTy *V) {
2579if (constauto *CI = dyn_cast<CallInst>(V))
2580if (constauto *F = CI->getCalledFunction())
2581returnF->getIntrinsicID() ==ID;
2582returnfalse;
2583 }
2584};
2585
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>
2594structm_Intrinsic_Ty;
2595template <typename T0>structm_Intrinsic_Ty<T0> {
2596usingTy =match_combine_and<IntrinsicID_match, Argument_match<T0>>;
2597};
2598template <typename T0,typename T1>structm_Intrinsic_Ty<T0,T1> {
2599usingTy =
2600match_combine_and<typename m_Intrinsic_Ty<T0>::Ty,Argument_match<T1>>;
2601};
2602template <typename T0,typename T1,typename T2>
2603structm_Intrinsic_Ty<T0,T1, T2> {
2604usingTy =match_combine_and<typename m_Intrinsic_Ty<T0, T1>::Ty,
2605Argument_match<T2>>;
2606};
2607template <typename T0,typename T1,typename T2,typename T3>
2608structm_Intrinsic_Ty<T0,T1, T2, T3> {
2609usingTy =match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2>::Ty,
2610Argument_match<T3>>;
2611};
2612
2613template <typename T0,typename T1,typename T2,typename T3,typename T4>
2614structm_Intrinsic_Ty<T0,T1, T2, T3, T4> {
2615usingTy =match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2, T3>::Ty,
2616Argument_match<T4>>;
2617};
2618
2619template <typename T0,typenameT1,typename T2,typename T3,typename T4,
2620typename T5>
2621structm_Intrinsic_Ty<T0,T1, T2, T3, T4, T5> {
2622usingTy =match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2, T3, T4>::Ty,
2623Argument_match<T5>>;
2624};
2625
2626/// Match intrinsic calls like this:
2627/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2628template <Intrinsic::ID IntrID>inlineIntrinsicID_matchm_Intrinsic() {
2629returnIntrinsicID_match(IntrID);
2630}
2631
2632/// Matches MaskedLoad Intrinsic.
2633template <typename Opnd0,typename Opnd1,typename Opnd2,typename Opnd3>
2634inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1, Opnd2, Opnd3>::Ty
2635m_MaskedLoad(const Opnd0 &Op0,const Opnd1 &Op1,const Opnd2 &Op2,
2636const Opnd3 &Op3) {
2637return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2, Op3);
2638}
2639
2640/// Matches MaskedGather Intrinsic.
2641template <typename Opnd0,typename Opnd1,typename Opnd2,typename Opnd3>
2642inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1, Opnd2, Opnd3>::Ty
2643m_MaskedGather(const Opnd0 &Op0,const Opnd1 &Op1,const Opnd2 &Op2,
2644const Opnd3 &Op3) {
2645return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2, Op3);
2646}
2647
2648template <Intrinsic::ID IntrID,typename T0>
2649inlinetypenamem_Intrinsic_Ty<T0>::Tym_Intrinsic(const T0 &Op0) {
2650returnm_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
2651}
2652
2653template <Intrinsic::ID IntrID,typename T0,typename T1>
2654inlinetypenamem_Intrinsic_Ty<T0, T1>::Tym_Intrinsic(const T0 &Op0,
2655constT1 &Op1) {
2656returnm_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
2657}
2658
2659template <Intrinsic::ID IntrID,typename T0,typename T1,typename T2>
2660inlinetypenamem_Intrinsic_Ty<T0, T1, T2>::Ty
2661m_Intrinsic(const T0 &Op0,constT1 &Op1,const T2 &Op2) {
2662returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2663}
2664
2665template <Intrinsic::ID IntrID,typename T0,typenameT1,typename T2,
2666typename T3>
2667inlinetypenamem_Intrinsic_Ty<T0, T1, T2, T3>::Ty
2668m_Intrinsic(const T0 &Op0,constT1 &Op1,const T2 &Op2,const T3 &Op3) {
2669returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2670}
2671
2672template <Intrinsic::ID IntrID,typename T0,typenameT1,typename T2,
2673typename T3,typename T4>
2674inlinetypenamem_Intrinsic_Ty<T0, T1, T2, T3, T4>::Ty
2675m_Intrinsic(const T0 &Op0,constT1 &Op1,const T2 &Op2,const T3 &Op3,
2676const T4 &Op4) {
2677returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2678 m_Argument<4>(Op4));
2679}
2680
2681template <Intrinsic::ID IntrID,typename T0,typenameT1,typename T2,
2682typename T3,typename T4,typename T5>
2683inlinetypenamem_Intrinsic_Ty<T0, T1, T2, T3, T4, T5>::Ty
2684m_Intrinsic(const T0 &Op0,constT1 &Op1,const T2 &Op2,const T3 &Op3,
2685const T4 &Op4,const T5 &Op5) {
2686returnm_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2687 m_Argument<5>(Op5));
2688}
2689
2690// Helper intrinsic matching specializations.
2691template <typename Opnd0>
2692inlinetypenamem_Intrinsic_Ty<Opnd0>::Tym_BitReverse(const Opnd0 &Op0) {
2693return m_Intrinsic<Intrinsic::bitreverse>(Op0);
2694}
2695
2696template <typename Opnd0>
2697inlinetypenamem_Intrinsic_Ty<Opnd0>::Tym_BSwap(const Opnd0 &Op0) {
2698return m_Intrinsic<Intrinsic::bswap>(Op0);
2699}
2700
2701template <typename Opnd0>
2702inlinetypenamem_Intrinsic_Ty<Opnd0>::Tym_FAbs(const Opnd0 &Op0) {
2703return m_Intrinsic<Intrinsic::fabs>(Op0);
2704}
2705
2706template <typename Opnd0>
2707inlinetypenamem_Intrinsic_Ty<Opnd0>::Tym_FCanonicalize(const Opnd0 &Op0) {
2708return m_Intrinsic<Intrinsic::canonicalize>(Op0);
2709}
2710
2711template <typename Opnd0,typename Opnd1>
2712inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1>::Tym_FMin(const Opnd0 &Op0,
2713const Opnd1 &Op1) {
2714return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2715}
2716
2717template <typename Opnd0,typename Opnd1>
2718inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1>::Tym_FMax(const Opnd0 &Op0,
2719const Opnd1 &Op1) {
2720return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2721}
2722
2723template <typename Opnd0,typename Opnd1,typename Opnd2>
2724inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1, Opnd2>::Ty
2725m_FShl(const Opnd0 &Op0,const Opnd1 &Op1,const Opnd2 &Op2) {
2726return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2727}
2728
2729template <typename Opnd0,typename Opnd1,typename Opnd2>
2730inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1, Opnd2>::Ty
2731m_FShr(const Opnd0 &Op0,const Opnd1 &Op1,const Opnd2 &Op2) {
2732return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2733}
2734
2735template <typename Opnd0>
2736inlinetypenamem_Intrinsic_Ty<Opnd0>::Tym_Sqrt(const Opnd0 &Op0) {
2737return m_Intrinsic<Intrinsic::sqrt>(Op0);
2738}
2739
2740template <typename Opnd0,typename Opnd1>
2741inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1>::Tym_CopySign(const Opnd0 &Op0,
2742const Opnd1 &Op1) {
2743return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2744}
2745
2746template <typename Opnd0>
2747inlinetypenamem_Intrinsic_Ty<Opnd0>::Tym_VecReverse(const Opnd0 &Op0) {
2748return m_Intrinsic<Intrinsic::vector_reverse>(Op0);
2749}
2750
2751//===----------------------------------------------------------------------===//
2752// Matchers for two-operands operators with the operators in either order
2753//
2754
2755/// Matches a BinaryOperator with LHS and RHS in either order.
2756template <typename LHS,typename RHS>
2757inlineAnyBinaryOp_match<LHS, RHS, true>m_c_BinOp(constLHS &L,constRHS &R) {
2758returnAnyBinaryOp_match<LHS, RHS, true>(L, R);
2759}
2760
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>
2764inlineCmpClass_match<LHS, RHS, ICmpInst, true>
2765m_c_ICmp(CmpPredicate &Pred,constLHS &L,constRHS &R) {
2766returnCmpClass_match<LHS, RHS, ICmpInst, true>(Pred, L, R);
2767}
2768
2769template <typename LHS,typename RHS>
2770inlineCmpClass_match<LHS, RHS, ICmpInst, true>m_c_ICmp(constLHS &L,
2771constRHS &R) {
2772returnCmpClass_match<LHS, RHS, ICmpInst, true>(L, R);
2773}
2774
2775/// Matches a specific opcode with LHS and RHS in either order.
2776template <typename LHS,typename RHS>
2777inlineSpecificBinaryOp_match<LHS, RHS, true>
2778m_c_BinOp(unsigned Opcode,constLHS &L,constRHS &R) {
2779returnSpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
2780}
2781
2782/// Matches a Add with LHS and RHS in either order.
2783template <typename LHS,typename RHS>
2784inlineBinaryOp_match<LHS, RHS, Instruction::Add, true>m_c_Add(constLHS &L,
2785constRHS &R) {
2786returnBinaryOp_match<LHS, RHS, Instruction::Add, true>(L, R);
2787}
2788
2789/// Matches a Mul with LHS and RHS in either order.
2790template <typename LHS,typename RHS>
2791inlineBinaryOp_match<LHS, RHS, Instruction::Mul, true>m_c_Mul(constLHS &L,
2792constRHS &R) {
2793returnBinaryOp_match<LHS, RHS, Instruction::Mul, true>(L, R);
2794}
2795
2796/// Matches an And with LHS and RHS in either order.
2797template <typename LHS,typename RHS>
2798inlineBinaryOp_match<LHS, RHS, Instruction::And, true>m_c_And(constLHS &L,
2799constRHS &R) {
2800returnBinaryOp_match<LHS, RHS, Instruction::And, true>(L, R);
2801}
2802
2803/// Matches an Or with LHS and RHS in either order.
2804template <typename LHS,typename RHS>
2805inlineBinaryOp_match<LHS, RHS, Instruction::Or, true>m_c_Or(constLHS &L,
2806constRHS &R) {
2807returnBinaryOp_match<LHS, RHS, Instruction::Or, true>(L, R);
2808}
2809
2810/// Matches an Xor with LHS and RHS in either order.
2811template <typename LHS,typename RHS>
2812inlineBinaryOp_match<LHS, RHS, Instruction::Xor, true>m_c_Xor(constLHS &L,
2813constRHS &R) {
2814returnBinaryOp_match<LHS, RHS, Instruction::Xor, true>(L, R);
2815}
2816
2817/// Matches a 'Neg' as 'sub 0, V'.
2818template <typename ValTy>
2819inlineBinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
2820m_Neg(const ValTy &V) {
2821returnm_Sub(m_ZeroInt(), V);
2822}
2823
2824/// Matches a 'Neg' as 'sub nsw 0, V'.
2825template <typename ValTy>
2826inlineOverflowingBinaryOp_match<cst_pred_ty<is_zero_int>, ValTy,
2827 Instruction::Sub,
2828OverflowingBinaryOperator::NoSignedWrap>
2829m_NSWNeg(const ValTy &V) {
2830returnm_NSWSub(m_ZeroInt(), V);
2831}
2832
2833/// Matches an SMin with LHS and RHS in either order.
2834template <typename LHS,typename RHS>
2835inlineMaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>
2836m_c_SMin(constLHS &L,constRHS &R) {
2837returnMaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>(L, R);
2838}
2839/// Matches an SMax with LHS and RHS in either order.
2840template <typename LHS,typename RHS>
2841inlineMaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true>
2842m_c_SMax(constLHS &L,constRHS &R) {
2843returnMaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true>(L, R);
2844}
2845/// Matches a UMin with LHS and RHS in either order.
2846template <typename LHS,typename RHS>
2847inlineMaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true>
2848m_c_UMin(constLHS &L,constRHS &R) {
2849returnMaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true>(L, R);
2850}
2851/// Matches a UMax with LHS and RHS in either order.
2852template <typename LHS,typename RHS>
2853inlineMaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true>
2854m_c_UMax(constLHS &L,constRHS &R) {
2855returnMaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true>(L, R);
2856}
2857
2858template <typename LHS,typename RHS>
2859inlinematch_combine_or<
2860match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true>,
2861MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>>,
2862match_combine_or<MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true>,
2863MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true>>>
2864m_c_MaxOrMin(constLHS &L,constRHS &R) {
2865returnm_CombineOr(m_CombineOr(m_c_SMax(L, R),m_c_SMin(L, R)),
2866m_CombineOr(m_c_UMax(L, R),m_c_UMin(L, R)));
2867}
2868
2869template <Intrinsic::ID IntrID,typename T0,typename T1>
2870inlinematch_combine_or<typename m_Intrinsic_Ty<T0, T1>::Ty,
2871typenamem_Intrinsic_Ty<T1, T0>::Ty>
2872m_c_Intrinsic(const T0 &Op0,constT1 &Op1) {
2873returnm_CombineOr(m_Intrinsic<IntrID>(Op0, Op1),
2874 m_Intrinsic<IntrID>(Op1, Op0));
2875}
2876
2877/// Matches FAdd with LHS and RHS in either order.
2878template <typename LHS,typename RHS>
2879inlineBinaryOp_match<LHS, RHS, Instruction::FAdd, true>
2880m_c_FAdd(constLHS &L,constRHS &R) {
2881returnBinaryOp_match<LHS, RHS, Instruction::FAdd, true>(L, R);
2882}
2883
2884/// Matches FMul with LHS and RHS in either order.
2885template <typename LHS,typename RHS>
2886inlineBinaryOp_match<LHS, RHS, Instruction::FMul, true>
2887m_c_FMul(constLHS &L,constRHS &R) {
2888returnBinaryOp_match<LHS, RHS, Instruction::FMul, true>(L, R);
2889}
2890
2891template <typename Opnd_t>structSignum_match {
2892 Opnd_tVal;
2893Signum_match(const Opnd_t &V) :Val(V) {}
2894
2895template <typename OpTy>boolmatch(OpTy *V) {
2896unsignedTypeSize = V->getType()->getScalarSizeInBits();
2897if (TypeSize == 0)
2898returnfalse;
2899
2900unsigned ShiftWidth =TypeSize - 1;
2901Value *Op;
2902
2903// This is the representation of signum we match:
2904//
2905// signum(x) == (x >> 63) | (-x >>u 63)
2906//
2907// An i1 value is its own signum, so it's correct to match
2908//
2909// signum(x) == (x >> 0) | (-x >>u 0)
2910//
2911// for i1 values.
2912
2913autoLHS =m_AShr(m_Value(Op),m_SpecificInt(ShiftWidth));
2914autoRHS =m_LShr(m_Neg(m_Deferred(Op)),m_SpecificInt(ShiftWidth));
2915auto Signum =m_c_Or(LHS,RHS);
2916
2917return Signum.match(V) &&Val.match(Op);
2918 }
2919};
2920
2921/// Matches a signum pattern.
2922///
2923/// signum(x) =
2924/// x > 0 -> 1
2925/// x == 0 -> 0
2926/// x < 0 -> -1
2927template <typename Val_t>inlineSignum_match<Val_t>m_Signum(const Val_t &V) {
2928returnSignum_match<Val_t>(V);
2929}
2930
2931template <int Ind,typename Opnd_t>structExtractValue_match {
2932 Opnd_tVal;
2933ExtractValue_match(const Opnd_t &V) :Val(V) {}
2934
2935template <typename OpTy>boolmatch(OpTy *V) {
2936if (auto *I = dyn_cast<ExtractValueInst>(V)) {
2937// If Ind is -1, don't inspect indices
2938if (Ind != -1 &&
2939 !(I->getNumIndices() == 1 &&I->getIndices()[0] == (unsigned)Ind))
2940returnfalse;
2941returnVal.match(I->getAggregateOperand());
2942 }
2943returnfalse;
2944 }
2945};
2946
2947/// Match a single index ExtractValue instruction.
2948/// For example m_ExtractValue<1>(...)
2949template <int Ind,typename Val_t>
2950inlineExtractValue_match<Ind, Val_t>m_ExtractValue(const Val_t &V) {
2951returnExtractValue_match<Ind, Val_t>(V);
2952}
2953
2954/// Match an ExtractValue instruction with any index.
2955/// For example m_ExtractValue(...)
2956template <typename Val_t>
2957inlineExtractValue_match<-1, Val_t>m_ExtractValue(const Val_t &V) {
2958returnExtractValue_match<-1, Val_t>(V);
2959}
2960
2961/// Matcher for a single index InsertValue instruction.
2962template <int Ind,typename T0,typename T1>structInsertValue_match {
2963 T0Op0;
2964T1Op1;
2965
2966InsertValue_match(const T0 &Op0,constT1 &Op1) :Op0(Op0),Op1(Op1) {}
2967
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];
2972 }
2973returnfalse;
2974 }
2975};
2976
2977/// Matches a single index InsertValue instruction.
2978template <int Ind,typename Val_t,typename Elt_t>
2979inlineInsertValue_match<Ind, Val_t, Elt_t>m_InsertValue(const Val_t &Val,
2980const Elt_t &Elt) {
2981returnInsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
2982}
2983
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.
2988structVScaleVal_match {
2989template <typename ITy>boolmatch(ITy *V) {
2990if (m_Intrinsic<Intrinsic::vscale>().match(V))
2991returntrue;
2992
2993Value *Ptr;
2994if (m_PtrToInt(m_Value(Ptr)).match(V)) {
2995if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
2996auto *DerefTy =
2997 dyn_cast<ScalableVectorType>(GEP->getSourceElementType());
2998if (GEP->getNumIndices() == 1 && DerefTy &&
2999 DerefTy->getElementType()->isIntegerTy(8) &&
3000m_Zero().match(GEP->getPointerOperand()) &&
3001m_SpecificInt(1).match(GEP->idx_begin()->get()))
3002returntrue;
3003 }
3004 }
3005
3006returnfalse;
3007 }
3008};
3009
3010inlineVScaleVal_matchm_VScale() {
3011returnVScaleVal_match();
3012}
3013
3014template <typename Opnd0,typename Opnd1>
3015inlinetypenamem_Intrinsic_Ty<Opnd0, Opnd1>::Ty
3016m_Interleave2(const Opnd0 &Op0,const Opnd1 &Op1) {
3017return m_Intrinsic<Intrinsic::vector_interleave2>(Op0, Op1);
3018}
3019
3020template <typename Opnd>
3021inlinetypenamem_Intrinsic_Ty<Opnd>::Tym_Deinterleave2(const Opnd &Op) {
3022return m_Intrinsic<Intrinsic::vector_deinterleave2>(Op);
3023}
3024
3025template <typename LHS,typename RHS,unsigned Opcode,bool Commutable = false>
3026structLogicalOp_match {
3027LHSL;
3028RHSR;
3029
3030LogicalOp_match(constLHS &L,constRHS &R) :L(L),R(R) {}
3031
3032template <typename T>boolmatch(T *V) {
3033auto *I = dyn_cast<Instruction>(V);
3034if (!I || !I->getType()->isIntOrIntVectorTy(1))
3035returnfalse;
3036
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));
3042 }
3043
3044if (auto *Select = dyn_cast<SelectInst>(I)) {
3045auto *Cond =Select->getCondition();
3046auto *TVal =Select->getTrueValue();
3047auto *FVal =Select->getFalseValue();
3048
3049// Don't match a scalar select of bool vectors.
3050// Transforms expect a single type for operands if this matches.
3051if (Cond->getType() !=Select->getType())
3052returnfalse;
3053
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));
3059 }else {
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));
3065 }
3066 }
3067
3068returnfalse;
3069 }
3070};
3071
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>
3075inlineLogicalOp_match<LHS, RHS, Instruction::And>m_LogicalAnd(constLHS &L,
3076constRHS &R) {
3077returnLogicalOp_match<LHS, RHS, Instruction::And>(L, R);
3078}
3079
3080/// Matches L && R where L and R are arbitrary values.
3081inlineautom_LogicalAnd() {returnm_LogicalAnd(m_Value(),m_Value()); }
3082
3083/// Matches L && R with LHS and RHS in either order.
3084template <typename LHS,typename RHS>
3085inlineLogicalOp_match<LHS, RHS, Instruction::And, true>
3086m_c_LogicalAnd(constLHS &L,constRHS &R) {
3087returnLogicalOp_match<LHS, RHS, Instruction::And, true>(L, R);
3088}
3089
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>
3093inlineLogicalOp_match<LHS, RHS, Instruction::Or>m_LogicalOr(constLHS &L,
3094constRHS &R) {
3095returnLogicalOp_match<LHS, RHS, Instruction::Or>(L, R);
3096}
3097
3098/// Matches L || R where L and R are arbitrary values.
3099inlineautom_LogicalOr() {returnm_LogicalOr(m_Value(),m_Value()); }
3100
3101/// Matches L || R with LHS and RHS in either order.
3102template <typename LHS,typename RHS>
3103inlineLogicalOp_match<LHS, RHS, Instruction::Or, true>
3104m_c_LogicalOr(constLHS &L,constRHS &R) {
3105returnLogicalOp_match<LHS, RHS, Instruction::Or, true>(L, R);
3106}
3107
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>
3112inlineautom_LogicalOp(constLHS &L,constRHS &R) {
3113returnm_CombineOr(
3114LogicalOp_match<LHS, RHS, Instruction::And, Commutable>(L, R),
3115LogicalOp_match<LHS, RHS, Instruction::Or, Commutable>(L, R));
3116}
3117
3118/// Matches either L && R or L || R where L and R are arbitrary values.
3119inlineautom_LogicalOp() {returnm_LogicalOp(m_Value(),m_Value()); }
3120
3121/// Matches either L && R or L || R with LHS and RHS in either order.
3122template <typename LHS,typename RHS>
3123inlineautom_c_LogicalOp(constLHS &L,constRHS &R) {
3124returnm_LogicalOp<LHS,RHS,/*Commutable=*/true>(L, R);
3125}
3126
3127}// end namespace PatternMatch
3128}// end namespace llvm
3129
3130#endif// LLVM_IR_PATTERNMATCH_H
Select
AMDGPU Register Bank Select
Definition:AMDGPURegBankSelect.cpp:71
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
APInt.h
This file implements a class to represent arbitrary precision integral constant values and operations...
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
Casting.h
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DataLayout.h
Idx
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
Definition:DeadArgumentElimination.cpp:353
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
GEP
Hexagon Common GEP
Definition:HexagonCommonGEP.cpp:170
Constant.h
Instruction.h
IntrinsicInst.h
Operator.h
Value.h
InstrTypes.h
Instructions.h
Intrinsics.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
T1
#define T1
Definition:Mips16ISelLowering.cpp:340
II
uint64_t IntrinsicInst * II
Definition:NVVMIntrRange.cpp:51
P
#define P(N)
Cond
const SmallVectorImpl< MachineOperand > & Cond
Definition:RISCVRedundantCopyElimination.cpp:75
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Ptr
@ Ptr
Definition:TargetLibraryInfo.cpp:77
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
LHS
Value * LHS
Definition:X86PartialReduction.cpp:73
LHS_t
Predicate
Definition:AMDGPURegBankLegalizeRules.cpp:332
RHS_t
T
bool
llvm::APFloat
Definition:APFloat.h:904
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::APInt::isSameValue
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!...
Definition:APInt.h:553
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:BasicBlock.h:61
llvm::BinaryOperator
Definition:InstrTypes.h:170
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition:InstrTypes.h:673
llvm::CmpInst::ICMP_SLT
@ ICMP_SLT
signed less than
Definition:InstrTypes.h:702
llvm::CmpInst::ICMP_SLE
@ ICMP_SLE
signed less or equal
Definition:InstrTypes.h:703
llvm::CmpInst::FCMP_OLT
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition:InstrTypes.h:679
llvm::CmpInst::FCMP_ULE
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition:InstrTypes.h:688
llvm::CmpInst::FCMP_OGT
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition:InstrTypes.h:677
llvm::CmpInst::FCMP_OGE
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition:InstrTypes.h:678
llvm::CmpInst::ICMP_UGE
@ ICMP_UGE
unsigned greater or equal
Definition:InstrTypes.h:697
llvm::CmpInst::ICMP_UGT
@ ICMP_UGT
unsigned greater than
Definition:InstrTypes.h:696
llvm::CmpInst::ICMP_SGT
@ ICMP_SGT
signed greater than
Definition:InstrTypes.h:700
llvm::CmpInst::FCMP_ULT
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition:InstrTypes.h:687
llvm::CmpInst::ICMP_ULT
@ ICMP_ULT
unsigned less than
Definition:InstrTypes.h:698
llvm::CmpInst::FCMP_UGT
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition:InstrTypes.h:685
llvm::CmpInst::FCMP_OLE
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition:InstrTypes.h:680
llvm::CmpInst::ICMP_EQ
@ ICMP_EQ
equal
Definition:InstrTypes.h:694
llvm::CmpInst::ICMP_SGE
@ ICMP_SGE
signed greater or equal
Definition:InstrTypes.h:701
llvm::CmpInst::ICMP_ULE
@ ICMP_ULE
unsigned less or equal
Definition:InstrTypes.h:699
llvm::CmpInst::FCMP_UGE
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition:InstrTypes.h:686
llvm::CmpPredicate
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition:CmpPredicate.h:22
llvm::CmpPredicate::getMatching
static std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
Definition:Instructions.cpp:3938
llvm::CmpPredicate::get
static CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
Definition:Instructions.cpp:3957
llvm::CmpPredicate::getSwapped
static CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
Definition:Instructions.cpp:3963
llvm::ConstantAggregate
Base class for aggregate constants (with operands).
Definition:Constants.h:402
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition:Constants.h:1108
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition:Constants.h:271
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition:Constants.h:83
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DataLayout::getTypeSizeInBits
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition:DataLayout.h:617
llvm::ICmpInst::compare
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
Definition:Instructions.cpp:3745
llvm::Instruction
Definition:Instruction.h:68
llvm::Instruction::isBitwiseLogicOp
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
Definition:Instruction.h:350
llvm::Instruction::isShift
bool isShift() const
Definition:Instruction.h:299
llvm::OverflowingBinaryOperator::NoUnsignedWrap
@ NoUnsignedWrap
Definition:Operator.h:81
llvm::OverflowingBinaryOperator::NoSignedWrap
@ NoSignedWrap
Definition:Operator.h:82
llvm::Pattern
Definition:FileCheckImpl.h:565
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition:SmallPtrSet.h:384
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorImpl::pop_back_val
T pop_back_val()
Definition:SmallVector.h:673
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition:SmallVector.h:937
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::TypeSize
Definition:TypeSize.h:334
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Type::isVectorTy
bool isVectorTy() const
True if this is an instance of VectorType.
Definition:Type.h:270
llvm::UnaryOperator
Definition:InstrTypes.h:100
llvm::UndefValue
'undef' values are things that do not have specified contents.
Definition:Constants.h:1412
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::VectorType
Base class of all SIMD vector types.
Definition:DerivedTypes.h:427
llvm::VectorType::getElementCount
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition:DerivedTypes.h:665
llvm::WithOverflowInst
Represents an op.with.overflow intrinsic.
Definition:IntrinsicInst.h:927
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition:STLFunctionalExtras.h:37
uint64_t
unsigned
UINT64_MAX
#define UINT64_MAX
Definition:DataTypes.h:77
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::Intrinsic::ID
unsigned ID
Definition:GenericSSAContext.h:28
llvm::PatternMatch::m_Store
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
Definition:PatternMatch.h:1930
llvm::PatternMatch::m_AllOnes
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
Definition:PatternMatch.h:524
llvm::PatternMatch::m_Poison
class_match< PoisonValue > m_Poison()
Match an arbitrary poison constant.
Definition:PatternMatch.h:160
llvm::PatternMatch::m_LowBitMask
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
Definition:PatternMatch.h:673
llvm::PatternMatch::m_And
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1216
llvm::PatternMatch::m_PtrAdd
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
Definition:PatternMatch.h:1944
llvm::PatternMatch::m_APFloatForbidPoison
apfloat_match m_APFloatForbidPoison(const APFloat *&Res)
Match APFloat while forbidding poison in splat vector constants.
Definition:PatternMatch.h:327
llvm::PatternMatch::m_Negative
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
Definition:PatternMatch.h:550
llvm::PatternMatch::m_NotForbidPoison
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
Definition:PatternMatch.h:2474
llvm::PatternMatch::m_UnordFMin
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
Definition:PatternMatch.h:2432
llvm::PatternMatch::m_PtrToIntSameSize
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
Definition:PatternMatch.h:2061
llvm::PatternMatch::m_Add
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1102
llvm::PatternMatch::m_BinOp
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Definition:PatternMatch.h:100
llvm::PatternMatch::m_FCanonicalize
m_Intrinsic_Ty< Opnd0 >::Ty m_FCanonicalize(const Opnd0 &Op0)
Definition:PatternMatch.h:2707
llvm::PatternMatch::m_FCmp
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1633
llvm::PatternMatch::m_c_FMul
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.
Definition:PatternMatch.h:2887
llvm::PatternMatch::m_SignMask
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
Definition:PatternMatch.h:664
llvm::PatternMatch::m_NUWAdd
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1314
llvm::PatternMatch::m_AShr
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1246
llvm::PatternMatch::m_Inf
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
Definition:PatternMatch.h:726
llvm::PatternMatch::m_BitReverse
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
Definition:PatternMatch.h:2692
llvm::PatternMatch::m_FSub
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1120
llvm::PatternMatch::m_Power2
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
Definition:PatternMatch.h:619
llvm::PatternMatch::m_FNegNSZ
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'.
Definition:PatternMatch.h:1163
llvm::PatternMatch::m_URem
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1198
llvm::PatternMatch::m_TruncOrSelf
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
Definition:PatternMatch.h:2095
llvm::PatternMatch::m_LogicalOp
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
Definition:PatternMatch.h:3119
llvm::PatternMatch::m_Constant
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition:PatternMatch.h:165
llvm::PatternMatch::m_AllowReassoc
AllowReassoc_match< T > m_AllowReassoc(const T &SubPattern)
Definition:PatternMatch.h:83
llvm::PatternMatch::m_Freeze
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
Definition:PatternMatch.h:1822
llvm::PatternMatch::m_c_And
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.
Definition:PatternMatch.h:2798
llvm::PatternMatch::m_Power2OrZero
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
Definition:PatternMatch.h:652
llvm::PatternMatch::m_Trunc
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
Definition:PatternMatch.h:2075
llvm::PatternMatch::m_Xor
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1228
llvm::PatternMatch::m_UnconditionalBr
br_match m_UnconditionalBr(BasicBlock *&Succ)
Definition:PatternMatch.h:2199
llvm::PatternMatch::m_NSWSub
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1289
llvm::PatternMatch::m_SpecificInt
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
Definition:PatternMatch.h:982
llvm::PatternMatch::m_FMul
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1174
llvm::PatternMatch::m_ZExtOrSelf
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
Definition:PatternMatch.h:2118
llvm::PatternMatch::match
bool match(Val *V, const Pattern &P)
Definition:PatternMatch.h:49
llvm::PatternMatch::m_IDiv
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
Definition:PatternMatch.h:1553
llvm::PatternMatch::m_FMax
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
Definition:PatternMatch.h:2718
llvm::PatternMatch::m_ShiftedMask
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
Definition:PatternMatch.h:515
llvm::PatternMatch::m_Instruction
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
Definition:PatternMatch.h:826
llvm::PatternMatch::m_AnyZeroFP
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
Definition:PatternMatch.h:764
llvm::PatternMatch::m_Specific
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Definition:PatternMatch.h:885
llvm::PatternMatch::m_DisjointOr
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1395
llvm::PatternMatch::m_ConstantExpr
constantexpr_match m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
Definition:PatternMatch.h:186
llvm::PatternMatch::m_Shr
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
Definition:PatternMatch.h:1525
llvm::PatternMatch::m_c_XorLike
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 ...
Definition:PatternMatch.h:1457
llvm::PatternMatch::m_SpecificIntAllowPoison
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
Definition:PatternMatch.h:990
llvm::PatternMatch::m_c_ICmp
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.
Definition:PatternMatch.h:2765
llvm::PatternMatch::m_c_NUWAdd
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true > m_c_NUWAdd(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1323
llvm::PatternMatch::m_NSWNeg
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'.
Definition:PatternMatch.h:2829
llvm::PatternMatch::m_ExtractElt
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
Definition:PatternMatch.h:1837
llvm::PatternMatch::m_Finite
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
Definition:PatternMatch.h:742
llvm::PatternMatch::m_NonNegative
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
Definition:PatternMatch.h:560
llvm::PatternMatch::m_ConstantInt
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Definition:PatternMatch.h:168
llvm::PatternMatch::m_One
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
Definition:PatternMatch.h:592
llvm::PatternMatch::m_Intrinsic
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
Definition:PatternMatch.h:2628
llvm::PatternMatch::m_Select
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
Definition:PatternMatch.h:1799
llvm::PatternMatch::m_NegZeroFP
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
Definition:PatternMatch.h:782
llvm::PatternMatch::m_SExtOrSelf
match_combine_or< CastInst_match< OpTy, SExtInst >, OpTy > m_SExtOrSelf(const OpTy &Op)
Definition:PatternMatch.h:2124
llvm::PatternMatch::m_InsertValue
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
Definition:PatternMatch.h:2979
llvm::PatternMatch::m_OrdOrUnordFMin
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.
Definition:PatternMatch.h:2457
llvm::PatternMatch::m_SpecificFP
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
Definition:PatternMatch.h:928
llvm::PatternMatch::m_Interleave2
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1)
Definition:PatternMatch.h:3016
llvm::PatternMatch::m_ExtractValue
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
Definition:PatternMatch.h:2950
llvm::PatternMatch::m_LogicalShift
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
Definition:PatternMatch.h:1533
llvm::PatternMatch::m_CombineAnd
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
Definition:PatternMatch.h:245
llvm::PatternMatch::m_SMin
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
Definition:PatternMatch.h:2348
llvm::PatternMatch::m_AnyIntegralConstant
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
Definition:PatternMatch.h:507
llvm::PatternMatch::m_FPToUI
CastInst_match< OpTy, FPToUIInst > m_FPToUI(const OpTy &Op)
Definition:PatternMatch.h:2161
llvm::PatternMatch::m_Sqrt
m_Intrinsic_Ty< Opnd0 >::Ty m_Sqrt(const Opnd0 &Op0)
Definition:PatternMatch.h:2736
llvm::PatternMatch::m_WithOverflowInst
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
Definition:PatternMatch.h:832
llvm::PatternMatch::m_c_Xor
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.
Definition:PatternMatch.h:2812
llvm::PatternMatch::m_FAdd
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1108
llvm::PatternMatch::m_SpecificCmp
SpecificCmpClass_match< LHS, RHS, CmpInst > m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1684
llvm::PatternMatch::m_c_Intrinsic
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)
Definition:PatternMatch.h:2872
llvm::PatternMatch::m_Mul
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1168
llvm::PatternMatch::m_Deferred
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()...
Definition:PatternMatch.h:903
llvm::PatternMatch::m_ZeroInt
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
Definition:PatternMatch.h:599
llvm::PatternMatch::m_APIntAllowPoison
apint_match m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
Definition:PatternMatch.h:305
llvm::PatternMatch::m_NSWTrunc
NoWrapTrunc_match< OpTy, TruncInst::NoSignedWrap > m_NSWTrunc(const OpTy &Op)
Matches trunc nsw.
Definition:PatternMatch.h:2089
llvm::PatternMatch::m_ZExtOrSExtOrSelf
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
Definition:PatternMatch.h:2146
llvm::PatternMatch::m_OneUse
OneUse_match< T > m_OneUse(const T &SubPattern)
Definition:PatternMatch.h:67
llvm::PatternMatch::m_NNegZExt
NNegZExt_match< OpTy > m_NNegZExt(const OpTy &Op)
Definition:PatternMatch.h:2112
llvm::PatternMatch::m_c_SMin
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.
Definition:PatternMatch.h:2836
llvm::PatternMatch::m_LogicalOr
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
Definition:PatternMatch.h:3099
llvm::PatternMatch::m_Neg
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
Definition:PatternMatch.h:2820
llvm::PatternMatch::m_Shuffle
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
Definition:PatternMatch.h:1911
llvm::PatternMatch::m_ImmConstant
match_combine_and< class_match< Constant >, match_unless< constantexpr_match > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
Definition:PatternMatch.h:864
llvm::PatternMatch::m_SpecificBB
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
Definition:PatternMatch.h:1015
llvm::PatternMatch::m_c_UMax
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.
Definition:PatternMatch.h:2854
llvm::PatternMatch::m_GEP
auto m_GEP(const OperandTypes &...Ops)
Matches GetElementPtrInst.
Definition:PatternMatch.h:1937
llvm::PatternMatch::m_StrictlyPositive
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
Definition:PatternMatch.h:570
llvm::PatternMatch::m_c_Select
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)
Definition:PatternMatch.h:1815
llvm::PatternMatch::m_FPExt
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
Definition:PatternMatch.h:2176
llvm::PatternMatch::m_NSWShl
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1305
llvm::PatternMatch::m_ConstantFP
class_match< ConstantFP > m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
Definition:PatternMatch.h:173
llvm::PatternMatch::m_NonNaN
cstfp_pred_ty< is_nonnan > m_NonNaN()
Match a non-NaN FP constant.
Definition:PatternMatch.h:717
llvm::PatternMatch::m_MaskedLoad
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.
Definition:PatternMatch.h:2635
llvm::PatternMatch::m_SpecificICmp
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1690
llvm::PatternMatch::m_Load
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
Definition:PatternMatch.h:1923
llvm::PatternMatch::m_APIntForbidPoison
apint_match m_APIntForbidPoison(const APInt *&Res)
Match APInt while forbidding poison in splat vector constants.
Definition:PatternMatch.h:310
llvm::PatternMatch::m_ZExt
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
Definition:PatternMatch.h:2107
llvm::PatternMatch::m_NUWShl
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1348
llvm::PatternMatch::m_NonZeroNotDenormalFP
cstfp_pred_ty< is_non_zero_not_denormal_fp > m_NonZeroNotDenormalFP()
Match a floating-point non-zero that is not a denormal.
Definition:PatternMatch.h:801
llvm::PatternMatch::m_AllOnesForbidPoison
cst_pred_ty< is_all_ones, false > m_AllOnesForbidPoison()
Definition:PatternMatch.h:528
llvm::PatternMatch::m_NUWMul
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1340
llvm::PatternMatch::m_UDiv
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1180
llvm::PatternMatch::m_c_BitwiseLogic
BinOpPred_match< LHS, RHS, is_bitwiselogic_op, true > m_c_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations in either order.
Definition:PatternMatch.h:1547
llvm::PatternMatch::m_UndefValue
class_match< UndefValue > m_UndefValue()
Match an arbitrary UndefValue constant.
Definition:PatternMatch.h:155
llvm::PatternMatch::m_UMax
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
Definition:PatternMatch.h:2354
llvm::PatternMatch::m_Cmp
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
Definition:PatternMatch.h:105
llvm::PatternMatch::m_Br
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
Definition:PatternMatch.h:2220
llvm::PatternMatch::m_NegatedPower2
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
Definition:PatternMatch.h:627
llvm::PatternMatch::m_NegatedPower2OrZero
cst_pred_ty< is_negated_power2_or_zero > m_NegatedPower2OrZero()
Match a integer or vector negated power-of-2.
Definition:PatternMatch.h:639
llvm::PatternMatch::m_c_LogicalOp
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
Definition:PatternMatch.h:3123
llvm::PatternMatch::m_NUWTrunc
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
Definition:PatternMatch.h:2082
llvm::PatternMatch::m_CheckedInt
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.
Definition:PatternMatch.h:481
llvm::PatternMatch::m_LowBitMaskOrZero
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
Definition:PatternMatch.h:683
llvm::PatternMatch::m_FPOne
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
Definition:PatternMatch.h:931
llvm::PatternMatch::m_c_DisjointOr
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1400
llvm::PatternMatch::m_c_UMin
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.
Definition:PatternMatch.h:2848
llvm::PatternMatch::m_c_Add
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.
Definition:PatternMatch.h:2784
llvm::PatternMatch::m_SpecificFCmp
SpecificCmpClass_match< LHS, RHS, FCmpInst > m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1702
llvm::PatternMatch::m_APFloatAllowPoison
apfloat_match m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
Definition:PatternMatch.h:322
llvm::PatternMatch::m_AddLike
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".
Definition:PatternMatch.h:1409
llvm::PatternMatch::m_UIToFP
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
Definition:PatternMatch.h:2151
llvm::PatternMatch::m_OrdOrUnordFMax
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.
Definition:PatternMatch.h:2444
llvm::PatternMatch::m_c_SMax
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.
Definition:PatternMatch.h:2842
llvm::PatternMatch::m_BitCast
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
Definition:PatternMatch.h:2021
llvm::PatternMatch::m_FShl
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Definition:PatternMatch.h:2725
llvm::PatternMatch::m_c_MaxOrMin
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)
Definition:PatternMatch.h:2864
llvm::PatternMatch::m_UnordFMax
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
Definition:PatternMatch.h:2417
llvm::PatternMatch::m_SExtLike
match_combine_or< CastInst_match< OpTy, SExtInst >, NNegZExt_match< OpTy > > m_SExtLike(const OpTy &Op)
Match either "sext" or "zext nneg".
Definition:PatternMatch.h:2131
llvm::PatternMatch::m_FiniteNonZero
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
Definition:PatternMatch.h:752
llvm::PatternMatch::m_UnOp
class_match< UnaryOperator > m_UnOp()
Match an arbitrary unary operation and ignore it.
Definition:PatternMatch.h:95
llvm::PatternMatch::m_VScale
VScaleVal_match m_VScale()
Definition:PatternMatch.h:3010
llvm::PatternMatch::m_FPToSI
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
Definition:PatternMatch.h:2166
llvm::PatternMatch::m_SDiv
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1186
llvm::PatternMatch::m_CheckedFp
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.
Definition:PatternMatch.h:493
llvm::PatternMatch::m_NUWSub
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1332
llvm::PatternMatch::m_SMax
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
Definition:PatternMatch.h:2342
llvm::PatternMatch::m_APInt
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
Definition:PatternMatch.h:299
llvm::PatternMatch::m_MaxSignedValue
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
Definition:PatternMatch.h:538
llvm::PatternMatch::m_OrdFMax
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
Definition:PatternMatch.h:2386
llvm::PatternMatch::m_NSWAddLike
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".
Definition:PatternMatch.h:1419
llvm::PatternMatch::m_Value
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition:PatternMatch.h:92
llvm::PatternMatch::m_c_BinOp
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Definition:PatternMatch.h:2757
llvm::PatternMatch::m_Signum
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
Definition:PatternMatch.h:2927
llvm::PatternMatch::m_NSWAdd
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1281
llvm::PatternMatch::m_SIToFP
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
Definition:PatternMatch.h:2156
llvm::PatternMatch::m_LShr
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1240
llvm::PatternMatch::m_ICmp
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1627
llvm::PatternMatch::m_Argument
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
Definition:PatternMatch.h:2568
llvm::PatternMatch::m_ZExtOrSExt
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
Definition:PatternMatch.h:2138
llvm::PatternMatch::m_Exact
Exact_match< T > m_Exact(const T &SubPattern)
Definition:PatternMatch.h:1580
llvm::PatternMatch::m_FNeg
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
Definition:PatternMatch.h:1156
llvm::PatternMatch::m_Shift
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
Definition:PatternMatch.h:1518
llvm::PatternMatch::m_PosZeroFP
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
Definition:PatternMatch.h:773
llvm::PatternMatch::m_c_FAdd
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.
Definition:PatternMatch.h:2880
llvm::PatternMatch::m_c_LogicalAnd
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.
Definition:PatternMatch.h:3086
llvm::PatternMatch::m_Shl
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1234
llvm::PatternMatch::m_NonZeroFP
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
Definition:PatternMatch.h:791
llvm::PatternMatch::m_UAddWithOverflow
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.
Definition:PatternMatch.h:2548
llvm::PatternMatch::m_FDiv
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1192
llvm::PatternMatch::m_VecReverse
m_Intrinsic_Ty< Opnd0 >::Ty m_VecReverse(const Opnd0 &Op0)
Definition:PatternMatch.h:2747
llvm::PatternMatch::m_IRem
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
Definition:PatternMatch.h:1560
llvm::PatternMatch::m_APFloat
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
Definition:PatternMatch.h:316
llvm::PatternMatch::m_LogicalAnd
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
Definition:PatternMatch.h:3081
llvm::PatternMatch::m_OrdFMin
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
Definition:PatternMatch.h:2401
llvm::PatternMatch::m_MaxOrMin
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)
Definition:PatternMatch.h:2371
llvm::PatternMatch::m_FShr
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Definition:PatternMatch.h:2731
llvm::PatternMatch::m_SelectCst
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))
Definition:PatternMatch.h:1808
llvm::PatternMatch::m_FRem
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1210
llvm::PatternMatch::m_FPTrunc
CastInst_match< OpTy, FPTruncInst > m_FPTrunc(const OpTy &Op)
Definition:PatternMatch.h:2171
llvm::PatternMatch::m_BasicBlock
class_match< BasicBlock > m_BasicBlock()
Match an arbitrary basic block value and ignore it.
Definition:PatternMatch.h:189
llvm::PatternMatch::m_SRem
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1204
llvm::PatternMatch::m_Undef
auto m_Undef()
Match an arbitrary undef constant.
Definition:PatternMatch.h:152
llvm::PatternMatch::m_NonPositive
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
Definition:PatternMatch.h:582
llvm::PatternMatch::m_NaN
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
Definition:PatternMatch.h:710
llvm::PatternMatch::m_Not
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'.
Definition:PatternMatch.h:2467
llvm::PatternMatch::m_FMin
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
Definition:PatternMatch.h:2712
llvm::PatternMatch::m_Or
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1222
llvm::PatternMatch::m_BSwap
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
Definition:PatternMatch.h:2697
llvm::PatternMatch::m_SExt
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
Definition:PatternMatch.h:2101
llvm::PatternMatch::m_Zero
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
Definition:PatternMatch.h:612
llvm::PatternMatch::m_c_Or
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.
Definition:PatternMatch.h:2805
llvm::PatternMatch::m_NUWAddLike
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".
Definition:PatternMatch.h:1429
llvm::PatternMatch::m_IntToPtr
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
Definition:PatternMatch.h:2069
llvm::PatternMatch::m_BitwiseLogic
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
Definition:PatternMatch.h:1540
llvm::PatternMatch::m_c_LogicalOr
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.
Definition:PatternMatch.h:3104
llvm::PatternMatch::m_InsertElt
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.
Definition:PatternMatch.h:1829
llvm::PatternMatch::m_c_SpecificICmp
SpecificCmpClass_match< LHS, RHS, ICmpInst, true > m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
Definition:PatternMatch.h:1696
llvm::PatternMatch::m_ElementWiseBitCast
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
Definition:PatternMatch.h:2049
llvm::PatternMatch::m_FAbs
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
Definition:PatternMatch.h:2702
llvm::PatternMatch::m_c_Mul
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.
Definition:PatternMatch.h:2791
llvm::PatternMatch::m_CopySign
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
Definition:PatternMatch.h:2741
llvm::PatternMatch::m_PtrToInt
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
Definition:PatternMatch.h:2056
llvm::PatternMatch::m_NSWMul
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1297
llvm::PatternMatch::m_Sub
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1114
llvm::PatternMatch::m_UMin
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
Definition:PatternMatch.h:2360
llvm::PatternMatch::m_NonInf
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
Definition:PatternMatch.h:733
llvm::PatternMatch::m_Deinterleave2
m_Intrinsic_Ty< Opnd >::Ty m_Deinterleave2(const Opnd &Op)
Definition:PatternMatch.h:3021
llvm::PatternMatch::m_MaskedGather
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.
Definition:PatternMatch.h:2643
llvm::PatternMatch::m_Unless
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
Definition:PatternMatch.h:203
llvm::PatternMatch::m_CombineOr
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
Definition:PatternMatch.h:239
llvm::PatternMatch::m_SpecificInt_ICMP
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.
Definition:PatternMatch.h:698
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1739
llvm::AlignStyle::Right
@ Right
llvm::AlignStyle::Left
@ Left
llvm::IRMemLocation::First
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
llvm::Op
DWARFExpression::Operation Op
Definition:DWARFExpression.cpp:22
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1766
llvm::PatternMatch::AllowReassoc_match
Definition:PatternMatch.h:71
llvm::PatternMatch::AllowReassoc_match::AllowReassoc_match
AllowReassoc_match(const SubPattern_t &SP)
Definition:PatternMatch.h:74
llvm::PatternMatch::AllowReassoc_match::SubPattern
SubPattern_t SubPattern
Definition:PatternMatch.h:72
llvm::PatternMatch::AllowReassoc_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:76
llvm::PatternMatch::AnyBinaryOp_match
Definition:PatternMatch.h:1032
llvm::PatternMatch::AnyBinaryOp_match::R
RHS_t R
Definition:PatternMatch.h:1034
llvm::PatternMatch::AnyBinaryOp_match::AnyBinaryOp_match
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1038
llvm::PatternMatch::AnyBinaryOp_match::L
LHS_t L
Definition:PatternMatch.h:1033
llvm::PatternMatch::AnyBinaryOp_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1040
llvm::PatternMatch::AnyOps_match
Matches instructions with Opcode and any number of operands.
Definition:PatternMatch.h:1767
llvm::PatternMatch::AnyOps_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1786
llvm::PatternMatch::AnyOps_match::match_operands
std::enable_if_t< Idx==Last, bool > match_operands(const Instruction *I)
Definition:PatternMatch.h:1782
llvm::PatternMatch::AnyOps_match::match_operands
std::enable_if_t< Idx !=Last, bool > match_operands(const Instruction *I)
Definition:PatternMatch.h:1777
llvm::PatternMatch::AnyOps_match::Operands
std::tuple< OperandTypes... > Operands
Definition:PatternMatch.h:1768
llvm::PatternMatch::AnyOps_match::AnyOps_match
AnyOps_match(const OperandTypes &...Ops)
Definition:PatternMatch.h:1770
llvm::PatternMatch::AnyUnaryOp_match
Definition:PatternMatch.h:1058
llvm::PatternMatch::AnyUnaryOp_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1063
llvm::PatternMatch::AnyUnaryOp_match::X
OP_t X
Definition:PatternMatch.h:1059
llvm::PatternMatch::AnyUnaryOp_match::AnyUnaryOp_match
AnyUnaryOp_match(const OP_t &X)
Definition:PatternMatch.h:1061
llvm::PatternMatch::Argument_match
Definition:PatternMatch.h:2552
llvm::PatternMatch::Argument_match::Argument_match
Argument_match(unsigned OpIdx, const Opnd_t &V)
Definition:PatternMatch.h:2556
llvm::PatternMatch::Argument_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2558
llvm::PatternMatch::Argument_match::OpI
unsigned OpI
Definition:PatternMatch.h:2553
llvm::PatternMatch::Argument_match::Val
Opnd_t Val
Definition:PatternMatch.h:2554
llvm::PatternMatch::BinOpPred_match
Definition:PatternMatch.h:1466
llvm::PatternMatch::BinOpPred_match::R
RHS_t R
Definition:PatternMatch.h:1468
llvm::PatternMatch::BinOpPred_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1472
llvm::PatternMatch::BinOpPred_match::BinOpPred_match
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1470
llvm::PatternMatch::BinOpPred_match::L
LHS_t L
Definition:PatternMatch.h:1467
llvm::PatternMatch::BinaryOp_match
Definition:PatternMatch.h:1080
llvm::PatternMatch::BinaryOp_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1098
llvm::PatternMatch::BinaryOp_match::BinaryOp_match
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1086
llvm::PatternMatch::BinaryOp_match::R
RHS_t R
Definition:PatternMatch.h:1082
llvm::PatternMatch::BinaryOp_match::L
LHS_t L
Definition:PatternMatch.h:1081
llvm::PatternMatch::BinaryOp_match::match
bool match(unsigned Opc, OpTy *V)
Definition:PatternMatch.h:1088
llvm::PatternMatch::CastInst_match
Definition:PatternMatch.h:1964
llvm::PatternMatch::CastInst_match::CastInst_match
CastInst_match(const Op_t &OpMatch)
Definition:PatternMatch.h:1967
llvm::PatternMatch::CastInst_match::Op
Op_t Op
Definition:PatternMatch.h:1965
llvm::PatternMatch::CastInst_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1969
llvm::PatternMatch::CastOperator_match
Definition:PatternMatch.h:1952
llvm::PatternMatch::CastOperator_match::CastOperator_match
CastOperator_match(const Op_t &OpMatch)
Definition:PatternMatch.h:1955
llvm::PatternMatch::CastOperator_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1957
llvm::PatternMatch::CastOperator_match::Op
Op_t Op
Definition:PatternMatch.h:1953
llvm::PatternMatch::CmpClass_match
Definition:PatternMatch.h:1590
llvm::PatternMatch::CmpClass_match::R
RHS_t R
Definition:PatternMatch.h:1593
llvm::PatternMatch::CmpClass_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1602
llvm::PatternMatch::CmpClass_match::L
LHS_t L
Definition:PatternMatch.h:1592
llvm::PatternMatch::CmpClass_match::CmpClass_match
CmpClass_match(CmpPredicate &Pred, const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1597
llvm::PatternMatch::CmpClass_match::Predicate
CmpPredicate * Predicate
Definition:PatternMatch.h:1591
llvm::PatternMatch::CmpClass_match::CmpClass_match
CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1599
llvm::PatternMatch::DisjointOr_match
Definition:PatternMatch.h:1375
llvm::PatternMatch::DisjointOr_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1381
llvm::PatternMatch::DisjointOr_match::L
LHS L
Definition:PatternMatch.h:1376
llvm::PatternMatch::DisjointOr_match::DisjointOr_match
DisjointOr_match(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1379
llvm::PatternMatch::DisjointOr_match::R
RHS R
Definition:PatternMatch.h:1377
llvm::PatternMatch::ElementWiseBitCast_match
Definition:PatternMatch.h:2025
llvm::PatternMatch::ElementWiseBitCast_match::ElementWiseBitCast_match
ElementWiseBitCast_match(const Op_t &OpMatch)
Definition:PatternMatch.h:2028
llvm::PatternMatch::ElementWiseBitCast_match::Op
Op_t Op
Definition:PatternMatch.h:2026
llvm::PatternMatch::ElementWiseBitCast_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2030
llvm::PatternMatch::Exact_match
Definition:PatternMatch.h:1568
llvm::PatternMatch::Exact_match::Exact_match
Exact_match(const SubPattern_t &SP)
Definition:PatternMatch.h:1571
llvm::PatternMatch::Exact_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1573
llvm::PatternMatch::Exact_match::SubPattern
SubPattern_t SubPattern
Definition:PatternMatch.h:1569
llvm::PatternMatch::ExtractValue_match
Definition:PatternMatch.h:2931
llvm::PatternMatch::ExtractValue_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2935
llvm::PatternMatch::ExtractValue_match::Val
Opnd_t Val
Definition:PatternMatch.h:2932
llvm::PatternMatch::ExtractValue_match::ExtractValue_match
ExtractValue_match(const Opnd_t &V)
Definition:PatternMatch.h:2933
llvm::PatternMatch::FNeg_match
Definition:PatternMatch.h:1125
llvm::PatternMatch::FNeg_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1129
llvm::PatternMatch::FNeg_match::FNeg_match
FNeg_match(const Op_t &Op)
Definition:PatternMatch.h:1128
llvm::PatternMatch::FNeg_match::X
Op_t X
Definition:PatternMatch.h:1126
llvm::PatternMatch::InsertValue_match
Matcher for a single index InsertValue instruction.
Definition:PatternMatch.h:2962
llvm::PatternMatch::InsertValue_match::InsertValue_match
InsertValue_match(const T0 &Op0, const T1 &Op1)
Definition:PatternMatch.h:2966
llvm::PatternMatch::InsertValue_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2968
llvm::PatternMatch::InsertValue_match::Op0
T0 Op0
Definition:PatternMatch.h:2963
llvm::PatternMatch::InsertValue_match::Op1
T1 Op1
Definition:PatternMatch.h:2964
llvm::PatternMatch::IntrinsicID_match
Intrinsic matchers.
Definition:PatternMatch.h:2573
llvm::PatternMatch::IntrinsicID_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2578
llvm::PatternMatch::IntrinsicID_match::ID
unsigned ID
Definition:PatternMatch.h:2574
llvm::PatternMatch::IntrinsicID_match::IntrinsicID_match
IntrinsicID_match(Intrinsic::ID IntrID)
Definition:PatternMatch.h:2576
llvm::PatternMatch::LogicalOp_match
Definition:PatternMatch.h:3026
llvm::PatternMatch::LogicalOp_match::L
LHS L
Definition:PatternMatch.h:3027
llvm::PatternMatch::LogicalOp_match::LogicalOp_match
LogicalOp_match(const LHS &L, const RHS &R)
Definition:PatternMatch.h:3030
llvm::PatternMatch::LogicalOp_match::match
bool match(T *V)
Definition:PatternMatch.h:3032
llvm::PatternMatch::LogicalOp_match::R
RHS R
Definition:PatternMatch.h:3028
llvm::PatternMatch::MaxMin_match
Definition:PatternMatch.h:2237
llvm::PatternMatch::MaxMin_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2246
llvm::PatternMatch::MaxMin_match::PredType
Pred_t PredType
Definition:PatternMatch.h:2238
llvm::PatternMatch::MaxMin_match::MaxMin_match
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:2244
llvm::PatternMatch::MaxMin_match::L
LHS_t L
Definition:PatternMatch.h:2239
llvm::PatternMatch::MaxMin_match::R
RHS_t R
Definition:PatternMatch.h:2240
llvm::PatternMatch::NNegZExt_match
Definition:PatternMatch.h:1993
llvm::PatternMatch::NNegZExt_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1998
llvm::PatternMatch::NNegZExt_match::NNegZExt_match
NNegZExt_match(const Op_t &OpMatch)
Definition:PatternMatch.h:1996
llvm::PatternMatch::NNegZExt_match::Op
Op_t Op
Definition:PatternMatch.h:1994
llvm::PatternMatch::NoWrapTrunc_match
Definition:PatternMatch.h:2005
llvm::PatternMatch::NoWrapTrunc_match::NoWrapTrunc_match
NoWrapTrunc_match(const Op_t &OpMatch)
Definition:PatternMatch.h:2008
llvm::PatternMatch::NoWrapTrunc_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2010
llvm::PatternMatch::NoWrapTrunc_match::Op
Op_t Op
Definition:PatternMatch.h:2006
llvm::PatternMatch::OneOps_match
Matches instructions with Opcode and three operands.
Definition:PatternMatch.h:1711
llvm::PatternMatch::OneOps_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1716
llvm::PatternMatch::OneOps_match::Op1
T0 Op1
Definition:PatternMatch.h:1712
llvm::PatternMatch::OneOps_match::OneOps_match
OneOps_match(const T0 &Op1)
Definition:PatternMatch.h:1714
llvm::PatternMatch::OneUse_match
Definition:PatternMatch.h:57
llvm::PatternMatch::OneUse_match::OneUse_match
OneUse_match(const SubPattern_t &SP)
Definition:PatternMatch.h:60
llvm::PatternMatch::OneUse_match::SubPattern
SubPattern_t SubPattern
Definition:PatternMatch.h:58
llvm::PatternMatch::OneUse_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:62
llvm::PatternMatch::OverflowingBinaryOp_match
Definition:PatternMatch.h:1253
llvm::PatternMatch::OverflowingBinaryOp_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1260
llvm::PatternMatch::OverflowingBinaryOp_match::OverflowingBinaryOp_match
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1257
llvm::PatternMatch::OverflowingBinaryOp_match::L
LHS_t L
Definition:PatternMatch.h:1254
llvm::PatternMatch::OverflowingBinaryOp_match::R
RHS_t R
Definition:PatternMatch.h:1255
llvm::PatternMatch::PtrAdd_match
Definition:PatternMatch.h:1893
llvm::PatternMatch::PtrAdd_match::OffsetOp
OffsetOpTy OffsetOp
Definition:PatternMatch.h:1895
llvm::PatternMatch::PtrAdd_match::PointerOp
PointerOpTy PointerOp
Definition:PatternMatch.h:1894
llvm::PatternMatch::PtrAdd_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1900
llvm::PatternMatch::PtrAdd_match::PtrAdd_match
PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Definition:PatternMatch.h:1897
llvm::PatternMatch::PtrToIntSameSize_match
Definition:PatternMatch.h:1976
llvm::PatternMatch::PtrToIntSameSize_match::PtrToIntSameSize_match
PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
Definition:PatternMatch.h:1980
llvm::PatternMatch::PtrToIntSameSize_match::DL
const DataLayout & DL
Definition:PatternMatch.h:1977
llvm::PatternMatch::PtrToIntSameSize_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1983
llvm::PatternMatch::PtrToIntSameSize_match::Op
Op_t Op
Definition:PatternMatch.h:1978
llvm::PatternMatch::Shuffle_match
Matches shuffle.
Definition:PatternMatch.h:1842
llvm::PatternMatch::Shuffle_match::Shuffle_match
Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
Definition:PatternMatch.h:1847
llvm::PatternMatch::Shuffle_match::Op1
T0 Op1
Definition:PatternMatch.h:1843
llvm::PatternMatch::Shuffle_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1850
llvm::PatternMatch::Shuffle_match::Mask
T2 Mask
Definition:PatternMatch.h:1845
llvm::PatternMatch::Shuffle_match::Op2
T1 Op2
Definition:PatternMatch.h:1844
llvm::PatternMatch::Signum_match
Definition:PatternMatch.h:2891
llvm::PatternMatch::Signum_match::Val
Opnd_t Val
Definition:PatternMatch.h:2892
llvm::PatternMatch::Signum_match::Signum_match
Signum_match(const Opnd_t &V)
Definition:PatternMatch.h:2893
llvm::PatternMatch::Signum_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2895
llvm::PatternMatch::SpecificBinaryOp_match
Definition:PatternMatch.h:1356
llvm::PatternMatch::SpecificBinaryOp_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1362
llvm::PatternMatch::SpecificBinaryOp_match::SpecificBinaryOp_match
SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1359
llvm::PatternMatch::SpecificBinaryOp_match::Opcode
unsigned Opcode
Definition:PatternMatch.h:1357
llvm::PatternMatch::SpecificCmpClass_match
Definition:PatternMatch.h:1657
llvm::PatternMatch::SpecificCmpClass_match::R
RHS_t R
Definition:PatternMatch.h:1660
llvm::PatternMatch::SpecificCmpClass_match::L
LHS_t L
Definition:PatternMatch.h:1659
llvm::PatternMatch::SpecificCmpClass_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1665
llvm::PatternMatch::SpecificCmpClass_match::SpecificCmpClass_match
SpecificCmpClass_match(CmpPredicate Pred, const LHS_t &LHS, const RHS_t &RHS)
Definition:PatternMatch.h:1662
llvm::PatternMatch::SpecificCmpClass_match::Predicate
const CmpPredicate Predicate
Definition:PatternMatch.h:1658
llvm::PatternMatch::ThreeOps_match
Matches instructions with Opcode and three operands.
Definition:PatternMatch.h:1744
llvm::PatternMatch::ThreeOps_match::Op1
T0 Op1
Definition:PatternMatch.h:1745
llvm::PatternMatch::ThreeOps_match::ThreeOps_match
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
Definition:PatternMatch.h:1749
llvm::PatternMatch::ThreeOps_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1752
llvm::PatternMatch::ThreeOps_match::Op3
T2 Op3
Definition:PatternMatch.h:1747
llvm::PatternMatch::ThreeOps_match::Op2
T1 Op2
Definition:PatternMatch.h:1746
llvm::PatternMatch::TwoOps_match
Matches instructions with Opcode and three operands.
Definition:PatternMatch.h:1726
llvm::PatternMatch::TwoOps_match::TwoOps_match
TwoOps_match(const T0 &Op1, const T1 &Op2)
Definition:PatternMatch.h:1730
llvm::PatternMatch::TwoOps_match::Op1
T0 Op1
Definition:PatternMatch.h:1727
llvm::PatternMatch::TwoOps_match::Op2
T1 Op2
Definition:PatternMatch.h:1728
llvm::PatternMatch::TwoOps_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1732
llvm::PatternMatch::UAddWithOverflow_match
Definition:PatternMatch.h:2484
llvm::PatternMatch::UAddWithOverflow_match::UAddWithOverflow_match
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Definition:PatternMatch.h:2489
llvm::PatternMatch::UAddWithOverflow_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2492
llvm::PatternMatch::UAddWithOverflow_match::R
RHS_t R
Definition:PatternMatch.h:2486
llvm::PatternMatch::UAddWithOverflow_match::L
LHS_t L
Definition:PatternMatch.h:2485
llvm::PatternMatch::UAddWithOverflow_match::S
Sum_t S
Definition:PatternMatch.h:2487
llvm::PatternMatch::VScaleVal_match
Matches patterns for vscale.
Definition:PatternMatch.h:2988
llvm::PatternMatch::VScaleVal_match::match
bool match(ITy *V)
Definition:PatternMatch.h:2989
llvm::PatternMatch::XorLike_match
Definition:PatternMatch.h:1434
llvm::PatternMatch::XorLike_match::R
RHS R
Definition:PatternMatch.h:1436
llvm::PatternMatch::XorLike_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:1440
llvm::PatternMatch::XorLike_match::L
LHS L
Definition:PatternMatch.h:1435
llvm::PatternMatch::XorLike_match::XorLike_match
XorLike_match(const LHS &L, const RHS &R)
Definition:PatternMatch.h:1438
llvm::PatternMatch::apf_pred_ty
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
Definition:PatternMatch.h:440
llvm::PatternMatch::apf_pred_ty::apf_pred_ty
apf_pred_ty(const APFloat *&R)
Definition:PatternMatch.h:443
llvm::PatternMatch::apf_pred_ty::Res
const APFloat *& Res
Definition:PatternMatch.h:441
llvm::PatternMatch::apf_pred_ty::match
bool match(ITy *V)
Definition:PatternMatch.h:445
llvm::PatternMatch::apfloat_match
Definition:PatternMatch.h:274
llvm::PatternMatch::apfloat_match::match
bool match(ITy *V)
Definition:PatternMatch.h:281
llvm::PatternMatch::apfloat_match::Res
const APFloat *& Res
Definition:PatternMatch.h:275
llvm::PatternMatch::apfloat_match::AllowPoison
bool AllowPoison
Definition:PatternMatch.h:276
llvm::PatternMatch::apfloat_match::apfloat_match
apfloat_match(const APFloat *&Res, bool AllowPoison)
Definition:PatternMatch.h:278
llvm::PatternMatch::api_pred_ty
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
Definition:PatternMatch.h:413
llvm::PatternMatch::api_pred_ty::match
bool match(ITy *V)
Definition:PatternMatch.h:418
llvm::PatternMatch::api_pred_ty::api_pred_ty
api_pred_ty(const APInt *&R)
Definition:PatternMatch.h:416
llvm::PatternMatch::api_pred_ty::Res
const APInt *& Res
Definition:PatternMatch.h:414
llvm::PatternMatch::apint_match
Definition:PatternMatch.h:249
llvm::PatternMatch::apint_match::Res
const APInt *& Res
Definition:PatternMatch.h:250
llvm::PatternMatch::apint_match::match
bool match(ITy *V)
Definition:PatternMatch.h:256
llvm::PatternMatch::apint_match::apint_match
apint_match(const APInt *&Res, bool AllowPoison)
Definition:PatternMatch.h:253
llvm::PatternMatch::apint_match::AllowPoison
bool AllowPoison
Definition:PatternMatch.h:251
llvm::PatternMatch::bind_const_intval_ty
Definition:PatternMatch.h:933
llvm::PatternMatch::bind_const_intval_ty::VR
uint64_t & VR
Definition:PatternMatch.h:934
llvm::PatternMatch::bind_const_intval_ty::bind_const_intval_ty
bind_const_intval_ty(uint64_t &V)
Definition:PatternMatch.h:936
llvm::PatternMatch::bind_const_intval_ty::match
bool match(ITy *V)
Definition:PatternMatch.h:938
llvm::PatternMatch::bind_ty
Definition:PatternMatch.h:807
llvm::PatternMatch::bind_ty::bind_ty
bind_ty(Class *&V)
Definition:PatternMatch.h:810
llvm::PatternMatch::bind_ty::match
bool match(ITy *V)
Definition:PatternMatch.h:812
llvm::PatternMatch::bind_ty::VR
Class *& VR
Definition:PatternMatch.h:808
llvm::PatternMatch::br_match
Definition:PatternMatch.h:2184
llvm::PatternMatch::br_match::Succ
BasicBlock *& Succ
Definition:PatternMatch.h:2185
llvm::PatternMatch::br_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2189
llvm::PatternMatch::br_match::br_match
br_match(BasicBlock *&Succ)
Definition:PatternMatch.h:2187
llvm::PatternMatch::brc_match
Definition:PatternMatch.h:2202
llvm::PatternMatch::brc_match::F
FalseBlock_t F
Definition:PatternMatch.h:2205
llvm::PatternMatch::brc_match::Cond
Cond_t Cond
Definition:PatternMatch.h:2203
llvm::PatternMatch::brc_match::brc_match
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
Definition:PatternMatch.h:2207
llvm::PatternMatch::brc_match::T
TrueBlock_t T
Definition:PatternMatch.h:2204
llvm::PatternMatch::brc_match::match
bool match(OpTy *V)
Definition:PatternMatch.h:2210
llvm::PatternMatch::class_match
Definition:PatternMatch.h:87
llvm::PatternMatch::class_match::match
bool match(ITy *V)
Definition:PatternMatch.h:88
llvm::PatternMatch::constantexpr_match
Definition:PatternMatch.h:177
llvm::PatternMatch::constantexpr_match::match
bool match(ITy *V)
Definition:PatternMatch.h:178
llvm::PatternMatch::constantint_match
Definition:PatternMatch.h:331
llvm::PatternMatch::constantint_match::match
bool match(ITy *V)
Definition:PatternMatch.h:332
llvm::PatternMatch::cstval_pred_ty
This helper class is used to match constant scalars, vector splats, and fixed width vectors that sati...
Definition:PatternMatch.h:356
llvm::PatternMatch::cstval_pred_ty::match
bool match(ITy *V)
Definition:PatternMatch.h:392
llvm::PatternMatch::cstval_pred_ty::match_impl
bool match_impl(ITy *V)
Definition:PatternMatch.h:358
llvm::PatternMatch::cstval_pred_ty::Res
const Constant ** Res
Definition:PatternMatch.h:357
llvm::PatternMatch::custom_checkfn
Definition:PatternMatch.h:473
llvm::PatternMatch::custom_checkfn::isValue
bool isValue(const APTy &C)
Definition:PatternMatch.h:475
llvm::PatternMatch::custom_checkfn::CheckFn
function_ref< bool(const APTy &)> CheckFn
Definition:PatternMatch.h:474
llvm::PatternMatch::deferredval_ty
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers.
Definition:PatternMatch.h:889
llvm::PatternMatch::deferredval_ty::Val
Class *const & Val
Definition:PatternMatch.h:890
llvm::PatternMatch::deferredval_ty::deferredval_ty
deferredval_ty(Class *const &V)
Definition:PatternMatch.h:892
llvm::PatternMatch::deferredval_ty::match
bool match(ITy *const V)
Definition:PatternMatch.h:894
llvm::PatternMatch::icmp_pred_with_threshold
Definition:PatternMatch.h:690
llvm::PatternMatch::icmp_pred_with_threshold::Pred
CmpPredicate Pred
Definition:PatternMatch.h:691
llvm::PatternMatch::icmp_pred_with_threshold::Thr
const APInt * Thr
Definition:PatternMatch.h:692
llvm::PatternMatch::icmp_pred_with_threshold::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:693
llvm::PatternMatch::is_all_ones
Definition:PatternMatch.h:519
llvm::PatternMatch::is_all_ones::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:520
llvm::PatternMatch::is_any_apint
Definition:PatternMatch.h:502
llvm::PatternMatch::is_any_apint::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:503
llvm::PatternMatch::is_any_zero_fp
Definition:PatternMatch.h:759
llvm::PatternMatch::is_any_zero_fp::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:760
llvm::PatternMatch::is_bitwiselogic_op
Definition:PatternMatch.h:1498
llvm::PatternMatch::is_bitwiselogic_op::isOpType
bool isOpType(unsigned Opcode)
Definition:PatternMatch.h:1499
llvm::PatternMatch::is_finite
Definition:PatternMatch.h:737
llvm::PatternMatch::is_finite::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:738
llvm::PatternMatch::is_finitenonzero
Definition:PatternMatch.h:747
llvm::PatternMatch::is_finitenonzero::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:748
llvm::PatternMatch::is_idiv_op
Definition:PatternMatch.h:1504
llvm::PatternMatch::is_idiv_op::isOpType
bool isOpType(unsigned Opcode)
Definition:PatternMatch.h:1505
llvm::PatternMatch::is_inf
Definition:PatternMatch.h:721
llvm::PatternMatch::is_inf::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:722
llvm::PatternMatch::is_irem_op
Definition:PatternMatch.h:1510
llvm::PatternMatch::is_irem_op::isOpType
bool isOpType(unsigned Opcode)
Definition:PatternMatch.h:1511
llvm::PatternMatch::is_logical_shift_op
Definition:PatternMatch.h:1492
llvm::PatternMatch::is_logical_shift_op::isOpType
bool isOpType(unsigned Opcode)
Definition:PatternMatch.h:1493
llvm::PatternMatch::is_lowbit_mask_or_zero
Definition:PatternMatch.h:678
llvm::PatternMatch::is_lowbit_mask_or_zero::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:679
llvm::PatternMatch::is_lowbit_mask
Definition:PatternMatch.h:668
llvm::PatternMatch::is_lowbit_mask::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:669
llvm::PatternMatch::is_maxsignedvalue
Definition:PatternMatch.h:532
llvm::PatternMatch::is_maxsignedvalue::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:533
llvm::PatternMatch::is_nan
Definition:PatternMatch.h:705
llvm::PatternMatch::is_nan::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:706
llvm::PatternMatch::is_neg_zero_fp
Definition:PatternMatch.h:777
llvm::PatternMatch::is_neg_zero_fp::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:778
llvm::PatternMatch::is_negated_power2_or_zero
Definition:PatternMatch.h:634
llvm::PatternMatch::is_negated_power2_or_zero::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:635
llvm::PatternMatch::is_negated_power2
Definition:PatternMatch.h:622
llvm::PatternMatch::is_negated_power2::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:623
llvm::PatternMatch::is_negative
Definition:PatternMatch.h:545
llvm::PatternMatch::is_negative::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:546
llvm::PatternMatch::is_non_zero_fp
Definition:PatternMatch.h:786
llvm::PatternMatch::is_non_zero_fp::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:787
llvm::PatternMatch::is_non_zero_not_denormal_fp
Definition:PatternMatch.h:795
llvm::PatternMatch::is_non_zero_not_denormal_fp::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:796
llvm::PatternMatch::is_noninf
Definition:PatternMatch.h:728
llvm::PatternMatch::is_noninf::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:729
llvm::PatternMatch::is_nonnan
Definition:PatternMatch.h:712
llvm::PatternMatch::is_nonnan::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:713
llvm::PatternMatch::is_nonnegative
Definition:PatternMatch.h:555
llvm::PatternMatch::is_nonnegative::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:556
llvm::PatternMatch::is_nonpositive
Definition:PatternMatch.h:577
llvm::PatternMatch::is_nonpositive::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:578
llvm::PatternMatch::is_one
Definition:PatternMatch.h:587
llvm::PatternMatch::is_one::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:588
llvm::PatternMatch::is_pos_zero_fp
Definition:PatternMatch.h:768
llvm::PatternMatch::is_pos_zero_fp::isValue
bool isValue(const APFloat &C)
Definition:PatternMatch.h:769
llvm::PatternMatch::is_power2_or_zero
Definition:PatternMatch.h:647
llvm::PatternMatch::is_power2_or_zero::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:648
llvm::PatternMatch::is_power2
Definition:PatternMatch.h:614
llvm::PatternMatch::is_power2::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:615
llvm::PatternMatch::is_right_shift_op
Definition:PatternMatch.h:1486
llvm::PatternMatch::is_right_shift_op::isOpType
bool isOpType(unsigned Opcode)
Definition:PatternMatch.h:1487
llvm::PatternMatch::is_shift_op
Definition:PatternMatch.h:1482
llvm::PatternMatch::is_shift_op::isOpType
bool isOpType(unsigned Opcode)
Definition:PatternMatch.h:1483
llvm::PatternMatch::is_shifted_mask
Definition:PatternMatch.h:511
llvm::PatternMatch::is_shifted_mask::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:512
llvm::PatternMatch::is_sign_mask
Definition:PatternMatch.h:659
llvm::PatternMatch::is_sign_mask::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:660
llvm::PatternMatch::is_strictlypositive
Definition:PatternMatch.h:565
llvm::PatternMatch::is_strictlypositive::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:566
llvm::PatternMatch::is_zero_int
Definition:PatternMatch.h:594
llvm::PatternMatch::is_zero_int::isValue
bool isValue(const APInt &C)
Definition:PatternMatch.h:595
llvm::PatternMatch::is_zero
Definition:PatternMatch.h:603
llvm::PatternMatch::is_zero::match
bool match(ITy *V)
Definition:PatternMatch.h:604
llvm::PatternMatch::m_Intrinsic_Ty
Intrinsic matches are combinations of ID matchers, and argument matchers.
Definition:PatternMatch.h:2594
llvm::PatternMatch::m_Mask
Definition:PatternMatch.h:1859
llvm::PatternMatch::m_Mask::match
bool match(ArrayRef< int > Mask)
Definition:PatternMatch.h:1862
llvm::PatternMatch::m_Mask::MaskRef
ArrayRef< int > & MaskRef
Definition:PatternMatch.h:1860
llvm::PatternMatch::m_Mask::m_Mask
m_Mask(ArrayRef< int > &MaskRef)
Definition:PatternMatch.h:1861
llvm::PatternMatch::m_SpecificMask
Definition:PatternMatch.h:1874
llvm::PatternMatch::m_SpecificMask::Val
ArrayRef< int > Val
Definition:PatternMatch.h:1875
llvm::PatternMatch::m_SpecificMask::match
bool match(ArrayRef< int > Mask)
Definition:PatternMatch.h:1877
llvm::PatternMatch::m_SpecificMask::m_SpecificMask
m_SpecificMask(ArrayRef< int > Val)
Definition:PatternMatch.h:1876
llvm::PatternMatch::m_SplatOrPoisonMask
Definition:PatternMatch.h:1880
llvm::PatternMatch::m_SplatOrPoisonMask::SplatIndex
int & SplatIndex
Definition:PatternMatch.h:1881
llvm::PatternMatch::m_SplatOrPoisonMask::match
bool match(ArrayRef< int > Mask)
Definition:PatternMatch.h:1883
llvm::PatternMatch::m_SplatOrPoisonMask::m_SplatOrPoisonMask
m_SplatOrPoisonMask(int &SplatIndex)
Definition:PatternMatch.h:1882
llvm::PatternMatch::m_ZeroMask
Definition:PatternMatch.h:1868
llvm::PatternMatch::m_ZeroMask::match
bool match(ArrayRef< int > Mask)
Definition:PatternMatch.h:1869
llvm::PatternMatch::match_combine_and
Definition:PatternMatch.h:223
llvm::PatternMatch::match_combine_and::L
LTy L
Definition:PatternMatch.h:224
llvm::PatternMatch::match_combine_and::match
bool match(ITy *V)
Definition:PatternMatch.h:229
llvm::PatternMatch::match_combine_and::match_combine_and
match_combine_and(const LTy &Left, const RTy &Right)
Definition:PatternMatch.h:227
llvm::PatternMatch::match_combine_and::R
RTy R
Definition:PatternMatch.h:225
llvm::PatternMatch::match_combine_or
Matching combinators.
Definition:PatternMatch.h:208
llvm::PatternMatch::match_combine_or::match_combine_or
match_combine_or(const LTy &Left, const RTy &Right)
Definition:PatternMatch.h:212
llvm::PatternMatch::match_combine_or::match
bool match(ITy *V)
Definition:PatternMatch.h:214
llvm::PatternMatch::match_combine_or::L
LTy L
Definition:PatternMatch.h:209
llvm::PatternMatch::match_combine_or::R
RTy R
Definition:PatternMatch.h:210
llvm::PatternMatch::match_unless
Inverting matcher.
Definition:PatternMatch.h:194
llvm::PatternMatch::match_unless::M
Ty M
Definition:PatternMatch.h:195
llvm::PatternMatch::match_unless::match_unless
match_unless(const Ty &Matcher)
Definition:PatternMatch.h:197
llvm::PatternMatch::match_unless::match
bool match(ITy *V)
Definition:PatternMatch.h:199
llvm::PatternMatch::ofmax_pred_ty
Helper class for identifying ordered max predicates.
Definition:PatternMatch.h:2314
llvm::PatternMatch::ofmax_pred_ty::match
static bool match(FCmpInst::Predicate Pred)
Definition:PatternMatch.h:2315
llvm::PatternMatch::ofmin_pred_ty
Helper class for identifying ordered min predicates.
Definition:PatternMatch.h:2321
llvm::PatternMatch::ofmin_pred_ty::match
static bool match(FCmpInst::Predicate Pred)
Definition:PatternMatch.h:2322
llvm::PatternMatch::smax_pred_ty
Helper class for identifying signed max predicates.
Definition:PatternMatch.h:2286
llvm::PatternMatch::smax_pred_ty::match
static bool match(ICmpInst::Predicate Pred)
Definition:PatternMatch.h:2287
llvm::PatternMatch::smin_pred_ty
Helper class for identifying signed min predicates.
Definition:PatternMatch.h:2293
llvm::PatternMatch::smin_pred_ty::match
static bool match(ICmpInst::Predicate Pred)
Definition:PatternMatch.h:2294
llvm::PatternMatch::specific_bbval
Match a specified basic block value.
Definition:PatternMatch.h:1003
llvm::PatternMatch::specific_bbval::specific_bbval
specific_bbval(BasicBlock *Val)
Definition:PatternMatch.h:1006
llvm::PatternMatch::specific_bbval::Val
BasicBlock * Val
Definition:PatternMatch.h:1004
llvm::PatternMatch::specific_bbval::match
bool match(ITy *V)
Definition:PatternMatch.h:1008
llvm::PatternMatch::specific_fpval
Match a specified floating point value or vector of all elements of that value.
Definition:PatternMatch.h:910
llvm::PatternMatch::specific_fpval::match
bool match(ITy *V)
Definition:PatternMatch.h:915
llvm::PatternMatch::specific_fpval::specific_fpval
specific_fpval(double V)
Definition:PatternMatch.h:913
llvm::PatternMatch::specific_fpval::Val
double Val
Definition:PatternMatch.h:911
llvm::PatternMatch::specific_intval64
Definition:PatternMatch.h:965
llvm::PatternMatch::specific_intval64::Val
uint64_t Val
Definition:PatternMatch.h:966
llvm::PatternMatch::specific_intval64::specific_intval64
specific_intval64(uint64_t V)
Definition:PatternMatch.h:968
llvm::PatternMatch::specific_intval64::match
bool match(ITy *V)
Definition:PatternMatch.h:970
llvm::PatternMatch::specific_intval
Match a specified integer value or vector of all elements of that value.
Definition:PatternMatch.h:950
llvm::PatternMatch::specific_intval::specific_intval
specific_intval(const APInt &V)
Definition:PatternMatch.h:953
llvm::PatternMatch::specific_intval::Val
const APInt & Val
Definition:PatternMatch.h:951
llvm::PatternMatch::specific_intval::match
bool match(ITy *V)
Definition:PatternMatch.h:955
llvm::PatternMatch::specificval_ty
Match a specified Value*.
Definition:PatternMatch.h:876
llvm::PatternMatch::specificval_ty::Val
const Value * Val
Definition:PatternMatch.h:877
llvm::PatternMatch::specificval_ty::specificval_ty
specificval_ty(const Value *V)
Definition:PatternMatch.h:879
llvm::PatternMatch::specificval_ty::match
bool match(ITy *V)
Definition:PatternMatch.h:881
llvm::PatternMatch::ufmax_pred_ty
Helper class for identifying unordered max predicates.
Definition:PatternMatch.h:2328
llvm::PatternMatch::ufmax_pred_ty::match
static bool match(FCmpInst::Predicate Pred)
Definition:PatternMatch.h:2329
llvm::PatternMatch::ufmin_pred_ty
Helper class for identifying unordered min predicates.
Definition:PatternMatch.h:2335
llvm::PatternMatch::ufmin_pred_ty::match
static bool match(FCmpInst::Predicate Pred)
Definition:PatternMatch.h:2336
llvm::PatternMatch::umax_pred_ty
Helper class for identifying unsigned max predicates.
Definition:PatternMatch.h:2300
llvm::PatternMatch::umax_pred_ty::match
static bool match(ICmpInst::Predicate Pred)
Definition:PatternMatch.h:2301
llvm::PatternMatch::umin_pred_ty
Helper class for identifying unsigned min predicates.
Definition:PatternMatch.h:2307
llvm::PatternMatch::umin_pred_ty::match
static bool match(ICmpInst::Predicate Pred)
Definition:PatternMatch.h:2308
llvm::PatternMatch::undef_match
Definition:PatternMatch.h:107
llvm::PatternMatch::undef_match::check
static bool check(const Value *V)
Definition:PatternMatch.h:108
llvm::PatternMatch::undef_match::match
bool match(ITy *V)
Definition:PatternMatch.h:146

Generated on Thu Jul 17 2025 10:06:28 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp