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(AllowPoison))) {
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(AllowPoison))) {
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 poison by default to maintain previous behavior.
296 return apint_match(Res, /* AllowPoison */ false);
297}
298
299/// Match APInt while allowing poison in splat vector constants.
301 return apint_match(Res, /* AllowPoison */ true);
302}
303
304/// Match APInt while forbidding poison in splat vector constants.
306 return apint_match(Res, /* AllowPoison */ 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, /* AllowPoison */ false);
314}
315
316/// Match APFloat while allowing poison in splat vector constants.
318 return apfloat_match(Res, /* AllowPoison */ true);
319}
320
321/// Match APFloat while forbidding poison in splat vector constants.
323 return apfloat_match(Res, /* AllowPoison */ 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, poison 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 HasNonPoisonElements = false;
368 for (unsigned i = 0; i != NumElts; ++i) {
369 Constant *Elt = C->getAggregateElement(i);
370 if (!Elt)
371 return false;
372 if (isa<PoisonValue>(Elt))
373 continue;
374 auto *CV = dyn_cast<ConstantVal>(Elt);
375 if (!CV || !this->isValue(CV->getValue()))
376 return false;
377 HasNonPoisonElements = true;
378 }
379 return HasNonPoisonElements;
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/// Poison is 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(/* AllowPoison */ 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 AllowPoison> struct specific_intval {
887 const APInt &Val;
888
889 specific_intval(const APInt &V) : Val(V) {}
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(AllowPoison));
896
897 return CI && APInt::isSameValue(CI->getValue(), Val);
898 }
899};
900
901template <bool AllowPoison> struct specific_intval64 {
903
905
906 template <typename ITy> bool match(ITy *V) {
907 const auto *CI = dyn_cast<ConstantInt>(V);
908 if (!CI && V->getType()->isVectorTy())
909 if (const auto *C = dyn_cast<Constant>(V))
910 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
911
912 return CI && CI->getValue() == Val;
913 }
914};
915
916/// Match a specific integer value or vector with all elements equal to
917/// the value.
919 return specific_intval<false>(V);
920}
921
923 return specific_intval64<false>(V);
924}
925
927 return specific_intval<true>(V);
928}
929
931 return specific_intval64<true>(V);
932}
933
934/// Match a ConstantInt and bind to its value. This does not match
935/// ConstantInts wider than 64-bits.
937
938/// Match a specified basic block value.
941
943
944 template <typename ITy> bool match(ITy *V) {
945 const auto *BB = dyn_cast<BasicBlock>(V);
946 return BB && BB == Val;
947 }
948};
949
950/// Match a specific basic block value.
952 return specific_bbval(BB);
953}
954
955/// A commutative-friendly version of m_Specific().
957 return BB;
958}
960m_Deferred(const BasicBlock *const &BB) {
961 return BB;
962}
963
964//===----------------------------------------------------------------------===//
965// Matcher for any binary operator.
966//
967template <typename LHS_t, typename RHS_t, bool Commutable = false>
971
972 // The evaluation order is always stable, regardless of Commutability.
973 // The LHS is always matched first.
974 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
975
976 template <typename OpTy> bool match(OpTy *V) {
977 if (auto *I = dyn_cast<BinaryOperator>(V))
978 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
979 (Commutable && L.match(I->getOperand(1)) &&
980 R.match(I->getOperand(0)));
981 return false;
982 }
983};
984
985template <typename LHS, typename RHS>
986inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
987 return AnyBinaryOp_match<LHS, RHS>(L, R);
988}
989
990//===----------------------------------------------------------------------===//
991// Matcher for any unary operator.
992// TODO fuse unary, binary matcher into n-ary matcher
993//
994template <typename OP_t> struct AnyUnaryOp_match {
995 OP_t X;
996
997 AnyUnaryOp_match(const OP_t &X) : X(X) {}
998
999 template <typename OpTy> bool match(OpTy *V) {
1000 if (auto *I = dyn_cast<UnaryOperator>(V))
1001 return X.match(I->getOperand(0));
1002 return false;
1003 }
1004};
1005
1006template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1007 return AnyUnaryOp_match<OP_t>(X);
1008}
1009
1010//===----------------------------------------------------------------------===//
1011// Matchers for specific binary operators.
1012//
1013
1014template <typename LHS_t, typename RHS_t, unsigned Opcode,
1015 bool Commutable = false>
1019
1020 // The evaluation order is always stable, regardless of Commutability.
1021 // The LHS is always matched first.
1022 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1023
1024 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) {
1025 if (V->getValueID() == Value::InstructionVal + Opc) {
1026 auto *I = cast<BinaryOperator>(V);
1027 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1028 (Commutable && L.match(I->getOperand(1)) &&
1029 R.match(I->getOperand(0)));
1030 }
1031 return false;
1032 }
1033
1034 template <typename OpTy> bool match(OpTy *V) { return match(Opcode, V); }
1035};
1036
1037template <typename LHS, typename RHS>
1039 const RHS &R) {
1041}
1042
1043template <typename LHS, typename RHS>
1045 const RHS &R) {
1047}
1048
1049template <typename LHS, typename RHS>
1051 const RHS &R) {
1053}
1054
1055template <typename LHS, typename RHS>
1057 const RHS &R) {
1059}
1060
1061template <typename Op_t> struct FNeg_match {
1062 Op_t X;
1063
1064 FNeg_match(const Op_t &Op) : X(Op) {}
1065 template <typename OpTy> bool match(OpTy *V) {
1066 auto *FPMO = dyn_cast<FPMathOperator>(V);
1067 if (!FPMO)
1068 return false;
1069
1070 if (FPMO->getOpcode() == Instruction::FNeg)
1071 return X.match(FPMO->getOperand(0));
1072
1073 if (FPMO->getOpcode() == Instruction::FSub) {
1074 if (FPMO->hasNoSignedZeros()) {
1075 // With 'nsz', any zero goes.
1076 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1077 return false;
1078 } else {
1079 // Without 'nsz', we need fsub -0.0, X exactly.
1080 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1081 return false;
1082 }
1083
1084 return X.match(FPMO->getOperand(1));
1085 }
1086
1087 return false;
1088 }
1089};
1090
1091/// Match 'fneg X' as 'fsub -0.0, X'.
1092template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1093 return FNeg_match<OpTy>(X);
1094}
1095
1096/// Match 'fneg X' as 'fsub +-0.0, X'.
1097template <typename RHS>
1098inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1099m_FNegNSZ(const RHS &X) {
1100 return m_FSub(m_AnyZeroFP(), X);
1101}
1102
1103template <typename LHS, typename RHS>
1105 const RHS &R) {
1107}
1108
1109template <typename LHS, typename RHS>
1111 const RHS &R) {
1113}
1114
1115template <typename LHS, typename RHS>
1117 const RHS &R) {
1119}
1120
1121template <typename LHS, typename RHS>
1123 const RHS &R) {
1125}
1126
1127template <typename LHS, typename RHS>
1129 const RHS &R) {
1131}
1132
1133template <typename LHS, typename RHS>
1135 const RHS &R) {
1137}
1138
1139template <typename LHS, typename RHS>
1141 const RHS &R) {
1143}
1144
1145template <typename LHS, typename RHS>
1147 const RHS &R) {
1149}
1150
1151template <typename LHS, typename RHS>
1153 const RHS &R) {
1155}
1156
1157template <typename LHS, typename RHS>
1159 const RHS &R) {
1161}
1162
1163template <typename LHS, typename RHS>
1165 const RHS &R) {
1167}
1168
1169template <typename LHS, typename RHS>
1171 const RHS &R) {
1173}
1174
1175template <typename LHS, typename RHS>
1177 const RHS &R) {
1179}
1180
1181template <typename LHS, typename RHS>
1183 const RHS &R) {
1185}
1186
1187template <typename LHS_t, typename RHS_t, unsigned Opcode,
1188 unsigned WrapFlags = 0, bool Commutable = false>
1192
1194 : L(LHS), R(RHS) {}
1195
1196 template <typename OpTy> bool match(OpTy *V) {
1197 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1198 if (Op->getOpcode() != Opcode)
1199 return false;
1201 !Op->hasNoUnsignedWrap())
1202 return false;
1203 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1204 !Op->hasNoSignedWrap())
1205 return false;
1206 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1207 (Commutable && L.match(Op->getOperand(1)) &&
1208 R.match(Op->getOperand(0)));
1209 }
1210 return false;
1211 }
1212};
1213
1214template <typename LHS, typename RHS>
1215inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1217m_NSWAdd(const LHS &L, const RHS &R) {
1218 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1220 R);
1221}
1222template <typename LHS, typename RHS>
1223inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1225m_NSWSub(const LHS &L, const RHS &R) {
1226 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1228 R);
1229}
1230template <typename LHS, typename RHS>
1231inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1233m_NSWMul(const LHS &L, const RHS &R) {
1234 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1236 R);
1237}
1238template <typename LHS, typename RHS>
1239inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1241m_NSWShl(const LHS &L, const RHS &R) {
1242 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1244 R);
1245}
1246
1247template <typename LHS, typename RHS>
1248inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1250m_NUWAdd(const LHS &L, const RHS &R) {
1251 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1253 L, R);
1254}
1255
1256template <typename LHS, typename RHS>
1258 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1259m_c_NUWAdd(const LHS &L, const RHS &R) {
1260 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1262 true>(L, R);
1263}
1264
1265template <typename LHS, typename RHS>
1266inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1268m_NUWSub(const LHS &L, const RHS &R) {
1269 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1271 L, R);
1272}
1273template <typename LHS, typename RHS>
1274inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1276m_NUWMul(const LHS &L, const RHS &R) {
1277 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1279 L, R);
1280}
1281template <typename LHS, typename RHS>
1282inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1284m_NUWShl(const LHS &L, const RHS &R) {
1285 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1287 L, R);
1288}
1289
1290template <typename LHS_t, typename RHS_t, bool Commutable = false>
1292 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1293 unsigned Opcode;
1294
1296 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1297
1298 template <typename OpTy> bool match(OpTy *V) {
1300 }
1301};
1302
1303/// Matches a specific opcode.
1304template <typename LHS, typename RHS>
1305inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1306 const RHS &R) {
1307 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1308}
1309
1310template <typename LHS, typename RHS, bool Commutable = false>
1314
1315 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1316
1317 template <typename OpTy> bool match(OpTy *V) {
1318 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1319 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1320 if (!PDI->isDisjoint())
1321 return false;
1322 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1323 (Commutable && L.match(PDI->getOperand(1)) &&
1324 R.match(PDI->getOperand(0)));
1325 }
1326 return false;
1327 }
1328};
1329
1330template <typename LHS, typename RHS>
1332 return DisjointOr_match<LHS, RHS>(L, R);
1333}
1334
1335template <typename LHS, typename RHS>
1337 const RHS &R) {
1339}
1340
1341/// Match either "add" or "or disjoint".
1342template <typename LHS, typename RHS>
1345m_AddLike(const LHS &L, const RHS &R) {
1346 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1347}
1348
1349/// Match either "add nsw" or "or disjoint"
1350template <typename LHS, typename RHS>
1351inline match_combine_or<
1352 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1355m_NSWAddLike(const LHS &L, const RHS &R) {
1356 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1357}
1358
1359/// Match either "add nuw" or "or disjoint"
1360template <typename LHS, typename RHS>
1361inline match_combine_or<
1362 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1365m_NUWAddLike(const LHS &L, const RHS &R) {
1366 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1367}
1368
1369//===----------------------------------------------------------------------===//
1370// Class that matches a group of binary opcodes.
1371//
1372template <typename LHS_t, typename RHS_t, typename Predicate,
1373 bool Commutable = false>
1374struct BinOpPred_match : Predicate {
1377
1378 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1379
1380 template <typename OpTy> bool match(OpTy *V) {
1381 if (auto *I = dyn_cast<Instruction>(V))
1382 return this->isOpType(I->getOpcode()) &&
1383 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1384 (Commutable && L.match(I->getOperand(1)) &&
1385 R.match(I->getOperand(0))));
1386 return false;
1387 }
1388};
1389
1391 bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); }
1392};
1393
1395 bool isOpType(unsigned Opcode) {
1396 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1397 }
1398};
1399
1401 bool isOpType(unsigned Opcode) {
1402 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1403 }
1404};
1405
1407 bool isOpType(unsigned Opcode) {
1408 return Instruction::isBitwiseLogicOp(Opcode);
1409 }
1410};
1411
1413 bool isOpType(unsigned Opcode) {
1414 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1415 }
1416};
1417
1419 bool isOpType(unsigned Opcode) {
1420 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1421 }
1422};
1423
1424/// Matches shift operations.
1425template <typename LHS, typename RHS>
1427 const RHS &R) {
1429}
1430
1431/// Matches logical shift operations.
1432template <typename LHS, typename RHS>
1434 const RHS &R) {
1436}
1437
1438/// Matches logical shift operations.
1439template <typename LHS, typename RHS>
1441m_LogicalShift(const LHS &L, const RHS &R) {
1443}
1444
1445/// Matches bitwise logic operations.
1446template <typename LHS, typename RHS>
1448m_BitwiseLogic(const LHS &L, const RHS &R) {
1450}
1451
1452/// Matches bitwise logic operations in either order.
1453template <typename LHS, typename RHS>
1455m_c_BitwiseLogic(const LHS &L, const RHS &R) {
1457}
1458
1459/// Matches integer division operations.
1460template <typename LHS, typename RHS>
1462 const RHS &R) {
1464}
1465
1466/// Matches integer remainder operations.
1467template <typename LHS, typename RHS>
1469 const RHS &R) {
1471}
1472
1473//===----------------------------------------------------------------------===//
1474// Class that matches exact binary ops.
1475//
1476template <typename SubPattern_t> struct Exact_match {
1477 SubPattern_t SubPattern;
1478
1479 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1480
1481 template <typename OpTy> bool match(OpTy *V) {
1482 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1483 return PEO->isExact() && SubPattern.match(V);
1484 return false;
1485 }
1486};
1487
1488template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1489 return SubPattern;
1490}
1491
1492//===----------------------------------------------------------------------===//
1493// Matchers for CmpInst classes
1494//
1495
1496template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
1497 bool Commutable = false>
1499 PredicateTy &Predicate;
1502
1503 // The evaluation order is always stable, regardless of Commutability.
1504 // The LHS is always matched first.
1505 CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
1506 : Predicate(Pred), L(LHS), R(RHS) {}
1507
1508 template <typename OpTy> bool match(OpTy *V) {
1509 if (auto *I = dyn_cast<Class>(V)) {
1510 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1511 Predicate = I->getPredicate();
1512 return true;
1513 } else if (Commutable && L.match(I->getOperand(1)) &&
1514 R.match(I->getOperand(0))) {
1515 Predicate = I->getSwappedPredicate();
1516 return true;
1517 }
1518 }
1519 return false;
1520 }
1521};
1522
1523template <typename LHS, typename RHS>
1525m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1527}
1528
1529template <typename LHS, typename RHS>
1531m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1533}
1534
1535template <typename LHS, typename RHS>
1537m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1539}
1540
1541//===----------------------------------------------------------------------===//
1542// Matchers for instructions with a given opcode and number of operands.
1543//
1544
1545/// Matches instructions with Opcode and three operands.
1546template <typename T0, unsigned Opcode> struct OneOps_match {
1548
1549 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1550
1551 template <typename OpTy> bool match(OpTy *V) {
1552 if (V->getValueID() == Value::InstructionVal + Opcode) {
1553 auto *I = cast<Instruction>(V);
1554 return Op1.match(I->getOperand(0));
1555 }
1556 return false;
1557 }
1558};
1559
1560/// Matches instructions with Opcode and three operands.
1561template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1564
1565 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1566
1567 template <typename OpTy> bool match(OpTy *V) {
1568 if (V->getValueID() == Value::InstructionVal + Opcode) {
1569 auto *I = cast<Instruction>(V);
1570 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1571 }
1572 return false;
1573 }
1574};
1575
1576/// Matches instructions with Opcode and three operands.
1577template <typename T0, typename T1, typename T2, unsigned Opcode>
1582
1583 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1584 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1585
1586 template <typename OpTy> bool match(OpTy *V) {
1587 if (V->getValueID() == Value::InstructionVal + Opcode) {
1588 auto *I = cast<Instruction>(V);
1589 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1590 Op3.match(I->getOperand(2));
1591 }
1592 return false;
1593 }
1594};
1595
1596/// Matches instructions with Opcode and any number of operands
1597template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1598 std::tuple<OperandTypes...> Operands;
1599
1600 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1601
1602 // Operand matching works by recursively calling match_operands, matching the
1603 // operands left to right. The first version is called for each operand but
1604 // the last, for which the second version is called. The second version of
1605 // match_operands is also used to match each individual operand.
1606 template <int Idx, int Last>
1607 std::enable_if_t<Idx != Last, bool> match_operands(const Instruction *I) {
1608 return match_operands<Idx, Idx>(I) && match_operands<Idx + 1, Last>(I);
1609 }
1610
1611 template <int Idx, int Last>
1612 std::enable_if_t<Idx == Last, bool> match_operands(const Instruction *I) {
1613 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1614 }
1615
1616 template <typename OpTy> bool match(OpTy *V) {
1617 if (V->getValueID() == Value::InstructionVal + Opcode) {
1618 auto *I = cast<Instruction>(V);
1619 return I->getNumOperands() == sizeof...(OperandTypes) &&
1620 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1621 }
1622 return false;
1623 }
1624};
1625
1626/// Matches SelectInst.
1627template <typename Cond, typename LHS, typename RHS>
1629m_Select(const Cond &C, const LHS &L, const RHS &R) {
1631}
1632
1633/// This matches a select of two constants, e.g.:
1634/// m_SelectCst<-1, 0>(m_Value(V))
1635template <int64_t L, int64_t R, typename Cond>
1637 Instruction::Select>
1639 return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1640}
1641
1642/// Matches FreezeInst.
1643template <typename OpTy>
1646}
1647
1648/// Matches InsertElementInst.
1649template <typename Val_t, typename Elt_t, typename Idx_t>
1651m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1653 Val, Elt, Idx);
1654}
1655
1656/// Matches ExtractElementInst.
1657template <typename Val_t, typename Idx_t>
1659m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
1661}
1662
1663/// Matches shuffle.
1664template <typename T0, typename T1, typename T2> struct Shuffle_match {
1668
1669 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
1670 : Op1(Op1), Op2(Op2), Mask(Mask) {}
1671
1672 template <typename OpTy> bool match(OpTy *V) {
1673 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
1674 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1675 Mask.match(I->getShuffleMask());
1676 }
1677 return false;
1678 }
1679};
1680
1681struct m_Mask {
1685 MaskRef = Mask;
1686 return true;
1687 }
1688};
1689
1692 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
1693 }
1694};
1695
1699 bool match(ArrayRef<int> Mask) { return MaskRef == Mask; }
1700};
1701
1706 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
1707 if (First == Mask.end())
1708 return false;
1709 SplatIndex = *First;
1710 return all_of(Mask,
1711 [First](int Elem) { return Elem == *First || Elem == -1; });
1712 }
1713};
1714
1715template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
1716 PointerOpTy PointerOp;
1717 OffsetOpTy OffsetOp;
1718
1719 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
1721
1722 template <typename OpTy> bool match(OpTy *V) {
1723 auto *GEP = dyn_cast<GEPOperator>(V);
1724 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
1725 PointerOp.match(GEP->getPointerOperand()) &&
1726 OffsetOp.match(GEP->idx_begin()->get());
1727 }
1728};
1729
1730/// Matches ShuffleVectorInst independently of mask value.
1731template <typename V1_t, typename V2_t>
1733m_Shuffle(const V1_t &v1, const V2_t &v2) {
1735}
1736
1737template <typename V1_t, typename V2_t, typename Mask_t>
1739m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
1740 return Shuffle_match<V1_t, V2_t, Mask_t>(v1, v2, mask);
1741}
1742
1743/// Matches LoadInst.
1744template <typename OpTy>
1747}
1748
1749/// Matches StoreInst.
1750template <typename ValueOpTy, typename PointerOpTy>
1752m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
1754 PointerOp);
1755}
1756
1757/// Matches GetElementPtrInst.
1758template <typename... OperandTypes>
1759inline auto m_GEP(const OperandTypes &...Ops) {
1760 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
1761}
1762
1763/// Matches GEP with i8 source element type
1764template <typename PointerOpTy, typename OffsetOpTy>
1766m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
1767 return PtrAdd_match<PointerOpTy, OffsetOpTy>(PointerOp, OffsetOp);
1768}
1769
1770//===----------------------------------------------------------------------===//
1771// Matchers for CastInst classes
1772//
1773
1774template <typename Op_t, unsigned Opcode> struct CastOperator_match {
1775 Op_t Op;
1776
1777 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
1778
1779 template <typename OpTy> bool match(OpTy *V) {
1780 if (auto *O = dyn_cast<Operator>(V))
1781 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
1782 return false;
1783 }
1784};
1785
1786template <typename Op_t, typename Class> struct CastInst_match {
1787 Op_t Op;
1788
1789 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
1790
1791 template <typename OpTy> bool match(OpTy *V) {
1792 if (auto *I = dyn_cast<Class>(V))
1793 return Op.match(I->getOperand(0));
1794 return false;
1795 }
1796};
1797
1798template <typename Op_t> struct PtrToIntSameSize_match {
1800 Op_t Op;
1801
1802 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
1803 : DL(DL), Op(OpMatch) {}
1804
1805 template <typename OpTy> bool match(OpTy *V) {
1806 if (auto *O = dyn_cast<Operator>(V))
1807 return O->getOpcode() == Instruction::PtrToInt &&
1808 DL.getTypeSizeInBits(O->getType()) ==
1809 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
1810 Op.match(O->getOperand(0));
1811 return false;
1812 }
1813};
1814
1815template <typename Op_t> struct NNegZExt_match {
1816 Op_t Op;
1817
1818 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
1819
1820 template <typename OpTy> bool match(OpTy *V) {
1821 if (auto *I = dyn_cast<ZExtInst>(V))
1822 return I->hasNonNeg() && Op.match(I->getOperand(0));
1823 return false;
1824 }
1825};
1826
1827/// Matches BitCast.
1828template <typename OpTy>
1830m_BitCast(const OpTy &Op) {
1832}
1833
1834template <typename Op_t> struct ElementWiseBitCast_match {
1835 Op_t Op;
1836
1837 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
1838
1839 template <typename OpTy> bool match(OpTy *V) {
1840 BitCastInst *I = dyn_cast<BitCastInst>(V);
1841 if (!I)
1842 return false;
1843 Type *SrcType = I->getSrcTy();
1844 Type *DstType = I->getType();
1845 // Make sure the bitcast doesn't change between scalar and vector and
1846 // doesn't change the number of vector elements.
1847 if (SrcType->isVectorTy() != DstType->isVectorTy())
1848 return false;
1849 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
1850 SrcVecTy && SrcVecTy->getElementCount() !=
1851 cast<VectorType>(DstType)->getElementCount())
1852 return false;
1853 return Op.match(I->getOperand(0));
1854 }
1855};
1856
1857template <typename OpTy>
1860}
1861
1862/// Matches PtrToInt.
1863template <typename OpTy>
1865m_PtrToInt(const OpTy &Op) {
1867}
1868
1869template <typename OpTy>
1871 const OpTy &Op) {
1873}
1874
1875/// Matches IntToPtr.
1876template <typename OpTy>
1878m_IntToPtr(const OpTy &Op) {
1880}
1881
1882/// Matches Trunc.
1883template <typename OpTy>
1886}
1887
1888template <typename OpTy>
1890m_TruncOrSelf(const OpTy &Op) {
1891 return m_CombineOr(m_Trunc(Op), Op);
1892}
1893
1894/// Matches SExt.
1895template <typename OpTy>
1898}
1899
1900/// Matches ZExt.
1901template <typename OpTy>
1904}
1905
1906template <typename OpTy>
1908 return NNegZExt_match<OpTy>(Op);
1909}
1910
1911template <typename OpTy>
1913m_ZExtOrSelf(const OpTy &Op) {
1914 return m_CombineOr(m_ZExt(Op), Op);
1915}
1916
1917template <typename OpTy>
1919m_SExtOrSelf(const OpTy &Op) {
1920 return m_CombineOr(m_SExt(Op), Op);
1921}
1922
1923/// Match either "sext" or "zext nneg".
1924template <typename OpTy>
1926m_SExtLike(const OpTy &Op) {
1927 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
1928}
1929
1930template <typename OpTy>
1933m_ZExtOrSExt(const OpTy &Op) {
1934 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
1935}
1936
1937template <typename OpTy>
1940 OpTy>
1942 return m_CombineOr(m_ZExtOrSExt(Op), Op);
1943}
1944
1945template <typename OpTy>
1948}
1949
1950template <typename OpTy>
1953}
1954
1955template <typename OpTy>
1958}
1959
1960template <typename OpTy>
1963}
1964
1965template <typename OpTy>
1968}
1969
1970template <typename OpTy>
1973}
1974
1975//===----------------------------------------------------------------------===//
1976// Matchers for control flow.
1977//
1978
1979struct br_match {
1981
1983
1984 template <typename OpTy> bool match(OpTy *V) {
1985 if (auto *BI = dyn_cast<BranchInst>(V))
1986 if (BI->isUnconditional()) {
1987 Succ = BI->getSuccessor(0);
1988 return true;
1989 }
1990 return false;
1991 }
1992};
1993
1994inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
1995
1996template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
1998 Cond_t Cond;
1999 TrueBlock_t T;
2000 FalseBlock_t F;
2001
2002 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2003 : Cond(C), T(t), F(f) {}
2004
2005 template <typename OpTy> bool match(OpTy *V) {
2006 if (auto *BI = dyn_cast<BranchInst>(V))
2007 if (BI->isConditional() && Cond.match(BI->getCondition()))
2008 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2009 return false;
2010 }
2011};
2012
2013template <typename Cond_t>
2015m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) {
2018}
2019
2020template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2022m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2024}
2025
2026//===----------------------------------------------------------------------===//
2027// Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2028//
2029
2030template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t,
2031 bool Commutable = false>
2033 using PredType = Pred_t;
2036
2037 // The evaluation order is always stable, regardless of Commutability.
2038 // The LHS is always matched first.
2039 MaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2040
2041 template <typename OpTy> bool match(OpTy *V) {
2042 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
2043 Intrinsic::ID IID = II->getIntrinsicID();
2044 if ((IID == Intrinsic::smax && Pred_t::match(ICmpInst::ICMP_SGT)) ||
2045 (IID == Intrinsic::smin && Pred_t::match(ICmpInst::ICMP_SLT)) ||
2046 (IID == Intrinsic::umax && Pred_t::match(ICmpInst::ICMP_UGT)) ||
2047 (IID == Intrinsic::umin && Pred_t::match(ICmpInst::ICMP_ULT))) {
2048 Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
2049 return (L.match(LHS) && R.match(RHS)) ||
2050 (Commutable && L.match(RHS) && R.match(LHS));
2051 }
2052 }
2053 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2054 auto *SI = dyn_cast<SelectInst>(V);
2055 if (!SI)
2056 return false;
2057 auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
2058 if (!Cmp)
2059 return false;
2060 // At this point we have a select conditioned on a comparison. Check that
2061 // it is the values returned by the select that are being compared.
2062 auto *TrueVal = SI->getTrueValue();
2063 auto *FalseVal = SI->getFalseValue();
2064 auto *LHS = Cmp->getOperand(0);
2065 auto *RHS = Cmp->getOperand(1);
2066 if ((TrueVal != LHS || FalseVal != RHS) &&
2067 (TrueVal != RHS || FalseVal != LHS))
2068 return false;
2069 typename CmpInst_t::Predicate Pred =
2070 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2071 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2072 if (!Pred_t::match(Pred))
2073 return false;
2074 // It does! Bind the operands.
2075 return (L.match(LHS) && R.match(RHS)) ||
2076 (Commutable && L.match(RHS) && R.match(LHS));
2077 }
2078};
2079
2080/// Helper class for identifying signed max predicates.
2082 static bool match(ICmpInst::Predicate Pred) {
2083 return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE;
2084 }
2085};
2086
2087/// Helper class for identifying signed min predicates.
2089 static bool match(ICmpInst::Predicate Pred) {
2090 return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE;
2091 }
2092};
2093
2094/// Helper class for identifying unsigned max predicates.
2096 static bool match(ICmpInst::Predicate Pred) {
2097 return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE;
2098 }
2099};
2100
2101/// Helper class for identifying unsigned min predicates.
2103 static bool match(ICmpInst::Predicate Pred) {
2104 return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE;
2105 }
2106};
2107
2108/// Helper class for identifying ordered max predicates.
2110 static bool match(FCmpInst::Predicate Pred) {
2111 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2112 }
2113};
2114
2115/// Helper class for identifying ordered min predicates.
2117 static bool match(FCmpInst::Predicate Pred) {
2118 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2119 }
2120};
2121
2122/// Helper class for identifying unordered max predicates.
2124 static bool match(FCmpInst::Predicate Pred) {
2125 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2126 }
2127};
2128
2129/// Helper class for identifying unordered min predicates.
2131 static bool match(FCmpInst::Predicate Pred) {
2132 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2133 }
2134};
2135
2136template <typename LHS, typename RHS>
2138 const RHS &R) {
2140}
2141
2142template <typename LHS, typename RHS>
2144 const RHS &R) {
2146}
2147
2148template <typename LHS, typename RHS>
2150 const RHS &R) {
2152}
2153
2154template <typename LHS, typename RHS>
2156 const RHS &R) {
2158}
2159
2160template <typename LHS, typename RHS>
2161inline match_combine_or<
2166m_MaxOrMin(const LHS &L, const RHS &R) {
2167 return m_CombineOr(m_CombineOr(m_SMax(L, R), m_SMin(L, R)),
2168 m_CombineOr(m_UMax(L, R), m_UMin(L, R)));
2169}
2170
2171/// Match an 'ordered' floating point maximum function.
2172/// Floating point has one special value 'NaN'. Therefore, there is no total
2173/// order. However, if we can ignore the 'NaN' value (for example, because of a
2174/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2175/// semantics. In the presence of 'NaN' we have to preserve the original
2176/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2177///
2178/// max(L, R) iff L and R are not NaN
2179/// m_OrdFMax(L, R) = R iff L or R are NaN
2180template <typename LHS, typename RHS>
2182 const RHS &R) {
2184}
2185
2186/// Match an 'ordered' floating point minimum function.
2187/// Floating point has one special value 'NaN'. Therefore, there is no total
2188/// order. However, if we can ignore the 'NaN' value (for example, because of a
2189/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2190/// semantics. In the presence of 'NaN' we have to preserve the original
2191/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2192///
2193/// min(L, R) iff L and R are not NaN
2194/// m_OrdFMin(L, R) = R iff L or R are NaN
2195template <typename LHS, typename RHS>
2197 const RHS &R) {
2199}
2200
2201/// Match an 'unordered' floating point maximum function.
2202/// Floating point has one special value 'NaN'. Therefore, there is no total
2203/// order. However, if we can ignore the 'NaN' value (for example, because of a
2204/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2205/// semantics. In the presence of 'NaN' we have to preserve the original
2206/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2207///
2208/// max(L, R) iff L and R are not NaN
2209/// m_UnordFMax(L, R) = L iff L or R are NaN
2210template <typename LHS, typename RHS>
2212m_UnordFMax(const LHS &L, const RHS &R) {
2214}
2215
2216/// Match an 'unordered' floating point minimum function.
2217/// Floating point has one special value 'NaN'. Therefore, there is no total
2218/// order. However, if we can ignore the 'NaN' value (for example, because of a
2219/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2220/// semantics. In the presence of 'NaN' we have to preserve the original
2221/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2222///
2223/// min(L, R) iff L and R are not NaN
2224/// m_UnordFMin(L, R) = L iff L or R are NaN
2225template <typename LHS, typename RHS>
2227m_UnordFMin(const LHS &L, const RHS &R) {
2229}
2230
2231//===----------------------------------------------------------------------===//
2232// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2233// Note that S might be matched to other instructions than AddInst.
2234//
2235
2236template <typename LHS_t, typename RHS_t, typename Sum_t>
2240 Sum_t S;
2241
2242 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2243 : L(L), R(R), S(S) {}
2244
2245 template <typename OpTy> bool match(OpTy *V) {
2246 Value *ICmpLHS, *ICmpRHS;
2248 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2249 return false;
2250
2251 Value *AddLHS, *AddRHS;
2252 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2253
2254 // (a + b) u< a, (a + b) u< b
2255 if (Pred == ICmpInst::ICMP_ULT)
2256 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2257 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2258
2259 // a >u (a + b), b >u (a + b)
2260 if (Pred == ICmpInst::ICMP_UGT)
2261 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2262 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2263
2264 Value *Op1;
2265 auto XorExpr = m_OneUse(m_Xor(m_Value(Op1), m_AllOnes()));
2266 // (a ^ -1) <u b
2267 if (Pred == ICmpInst::ICMP_ULT) {
2268 if (XorExpr.match(ICmpLHS))
2269 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2270 }
2271 // b > u (a ^ -1)
2272 if (Pred == ICmpInst::ICMP_UGT) {
2273 if (XorExpr.match(ICmpRHS))
2274 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2275 }
2276
2277 // Match special-case for increment-by-1.
2278 if (Pred == ICmpInst::ICMP_EQ) {
2279 // (a + 1) == 0
2280 // (1 + a) == 0
2281 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2282 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2283 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2284 // 0 == (a + 1)
2285 // 0 == (1 + a)
2286 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2287 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2288 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2289 }
2290
2291 return false;
2292 }
2293};
2294
2295/// Match an icmp instruction checking for unsigned overflow on addition.
2296///
2297/// S is matched to the addition whose result is being checked for overflow, and
2298/// L and R are matched to the LHS and RHS of S.
2299template <typename LHS_t, typename RHS_t, typename Sum_t>
2301m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2303}
2304
2305template <typename Opnd_t> struct Argument_match {
2306 unsigned OpI;
2307 Opnd_t Val;
2308
2309 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2310
2311 template <typename OpTy> bool match(OpTy *V) {
2312 // FIXME: Should likely be switched to use `CallBase`.
2313 if (const auto *CI = dyn_cast<CallInst>(V))
2314 return Val.match(CI->getArgOperand(OpI));
2315 return false;
2316 }
2317};
2318
2319/// Match an argument.
2320template <unsigned OpI, typename Opnd_t>
2321inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2322 return Argument_match<Opnd_t>(OpI, Op);
2323}
2324
2325/// Intrinsic matchers.
2327 unsigned ID;
2328
2330
2331 template <typename OpTy> bool match(OpTy *V) {
2332 if (const auto *CI = dyn_cast<CallInst>(V))
2333 if (const auto *F = CI->getCalledFunction())
2334 return F->getIntrinsicID() == ID;
2335 return false;
2336 }
2337};
2338
2339/// Intrinsic matches are combinations of ID matchers, and argument
2340/// matchers. Higher arity matcher are defined recursively in terms of and-ing
2341/// them with lower arity matchers. Here's some convenient typedefs for up to
2342/// several arguments, and more can be added as needed
2343template <typename T0 = void, typename T1 = void, typename T2 = void,
2344 typename T3 = void, typename T4 = void, typename T5 = void,
2345 typename T6 = void, typename T7 = void, typename T8 = void,
2346 typename T9 = void, typename T10 = void>
2348template <typename T0> struct m_Intrinsic_Ty<T0> {
2350};
2351template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
2352 using Ty =
2354};
2355template <typename T0, typename T1, typename T2>
2356struct m_Intrinsic_Ty<T0, T1, T2> {
2359};
2360template <typename T0, typename T1, typename T2, typename T3>
2361struct m_Intrinsic_Ty<T0, T1, T2, T3> {
2364};
2365
2366template <typename T0, typename T1, typename T2, typename T3, typename T4>
2367struct m_Intrinsic_Ty<T0, T1, T2, T3, T4> {
2370};
2371
2372template <typename T0, typename T1, typename T2, typename T3, typename T4,
2373 typename T5>
2374struct m_Intrinsic_Ty<T0, T1, T2, T3, T4, T5> {
2377};
2378
2379/// Match intrinsic calls like this:
2380/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2381template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
2382 return IntrinsicID_match(IntrID);
2383}
2384
2385/// Matches MaskedLoad Intrinsic.
2386template <typename Opnd0, typename Opnd1, typename Opnd2, typename Opnd3>
2388m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2,
2389 const Opnd3 &Op3) {
2390 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2, Op3);
2391}
2392
2393/// Matches MaskedGather Intrinsic.
2394template <typename Opnd0, typename Opnd1, typename Opnd2, typename Opnd3>
2396m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2,
2397 const Opnd3 &Op3) {
2398 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2, Op3);
2399}
2400
2401template <Intrinsic::ID IntrID, typename T0>
2402inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
2403 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
2404}
2405
2406template <Intrinsic::ID IntrID, typename T0, typename T1>
2407inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
2408 const T1 &Op1) {
2409 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
2410}
2411
2412template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
2413inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
2414m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
2415 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2416}
2417
2418template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2419 typename T3>
2421m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
2422 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2423}
2424
2425template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2426 typename T3, typename T4>
2428m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
2429 const T4 &Op4) {
2430 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2431 m_Argument<4>(Op4));
2432}
2433
2434template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2435 typename T3, typename T4, typename T5>
2437m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
2438 const T4 &Op4, const T5 &Op5) {
2439 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2440 m_Argument<5>(Op5));
2441}
2442
2443// Helper intrinsic matching specializations.
2444template <typename Opnd0>
2445inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BitReverse(const Opnd0 &Op0) {
2446 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
2447}
2448
2449template <typename Opnd0>
2450inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BSwap(const Opnd0 &Op0) {
2451 return m_Intrinsic<Intrinsic::bswap>(Op0);
2452}
2453
2454template <typename Opnd0>
2455inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FAbs(const Opnd0 &Op0) {
2456 return m_Intrinsic<Intrinsic::fabs>(Op0);
2457}
2458
2459template <typename Opnd0>
2460inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FCanonicalize(const Opnd0 &Op0) {
2461 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
2462}
2463
2464template <typename Opnd0, typename Opnd1>
2465inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMin(const Opnd0 &Op0,
2466 const Opnd1 &Op1) {
2467 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2468}
2469
2470template <typename Opnd0, typename Opnd1>
2471inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMax(const Opnd0 &Op0,
2472 const Opnd1 &Op1) {
2473 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2474}
2475
2476template <typename Opnd0, typename Opnd1, typename Opnd2>
2478m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2479 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2480}
2481
2482template <typename Opnd0, typename Opnd1, typename Opnd2>
2484m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2485 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2486}
2487
2488template <typename Opnd0>
2489inline typename m_Intrinsic_Ty<Opnd0>::Ty m_Sqrt(const Opnd0 &Op0) {
2490 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2491}
2492
2493template <typename Opnd0, typename Opnd1>
2494inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_CopySign(const Opnd0 &Op0,
2495 const Opnd1 &Op1) {
2496 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2497}
2498
2499template <typename Opnd0>
2500inline typename m_Intrinsic_Ty<Opnd0>::Ty m_VecReverse(const Opnd0 &Op0) {
2501 return m_Intrinsic<Intrinsic::experimental_vector_reverse>(Op0);
2502}
2503
2504//===----------------------------------------------------------------------===//
2505// Matchers for two-operands operators with the operators in either order
2506//
2507
2508/// Matches a BinaryOperator with LHS and RHS in either order.
2509template <typename LHS, typename RHS>
2512}
2513
2514/// Matches an ICmp with a predicate over LHS and RHS in either order.
2515/// Swaps the predicate if operands are commuted.
2516template <typename LHS, typename RHS>
2518m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
2520 R);
2521}
2522
2523/// Matches a specific opcode with LHS and RHS in either order.
2524template <typename LHS, typename RHS>
2526m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
2527 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
2528}
2529
2530/// Matches a Add with LHS and RHS in either order.
2531template <typename LHS, typename RHS>
2533 const RHS &R) {
2535}
2536
2537/// Matches a Mul with LHS and RHS in either order.
2538template <typename LHS, typename RHS>
2540 const RHS &R) {
2542}
2543
2544/// Matches an And with LHS and RHS in either order.
2545template <typename LHS, typename RHS>
2547 const RHS &R) {
2549}
2550
2551/// Matches an Or with LHS and RHS in either order.
2552template <typename LHS, typename RHS>
2554 const RHS &R) {
2556}
2557
2558/// Matches an Xor with LHS and RHS in either order.
2559template <typename LHS, typename RHS>
2561 const RHS &R) {
2563}
2564
2565/// Matches a 'Neg' as 'sub 0, V'.
2566template <typename ValTy>
2567inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
2568m_Neg(const ValTy &V) {
2569 return m_Sub(m_ZeroInt(), V);
2570}
2571
2572/// Matches a 'Neg' as 'sub nsw 0, V'.
2573template <typename ValTy>
2575 Instruction::Sub,
2577m_NSWNeg(const ValTy &V) {
2578 return m_NSWSub(m_ZeroInt(), V);
2579}
2580
2581/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2582/// NOTE: we first match the 'Not' (by matching '-1'),
2583/// and only then match the inner matcher!
2584template <typename ValTy>
2585inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2586m_Not(const ValTy &V) {
2587 return m_c_Xor(m_AllOnes(), V);
2588}
2589
2590/// Matches an SMin with LHS and RHS in either order.
2591template <typename LHS, typename RHS>
2593m_c_SMin(const LHS &L, const RHS &R) {
2595}
2596/// Matches an SMax with LHS and RHS in either order.
2597template <typename LHS, typename RHS>
2599m_c_SMax(const LHS &L, const RHS &R) {
2601}
2602/// Matches a UMin with LHS and RHS in either order.
2603template <typename LHS, typename RHS>
2605m_c_UMin(const LHS &L, const RHS &R) {
2607}
2608/// Matches a UMax with LHS and RHS in either order.
2609template <typename LHS, typename RHS>
2611m_c_UMax(const LHS &L, const RHS &R) {
2613}
2614
2615template <typename LHS, typename RHS>
2616inline match_combine_or<
2621m_c_MaxOrMin(const LHS &L, const RHS &R) {
2622 return m_CombineOr(m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R)),
2623 m_CombineOr(m_c_UMax(L, R), m_c_UMin(L, R)));
2624}
2625
2626template <Intrinsic::ID IntrID, typename T0, typename T1>
2629m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
2630 return m_CombineOr(m_Intrinsic<IntrID>(Op0, Op1),
2631 m_Intrinsic<IntrID>(Op1, Op0));
2632}
2633
2634/// Matches FAdd with LHS and RHS in either order.
2635template <typename LHS, typename RHS>
2637m_c_FAdd(const LHS &L, const RHS &R) {
2639}
2640
2641/// Matches FMul with LHS and RHS in either order.
2642template <typename LHS, typename RHS>
2644m_c_FMul(const LHS &L, const RHS &R) {
2646}
2647
2648template <typename Opnd_t> struct Signum_match {
2649 Opnd_t Val;
2650 Signum_match(const Opnd_t &V) : Val(V) {}
2651
2652 template <typename OpTy> bool match(OpTy *V) {
2653 unsigned TypeSize = V->getType()->getScalarSizeInBits();
2654 if (TypeSize == 0)
2655 return false;
2656
2657 unsigned ShiftWidth = TypeSize - 1;
2658 Value *OpL = nullptr, *OpR = nullptr;
2659
2660 // This is the representation of signum we match:
2661 //
2662 // signum(x) == (x >> 63) | (-x >>u 63)
2663 //
2664 // An i1 value is its own signum, so it's correct to match
2665 //
2666 // signum(x) == (x >> 0) | (-x >>u 0)
2667 //
2668 // for i1 values.
2669
2670 auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
2671 auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
2672 auto Signum = m_Or(LHS, RHS);
2673
2674 return Signum.match(V) && OpL == OpR && Val.match(OpL);
2675 }
2676};
2677
2678/// Matches a signum pattern.
2679///
2680/// signum(x) =
2681/// x > 0 -> 1
2682/// x == 0 -> 0
2683/// x < 0 -> -1
2684template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
2685 return Signum_match<Val_t>(V);
2686}
2687
2688template <int Ind, typename Opnd_t> struct ExtractValue_match {
2689 Opnd_t Val;
2690 ExtractValue_match(const Opnd_t &V) : Val(V) {}
2691
2692 template <typename OpTy> bool match(OpTy *V) {
2693 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
2694 // If Ind is -1, don't inspect indices
2695 if (Ind != -1 &&
2696 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
2697 return false;
2698 return Val.match(I->getAggregateOperand());
2699 }
2700 return false;
2701 }
2702};
2703
2704/// Match a single index ExtractValue instruction.
2705/// For example m_ExtractValue<1>(...)
2706template <int Ind, typename Val_t>
2709}
2710
2711/// Match an ExtractValue instruction with any index.
2712/// For example m_ExtractValue(...)
2713template <typename Val_t>
2714inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
2715 return ExtractValue_match<-1, Val_t>(V);
2716}
2717
2718/// Matcher for a single index InsertValue instruction.
2719template <int Ind, typename T0, typename T1> struct InsertValue_match {
2722
2723 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
2724
2725 template <typename OpTy> bool match(OpTy *V) {
2726 if (auto *I = dyn_cast<InsertValueInst>(V)) {
2727 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
2728 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
2729 }
2730 return false;
2731 }
2732};
2733
2734/// Matches a single index InsertValue instruction.
2735template <int Ind, typename Val_t, typename Elt_t>
2737 const Elt_t &Elt) {
2738 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
2739}
2740
2741/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or
2742/// the constant expression
2743/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>`
2744/// under the right conditions determined by DataLayout.
2746 template <typename ITy> bool match(ITy *V) {
2747 if (m_Intrinsic<Intrinsic::vscale>().match(V))
2748 return true;
2749
2750 Value *Ptr;
2751 if (m_PtrToInt(m_Value(Ptr)).match(V)) {
2752 if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
2753 auto *DerefTy =
2754 dyn_cast<ScalableVectorType>(GEP->getSourceElementType());
2755 if (GEP->getNumIndices() == 1 && DerefTy &&
2756 DerefTy->getElementType()->isIntegerTy(8) &&
2757 m_Zero().match(GEP->getPointerOperand()) &&
2758 m_SpecificInt(1).match(GEP->idx_begin()->get()))
2759 return true;
2760 }
2761 }
2762
2763 return false;
2764 }
2765};
2766
2768 return VScaleVal_match();
2769}
2770
2771template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
2775
2776 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
2777
2778 template <typename T> bool match(T *V) {
2779 auto *I = dyn_cast<Instruction>(V);
2780 if (!I || !I->getType()->isIntOrIntVectorTy(1))
2781 return false;
2782
2783 if (I->getOpcode() == Opcode) {
2784 auto *Op0 = I->getOperand(0);
2785 auto *Op1 = I->getOperand(1);
2786 return (L.match(Op0) && R.match(Op1)) ||
2787 (Commutable && L.match(Op1) && R.match(Op0));
2788 }
2789
2790 if (auto *Select = dyn_cast<SelectInst>(I)) {
2791 auto *Cond = Select->getCondition();
2792 auto *TVal = Select->getTrueValue();
2793 auto *FVal = Select->getFalseValue();
2794
2795 // Don't match a scalar select of bool vectors.
2796 // Transforms expect a single type for operands if this matches.
2797 if (Cond->getType() != Select->getType())
2798 return false;
2799
2800 if (Opcode == Instruction::And) {
2801 auto *C = dyn_cast<Constant>(FVal);
2802 if (C && C->isNullValue())
2803 return (L.match(Cond) && R.match(TVal)) ||
2804 (Commutable && L.match(TVal) && R.match(Cond));
2805 } else {
2806 assert(Opcode == Instruction::Or);
2807 auto *C = dyn_cast<Constant>(TVal);
2808 if (C && C->isOneValue())
2809 return (L.match(Cond) && R.match(FVal)) ||
2810 (Commutable && L.match(FVal) && R.match(Cond));
2811 }
2812 }
2813
2814 return false;
2815 }
2816};
2817
2818/// Matches L && R either in the form of L & R or L ? R : false.
2819/// Note that the latter form is poison-blocking.
2820template <typename LHS, typename RHS>
2822 const RHS &R) {
2824}
2825
2826/// Matches L && R where L and R are arbitrary values.
2827inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
2828
2829/// Matches L && R with LHS and RHS in either order.
2830template <typename LHS, typename RHS>
2832m_c_LogicalAnd(const LHS &L, const RHS &R) {
2834}
2835
2836/// Matches L || R either in the form of L | R or L ? true : R.
2837/// Note that the latter form is poison-blocking.
2838template <typename LHS, typename RHS>
2840 const RHS &R) {
2842}
2843
2844/// Matches L || R where L and R are arbitrary values.
2845inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
2846
2847/// Matches L || R with LHS and RHS in either order.
2848template <typename LHS, typename RHS>
2850m_c_LogicalOr(const LHS &L, const RHS &R) {
2852}
2853
2854/// Matches either L && R or L || R,
2855/// either one being in the either binary or logical form.
2856/// Note that the latter form is poison-blocking.
2857template <typename LHS, typename RHS, bool Commutable = false>
2858inline auto m_LogicalOp(const LHS &L, const RHS &R) {
2859 return m_CombineOr(
2862}
2863
2864/// Matches either L && R or L || R where L and R are arbitrary values.
2865inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
2866
2867/// Matches either L && R or L || R with LHS and RHS in either order.
2868template <typename LHS, typename RHS>
2869inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
2870 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
2871}
2872
2873} // end namespace PatternMatch
2874} // end namespace llvm
2875
2876#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:993
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:1022
@ ICMP_SLE
signed less or equal
Definition: InstrTypes.h:1023
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:999
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:1008
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:997
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:998
@ ICMP_UGE
unsigned greater or equal
Definition: InstrTypes.h:1017
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:1016
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:1020
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:1007
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:1018
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:1005
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:1000
@ ICMP_EQ
equal
Definition: InstrTypes.h:1014
@ ICMP_SGE
signed greater or equal
Definition: InstrTypes.h:1021
@ ICMP_ULE
unsigned less or equal
Definition: InstrTypes.h:1019
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:1006
Base class for aggregate constants (with operands).
Definition: Constants.h:399
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:1017
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:268
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
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:306
bool isShift() const
Definition: Instruction.h:259
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)
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
apfloat_match m_APFloatForbidPoison(const APFloat *&Res)
Match APFloat while forbidding poison in splat vector constants.
Definition: PatternMatch.h:322
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
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)
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)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
Definition: PatternMatch.h:918
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.
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
Definition: PatternMatch.h:926
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true > m_c_NUWAdd(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWNeg(const ValTy &V)
Matches a 'Neg' as 'sub nsw 0, V'.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
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
apint_match m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
Definition: PatternMatch.h:300
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:951
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true > m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
auto m_GEP(const OperandTypes &...Ops)
Matches GetElementPtrInst.
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
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.
apint_match m_APIntForbidPoison(const APInt *&Res)
Match APInt while forbidding poison in splat vector constants.
Definition: PatternMatch.h:305
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)
BinOpPred_match< LHS, RHS, is_bitwiselogic_op, true > m_c_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations in either order.
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.
apfloat_match m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
Definition: PatternMatch.h:317
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)
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.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap >, DisjointOr_match< LHS, RHS > > m_NSWAddLike(const LHS &L, const RHS &R)
Match either "add nsw" or "or disjoint".
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
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)
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
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.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap >, DisjointOr_match< LHS, RHS > > m_NUWAddLike(const LHS &L, const RHS &R)
Match either "add nuw" or "or disjoint".
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
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:1722
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1749
AllowReassoc_match(const SubPattern_t &SP)
Definition: PatternMatch.h:74
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:974
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 AllowPoison)
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 AllowPoison)
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:939
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