LLVM 19.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"
40#include "llvm/IR/Intrinsics.h"
41#include "llvm/IR/Operator.h"
42#include "llvm/IR/Value.h"
44#include <cstdint>
45
46namespace llvm {
47namespace PatternMatch {
48
49template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
50 return const_cast<Pattern &>(P).match(V);
51}
52
53template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
54 return const_cast<Pattern &>(P).match(Mask);
55}
56
57template <typename SubPattern_t> struct OneUse_match {
58 SubPattern_t SubPattern;
59
60 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
61
62 template <typename OpTy> bool match(OpTy *V) {
63 return V->hasOneUse() && SubPattern.match(V);
64 }
65};
66
67template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
68 return SubPattern;
69}
70
71template <typename SubPattern_t> struct AllowReassoc_match {
72 SubPattern_t SubPattern;
73
74 AllowReassoc_match(const SubPattern_t &SP) : SubPattern(SP) {}
75
76 template <typename OpTy> bool match(OpTy *V) {
77 auto *I = dyn_cast<FPMathOperator>(V);
78 return I && I->hasAllowReassoc() && SubPattern.match(I);
79 }
80};
81
82template <typename T>
83inline AllowReassoc_match<T> m_AllowReassoc(const T &SubPattern) {
84 return SubPattern;
85}
86
87template <typename Class> struct class_match {
88 template <typename ITy> bool match(ITy *V) { return isa<Class>(V); }
89};
90
91/// Match an arbitrary value and ignore it.
93
94/// Match an arbitrary unary operation and ignore it.
97}
98
99/// Match an arbitrary binary operation and ignore it.
102}
103
104/// Matches any compare instruction and ignore it.
106
108 static bool check(const Value *V) {
109 if (isa<UndefValue>(V))
110 return true;
111
112 const auto *CA = dyn_cast<ConstantAggregate>(V);
113 if (!CA)
114 return false;
115
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.
122 auto CheckValue = [&](const ConstantAggregate *CA) {
123 for (const Value *Op : CA->operand_values()) {
124 if (isa<UndefValue>(Op))
125 continue;
126
127 const auto *CA = dyn_cast<ConstantAggregate>(Op);
128 if (!CA)
129 return false;
130 if (Seen.insert(CA).second)
131 Worklist.emplace_back(CA);
132 }
133
134 return true;
135 };
136
137 if (!CheckValue(CA))
138 return false;
139
140 while (!Worklist.empty()) {
141 if (!CheckValue(Worklist.pop_back_val()))
142 return false;
143 }
144 return true;
145 }
146 template <typename ITy> bool match(ITy *V) { return check(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.
152inline auto m_Undef() { return undef_match(); }
153
154/// Match an arbitrary poison constant.
157}
158
159/// Match an arbitrary Constant and ignore it.
161
162/// Match an arbitrary ConstantInt and ignore it.
165}
166
167/// Match an arbitrary ConstantFP and ignore it.
170}
171
173 template <typename ITy> bool match(ITy *V) {
174 auto *C = dyn_cast<Constant>(V);
175 return C && (isa<ConstantExpr>(C) || C->containsConstantExpression());
176 }
177};
178
179/// Match a constant expression or a constant that contains a constant
180/// expression.
182
183/// Match an arbitrary basic block value and ignore it.
186}
187
188/// Inverting matcher
189template <typename Ty> struct match_unless {
190 Ty M;
191
192 match_unless(const Ty &Matcher) : M(Matcher) {}
193
194 template <typename ITy> bool match(ITy *V) { return !M.match(V); }
195};
196
197/// Match if the inner matcher does *NOT* match.
198template <typename Ty> inline match_unless<Ty> m_Unless(const Ty &M) {
199 return match_unless<Ty>(M);
200}
201
202/// Matching combinators
203template <typename LTy, typename RTy> struct match_combine_or {
204 LTy L;
205 RTy R;
206
207 match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
208
209 template <typename ITy> bool match(ITy *V) {
210 if (L.match(V))
211 return true;
212 if (R.match(V))
213 return true;
214 return false;
215 }
216};
217
218template <typename LTy, typename RTy> struct match_combine_and {
219 LTy L;
220 RTy R;
221
222 match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
223
224 template <typename ITy> bool match(ITy *V) {
225 if (L.match(V))
226 if (R.match(V))
227 return true;
228 return false;
229 }
230};
231
232/// Combine two pattern matchers matching L || R
233template <typename LTy, typename RTy>
234inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
235 return match_combine_or<LTy, RTy>(L, R);
236}
237
238/// Combine two pattern matchers matching L && R
239template <typename LTy, typename RTy>
240inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
241 return match_combine_and<LTy, RTy>(L, R);
242}
243
245 const APInt *&Res;
247
250
251 template <typename ITy> bool match(ITy *V) {
252 if (auto *CI = dyn_cast<ConstantInt>(V)) {
253 Res = &CI->getValue();
254 return true;
255 }
256 if (V->getType()->isVectorTy())
257 if (const auto *C = dyn_cast<Constant>(V))
258 if (auto *CI =
259 dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowUndef))) {
260 Res = &CI->getValue();
261 return true;
262 }
263 return false;
264 }
265};
266// Either constexpr if or renaming ConstantFP::getValueAPF to
267// ConstantFP::getValue is needed to do it via single template
268// function for both apint/apfloat.
270 const APFloat *&Res;
272
275
276 template <typename ITy> bool match(ITy *V) {
277 if (auto *CI = dyn_cast<ConstantFP>(V)) {
278 Res = &CI->getValueAPF();
279 return true;
280 }
281 if (V->getType()->isVectorTy())
282 if (const auto *C = dyn_cast<Constant>(V))
283 if (auto *CI =
284 dyn_cast_or_null<ConstantFP>(C->getSplatValue(AllowUndef))) {
285 Res = &CI->getValueAPF();
286 return true;
287 }
288 return false;
289 }
290};
291
292/// Match a ConstantInt or splatted ConstantVector, binding the
293/// specified pointer to the contained APInt.
294inline apint_match m_APInt(const APInt *&Res) {
295 // Forbid undefs by default to maintain previous behavior.
296 return apint_match(Res, /* AllowUndef */ false);
297}
298
299/// Match APInt while allowing undefs in splat vector constants.
301 return apint_match(Res, /* AllowUndef */ true);
302}
303
304/// Match APInt while forbidding undefs in splat vector constants.
306 return apint_match(Res, /* AllowUndef */ false);
307}
308
309/// Match a ConstantFP or splatted ConstantVector, binding the
310/// specified pointer to the contained APFloat.
311inline apfloat_match m_APFloat(const APFloat *&Res) {
312 // Forbid undefs by default to maintain previous behavior.
313 return apfloat_match(Res, /* AllowUndef */ false);
314}
315
316/// Match APFloat while allowing undefs in splat vector constants.
318 return apfloat_match(Res, /* AllowUndef */ true);
319}
320
321/// Match APFloat while forbidding undefs in splat vector constants.
323 return apfloat_match(Res, /* AllowUndef */ false);
324}
325
326template <int64_t Val> struct constantint_match {
327 template <typename ITy> bool match(ITy *V) {
328 if (const auto *CI = dyn_cast<ConstantInt>(V)) {
329 const APInt &CIV = CI->getValue();
330 if (Val >= 0)
331 return CIV == static_cast<uint64_t>(Val);
332 // If Val is negative, and CI is shorter than it, truncate to the right
333 // number of bits. If it is larger, then we have to sign extend. Just
334 // compare their negated values.
335 return -CIV == -Val;
336 }
337 return false;
338 }
339};
340
341/// Match a ConstantInt with a specific value.
342template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
343 return constantint_match<Val>();
344}
345
346/// This helper class is used to match constant scalars, vector splats,
347/// and fixed width vectors that satisfy a specified predicate.
348/// For fixed width vector constants, undefined elements are ignored.
349template <typename Predicate, typename ConstantVal>
350struct cstval_pred_ty : public Predicate {
351 template <typename ITy> bool match(ITy *V) {
352 if (const auto *CV = dyn_cast<ConstantVal>(V))
353 return this->isValue(CV->getValue());
354 if (const auto *VTy = dyn_cast<VectorType>(V->getType())) {
355 if (const auto *C = dyn_cast<Constant>(V)) {
356 if (const auto *CV = dyn_cast_or_null<ConstantVal>(C->getSplatValue()))
357 return this->isValue(CV->getValue());
358
359 // Number of elements of a scalable vector unknown at compile time
360 auto *FVTy = dyn_cast<FixedVectorType>(VTy);
361 if (!FVTy)
362 return false;
363
364 // Non-splat vector constant: check each element for a match.
365 unsigned NumElts = FVTy->getNumElements();
366 assert(NumElts != 0 && "Constant vector with no elements?");
367 bool HasNonUndefElements = false;
368 for (unsigned i = 0; i != NumElts; ++i) {
369 Constant *Elt = C->getAggregateElement(i);
370 if (!Elt)
371 return false;
372 if (isa<UndefValue>(Elt))
373 continue;
374 auto *CV = dyn_cast<ConstantVal>(Elt);
375 if (!CV || !this->isValue(CV->getValue()))
376 return false;
377 HasNonUndefElements = true;
378 }
379 return HasNonUndefElements;
380 }
381 }
382 return false;
383 }
384};
385
386/// specialization of cstval_pred_ty for ConstantInt
387template <typename Predicate>
389
390/// specialization of cstval_pred_ty for ConstantFP
391template <typename Predicate>
393
394/// This helper class is used to match scalar and vector constants that
395/// satisfy a specified predicate, and bind them to an APInt.
396template <typename Predicate> struct api_pred_ty : public Predicate {
397 const APInt *&Res;
398
399 api_pred_ty(const APInt *&R) : Res(R) {}
400
401 template <typename ITy> bool match(ITy *V) {
402 if (const auto *CI = dyn_cast<ConstantInt>(V))
403 if (this->isValue(CI->getValue())) {
404 Res = &CI->getValue();
405 return true;
406 }
407 if (V->getType()->isVectorTy())
408 if (const auto *C = dyn_cast<Constant>(V))
409 if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
410 if (this->isValue(CI->getValue())) {
411 Res = &CI->getValue();
412 return true;
413 }
414
415 return false;
416 }
417};
418
419/// This helper class is used to match scalar and vector constants that
420/// satisfy a specified predicate, and bind them to an APFloat.
421/// Undefs are allowed in splat vector constants.
422template <typename Predicate> struct apf_pred_ty : public Predicate {
423 const APFloat *&Res;
424
425 apf_pred_ty(const APFloat *&R) : Res(R) {}
426
427 template <typename ITy> bool match(ITy *V) {
428 if (const auto *CI = dyn_cast<ConstantFP>(V))
429 if (this->isValue(CI->getValue())) {
430 Res = &CI->getValue();
431 return true;
432 }
433 if (V->getType()->isVectorTy())
434 if (const auto *C = dyn_cast<Constant>(V))
435 if (auto *CI = dyn_cast_or_null<ConstantFP>(
436 C->getSplatValue(/* AllowUndef */ true)))
437 if (this->isValue(CI->getValue())) {
438 Res = &CI->getValue();
439 return true;
440 }
441
442 return false;
443 }
444};
445
446///////////////////////////////////////////////////////////////////////////////
447//
448// Encapsulate constant value queries for use in templated predicate matchers.
449// This allows checking if constants match using compound predicates and works
450// with vector constants, possibly with relaxed constraints. For example, ignore
451// undef values.
452//
453///////////////////////////////////////////////////////////////////////////////
454
456 bool isValue(const APInt &C) { return true; }
457};
458/// Match an integer or vector with any integral constant.
459/// For vectors, this includes constants with undefined elements.
462}
463
465 bool isValue(const APInt &C) { return C.isShiftedMask(); }
466};
467
470}
471
473 bool isValue(const APInt &C) { return C.isAllOnes(); }
474};
475/// Match an integer or vector with all bits set.
476/// For vectors, this includes constants with undefined elements.
479}
480
482 bool isValue(const APInt &C) { return C.isMaxSignedValue(); }
483};
484/// Match an integer or vector with values having all bits except for the high
485/// bit set (0x7f...).
486/// For vectors, this includes constants with undefined elements.
489}
491 return V;
492}
493
495 bool isValue(const APInt &C) { return C.isNegative(); }
496};
497/// Match an integer or vector of negative values.
498/// For vectors, this includes constants with undefined elements.
501}
502inline api_pred_ty<is_negative> m_Negative(const APInt *&V) { return V; }
503
505 bool isValue(const APInt &C) { return C.isNonNegative(); }
506};
507/// Match an integer or vector of non-negative values.
508/// For vectors, this includes constants with undefined elements.
511}
512inline api_pred_ty<is_nonnegative> m_NonNegative(const APInt *&V) { return V; }
513
515 bool isValue(const APInt &C) { return C.isStrictlyPositive(); }
516};
517/// Match an integer or vector of strictly positive values.
518/// For vectors, this includes constants with undefined elements.
521}
523 return V;
524}
525
527 bool isValue(const APInt &C) { return C.isNonPositive(); }
528};
529/// Match an integer or vector of non-positive values.
530/// For vectors, this includes constants with undefined elements.
533}
534inline api_pred_ty<is_nonpositive> m_NonPositive(const APInt *&V) { return V; }
535
536struct is_one {
537 bool isValue(const APInt &C) { return C.isOne(); }
538};
539/// Match an integer 1 or a vector with all elements equal to 1.
540/// For vectors, this includes constants with undefined elements.
542
544 bool isValue(const APInt &C) { return C.isZero(); }
545};
546/// Match an integer 0 or a vector with all elements equal to 0.
547/// For vectors, this includes constants with undefined elements.
550}
551
552struct is_zero {
553 template <typename ITy> bool match(ITy *V) {
554 auto *C = dyn_cast<Constant>(V);
555 // FIXME: this should be able to do something for scalable vectors
556 return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C));
557 }
558};
559/// Match any null constant or a vector with all elements equal to 0.
560/// For vectors, this includes constants with undefined elements.
561inline is_zero m_Zero() { return is_zero(); }
562
563struct is_power2 {
564 bool isValue(const APInt &C) { return C.isPowerOf2(); }
565};
566/// Match an integer or vector power-of-2.
567/// For vectors, this includes constants with undefined elements.
569inline api_pred_ty<is_power2> m_Power2(const APInt *&V) { return V; }
570
572 bool isValue(const APInt &C) { return C.isNegatedPowerOf2(); }
573};
574/// Match a integer or vector negated power-of-2.
575/// For vectors, this includes constants with undefined elements.
578}
580 return V;
581}
582
584 bool isValue(const APInt &C) { return !C || C.isNegatedPowerOf2(); }
585};
586/// Match a integer or vector negated power-of-2.
587/// For vectors, this includes constants with undefined elements.
590}
593 return V;
594}
595
597 bool isValue(const APInt &C) { return !C || C.isPowerOf2(); }
598};
599/// Match an integer or vector of 0 or power-of-2 values.
600/// For vectors, this includes constants with undefined elements.
603}
605 return V;
606}
607
609 bool isValue(const APInt &C) { return C.isSignMask(); }
610};
611/// Match an integer or vector with only the sign bit(s) set.
612/// For vectors, this includes constants with undefined elements.
615}
616
618 bool isValue(const APInt &C) { return C.isMask(); }
619};
620/// Match an integer or vector with only the low bit(s) set.
621/// For vectors, this includes constants with undefined elements.
624}
625inline api_pred_ty<is_lowbit_mask> m_LowBitMask(const APInt *&V) { return V; }
626
628 bool isValue(const APInt &C) { return !C || C.isMask(); }
629};
630/// Match an integer or vector with only the low bit(s) set.
631/// For vectors, this includes constants with undefined elements.
634}
636 return V;
637}
638
641 const APInt *Thr;
642 bool isValue(const APInt &C) { return ICmpInst::compare(C, *Thr, Pred); }
643};
644/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
645/// to Threshold. For vectors, this includes constants with undefined elements.
647m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold) {
649 P.Pred = Predicate;
650 P.Thr = &Threshold;
651 return P;
652}
653
654struct is_nan {
655 bool isValue(const APFloat &C) { return C.isNaN(); }
656};
657/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
658/// For vectors, this includes constants with undefined elements.
660
661struct is_nonnan {
662 bool isValue(const APFloat &C) { return !C.isNaN(); }
663};
664/// Match a non-NaN FP constant.
665/// For vectors, this includes constants with undefined elements.
668}
669
670struct is_inf {
671 bool isValue(const APFloat &C) { return C.isInfinity(); }
672};
673/// Match a positive or negative infinity FP constant.
674/// For vectors, this includes constants with undefined elements.
676
677struct is_noninf {
678 bool isValue(const APFloat &C) { return !C.isInfinity(); }
679};
680/// Match a non-infinity FP constant, i.e. finite or NaN.
681/// For vectors, this includes constants with undefined elements.
684}
685
686struct is_finite {
687 bool isValue(const APFloat &C) { return C.isFinite(); }
688};
689/// Match a finite FP constant, i.e. not infinity or NaN.
690/// For vectors, this includes constants with undefined elements.
693}
694inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
695
697 bool isValue(const APFloat &C) { return C.isFiniteNonZero(); }
698};
699/// Match a finite non-zero FP constant.
700/// For vectors, this includes constants with undefined elements.
703}
705 return V;
706}
707
709 bool isValue(const APFloat &C) { return C.isZero(); }
710};
711/// Match a floating-point negative zero or positive zero.
712/// For vectors, this includes constants with undefined elements.
715}
716
718 bool isValue(const APFloat &C) { return C.isPosZero(); }
719};
720/// Match a floating-point positive zero.
721/// For vectors, this includes constants with undefined elements.
724}
725
727 bool isValue(const APFloat &C) { return C.isNegZero(); }
728};
729/// Match a floating-point negative zero.
730/// For vectors, this includes constants with undefined elements.
733}
734
736 bool isValue(const APFloat &C) { return C.isNonZero(); }
737};
738/// Match a floating-point non-zero.
739/// For vectors, this includes constants with undefined elements.
742}
743
744///////////////////////////////////////////////////////////////////////////////
745
746template <typename Class> struct bind_ty {
747 Class *&VR;
748
749 bind_ty(Class *&V) : VR(V) {}
750
751 template <typename ITy> bool match(ITy *V) {
752 if (auto *CV = dyn_cast<Class>(V)) {
753 VR = CV;
754 return true;
755 }
756 return false;
757 }
758};
759
760/// Match a value, capturing it if we match.
761inline bind_ty<Value> m_Value(Value *&V) { return V; }
762inline bind_ty<const Value> m_Value(const Value *&V) { return V; }
763
764/// Match an instruction, capturing it if we match.
766/// Match a unary operator, capturing it if we match.
768/// Match a binary operator, capturing it if we match.
770/// Match a with overflow intrinsic, capturing it if we match.
772 return I;
773}
776 return I;
777}
778
779/// Match a Constant, capturing the value if we match.
781
782/// Match a ConstantInt, capturing the value if we match.
784
785/// Match a ConstantFP, capturing the value if we match.
787
788/// Match a ConstantExpr, capturing the value if we match.
790
791/// Match a basic block value, capturing it if we match.
794 return V;
795}
796
797/// Match an arbitrary immediate Constant and ignore it.
802}
803
804/// Match an immediate Constant, capturing the value if we match.
809}
810
811/// Match a specified Value*.
813 const Value *Val;
814
815 specificval_ty(const Value *V) : Val(V) {}
816
817 template <typename ITy> bool match(ITy *V) { return V == Val; }
818};
819
820/// Match if we have a specific specified value.
821inline specificval_ty m_Specific(const Value *V) { return V; }
822
823/// Stores a reference to the Value *, not the Value * itself,
824/// thus can be used in commutative matchers.
825template <typename Class> struct deferredval_ty {
826 Class *const &Val;
827
828 deferredval_ty(Class *const &V) : Val(V) {}
829
830 template <typename ITy> bool match(ITy *const V) { return V == Val; }
831};
832
833/// Like m_Specific(), but works if the specific value to match is determined
834/// as part of the same match() expression. For example:
835/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
836/// bind X before the pattern match starts.
837/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
838/// whichever value m_Value(X) populated.
839inline deferredval_ty<Value> m_Deferred(Value *const &V) { return V; }
841 return V;
842}
843
844/// Match a specified floating point value or vector of all elements of
845/// that value.
847 double Val;
848
849 specific_fpval(double V) : Val(V) {}
850
851 template <typename ITy> bool match(ITy *V) {
852 if (const auto *CFP = dyn_cast<ConstantFP>(V))
853 return CFP->isExactlyValue(Val);
854 if (V->getType()->isVectorTy())
855 if (const auto *C = dyn_cast<Constant>(V))
856 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
857 return CFP->isExactlyValue(Val);
858 return false;
859 }
860};
861
862/// Match a specific floating point value or vector with all elements
863/// equal to the value.
864inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
865
866/// Match a float 1.0 or vector with all elements equal to 1.0.
867inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
868
871
873
874 template <typename ITy> bool match(ITy *V) {
875 if (const auto *CV = dyn_cast<ConstantInt>(V))
876 if (CV->getValue().ule(UINT64_MAX)) {
877 VR = CV->getZExtValue();
878 return true;
879 }
880 return false;
881 }
882};
883
884/// Match a specified integer value or vector of all elements of that
885/// value.
886template <bool AllowUndefs> struct specific_intval {
888
890
891 template <typename ITy> bool match(ITy *V) {
892 const auto *CI = dyn_cast<ConstantInt>(V);
893 if (!CI && V->getType()->isVectorTy())
894 if (const auto *C = dyn_cast<Constant>(V))
895 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowUndefs));
896
897 return CI && APInt::isSameValue(CI->getValue(), Val);
898 }
899};
900
901/// Match a specific integer value or vector with all elements equal to
902/// the value.
904 return specific_intval<false>(std::move(V));
905}
906
908 return m_SpecificInt(APInt(64, V));
909}
910
912 return specific_intval<true>(std::move(V));
913}
914
916 return m_SpecificIntAllowUndef(APInt(64, V));
917}
918
919/// Match a ConstantInt and bind to its value. This does not match
920/// ConstantInts wider than 64-bits.
922
923/// Match a specified basic block value.
926
928
929 template <typename ITy> bool match(ITy *V) {
930 const auto *BB = dyn_cast<BasicBlock>(V);
931 return BB && BB == Val;
932 }
933};
934
935/// Match a specific basic block value.
937 return specific_bbval(BB);
938}
939
940/// A commutative-friendly version of m_Specific().
942 return BB;
943}
945m_Deferred(const BasicBlock *const &BB) {
946 return BB;
947}
948
949//===----------------------------------------------------------------------===//
950// Matcher for any binary operator.
951//
952template <typename LHS_t, typename RHS_t, bool Commutable = false>
956
957 // The evaluation order is always stable, regardless of Commutability.
958 // The LHS is always matched first.
959 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
960
961 template <typename OpTy> bool match(OpTy *V) {
962 if (auto *I = dyn_cast<BinaryOperator>(V))
963 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
964 (Commutable && L.match(I->getOperand(1)) &&
965 R.match(I->getOperand(0)));
966 return false;
967 }
968};
969
970template <typename LHS, typename RHS>
971inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
972 return AnyBinaryOp_match<LHS, RHS>(L, R);
973}
974
975//===----------------------------------------------------------------------===//
976// Matcher for any unary operator.
977// TODO fuse unary, binary matcher into n-ary matcher
978//
979template <typename OP_t> struct AnyUnaryOp_match {
980 OP_t X;
981
982 AnyUnaryOp_match(const OP_t &X) : X(X) {}
983
984 template <typename OpTy> bool match(OpTy *V) {
985 if (auto *I = dyn_cast<UnaryOperator>(V))
986 return X.match(I->getOperand(0));
987 return false;
988 }
989};
990
991template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
993}
994
995//===----------------------------------------------------------------------===//
996// Matchers for specific binary operators.
997//
998
999template <typename LHS_t, typename RHS_t, unsigned Opcode,
1000 bool Commutable = false>
1004
1005 // The evaluation order is always stable, regardless of Commutability.
1006 // The LHS is always matched first.
1007 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1008
1009 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) {
1010 if (V->getValueID() == Value::InstructionVal + Opc) {
1011 auto *I = cast<BinaryOperator>(V);
1012 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1013 (Commutable && L.match(I->getOperand(1)) &&
1014 R.match(I->getOperand(0)));
1015 }
1016 return false;
1017 }
1018
1019 template <typename OpTy> bool match(OpTy *V) { return match(Opcode, V); }
1020};
1021
1022template <typename LHS, typename RHS>
1024 const RHS &R) {
1026}
1027
1028template <typename LHS, typename RHS>
1030 const RHS &R) {
1032}
1033
1034template <typename LHS, typename RHS>
1036 const RHS &R) {
1038}
1039
1040template <typename LHS, typename RHS>
1042 const RHS &R) {
1044}
1045
1046template <typename Op_t> struct FNeg_match {
1047 Op_t X;
1048
1049 FNeg_match(const Op_t &Op) : X(Op) {}
1050 template <typename OpTy> bool match(OpTy *V) {
1051 auto *FPMO = dyn_cast<FPMathOperator>(V);
1052 if (!FPMO)
1053 return false;
1054
1055 if (FPMO->getOpcode() == Instruction::FNeg)
1056 return X.match(FPMO->getOperand(0));
1057
1058 if (FPMO->getOpcode() == Instruction::FSub) {
1059 if (FPMO->hasNoSignedZeros()) {
1060 // With 'nsz', any zero goes.
1061 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1062 return false;
1063 } else {
1064 // Without 'nsz', we need fsub -0.0, X exactly.
1065 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1066 return false;
1067 }
1068
1069 return X.match(FPMO->getOperand(1));
1070 }
1071
1072 return false;
1073 }
1074};
1075
1076/// Match 'fneg X' as 'fsub -0.0, X'.
1077template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1078 return FNeg_match<OpTy>(X);
1079}
1080
1081/// Match 'fneg X' as 'fsub +-0.0, X'.
1082template <typename RHS>
1083inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1084m_FNegNSZ(const RHS &X) {
1085 return m_FSub(m_AnyZeroFP(), X);
1086}
1087
1088template <typename LHS, typename RHS>
1090 const RHS &R) {
1092}
1093
1094template <typename LHS, typename RHS>
1096 const RHS &R) {
1098}
1099
1100template <typename LHS, typename RHS>
1102 const RHS &R) {
1104}
1105
1106template <typename LHS, typename RHS>
1108 const RHS &R) {
1110}
1111
1112template <typename LHS, typename RHS>
1114 const RHS &R) {
1116}
1117
1118template <typename LHS, typename RHS>
1120 const RHS &R) {
1122}
1123
1124template <typename LHS, typename RHS>
1126 const RHS &R) {
1128}
1129
1130template <typename LHS, typename RHS>
1132 const RHS &R) {
1134}
1135
1136template <typename LHS, typename RHS>
1138 const RHS &R) {
1140}
1141
1142template <typename LHS, typename RHS>
1144 const RHS &R) {
1146}
1147
1148template <typename LHS, typename RHS>
1150 const RHS &R) {
1152}
1153
1154template <typename LHS, typename RHS>
1156 const RHS &R) {
1158}
1159
1160template <typename LHS, typename RHS>
1162 const RHS &R) {
1164}
1165
1166template <typename LHS, typename RHS>
1168 const RHS &R) {
1170}
1171
1172template <typename LHS_t, typename RHS_t, unsigned Opcode,
1173 unsigned WrapFlags = 0>
1177
1179 : L(LHS), R(RHS) {}
1180
1181 template <typename OpTy> bool match(OpTy *V) {
1182 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1183 if (Op->getOpcode() != Opcode)
1184 return false;
1186 !Op->hasNoUnsignedWrap())
1187 return false;
1188 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1189 !Op->hasNoSignedWrap())
1190 return false;
1191 return L.match(Op->getOperand(0)) && R.match(Op->getOperand(1));
1192 }
1193 return false;
1194 }
1195};
1196
1197template <typename LHS, typename RHS>
1198inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1200m_NSWAdd(const LHS &L, const RHS &R) {
1201 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1203 R);
1204}
1205template <typename LHS, typename RHS>
1206inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1208m_NSWSub(const LHS &L, const RHS &R) {
1209 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1211 R);
1212}
1213template <typename LHS, typename RHS>
1214inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1216m_NSWMul(const LHS &L, const RHS &R) {
1217 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1219 R);
1220}
1221template <typename LHS, typename RHS>
1222inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1224m_NSWShl(const LHS &L, const RHS &R) {
1225 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1227 R);
1228}
1229
1230template <typename LHS, typename RHS>
1231inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1233m_NUWAdd(const LHS &L, const RHS &R) {
1234 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1236 L, R);
1237}
1238template <typename LHS, typename RHS>
1239inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1241m_NUWSub(const LHS &L, const RHS &R) {
1242 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1244 L, R);
1245}
1246template <typename LHS, typename RHS>
1247inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1249m_NUWMul(const LHS &L, const RHS &R) {
1250 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1252 L, R);
1253}
1254template <typename LHS, typename RHS>
1255inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1257m_NUWShl(const LHS &L, const RHS &R) {
1258 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1260 L, R);
1261}
1262
1263template <typename LHS_t, typename RHS_t, bool Commutable = false>
1265 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1266 unsigned Opcode;
1267
1269 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1270
1271 template <typename OpTy> bool match(OpTy *V) {
1273 }
1274};
1275
1276/// Matches a specific opcode.
1277template <typename LHS, typename RHS>
1278inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1279 const RHS &R) {
1280 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1281}
1282
1283template <typename LHS, typename RHS, bool Commutable = false>
1287
1288 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1289
1290 template <typename OpTy> bool match(OpTy *V) {
1291 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1292 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1293 if (!PDI->isDisjoint())
1294 return false;
1295 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1296 (Commutable && L.match(PDI->getOperand(1)) &&
1297 R.match(PDI->getOperand(0)));
1298 }
1299 return false;
1300 }
1301};
1302
1303template <typename LHS, typename RHS>
1305 return DisjointOr_match<LHS, RHS>(L, R);
1306}
1307
1308template <typename LHS, typename RHS>
1310 const RHS &R) {
1312}
1313
1314/// Match either "add" or "or disjoint".
1315template <typename LHS, typename RHS>
1318m_AddLike(const LHS &L, const RHS &R) {
1319 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1320}
1321
1322//===----------------------------------------------------------------------===//
1323// Class that matches a group of binary opcodes.
1324//
1325template <typename LHS_t, typename RHS_t, typename Predicate>
1326struct BinOpPred_match : Predicate {
1329
1330 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1331
1332 template <typename OpTy> bool match(OpTy *V) {
1333 if (auto *I = dyn_cast<Instruction>(V))
1334 return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) &&
1335 R.match(I->getOperand(1));
1336 return false;
1337 }
1338};
1339
1341 bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); }
1342};
1343
1345 bool isOpType(unsigned Opcode) {
1346 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1347 }
1348};
1349
1351 bool isOpType(unsigned Opcode) {
1352 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1353 }
1354};
1355
1357 bool isOpType(unsigned Opcode) {
1358 return Instruction::isBitwiseLogicOp(Opcode);
1359 }
1360};
1361
1363 bool isOpType(unsigned Opcode) {
1364 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1365 }
1366};
1367
1369 bool isOpType(unsigned Opcode) {
1370 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1371 }
1372};
1373
1374/// Matches shift operations.
1375template <typename LHS, typename RHS>
1377 const RHS &R) {
1379}
1380
1381/// Matches logical shift operations.
1382template <typename LHS, typename RHS>
1384 const RHS &R) {
1386}
1387
1388/// Matches logical shift operations.
1389template <typename LHS, typename RHS>
1391m_LogicalShift(const LHS &L, const RHS &R) {
1393}
1394
1395/// Matches bitwise logic operations.
1396template <typename LHS, typename RHS>
1398m_BitwiseLogic(const LHS &L, const RHS &R) {
1400}
1401
1402/// Matches integer division operations.
1403template <typename LHS, typename RHS>
1405 const RHS &R) {
1407}
1408
1409/// Matches integer remainder operations.
1410template <typename LHS, typename RHS>
1412 const RHS &R) {
1414}
1415
1416//===----------------------------------------------------------------------===//
1417// Class that matches exact binary ops.
1418//
1419template <typename SubPattern_t> struct Exact_match {
1420 SubPattern_t SubPattern;
1421
1422 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1423
1424 template <typename OpTy> bool match(OpTy *V) {
1425 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1426 return PEO->isExact() && SubPattern.match(V);
1427 return false;
1428 }
1429};
1430
1431template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1432 return SubPattern;
1433}
1434
1435//===----------------------------------------------------------------------===//
1436// Matchers for CmpInst classes
1437//
1438
1439template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
1440 bool Commutable = false>
1442 PredicateTy &Predicate;
1445
1446 // The evaluation order is always stable, regardless of Commutability.
1447 // The LHS is always matched first.
1448 CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
1449 : Predicate(Pred), L(LHS), R(RHS) {}
1450
1451 template <typename OpTy> bool match(OpTy *V) {
1452 if (auto *I = dyn_cast<Class>(V)) {
1453 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1454 Predicate = I->getPredicate();
1455 return true;
1456 } else if (Commutable && L.match(I->getOperand(1)) &&
1457 R.match(I->getOperand(0))) {
1458 Predicate = I->getSwappedPredicate();
1459 return true;
1460 }
1461 }
1462 return false;
1463 }
1464};
1465
1466template <typename LHS, typename RHS>
1468m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1470}
1471
1472template <typename LHS, typename RHS>
1474m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1476}
1477
1478template <typename LHS, typename RHS>
1480m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1482}
1483
1484//===----------------------------------------------------------------------===//
1485// Matchers for instructions with a given opcode and number of operands.
1486//
1487
1488/// Matches instructions with Opcode and three operands.
1489template <typename T0, unsigned Opcode> struct OneOps_match {
1491
1492 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1493
1494 template <typename OpTy> bool match(OpTy *V) {
1495 if (V->getValueID() == Value::InstructionVal + Opcode) {
1496 auto *I = cast<Instruction>(V);
1497 return Op1.match(I->getOperand(0));
1498 }
1499 return false;
1500 }
1501};
1502
1503/// Matches instructions with Opcode and three operands.
1504template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1507
1508 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1509
1510 template <typename OpTy> bool match(OpTy *V) {
1511 if (V->getValueID() == Value::InstructionVal + Opcode) {
1512 auto *I = cast<Instruction>(V);
1513 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1514 }
1515 return false;
1516 }
1517};
1518
1519/// Matches instructions with Opcode and three operands.
1520template <typename T0, typename T1, typename T2, unsigned Opcode>
1525
1526 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1527 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1528
1529 template <typename OpTy> bool match(OpTy *V) {
1530 if (V->getValueID() == Value::InstructionVal + Opcode) {
1531 auto *I = cast<Instruction>(V);
1532 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1533 Op3.match(I->getOperand(2));
1534 }
1535 return false;
1536 }
1537};
1538
1539/// Matches instructions with Opcode and any number of operands
1540template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1541 std::tuple<OperandTypes...> Operands;
1542
1543 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1544
1545 // Operand matching works by recursively calling match_operands, matching the
1546 // operands left to right. The first version is called for each operand but
1547 // the last, for which the second version is called. The second version of
1548 // match_operands is also used to match each individual operand.
1549 template <int Idx, int Last>
1550 std::enable_if_t<Idx != Last, bool> match_operands(const Instruction *I) {
1551 return match_operands<Idx, Idx>(I) && match_operands<Idx + 1, Last>(I);
1552 }
1553
1554 template <int Idx, int Last>
1555 std::enable_if_t<Idx == Last, bool> match_operands(const Instruction *I) {
1556 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1557 }
1558
1559 template <typename OpTy> bool match(OpTy *V) {
1560 if (V->getValueID() == Value::InstructionVal + Opcode) {
1561 auto *I = cast<Instruction>(V);
1562 return I->getNumOperands() == sizeof...(OperandTypes) &&
1563 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1564 }
1565 return false;
1566 }
1567};
1568
1569/// Matches SelectInst.
1570template <typename Cond, typename LHS, typename RHS>
1572m_Select(const Cond &C, const LHS &L, const RHS &R) {
1574}
1575
1576/// This matches a select of two constants, e.g.:
1577/// m_SelectCst<-1, 0>(m_Value(V))
1578template <int64_t L, int64_t R, typename Cond>
1580 Instruction::Select>
1582 return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1583}
1584
1585/// Matches FreezeInst.
1586template <typename OpTy>
1589}
1590
1591/// Matches InsertElementInst.
1592template <typename Val_t, typename Elt_t, typename Idx_t>
1594m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1596 Val, Elt, Idx);
1597}
1598
1599/// Matches ExtractElementInst.
1600template <typename Val_t, typename Idx_t>
1602m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
1604}
1605
1606/// Matches shuffle.
1607template <typename T0, typename T1, typename T2> struct Shuffle_match {
1611
1612 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
1613 : Op1(Op1), Op2(Op2), Mask(Mask) {}
1614
1615 template <typename OpTy> bool match(OpTy *V) {
1616 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
1617 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1618 Mask.match(I->getShuffleMask());
1619 }
1620 return false;
1621 }
1622};
1623
1624struct m_Mask {
1628 MaskRef = Mask;
1629 return true;
1630 }
1631};
1632
1635 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
1636 }
1637};
1638
1642 bool match(ArrayRef<int> Mask) { return MaskRef == Mask; }
1643};
1644
1649 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
1650 if (First == Mask.end())
1651 return false;
1652 SplatIndex = *First;
1653 return all_of(Mask,
1654 [First](int Elem) { return Elem == *First || Elem == -1; });
1655 }
1656};
1657
1658template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
1659 PointerOpTy PointerOp;
1660 OffsetOpTy OffsetOp;
1661
1662 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
1664
1665 template <typename OpTy> bool match(OpTy *V) {
1666 auto *GEP = dyn_cast<GEPOperator>(V);
1667 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
1668 PointerOp.match(GEP->getPointerOperand()) &&
1669 OffsetOp.match(GEP->idx_begin()->get());
1670 }
1671};
1672
1673/// Matches ShuffleVectorInst independently of mask value.
1674template <typename V1_t, typename V2_t>
1676m_Shuffle(const V1_t &v1, const V2_t &v2) {
1678}
1679
1680template <typename V1_t, typename V2_t, typename Mask_t>
1682m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
1683 return Shuffle_match<V1_t, V2_t, Mask_t>(v1, v2, mask);
1684}
1685
1686/// Matches LoadInst.
1687template <typename OpTy>
1690}
1691
1692/// Matches StoreInst.
1693template <typename ValueOpTy, typename PointerOpTy>
1695m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
1697 PointerOp);
1698}
1699
1700/// Matches GetElementPtrInst.
1701template <typename... OperandTypes>
1702inline auto m_GEP(const OperandTypes &...Ops) {
1703 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
1704}
1705
1706/// Matches GEP with i8 source element type
1707template <typename PointerOpTy, typename OffsetOpTy>
1709m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
1710 return PtrAdd_match<PointerOpTy, OffsetOpTy>(PointerOp, OffsetOp);
1711}
1712
1713//===----------------------------------------------------------------------===//
1714// Matchers for CastInst classes
1715//
1716
1717template <typename Op_t, unsigned Opcode> struct CastOperator_match {
1718 Op_t Op;
1719
1720 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
1721
1722 template <typename OpTy> bool match(OpTy *V) {
1723 if (auto *O = dyn_cast<Operator>(V))
1724 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
1725 return false;
1726 }
1727};
1728
1729template <typename Op_t, typename Class> struct CastInst_match {
1730 Op_t Op;
1731
1732 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
1733
1734 template <typename OpTy> bool match(OpTy *V) {
1735 if (auto *I = dyn_cast<Class>(V))
1736 return Op.match(I->getOperand(0));
1737 return false;
1738 }
1739};
1740
1741template <typename Op_t> struct PtrToIntSameSize_match {
1743 Op_t Op;
1744
1745 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
1746 : DL(DL), Op(OpMatch) {}
1747
1748 template <typename OpTy> bool match(OpTy *V) {
1749 if (auto *O = dyn_cast<Operator>(V))
1750 return O->getOpcode() == Instruction::PtrToInt &&
1751 DL.getTypeSizeInBits(O->getType()) ==
1752 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
1753 Op.match(O->getOperand(0));
1754 return false;
1755 }
1756};
1757
1758template <typename Op_t> struct NNegZExt_match {
1759 Op_t Op;
1760
1761 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
1762
1763 template <typename OpTy> bool match(OpTy *V) {
1764 if (auto *I = dyn_cast<ZExtInst>(V))
1765 return I->hasNonNeg() && Op.match(I->getOperand(0));
1766 return false;
1767 }
1768};
1769
1770/// Matches BitCast.
1771template <typename OpTy>
1773m_BitCast(const OpTy &Op) {
1775}
1776
1777template <typename Op_t> struct ElementWiseBitCast_match {
1778 Op_t Op;
1779
1780 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
1781
1782 template <typename OpTy> bool match(OpTy *V) {
1783 BitCastInst *I = dyn_cast<BitCastInst>(V);
1784 if (!I)
1785 return false;
1786 Type *SrcType = I->getSrcTy();
1787 Type *DstType = I->getType();
1788 // Make sure the bitcast doesn't change between scalar and vector and
1789 // doesn't change the number of vector elements.
1790 if (SrcType->isVectorTy() != DstType->isVectorTy())
1791 return false;
1792 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
1793 SrcVecTy && SrcVecTy->getElementCount() !=
1794 cast<VectorType>(DstType)->getElementCount())
1795 return false;
1796 return Op.match(I->getOperand(0));
1797 }
1798};
1799
1800template <typename OpTy>
1803}
1804
1805/// Matches PtrToInt.
1806template <typename OpTy>
1808m_PtrToInt(const OpTy &Op) {
1810}
1811
1812template <typename OpTy>
1814 const OpTy &Op) {
1816}
1817
1818/// Matches IntToPtr.
1819template <typename OpTy>
1821m_IntToPtr(const OpTy &Op) {
1823}
1824
1825/// Matches Trunc.
1826template <typename OpTy>
1829}
1830
1831template <typename OpTy>
1833m_TruncOrSelf(const OpTy &Op) {
1834 return m_CombineOr(m_Trunc(Op), Op);
1835}
1836
1837/// Matches SExt.
1838template <typename OpTy>
1841}
1842
1843/// Matches ZExt.
1844template <typename OpTy>
1847}
1848
1849template <typename OpTy>
1851 return NNegZExt_match<OpTy>(Op);
1852}
1853
1854template <typename OpTy>
1856m_ZExtOrSelf(const OpTy &Op) {
1857 return m_CombineOr(m_ZExt(Op), Op);
1858}
1859
1860template <typename OpTy>
1862m_SExtOrSelf(const OpTy &Op) {
1863 return m_CombineOr(m_SExt(Op), Op);
1864}
1865
1866/// Match either "sext" or "zext nneg".
1867template <typename OpTy>
1869m_SExtLike(const OpTy &Op) {
1870 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
1871}
1872
1873template <typename OpTy>
1876m_ZExtOrSExt(const OpTy &Op) {
1877 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
1878}
1879
1880template <typename OpTy>
1883 OpTy>
1885 return m_CombineOr(m_ZExtOrSExt(Op), Op);
1886}
1887
1888template <typename OpTy>
1891}
1892
1893template <typename OpTy>
1896}
1897
1898template <typename OpTy>
1901}
1902
1903template <typename OpTy>
1906}
1907
1908template <typename OpTy>
1911}
1912
1913template <typename OpTy>
1916}
1917
1918//===----------------------------------------------------------------------===//
1919// Matchers for control flow.
1920//
1921
1922struct br_match {
1924
1926
1927 template <typename OpTy> bool match(OpTy *V) {
1928 if (auto *BI = dyn_cast<BranchInst>(V))
1929 if (BI->isUnconditional()) {
1930 Succ = BI->getSuccessor(0);
1931 return true;
1932 }
1933 return false;
1934 }
1935};
1936
1937inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
1938
1939template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
1941 Cond_t Cond;
1942 TrueBlock_t T;
1943 FalseBlock_t F;
1944
1945 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
1946 : Cond(C), T(t), F(f) {}
1947
1948 template <typename OpTy> bool match(OpTy *V) {
1949 if (auto *BI = dyn_cast<BranchInst>(V))
1950 if (BI->isConditional() && Cond.match(BI->getCondition()))
1951 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
1952 return false;
1953 }
1954};
1955
1956template <typename Cond_t>
1958m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) {
1961}
1962
1963template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
1965m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
1967}
1968
1969//===----------------------------------------------------------------------===//
1970// Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
1971//
1972
1973template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t,
1974 bool Commutable = false>
1976 using PredType = Pred_t;
1979
1980 // The evaluation order is always stable, regardless of Commutability.
1981 // The LHS is always matched first.
1982 MaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1983
1984 template <typename OpTy> bool match(OpTy *V) {
1985 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
1986 Intrinsic::ID IID = II->getIntrinsicID();
1987 if ((IID == Intrinsic::smax && Pred_t::match(ICmpInst::ICMP_SGT)) ||
1988 (IID == Intrinsic::smin && Pred_t::match(ICmpInst::ICMP_SLT)) ||
1989 (IID == Intrinsic::umax && Pred_t::match(ICmpInst::ICMP_UGT)) ||
1990 (IID == Intrinsic::umin && Pred_t::match(ICmpInst::ICMP_ULT))) {
1991 Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
1992 return (L.match(LHS) && R.match(RHS)) ||
1993 (Commutable && L.match(RHS) && R.match(LHS));
1994 }
1995 }
1996 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
1997 auto *SI = dyn_cast<SelectInst>(V);
1998 if (!SI)
1999 return false;
2000 auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
2001 if (!Cmp)
2002 return false;
2003 // At this point we have a select conditioned on a comparison. Check that
2004 // it is the values returned by the select that are being compared.
2005 auto *TrueVal = SI->getTrueValue();
2006 auto *FalseVal = SI->getFalseValue();
2007 auto *LHS = Cmp->getOperand(0);
2008 auto *RHS = Cmp->getOperand(1);
2009 if ((TrueVal != LHS || FalseVal != RHS) &&
2010 (TrueVal != RHS || FalseVal != LHS))
2011 return false;
2012 typename CmpInst_t::Predicate Pred =
2013 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2014 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2015 if (!Pred_t::match(Pred))
2016 return false;
2017 // It does! Bind the operands.
2018 return (L.match(LHS) && R.match(RHS)) ||
2019 (Commutable && L.match(RHS) && R.match(LHS));
2020 }
2021};
2022
2023/// Helper class for identifying signed max predicates.
2025 static bool match(ICmpInst::Predicate Pred) {
2026 return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE;
2027 }
2028};
2029
2030/// Helper class for identifying signed min predicates.
2032 static bool match(ICmpInst::Predicate Pred) {
2033 return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE;
2034 }
2035};
2036
2037/// Helper class for identifying unsigned max predicates.
2039 static bool match(ICmpInst::Predicate Pred) {
2040 return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE;
2041 }
2042};
2043
2044/// Helper class for identifying unsigned min predicates.
2046 static bool match(ICmpInst::Predicate Pred) {
2047 return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE;
2048 }
2049};
2050
2051/// Helper class for identifying ordered max predicates.
2053 static bool match(FCmpInst::Predicate Pred) {
2054 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2055 }
2056};
2057
2058/// Helper class for identifying ordered min predicates.
2060 static bool match(FCmpInst::Predicate Pred) {
2061 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2062 }
2063};
2064
2065/// Helper class for identifying unordered max predicates.
2067 static bool match(FCmpInst::Predicate Pred) {
2068 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2069 }
2070};
2071
2072/// Helper class for identifying unordered min predicates.
2074 static bool match(FCmpInst::Predicate Pred) {
2075 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2076 }
2077};
2078
2079template <typename LHS, typename RHS>
2081 const RHS &R) {
2083}
2084
2085template <typename LHS, typename RHS>
2087 const RHS &R) {
2089}
2090
2091template <typename LHS, typename RHS>
2093 const RHS &R) {
2095}
2096
2097template <typename LHS, typename RHS>
2099 const RHS &R) {
2101}
2102
2103template <typename LHS, typename RHS>
2104inline match_combine_or<
2109m_MaxOrMin(const LHS &L, const RHS &R) {
2110 return m_CombineOr(m_CombineOr(m_SMax(L, R), m_SMin(L, R)),
2111 m_CombineOr(m_UMax(L, R), m_UMin(L, R)));
2112}
2113
2114/// Match an 'ordered' floating point maximum function.
2115/// Floating point has one special value 'NaN'. Therefore, there is no total
2116/// order. However, if we can ignore the 'NaN' value (for example, because of a
2117/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2118/// semantics. In the presence of 'NaN' we have to preserve the original
2119/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2120///
2121/// max(L, R) iff L and R are not NaN
2122/// m_OrdFMax(L, R) = R iff L or R are NaN
2123template <typename LHS, typename RHS>
2125 const RHS &R) {
2127}
2128
2129/// Match an 'ordered' floating point minimum function.
2130/// Floating point has one special value 'NaN'. Therefore, there is no total
2131/// order. However, if we can ignore the 'NaN' value (for example, because of a
2132/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2133/// semantics. In the presence of 'NaN' we have to preserve the original
2134/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2135///
2136/// min(L, R) iff L and R are not NaN
2137/// m_OrdFMin(L, R) = R iff L or R are NaN
2138template <typename LHS, typename RHS>
2140 const RHS &R) {
2142}
2143
2144/// Match an 'unordered' floating point maximum function.
2145/// Floating point has one special value 'NaN'. Therefore, there is no total
2146/// order. However, if we can ignore the 'NaN' value (for example, because of a
2147/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2148/// semantics. In the presence of 'NaN' we have to preserve the original
2149/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2150///
2151/// max(L, R) iff L and R are not NaN
2152/// m_UnordFMax(L, R) = L iff L or R are NaN
2153template <typename LHS, typename RHS>
2155m_UnordFMax(const LHS &L, const RHS &R) {
2157}
2158
2159/// Match an 'unordered' floating point minimum function.
2160/// Floating point has one special value 'NaN'. Therefore, there is no total
2161/// order. However, if we can ignore the 'NaN' value (for example, because of a
2162/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2163/// semantics. In the presence of 'NaN' we have to preserve the original
2164/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2165///
2166/// min(L, R) iff L and R are not NaN
2167/// m_UnordFMin(L, R) = L iff L or R are NaN
2168template <typename LHS, typename RHS>
2170m_UnordFMin(const LHS &L, const RHS &R) {
2172}
2173
2174//===----------------------------------------------------------------------===//
2175// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2176// Note that S might be matched to other instructions than AddInst.
2177//
2178
2179template <typename LHS_t, typename RHS_t, typename Sum_t>
2183 Sum_t S;
2184
2185 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2186 : L(L), R(R), S(S) {}
2187
2188 template <typename OpTy> bool match(OpTy *V) {
2189 Value *ICmpLHS, *ICmpRHS;
2191 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2192 return false;
2193
2194 Value *AddLHS, *AddRHS;
2195 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2196
2197 // (a + b) u< a, (a + b) u< b
2198 if (Pred == ICmpInst::ICMP_ULT)
2199 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2200 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2201
2202 // a >u (a + b), b >u (a + b)
2203 if (Pred == ICmpInst::ICMP_UGT)
2204 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2205 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2206
2207 Value *Op1;
2208 auto XorExpr = m_OneUse(m_Xor(m_Value(Op1), m_AllOnes()));
2209 // (a ^ -1) <u b
2210 if (Pred == ICmpInst::ICMP_ULT) {
2211 if (XorExpr.match(ICmpLHS))
2212 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2213 }
2214 // b > u (a ^ -1)
2215 if (Pred == ICmpInst::ICMP_UGT) {
2216 if (XorExpr.match(ICmpRHS))
2217 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2218 }
2219
2220 // Match special-case for increment-by-1.
2221 if (Pred == ICmpInst::ICMP_EQ) {
2222 // (a + 1) == 0
2223 // (1 + a) == 0
2224 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2225 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2226 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2227 // 0 == (a + 1)
2228 // 0 == (1 + a)
2229 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2230 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2231 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2232 }
2233
2234 return false;
2235 }
2236};
2237
2238/// Match an icmp instruction checking for unsigned overflow on addition.
2239///
2240/// S is matched to the addition whose result is being checked for overflow, and
2241/// L and R are matched to the LHS and RHS of S.
2242template <typename LHS_t, typename RHS_t, typename Sum_t>
2244m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2246}
2247
2248template <typename Opnd_t> struct Argument_match {
2249 unsigned OpI;
2250 Opnd_t Val;
2251
2252 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2253
2254 template <typename OpTy> bool match(OpTy *V) {
2255 // FIXME: Should likely be switched to use `CallBase`.
2256 if (const auto *CI = dyn_cast<CallInst>(V))
2257 return Val.match(CI->getArgOperand(OpI));
2258 return false;
2259 }
2260};
2261
2262/// Match an argument.
2263template <unsigned OpI, typename Opnd_t>
2264inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2265 return Argument_match<Opnd_t>(OpI, Op);
2266}
2267
2268/// Intrinsic matchers.
2270 unsigned ID;
2271
2273
2274 template <typename OpTy> bool match(OpTy *V) {
2275 if (const auto *CI = dyn_cast<CallInst>(V))
2276 if (const auto *F = CI->getCalledFunction())
2277 return F->getIntrinsicID() == ID;
2278 return false;
2279 }
2280};
2281
2282/// Intrinsic matches are combinations of ID matchers, and argument
2283/// matchers. Higher arity matcher are defined recursively in terms of and-ing
2284/// them with lower arity matchers. Here's some convenient typedefs for up to
2285/// several arguments, and more can be added as needed
2286template <typename T0 = void, typename T1 = void, typename T2 = void,
2287 typename T3 = void, typename T4 = void, typename T5 = void,
2288 typename T6 = void, typename T7 = void, typename T8 = void,
2289 typename T9 = void, typename T10 = void>
2291template <typename T0> struct m_Intrinsic_Ty<T0> {
2293};
2294template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
2295 using Ty =
2297};
2298template <typename T0, typename T1, typename T2>
2299struct m_Intrinsic_Ty<T0, T1, T2> {
2302};
2303template <typename T0, typename T1, typename T2, typename T3>
2304struct m_Intrinsic_Ty<T0, T1, T2, T3> {
2307};
2308
2309template <typename T0, typename T1, typename T2, typename T3, typename T4>
2310struct m_Intrinsic_Ty<T0, T1, T2, T3, T4> {
2313};
2314
2315template <typename T0, typename T1, typename T2, typename T3, typename T4,
2316 typename T5>
2317struct m_Intrinsic_Ty<T0, T1, T2, T3, T4, T5> {
2320};
2321
2322/// Match intrinsic calls like this:
2323/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2324template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
2325 return IntrinsicID_match(IntrID);
2326}
2327
2328/// Matches MaskedLoad Intrinsic.
2329template <typename Opnd0, typename Opnd1, typename Opnd2, typename Opnd3>
2331m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2,
2332 const Opnd3 &Op3) {
2333 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2, Op3);
2334}
2335
2336/// Matches MaskedGather Intrinsic.
2337template <typename Opnd0, typename Opnd1, typename Opnd2, typename Opnd3>
2339m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2,
2340 const Opnd3 &Op3) {
2341 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2, Op3);
2342}
2343
2344template <Intrinsic::ID IntrID, typename T0>
2345inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
2346 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
2347}
2348
2349template <Intrinsic::ID IntrID, typename T0, typename T1>
2350inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
2351 const T1 &Op1) {
2352 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
2353}
2354
2355template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
2356inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
2357m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
2358 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2359}
2360
2361template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2362 typename T3>
2364m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
2365 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2366}
2367
2368template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2369 typename T3, typename T4>
2371m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
2372 const T4 &Op4) {
2373 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2374 m_Argument<4>(Op4));
2375}
2376
2377template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2378 typename T3, typename T4, typename T5>
2380m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
2381 const T4 &Op4, const T5 &Op5) {
2382 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2383 m_Argument<5>(Op5));
2384}
2385
2386// Helper intrinsic matching specializations.
2387template <typename Opnd0>
2388inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BitReverse(const Opnd0 &Op0) {
2389 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
2390}
2391
2392template <typename Opnd0>
2393inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BSwap(const Opnd0 &Op0) {
2394 return m_Intrinsic<Intrinsic::bswap>(Op0);
2395}
2396
2397template <typename Opnd0>
2398inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FAbs(const Opnd0 &Op0) {
2399 return m_Intrinsic<Intrinsic::fabs>(Op0);
2400}
2401
2402template <typename Opnd0>
2403inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FCanonicalize(const Opnd0 &Op0) {
2404 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
2405}
2406
2407template <typename Opnd0, typename Opnd1>
2408inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMin(const Opnd0 &Op0,
2409 const Opnd1 &Op1) {
2410 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2411}
2412
2413template <typename Opnd0, typename Opnd1>
2414inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMax(const Opnd0 &Op0,
2415 const Opnd1 &Op1) {
2416 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2417}
2418
2419template <typename Opnd0, typename Opnd1, typename Opnd2>
2421m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2422 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2423}
2424
2425template <typename Opnd0, typename Opnd1, typename Opnd2>
2427m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2428 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2429}
2430
2431template <typename Opnd0>
2432inline typename m_Intrinsic_Ty<Opnd0>::Ty m_Sqrt(const Opnd0 &Op0) {
2433 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2434}
2435
2436template <typename Opnd0, typename Opnd1>
2437inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_CopySign(const Opnd0 &Op0,
2438 const Opnd1 &Op1) {
2439 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2440}
2441
2442template <typename Opnd0>
2443inline typename m_Intrinsic_Ty<Opnd0>::Ty m_VecReverse(const Opnd0 &Op0) {
2444 return m_Intrinsic<Intrinsic::experimental_vector_reverse>(Op0);
2445}
2446
2447//===----------------------------------------------------------------------===//
2448// Matchers for two-operands operators with the operators in either order
2449//
2450
2451/// Matches a BinaryOperator with LHS and RHS in either order.
2452template <typename LHS, typename RHS>
2455}
2456
2457/// Matches an ICmp with a predicate over LHS and RHS in either order.
2458/// Swaps the predicate if operands are commuted.
2459template <typename LHS, typename RHS>
2461m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
2463 R);
2464}
2465
2466/// Matches a specific opcode with LHS and RHS in either order.
2467template <typename LHS, typename RHS>
2469m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
2470 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
2471}
2472
2473/// Matches a Add with LHS and RHS in either order.
2474template <typename LHS, typename RHS>
2476 const RHS &R) {
2478}
2479
2480/// Matches a Mul with LHS and RHS in either order.
2481template <typename LHS, typename RHS>
2483 const RHS &R) {
2485}
2486
2487/// Matches an And with LHS and RHS in either order.
2488template <typename LHS, typename RHS>
2490 const RHS &R) {
2492}
2493
2494/// Matches an Or with LHS and RHS in either order.
2495template <typename LHS, typename RHS>
2497 const RHS &R) {
2499}
2500
2501/// Matches an Xor with LHS and RHS in either order.
2502template <typename LHS, typename RHS>
2504 const RHS &R) {
2506}
2507
2508/// Matches a 'Neg' as 'sub 0, V'.
2509template <typename ValTy>
2510inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
2511m_Neg(const ValTy &V) {
2512 return m_Sub(m_ZeroInt(), V);
2513}
2514
2515/// Matches a 'Neg' as 'sub nsw 0, V'.
2516template <typename ValTy>
2518 Instruction::Sub,
2520m_NSWNeg(const ValTy &V) {
2521 return m_NSWSub(m_ZeroInt(), V);
2522}
2523
2524/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2525/// NOTE: we first match the 'Not' (by matching '-1'),
2526/// and only then match the inner matcher!
2527template <typename ValTy>
2528inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2529m_Not(const ValTy &V) {
2530 return m_c_Xor(m_AllOnes(), V);
2531}
2532
2533template <typename ValTy> struct NotForbidUndef_match {
2534 ValTy Val;
2535 NotForbidUndef_match(const ValTy &V) : Val(V) {}
2536
2537 template <typename OpTy> bool match(OpTy *V) {
2538 // We do not use m_c_Xor because that could match an arbitrary APInt that is
2539 // not -1 as C and then fail to match the other operand if it is -1.
2540 // This code should still work even when both operands are constants.
2541 Value *X;
2542 const APInt *C;
2543 if (m_Xor(m_Value(X), m_APIntForbidUndef(C)).match(V) && C->isAllOnes())
2544 return Val.match(X);
2545 if (m_Xor(m_APIntForbidUndef(C), m_Value(X)).match(V) && C->isAllOnes())
2546 return Val.match(X);
2547 return false;
2548 }
2549};
2550
2551/// Matches a bitwise 'not' as 'xor V, -1' or 'xor -1, V'. For vectors, the
2552/// constant value must be composed of only -1 scalar elements.
2553template <typename ValTy>
2556}
2557
2558/// Matches an SMin with LHS and RHS in either order.
2559template <typename LHS, typename RHS>
2561m_c_SMin(const LHS &L, const RHS &R) {
2563}
2564/// Matches an SMax with LHS and RHS in either order.
2565template <typename LHS, typename RHS>
2567m_c_SMax(const LHS &L, const RHS &R) {
2569}
2570/// Matches a UMin with LHS and RHS in either order.
2571template <typename LHS, typename RHS>
2573m_c_UMin(const LHS &L, const RHS &R) {
2575}
2576/// Matches a UMax with LHS and RHS in either order.
2577template <typename LHS, typename RHS>
2579m_c_UMax(const LHS &L, const RHS &R) {
2581}
2582
2583template <typename LHS, typename RHS>
2584inline match_combine_or<
2589m_c_MaxOrMin(const LHS &L, const RHS &R) {
2590 return m_CombineOr(m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R)),
2591 m_CombineOr(m_c_UMax(L, R), m_c_UMin(L, R)));
2592}
2593
2594template <Intrinsic::ID IntrID, typename T0, typename T1>
2597m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
2598 return m_CombineOr(m_Intrinsic<IntrID>(Op0, Op1),
2599 m_Intrinsic<IntrID>(Op1, Op0));
2600}
2601
2602/// Matches FAdd with LHS and RHS in either order.
2603template <typename LHS, typename RHS>
2605m_c_FAdd(const LHS &L, const RHS &R) {
2607}
2608
2609/// Matches FMul with LHS and RHS in either order.
2610template <typename LHS, typename RHS>
2612m_c_FMul(const LHS &L, const RHS &R) {
2614}
2615
2616template <typename Opnd_t> struct Signum_match {
2617 Opnd_t Val;
2618 Signum_match(const Opnd_t &V) : Val(V) {}
2619
2620 template <typename OpTy> bool match(OpTy *V) {
2621 unsigned TypeSize = V->getType()->getScalarSizeInBits();
2622 if (TypeSize == 0)
2623 return false;
2624
2625 unsigned ShiftWidth = TypeSize - 1;
2626 Value *OpL = nullptr, *OpR = nullptr;
2627
2628 // This is the representation of signum we match:
2629 //
2630 // signum(x) == (x >> 63) | (-x >>u 63)
2631 //
2632 // An i1 value is its own signum, so it's correct to match
2633 //
2634 // signum(x) == (x >> 0) | (-x >>u 0)
2635 //
2636 // for i1 values.
2637
2638 auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
2639 auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
2640 auto Signum = m_Or(LHS, RHS);
2641
2642 return Signum.match(V) && OpL == OpR && Val.match(OpL);
2643 }
2644};
2645
2646/// Matches a signum pattern.
2647///
2648/// signum(x) =
2649/// x > 0 -> 1
2650/// x == 0 -> 0
2651/// x < 0 -> -1
2652template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
2653 return Signum_match<Val_t>(V);
2654}
2655
2656template <int Ind, typename Opnd_t> struct ExtractValue_match {
2657 Opnd_t Val;
2658 ExtractValue_match(const Opnd_t &V) : Val(V) {}
2659
2660 template <typename OpTy> bool match(OpTy *V) {
2661 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
2662 // If Ind is -1, don't inspect indices
2663 if (Ind != -1 &&
2664 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
2665 return false;
2666 return Val.match(I->getAggregateOperand());
2667 }
2668 return false;
2669 }
2670};
2671
2672/// Match a single index ExtractValue instruction.
2673/// For example m_ExtractValue<1>(...)
2674template <int Ind, typename Val_t>
2677}
2678
2679/// Match an ExtractValue instruction with any index.
2680/// For example m_ExtractValue(...)
2681template <typename Val_t>
2682inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
2683 return ExtractValue_match<-1, Val_t>(V);
2684}
2685
2686/// Matcher for a single index InsertValue instruction.
2687template <int Ind, typename T0, typename T1> struct InsertValue_match {
2690
2691 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
2692
2693 template <typename OpTy> bool match(OpTy *V) {
2694 if (auto *I = dyn_cast<InsertValueInst>(V)) {
2695 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
2696 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
2697 }
2698 return false;
2699 }
2700};
2701
2702/// Matches a single index InsertValue instruction.
2703template <int Ind, typename Val_t, typename Elt_t>
2705 const Elt_t &Elt) {
2706 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
2707}
2708
2709/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or
2710/// the constant expression
2711/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>`
2712/// under the right conditions determined by DataLayout.
2714 template <typename ITy> bool match(ITy *V) {
2715 if (m_Intrinsic<Intrinsic::vscale>().match(V))
2716 return true;
2717
2718 Value *Ptr;
2719 if (m_PtrToInt(m_Value(Ptr)).match(V)) {
2720 if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
2721 auto *DerefTy =
2722 dyn_cast<ScalableVectorType>(GEP->getSourceElementType());
2723 if (GEP->getNumIndices() == 1 && DerefTy &&
2724 DerefTy->getElementType()->isIntegerTy(8) &&
2725 m_Zero().match(GEP->getPointerOperand()) &&
2726 m_SpecificInt(1).match(GEP->idx_begin()->get()))
2727 return true;
2728 }
2729 }
2730
2731 return false;
2732 }
2733};
2734
2736 return VScaleVal_match();
2737}
2738
2739template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
2743
2744 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
2745
2746 template <typename T> bool match(T *V) {
2747 auto *I = dyn_cast<Instruction>(V);
2748 if (!I || !I->getType()->isIntOrIntVectorTy(1))
2749 return false;
2750
2751 if (I->getOpcode() == Opcode) {
2752 auto *Op0 = I->getOperand(0);
2753 auto *Op1 = I->getOperand(1);
2754 return (L.match(Op0) && R.match(Op1)) ||
2755 (Commutable && L.match(Op1) && R.match(Op0));
2756 }
2757
2758 if (auto *Select = dyn_cast<SelectInst>(I)) {
2759 auto *Cond = Select->getCondition();
2760 auto *TVal = Select->getTrueValue();
2761 auto *FVal = Select->getFalseValue();
2762
2763 // Don't match a scalar select of bool vectors.
2764 // Transforms expect a single type for operands if this matches.
2765 if (Cond->getType() != Select->getType())
2766 return false;
2767
2768 if (Opcode == Instruction::And) {
2769 auto *C = dyn_cast<Constant>(FVal);
2770 if (C && C->isNullValue())
2771 return (L.match(Cond) && R.match(TVal)) ||
2772 (Commutable && L.match(TVal) && R.match(Cond));
2773 } else {
2774 assert(Opcode == Instruction::Or);
2775 auto *C = dyn_cast<Constant>(TVal);
2776 if (C && C->isOneValue())
2777 return (L.match(Cond) && R.match(FVal)) ||
2778 (Commutable && L.match(FVal) && R.match(Cond));
2779 }
2780 }
2781
2782 return false;
2783 }
2784};
2785
2786/// Matches L && R either in the form of L & R or L ? R : false.
2787/// Note that the latter form is poison-blocking.
2788template <typename LHS, typename RHS>
2790 const RHS &R) {
2792}
2793
2794/// Matches L && R where L and R are arbitrary values.
2795inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
2796
2797/// Matches L && R with LHS and RHS in either order.
2798template <typename LHS, typename RHS>
2800m_c_LogicalAnd(const LHS &L, const RHS &R) {
2802}
2803
2804/// Matches L || R either in the form of L | R or L ? true : R.
2805/// Note that the latter form is poison-blocking.
2806template <typename LHS, typename RHS>
2808 const RHS &R) {
2810}
2811
2812/// Matches L || R where L and R are arbitrary values.
2813inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
2814
2815/// Matches L || R with LHS and RHS in either order.
2816template <typename LHS, typename RHS>
2818m_c_LogicalOr(const LHS &L, const RHS &R) {
2820}
2821
2822/// Matches either L && R or L || R,
2823/// either one being in the either binary or logical form.
2824/// Note that the latter form is poison-blocking.
2825template <typename LHS, typename RHS, bool Commutable = false>
2826inline auto m_LogicalOp(const LHS &L, const RHS &R) {
2827 return m_CombineOr(
2830}
2831
2832/// Matches either L && R or L || R where L and R are arbitrary values.
2833inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
2834
2835/// Matches either L && R or L || R with LHS and RHS in either order.
2836template <typename LHS, typename RHS>
2837inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
2838 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
2839}
2840
2841} // end namespace PatternMatch
2842} // end namespace llvm
2843
2844#endif // LLVM_IR_PATTERNMATCH_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
#define check(cond)
Hexagon Common GEP
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define T1
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:76
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:531
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
This class represents a no-op cast from one type to another.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:965
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:994
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:995
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:971
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:980
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:969
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:970
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:989
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:988
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:992
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:979
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:990
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:977
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:972
@ ICMP_EQ
equal
Definition: InstrTypes.h:986
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:993
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:991
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:978
Base class for aggregate constants (with operands).
Definition: Constants.h:398
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1016
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:267
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
This is an important base class in LLVM.
Definition: Constant.h:41
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Definition: DataLayout.h:672
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
Definition: Instruction.h:305
bool isShift() const
Definition: Instruction.h:258
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:342
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:427
bool empty() const
Definition: SmallVector.h:94
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:950
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:265
LLVM Value Representation.
Definition: Value.h:74
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:641
Represents an op.with.overflow intrinsic.
#define UINT64_MAX
Definition: DataTypes.h:77
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
Definition: PatternMatch.h:477
class_match< PoisonValue > m_Poison()
Match an arbitrary poison constant.
Definition: PatternMatch.h:155
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
Definition: PatternMatch.h:622
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
specific_intval< false > m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
Definition: PatternMatch.h:903
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
Definition: PatternMatch.h:499
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Definition: PatternMatch.h:100
apfloat_match m_APFloatAllowUndef(const APFloat *&Res)
Match APFloat while allowing undefs in splat vector constants.
Definition: PatternMatch.h:317
m_Intrinsic_Ty< Opnd0 >::Ty m_FCanonicalize(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
Definition: PatternMatch.h:613
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
Definition: PatternMatch.h:675
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
apint_match m_APIntAllowUndef(const APInt *&Res)
Match APInt while allowing undefs in splat vector constants.
Definition: PatternMatch.h:300
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
Definition: PatternMatch.h:568
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition: PatternMatch.h:160
AllowReassoc_match< T > m_AllowReassoc(const T &SubPattern)
Definition: PatternMatch.h:83
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
Definition: PatternMatch.h:601
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
br_match m_UnconditionalBr(BasicBlock *&Succ)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
Definition: PatternMatch.h:468
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
Definition: PatternMatch.h:765
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
Definition: PatternMatch.h:713
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Definition: PatternMatch.h:821
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
constantexpr_match m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
Definition: PatternMatch.h:181
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
OverflowingBinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWNeg(const ValTy &V)
Matches a 'Neg' as 'sub nsw 0, V'.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
Definition: PatternMatch.h:691
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
Definition: PatternMatch.h:509
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Definition: PatternMatch.h:163
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
Definition: PatternMatch.h:541
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
Definition: PatternMatch.h:731
match_combine_or< CastInst_match< OpTy, SExtInst >, OpTy > m_SExtOrSelf(const OpTy &Op)
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
Definition: PatternMatch.h:864
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
Definition: PatternMatch.h:240
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
Definition: PatternMatch.h:460
CmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R)
CastOperator_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
CastInst_match< OpTy, FPToUIInst > m_FPToUI(const OpTy &Op)
m_Intrinsic_Ty< Opnd0 >::Ty m_Sqrt(const Opnd0 &Op0)
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
Definition: PatternMatch.h:771
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
match_combine_or< typename m_Intrinsic_Ty< T0, T1 >::Ty, typename m_Intrinsic_Ty< T1, T0 >::Ty > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
Definition: PatternMatch.h:839
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
Definition: PatternMatch.h:548
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
OneUse_match< T > m_OneUse(const T &SubPattern)
Definition: PatternMatch.h:67
NNegZExt_match< OpTy > m_NNegZExt(const OpTy &Op)
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
match_combine_and< class_match< Constant >, match_unless< constantexpr_match > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
Definition: PatternMatch.h:800
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
Definition: PatternMatch.h:936
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true > m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
auto m_GEP(const OperandTypes &...Ops)
Matches GetElementPtrInst.
apint_match m_APIntForbidUndef(const APInt *&Res)
Match APInt while forbidding undefs in splat vector constants.
Definition: PatternMatch.h:305
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
Definition: PatternMatch.h:519
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
class_match< ConstantFP > m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
Definition: PatternMatch.h:168
cstfp_pred_ty< is_nonnan > m_NonNaN()
Match a non-NaN FP constant.
Definition: PatternMatch.h:666
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2, Opnd3 >::Ty m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2, const Opnd3 &Op3)
Matches MaskedLoad Intrinsic.
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
Definition: PatternMatch.h:105
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
Definition: PatternMatch.h:576
cst_pred_ty< is_negated_power2_or_zero > m_NegatedPower2OrZero()
Match a integer or vector negated power-of-2.
Definition: PatternMatch.h:588
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
Definition: PatternMatch.h:632
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
Definition: PatternMatch.h:867
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)
Match either "add" or "or disjoint".
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true > m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
match_combine_or< match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true >, MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > >, match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true >, MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > > > m_c_MaxOrMin(const LHS &L, const RHS &R)
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
match_combine_or< CastOperator_match< OpTy, Instruction::Trunc >, OpTy > m_TruncOrSelf(const OpTy &Op)
match_combine_or< CastInst_match< OpTy, SExtInst >, NNegZExt_match< OpTy > > m_SExtLike(const OpTy &Op)
Match either "sext" or "zext nneg".
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
Definition: PatternMatch.h:701
class_match< UnaryOperator > m_UnOp()
Match an arbitrary unary operation and ignore it.
Definition: PatternMatch.h:95
VScaleVal_match m_VScale()
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
specific_intval< true > m_SpecificIntAllowUndef(APInt V)
Definition: PatternMatch.h:911
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
Definition: PatternMatch.h:294
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:487
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:92
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
Exact_match< T > m_Exact(const T &SubPattern)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
Definition: PatternMatch.h:722
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
Definition: PatternMatch.h:740
UAddWithOverflow_match< LHS_t, RHS_t, Sum_t > m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Match an icmp instruction checking for unsigned overflow on addition.
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
NotForbidUndef_match< ValTy > m_NotForbidUndef(const ValTy &V)
Matches a bitwise 'not' as 'xor V, -1' or 'xor -1, V'.
m_Intrinsic_Ty< Opnd0 >::Ty m_VecReverse(const Opnd0 &Op0)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
Definition: PatternMatch.h:311
apfloat_match m_APFloatForbidUndef(const APFloat *&Res)
Match APFloat while forbidding undefs in splat vector constants.
Definition: PatternMatch.h:322
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
match_combine_or< match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty >, MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > >, match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty >, MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > > > m_MaxOrMin(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
ThreeOps_match< Cond, constantint_match< L >, constantint_match< R >, Instruction::Select > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.: m_SelectCst<-1, 0>(m_Value(V))
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
CastInst_match< OpTy, FPTruncInst > m_FPTrunc(const OpTy &Op)
class_match< BasicBlock > m_BasicBlock()
Match an arbitrary basic block value and ignore it.
Definition: PatternMatch.h:184
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
Definition: PatternMatch.h:152
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
Definition: PatternMatch.h:531
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
Definition: PatternMatch.h:659
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
Definition: PatternMatch.h:561
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.
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
Definition: PatternMatch.h:682
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2, Opnd3 >::Ty m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2, const Opnd3 &Op3)
Matches MaskedGather Intrinsic.
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
Definition: PatternMatch.h:198
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
Definition: PatternMatch.h:234
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:647
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1731
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1858
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:1758
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
AllowReassoc_match(const SubPattern_t &SP)
Definition: PatternMatch.h:74
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:959
Matches instructions with Opcode and any number of operands.
std::enable_if_t< Idx==Last, bool > match_operands(const Instruction *I)
std::enable_if_t< Idx !=Last, bool > match_operands(const Instruction *I)
std::tuple< OperandTypes... > Operands
AnyOps_match(const OperandTypes &...Ops)
Argument_match(unsigned OpIdx, const Opnd_t &V)
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
bool match(unsigned Opc, OpTy *V)
CastInst_match(const Op_t &OpMatch)
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
DisjointOr_match(const LHS &L, const RHS &R)
Exact_match(const SubPattern_t &SP)
Matcher for a single index InsertValue instruction.
InsertValue_match(const T0 &Op0, const T1 &Op1)
IntrinsicID_match(Intrinsic::ID IntrID)
LogicalOp_match(const LHS &L, const RHS &R)
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
NNegZExt_match(const Op_t &OpMatch)
Matches instructions with Opcode and three operands.
OneUse_match(const SubPattern_t &SP)
Definition: PatternMatch.h:60
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
Matches instructions with Opcode and three operands.
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
Matches instructions with Opcode and three operands.
TwoOps_match(const T0 &Op1, const T1 &Op2)
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Matches patterns for vscale.
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
Definition: PatternMatch.h:422
apf_pred_ty(const APFloat *&R)
Definition: PatternMatch.h:425
apfloat_match(const APFloat *&Res, bool AllowUndef)
Definition: PatternMatch.h:273
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
Definition: PatternMatch.h:396
apint_match(const APInt *&Res, bool AllowUndef)
Definition: PatternMatch.h:248
br_match(BasicBlock *&Succ)
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
This helper class is used to match constant scalars, vector splats, and fixed width vectors that sati...
Definition: PatternMatch.h:350
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers.
Definition: PatternMatch.h:825
bool isValue(const APInt &C)
Definition: PatternMatch.h:473
bool isValue(const APInt &C)
Definition: PatternMatch.h:456
bool isValue(const APFloat &C)
Definition: PatternMatch.h:709
bool isValue(const APFloat &C)
Definition: PatternMatch.h:687
bool isValue(const APFloat &C)
Definition: PatternMatch.h:697
bool isOpType(unsigned Opcode)
bool isValue(const APFloat &C)
Definition: PatternMatch.h:671
bool isOpType(unsigned Opcode)
bool isValue(const APFloat &C)
Definition: PatternMatch.h:655
bool isValue(const APFloat &C)
Definition: PatternMatch.h:727
bool isValue(const APInt &C)
Definition: PatternMatch.h:495
bool isValue(const APFloat &C)
Definition: PatternMatch.h:736
bool isValue(const APFloat &C)
Definition: PatternMatch.h:678
bool isValue(const APFloat &C)
Definition: PatternMatch.h:662
bool isValue(const APInt &C)
Definition: PatternMatch.h:537
bool isValue(const APFloat &C)
Definition: PatternMatch.h:718
bool isValue(const APInt &C)
Definition: PatternMatch.h:564
bool isOpType(unsigned Opcode)
bool isValue(const APInt &C)
Definition: PatternMatch.h:609
bool isValue(const APInt &C)
Definition: PatternMatch.h:544
Intrinsic matches are combinations of ID matchers, and argument matchers.
bool match(ArrayRef< int > Mask)
ArrayRef< int > & MaskRef
m_Mask(ArrayRef< int > &MaskRef)
bool match(ArrayRef< int > Mask)
m_SpecificMask(ArrayRef< int > &MaskRef)
bool match(ArrayRef< int > Mask)
bool match(ArrayRef< int > Mask)
match_combine_and(const LTy &Left, const RTy &Right)
Definition: PatternMatch.h:222
match_combine_or(const LTy &Left, const RTy &Right)
Definition: PatternMatch.h:207
match_unless(const Ty &Matcher)
Definition: PatternMatch.h:192
Helper class for identifying ordered max predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying ordered min predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying signed max predicates.
static bool match(ICmpInst::Predicate Pred)
Helper class for identifying signed min predicates.
static bool match(ICmpInst::Predicate Pred)
Match a specified basic block value.
Definition: PatternMatch.h:924
Match a specified floating point value or vector of all elements of that value.
Definition: PatternMatch.h:846
Match a specified integer value or vector of all elements of that value.
Definition: PatternMatch.h:886
Match a specified Value*.
Definition: PatternMatch.h:812
Helper class for identifying unordered max predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying unordered min predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying unsigned max predicates.
static bool match(ICmpInst::Predicate Pred)
Helper class for identifying unsigned min predicates.
static bool match(ICmpInst::Predicate Pred)
static bool check(const Value *V)
Definition: PatternMatch.h:108