LLVM 23.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/FMF.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
41#include "llvm/IR/Intrinsics.h"
42#include "llvm/IR/Operator.h"
43#include "llvm/IR/Value.h"
45#include <cstdint>
46
47namespace llvm {
48namespace PatternMatch {
49
50template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
51 return P.match(V);
52}
53
54/// A match functor that can be used as a UnaryPredicate in functional
55/// algorithms like all_of.
56template <typename Val = const Value, typename Pattern>
57auto match_fn(const Pattern &P) {
59}
60
61template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
62 return P.match(Mask);
63}
64
65template <typename SubPattern_t> struct OneUse_match {
66 SubPattern_t SubPattern;
67
68 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
69
70 template <typename OpTy> bool match(OpTy *V) const {
71 return V->hasOneUse() && SubPattern.match(V);
72 }
73};
74
75template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
76 return SubPattern;
77}
78
79template <typename SubPattern_t, int Flag> struct AllowFmf_match {
80 SubPattern_t SubPattern;
82
83 AllowFmf_match(const SubPattern_t &SP) : SubPattern(SP), FMF(Flag) {}
84
85 template <typename OpTy> bool match(OpTy *V) const {
86 auto *I = dyn_cast<FPMathOperator>(V);
87 return I && ((I->getFastMathFlags() & FMF) == FMF) && SubPattern.match(I);
88 }
89};
90
91template <typename T>
93m_AllowReassoc(const T &SubPattern) {
94 return SubPattern;
95}
96
97template <typename T>
99m_AllowReciprocal(const T &SubPattern) {
100 return SubPattern;
101}
102
103template <typename T>
105m_AllowContract(const T &SubPattern) {
106 return SubPattern;
107}
108
109template <typename T>
111m_ApproxFunc(const T &SubPattern) {
112 return SubPattern;
113}
114
115template <typename T>
117 return SubPattern;
118}
119
120template <typename T>
122 return SubPattern;
123}
124
125template <typename T>
127m_NoSignedZeros(const T &SubPattern) {
128 return SubPattern;
129}
130
131template <typename Class> struct class_match {
132 template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
133};
134
135/// Match an arbitrary value and ignore it.
137
138/// Match an arbitrary unary operation and ignore it.
142
143/// Match an arbitrary binary operation and ignore it.
147
148/// Matches any compare instruction and ignore it.
150
151/// Matches any intrinsic call and ignore it.
155
157 static bool check(const Value *V) {
158 if (isa<UndefValue>(V))
159 return true;
160
161 const auto *CA = dyn_cast<ConstantAggregate>(V);
162 if (!CA)
163 return false;
164
167
168 // Either UndefValue, PoisonValue, or an aggregate that only contains
169 // these is accepted by matcher.
170 // CheckValue returns false if CA cannot satisfy this constraint.
171 auto CheckValue = [&](const ConstantAggregate *CA) {
172 for (const Value *Op : CA->operand_values()) {
173 if (isa<UndefValue>(Op))
174 continue;
175
176 const auto *CA = dyn_cast<ConstantAggregate>(Op);
177 if (!CA)
178 return false;
179 if (Seen.insert(CA).second)
180 Worklist.emplace_back(CA);
181 }
182
183 return true;
184 };
185
186 if (!CheckValue(CA))
187 return false;
188
189 while (!Worklist.empty()) {
190 if (!CheckValue(Worklist.pop_back_val()))
191 return false;
192 }
193 return true;
194 }
195 template <typename ITy> bool match(ITy *V) const { return check(V); }
196};
197
198/// Match an arbitrary undef constant. This matches poison as well.
199/// If this is an aggregate and contains a non-aggregate element that is
200/// neither undef nor poison, the aggregate is not matched.
201inline auto m_Undef() { return undef_match(); }
202
203/// Match an arbitrary UndefValue constant.
207
208/// Match an arbitrary poison constant.
212
213/// Match an arbitrary Constant and ignore it.
215
216/// Match an arbitrary ConstantInt and ignore it.
220
221/// Match an arbitrary ConstantFP and ignore it.
225
227 template <typename ITy> bool match(ITy *V) const {
228 auto *C = dyn_cast<Constant>(V);
229 return C && (isa<ConstantExpr>(C) || C->containsConstantExpression());
230 }
231};
232
233/// Match a constant expression or a constant that contains a constant
234/// expression.
236
237template <typename SubPattern_t> struct Splat_match {
238 SubPattern_t SubPattern;
239 Splat_match(const SubPattern_t &SP) : SubPattern(SP) {}
240
241 template <typename OpTy> bool match(OpTy *V) const {
242 if (auto *C = dyn_cast<Constant>(V)) {
243 auto *Splat = C->getSplatValue();
244 return Splat ? SubPattern.match(Splat) : false;
245 }
246 // TODO: Extend to other cases (e.g. shufflevectors).
247 return false;
248 }
249};
250
251/// Match a constant splat. TODO: Extend this to non-constant splats.
252template <typename T>
253inline Splat_match<T> m_ConstantSplat(const T &SubPattern) {
254 return SubPattern;
255}
256
257/// Match an arbitrary basic block value and ignore it.
261
262/// Inverting matcher
263template <typename Ty> struct match_unless {
264 Ty M;
265
266 match_unless(const Ty &Matcher) : M(Matcher) {}
267
268 template <typename ITy> bool match(ITy *V) const { return !M.match(V); }
269};
270
271/// Match if the inner matcher does *NOT* match.
272template <typename Ty> inline match_unless<Ty> m_Unless(const Ty &M) {
273 return match_unless<Ty>(M);
274}
275
276/// Matching combinators
277template <typename LTy, typename RTy> struct match_combine_or {
278 LTy L;
279 RTy R;
280
281 match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
282
283 template <typename ITy> bool match(ITy *V) const {
284 if (L.match(V))
285 return true;
286 if (R.match(V))
287 return true;
288 return false;
289 }
290};
291
292template <typename LTy, typename RTy> struct match_combine_and {
293 LTy L;
294 RTy R;
295
296 match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
297
298 template <typename ITy> bool match(ITy *V) const {
299 if (L.match(V))
300 if (R.match(V))
301 return true;
302 return false;
303 }
304};
305
306/// Combine two pattern matchers matching L || R
307template <typename LTy, typename RTy>
308inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
309 return match_combine_or<LTy, RTy>(L, R);
310}
311
312/// Combine two pattern matchers matching L && R
313template <typename LTy, typename RTy>
314inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
315 return match_combine_and<LTy, RTy>(L, R);
316}
317
318template <typename APTy> struct ap_match {
319 static_assert(std::is_same_v<APTy, APInt> || std::is_same_v<APTy, APFloat>);
321 std::conditional_t<std::is_same_v<APTy, APInt>, ConstantInt, ConstantFP>;
322
323 const APTy *&Res;
325
326 ap_match(const APTy *&Res, bool AllowPoison)
328
329 template <typename ITy> bool match(ITy *V) const {
330 if (auto *CI = dyn_cast<ConstantTy>(V)) {
331 Res = &CI->getValue();
332 return true;
333 }
334 if (V->getType()->isVectorTy())
335 if (const auto *C = dyn_cast<Constant>(V))
336 if (auto *CI =
337 dyn_cast_or_null<ConstantTy>(C->getSplatValue(AllowPoison))) {
338 Res = &CI->getValue();
339 return true;
340 }
341 return false;
342 }
343};
344
345/// Match a ConstantInt or splatted ConstantVector, binding the
346/// specified pointer to the contained APInt.
347inline ap_match<APInt> m_APInt(const APInt *&Res) {
348 // Forbid poison by default to maintain previous behavior.
349 return ap_match<APInt>(Res, /* AllowPoison */ false);
350}
351
352/// Match APInt while allowing poison in splat vector constants.
354 return ap_match<APInt>(Res, /* AllowPoison */ true);
355}
356
357/// Match APInt while forbidding poison in splat vector constants.
359 return ap_match<APInt>(Res, /* AllowPoison */ false);
360}
361
362/// Match a ConstantFP or splatted ConstantVector, binding the
363/// specified pointer to the contained APFloat.
365 // Forbid undefs by default to maintain previous behavior.
366 return ap_match<APFloat>(Res, /* AllowPoison */ false);
367}
368
369/// Match APFloat while allowing poison in splat vector constants.
371 return ap_match<APFloat>(Res, /* AllowPoison */ true);
372}
373
374/// Match APFloat while forbidding poison in splat vector constants.
376 return ap_match<APFloat>(Res, /* AllowPoison */ false);
377}
378
379template <int64_t Val> struct constantint_match {
380 template <typename ITy> bool match(ITy *V) const {
381 if (const auto *CI = dyn_cast<ConstantInt>(V)) {
382 const APInt &CIV = CI->getValue();
383 if (Val >= 0)
384 return CIV == static_cast<uint64_t>(Val);
385 // If Val is negative, and CI is shorter than it, truncate to the right
386 // number of bits. If it is larger, then we have to sign extend. Just
387 // compare their negated values.
388 return -CIV == -Val;
389 }
390 return false;
391 }
392};
393
394/// Match a ConstantInt with a specific value.
395template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
396 return constantint_match<Val>();
397}
398
399/// This helper class is used to match constant scalars, vector splats,
400/// and fixed width vectors that satisfy a specified predicate.
401/// For fixed width vector constants, poison elements are ignored if AllowPoison
402/// is true.
403template <typename Predicate, typename ConstantVal, bool AllowPoison>
404struct cstval_pred_ty : public Predicate {
405 const Constant **Res = nullptr;
406 template <typename ITy> bool match_impl(ITy *V) const {
407 if (const auto *CV = dyn_cast<ConstantVal>(V))
408 return this->isValue(CV->getValue());
409 if (const auto *VTy = dyn_cast<VectorType>(V->getType())) {
410 if (const auto *C = dyn_cast<Constant>(V)) {
411 if (const auto *CV = dyn_cast_or_null<ConstantVal>(C->getSplatValue()))
412 return this->isValue(CV->getValue());
413
414 // Number of elements of a scalable vector unknown at compile time
415 auto *FVTy = dyn_cast<FixedVectorType>(VTy);
416 if (!FVTy)
417 return false;
418
419 // Non-splat vector constant: check each element for a match.
420 unsigned NumElts = FVTy->getNumElements();
421 assert(NumElts != 0 && "Constant vector with no elements?");
422 bool HasNonPoisonElements = false;
423 for (unsigned i = 0; i != NumElts; ++i) {
424 Constant *Elt = C->getAggregateElement(i);
425 if (!Elt)
426 return false;
427 if (AllowPoison && isa<PoisonValue>(Elt))
428 continue;
429 auto *CV = dyn_cast<ConstantVal>(Elt);
430 if (!CV || !this->isValue(CV->getValue()))
431 return false;
432 HasNonPoisonElements = true;
433 }
434 return HasNonPoisonElements;
435 }
436 }
437 return false;
438 }
439
440 template <typename ITy> bool match(ITy *V) const {
441 if (this->match_impl(V)) {
442 if (Res)
443 *Res = cast<Constant>(V);
444 return true;
445 }
446 return false;
447 }
448};
449
450/// specialization of cstval_pred_ty for ConstantInt
451template <typename Predicate, bool AllowPoison = true>
453
454/// specialization of cstval_pred_ty for ConstantFP
455template <typename Predicate>
457 /*AllowPoison=*/true>;
458
459/// This helper class is used to match scalar and vector constants that
460/// satisfy a specified predicate, and bind them to an APInt.
461template <typename Predicate> struct api_pred_ty : public Predicate {
462 const APInt *&Res;
463
464 api_pred_ty(const APInt *&R) : Res(R) {}
465
466 template <typename ITy> bool match(ITy *V) const {
467 if (const auto *CI = dyn_cast<ConstantInt>(V))
468 if (this->isValue(CI->getValue())) {
469 Res = &CI->getValue();
470 return true;
471 }
472 if (V->getType()->isVectorTy())
473 if (const auto *C = dyn_cast<Constant>(V))
474 if (auto *CI = dyn_cast_or_null<ConstantInt>(
475 C->getSplatValue(/*AllowPoison=*/true)))
476 if (this->isValue(CI->getValue())) {
477 Res = &CI->getValue();
478 return true;
479 }
480
481 return false;
482 }
483};
484
485/// This helper class is used to match scalar and vector constants that
486/// satisfy a specified predicate, and bind them to an APFloat.
487/// Poison is allowed in splat vector constants.
488template <typename Predicate> struct apf_pred_ty : public Predicate {
489 const APFloat *&Res;
490
491 apf_pred_ty(const APFloat *&R) : Res(R) {}
492
493 template <typename ITy> bool match(ITy *V) const {
494 if (const auto *CI = dyn_cast<ConstantFP>(V))
495 if (this->isValue(CI->getValue())) {
496 Res = &CI->getValue();
497 return true;
498 }
499 if (V->getType()->isVectorTy())
500 if (const auto *C = dyn_cast<Constant>(V))
501 if (auto *CI = dyn_cast_or_null<ConstantFP>(
502 C->getSplatValue(/* AllowPoison */ true)))
503 if (this->isValue(CI->getValue())) {
504 Res = &CI->getValue();
505 return true;
506 }
507
508 return false;
509 }
510};
511
512///////////////////////////////////////////////////////////////////////////////
513//
514// Encapsulate constant value queries for use in templated predicate matchers.
515// This allows checking if constants match using compound predicates and works
516// with vector constants, possibly with relaxed constraints. For example, ignore
517// undef values.
518//
519///////////////////////////////////////////////////////////////////////////////
520
521template <typename APTy> struct custom_checkfn {
522 function_ref<bool(const APTy &)> CheckFn;
523 bool isValue(const APTy &C) const { return CheckFn(C); }
524};
525
526/// Match an integer or vector where CheckFn(ele) for each element is true.
527/// For vectors, poison elements are assumed to match.
529m_CheckedInt(function_ref<bool(const APInt &)> CheckFn) {
530 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}};
531}
532
534m_CheckedInt(const Constant *&V, function_ref<bool(const APInt &)> CheckFn) {
535 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}, &V};
536}
537
538/// Match a float or vector where CheckFn(ele) for each element is true.
539/// For vectors, poison elements are assumed to match.
541m_CheckedFp(function_ref<bool(const APFloat &)> CheckFn) {
542 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}};
543}
544
546m_CheckedFp(const Constant *&V, function_ref<bool(const APFloat &)> CheckFn) {
547 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}, &V};
548}
549
551 bool isValue(const APInt &C) const { return true; }
552};
553/// Match an integer or vector with any integral constant.
554/// For vectors, this includes constants with undefined elements.
558
560 bool isValue(const APInt &C) const { return C.isShiftedMask(); }
561};
562
566
568 bool isValue(const APInt &C) const { return C.isAllOnes(); }
569};
570/// Match an integer or vector with all bits set.
571/// For vectors, this includes constants with undefined elements.
575
579
581 bool isValue(const APInt &C) const { return C.isMaxSignedValue(); }
582};
583/// Match an integer or vector with values having all bits except for the high
584/// bit set (0x7f...).
585/// For vectors, this includes constants with undefined elements.
590 return V;
591}
592
594 bool isValue(const APInt &C) const { return C.isNegative(); }
595};
596/// Match an integer or vector of negative values.
597/// For vectors, this includes constants with undefined elements.
601inline api_pred_ty<is_negative> m_Negative(const APInt *&V) { return V; }
602
604 bool isValue(const APInt &C) const { return C.isNonNegative(); }
605};
606/// Match an integer or vector of non-negative values.
607/// For vectors, this includes constants with undefined elements.
611inline api_pred_ty<is_nonnegative> m_NonNegative(const APInt *&V) { return V; }
612
614 bool isValue(const APInt &C) const { return C.isStrictlyPositive(); }
615};
616/// Match an integer or vector of strictly positive values.
617/// For vectors, this includes constants with undefined elements.
622 return V;
623}
624
626 bool isValue(const APInt &C) const { return C.isNonPositive(); }
627};
628/// Match an integer or vector of non-positive values.
629/// For vectors, this includes constants with undefined elements.
633inline api_pred_ty<is_nonpositive> m_NonPositive(const APInt *&V) { return V; }
634
635struct is_one {
636 bool isValue(const APInt &C) const { return C.isOne(); }
637};
638/// Match an integer 1 or a vector with all elements equal to 1.
639/// For vectors, this includes constants with undefined elements.
641
643 bool isValue(const APInt &C) const { return C.isZero(); }
644};
645/// Match an integer 0 or a vector with all elements equal to 0.
646/// For vectors, this includes constants with undefined elements.
650
652 bool isValue(const APInt &C) const { return !C.isZero(); }
653};
654/// Match a non-zero integer or a vector with all non-zero elements.
655/// For vectors, this includes constants with undefined elements.
659
660struct is_zero {
661 template <typename ITy> bool match(ITy *V) const {
662 auto *C = dyn_cast<Constant>(V);
663 // FIXME: this should be able to do something for scalable vectors
664 return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C));
665 }
666};
667/// Match any null constant or a vector with all elements equal to 0.
668/// For vectors, this includes constants with undefined elements.
669inline is_zero m_Zero() { return is_zero(); }
670
671struct is_power2 {
672 bool isValue(const APInt &C) const { return C.isPowerOf2(); }
673};
674/// Match an integer or vector power-of-2.
675/// For vectors, this includes constants with undefined elements.
677inline api_pred_ty<is_power2> m_Power2(const APInt *&V) { return V; }
678
680 bool isValue(const APInt &C) const { return C.isNegatedPowerOf2(); }
681};
682/// Match a integer or vector negated power-of-2.
683/// For vectors, this includes constants with undefined elements.
688 return V;
689}
690
692 bool isValue(const APInt &C) const { return !C || C.isNegatedPowerOf2(); }
693};
694/// Match a integer or vector negated power-of-2.
695/// For vectors, this includes constants with undefined elements.
701 return V;
702}
703
705 bool isValue(const APInt &C) const { return !C || C.isPowerOf2(); }
706};
707/// Match an integer or vector of 0 or power-of-2 values.
708/// For vectors, this includes constants with undefined elements.
713 return V;
714}
715
717 bool isValue(const APInt &C) const { return C.isSignMask(); }
718};
719/// Match an integer or vector with only the sign bit(s) set.
720/// For vectors, this includes constants with undefined elements.
724
726 bool isValue(const APInt &C) const { return C.isMask(); }
727};
728/// Match an integer or vector with only the low bit(s) set.
729/// For vectors, this includes constants with undefined elements.
733inline api_pred_ty<is_lowbit_mask> m_LowBitMask(const APInt *&V) { return V; }
734
736 bool isValue(const APInt &C) const { return !C || C.isMask(); }
737};
738/// Match an integer or vector with only the low bit(s) set.
739/// For vectors, this includes constants with undefined elements.
744 return V;
745}
746
749 const APInt *Thr;
750 bool isValue(const APInt &C) const {
751 return ICmpInst::compare(C, *Thr, Pred);
752 }
753};
754/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
755/// to Threshold. For vectors, this includes constants with undefined elements.
759 P.Pred = Predicate;
760 P.Thr = &Threshold;
761 return P;
762}
763
764struct is_nan {
765 bool isValue(const APFloat &C) const { return C.isNaN(); }
766};
767/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
768/// For vectors, this includes constants with undefined elements.
770
771struct is_nonnan {
772 bool isValue(const APFloat &C) const { return !C.isNaN(); }
773};
774/// Match a non-NaN FP constant.
775/// For vectors, this includes constants with undefined elements.
779
780struct is_inf {
781 bool isValue(const APFloat &C) const { return C.isInfinity(); }
782};
783/// Match a positive or negative infinity FP constant.
784/// For vectors, this includes constants with undefined elements.
786
787struct is_noninf {
788 bool isValue(const APFloat &C) const { return !C.isInfinity(); }
789};
790/// Match a non-infinity FP constant, i.e. finite or NaN.
791/// For vectors, this includes constants with undefined elements.
795
796struct is_finite {
797 bool isValue(const APFloat &C) const { return C.isFinite(); }
798};
799/// Match a finite FP constant, i.e. not infinity or NaN.
800/// For vectors, this includes constants with undefined elements.
804inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
805
807 bool isValue(const APFloat &C) const { return C.isFiniteNonZero(); }
808};
809/// Match a finite non-zero FP constant.
810/// For vectors, this includes constants with undefined elements.
815 return V;
816}
817
819 bool isValue(const APFloat &C) const { return C.isZero(); }
820};
821/// Match a floating-point negative zero or positive zero.
822/// For vectors, this includes constants with undefined elements.
826
828 bool isValue(const APFloat &C) const { return C.isPosZero(); }
829};
830/// Match a floating-point positive zero.
831/// For vectors, this includes constants with undefined elements.
835
837 bool isValue(const APFloat &C) const { return C.isNegZero(); }
838};
839/// Match a floating-point negative zero.
840/// For vectors, this includes constants with undefined elements.
844
846 bool isValue(const APFloat &C) const { return C.isNonZero(); }
847};
848/// Match a floating-point non-zero.
849/// For vectors, this includes constants with undefined elements.
853
855 bool isValue(const APFloat &C) const {
856 return !C.isDenormal() && C.isNonZero();
857 }
858};
859
860/// Match a floating-point non-zero that is not a denormal.
861/// For vectors, this includes constants with undefined elements.
865
866///////////////////////////////////////////////////////////////////////////////
867
868template <typename Class> struct bind_ty {
869 Class *&VR;
870
871 bind_ty(Class *&V) : VR(V) {}
872
873 template <typename ITy> bool match(ITy *V) const {
874 if (auto *CV = dyn_cast<Class>(V)) {
875 VR = CV;
876 return true;
877 }
878 return false;
879 }
880};
881
882/// Check whether the value has the given Class and matches the nested
883/// pattern. Capture it into the provided variable if successful.
884template <typename Class, typename MatchTy> struct bind_and_match_ty {
885 Class *&VR;
886 MatchTy Match;
887
888 bind_and_match_ty(Class *&V, const MatchTy &Match) : VR(V), Match(Match) {}
889
890 template <typename ITy> bool match(ITy *V) const {
891 auto *CV = dyn_cast<Class>(V);
892 if (CV && Match.match(V)) {
893 VR = CV;
894 return true;
895 }
896 return false;
897 }
898};
899
900/// Match a value, capturing it if we match.
901inline bind_ty<Value> m_Value(Value *&V) { return V; }
902inline bind_ty<const Value> m_Value(const Value *&V) { return V; }
903
904/// Match against the nested pattern, and capture the value if we match.
905template <typename MatchTy>
907 const MatchTy &Match) {
908 return {V, Match};
909}
910
911/// Match against the nested pattern, and capture the value if we match.
912template <typename MatchTy>
914 const MatchTy &Match) {
915 return {V, Match};
916}
917
918/// Match an instruction, capturing it if we match.
921 return I;
922}
923
924/// Match against the nested pattern, and capture the instruction if we match.
925template <typename MatchTy>
927m_Instruction(Instruction *&I, const MatchTy &Match) {
928 return {I, Match};
929}
930template <typename MatchTy>
932m_Instruction(const Instruction *&I, const MatchTy &Match) {
933 return {I, Match};
934}
935
936/// Match a unary operator, capturing it if we match.
939 return I;
940}
941/// Match a binary operator, capturing it if we match.
944 return I;
945}
946/// Match any intrinsic call, capturing it if we match.
951/// Match a with overflow intrinsic, capturing it if we match.
957 return I;
958}
959
960/// Match an UndefValue, capturing the value if we match.
962
963/// Match a Constant, capturing the value if we match.
965
966/// Match a ConstantInt, capturing the value if we match.
968
969/// Match a ConstantFP, capturing the value if we match.
971
972/// Match a ConstantExpr, capturing the value if we match.
974
975/// Match a basic block value, capturing it if we match.
978 return V;
979}
980
981// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
982// and use m_Unless(m_ConstantExpr).
984 template <typename ITy> static bool isImmConstant(ITy *V) {
985 if (auto *CV = dyn_cast<Constant>(V)) {
986 if (!isa<ConstantExpr>(CV) && !CV->containsConstantExpression())
987 return true;
988
989 if (CV->getType()->isVectorTy()) {
990 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
991 if (!isa<ConstantExpr>(Splat) &&
992 !Splat->containsConstantExpression()) {
993 return true;
994 }
995 }
996 }
997 }
998 return false;
999 }
1000};
1001
1003 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
1004};
1005
1006/// Match an arbitrary immediate Constant and ignore it.
1008
1011
1013
1014 template <typename ITy> bool match(ITy *V) const {
1015 if (isImmConstant(V)) {
1016 VR = cast<Constant>(V);
1017 return true;
1018 }
1019 return false;
1020 }
1021};
1022
1023/// Match an immediate Constant, capturing the value if we match.
1027
1028/// Match a specified Value*.
1030 const Value *Val;
1031
1032 specificval_ty(const Value *V) : Val(V) {}
1033
1034 template <typename ITy> bool match(ITy *V) const { return V == Val; }
1035};
1036
1037/// Match if we have a specific specified value.
1038inline specificval_ty m_Specific(const Value *V) { return V; }
1039
1040/// Stores a reference to the Value *, not the Value * itself,
1041/// thus can be used in commutative matchers.
1042template <typename Class> struct deferredval_ty {
1043 Class *const &Val;
1044
1045 deferredval_ty(Class *const &V) : Val(V) {}
1046
1047 template <typename ITy> bool match(ITy *const V) const { return V == Val; }
1048};
1049
1050/// Like m_Specific(), but works if the specific value to match is determined
1051/// as part of the same match() expression. For example:
1052/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
1053/// bind X before the pattern match starts.
1054/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
1055/// whichever value m_Value(X) populated.
1056inline deferredval_ty<Value> m_Deferred(Value *const &V) { return V; }
1058 return V;
1059}
1060
1061/// Match a specified floating point value or vector of all elements of
1062/// that value.
1064 double Val;
1065
1066 specific_fpval(double V) : Val(V) {}
1067
1068 template <typename ITy> bool match(ITy *V) const {
1069 if (const auto *CFP = dyn_cast<ConstantFP>(V))
1070 return CFP->isExactlyValue(Val);
1071 if (V->getType()->isVectorTy())
1072 if (const auto *C = dyn_cast<Constant>(V))
1073 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
1074 return CFP->isExactlyValue(Val);
1075 return false;
1076 }
1077};
1078
1079/// Match a specific floating point value or vector with all elements
1080/// equal to the value.
1081inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
1082
1083/// Match a float 1.0 or vector with all elements equal to 1.0.
1084inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
1085
1088
1090
1091 template <typename ITy> bool match(ITy *V) const {
1092 const APInt *ConstInt;
1093 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1094 return false;
1095 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1096 if (!ZExtVal)
1097 return false;
1098 VR = *ZExtVal;
1099 return true;
1100 }
1101};
1102
1103/// Match a specified integer value or vector of all elements of that
1104/// value.
1105template <bool AllowPoison> struct specific_intval {
1106 const APInt &Val;
1107
1108 specific_intval(const APInt &V) : Val(V) {}
1109
1110 template <typename ITy> bool match(ITy *V) const {
1111 const auto *CI = dyn_cast<ConstantInt>(V);
1112 if (!CI && V->getType()->isVectorTy())
1113 if (const auto *C = dyn_cast<Constant>(V))
1114 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1115
1116 return CI && APInt::isSameValue(CI->getValue(), Val);
1117 }
1118};
1119
1120template <bool AllowPoison> struct specific_intval64 {
1122
1124
1125 template <typename ITy> bool match(ITy *V) const {
1126 const auto *CI = dyn_cast<ConstantInt>(V);
1127 if (!CI && V->getType()->isVectorTy())
1128 if (const auto *C = dyn_cast<Constant>(V))
1129 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1130
1131 return CI && CI->getValue() == Val;
1132 }
1133};
1134
1135/// Match a specific integer value or vector with all elements equal to
1136/// the value.
1138 return specific_intval<false>(V);
1139}
1140
1144
1148
1152
1153/// Match a ConstantInt and bind to its value. This does not match
1154/// ConstantInts wider than 64-bits.
1156
1157/// Match a specified basic block value.
1160
1162
1163 template <typename ITy> bool match(ITy *V) const {
1164 const auto *BB = dyn_cast<BasicBlock>(V);
1165 return BB && BB == Val;
1166 }
1167};
1168
1169/// Match a specific basic block value.
1171 return specific_bbval(BB);
1172}
1173
1174/// A commutative-friendly version of m_Specific().
1176 return BB;
1177}
1179m_Deferred(const BasicBlock *const &BB) {
1180 return BB;
1181}
1182
1183//===----------------------------------------------------------------------===//
1184// Matcher for any binary operator.
1185//
1186template <typename LHS_t, typename RHS_t, bool Commutable = false>
1190
1191 // The evaluation order is always stable, regardless of Commutability.
1192 // The LHS is always matched first.
1193 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1194
1195 template <typename OpTy> bool match(OpTy *V) const {
1196 if (auto *I = dyn_cast<BinaryOperator>(V))
1197 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1198 (Commutable && L.match(I->getOperand(1)) &&
1199 R.match(I->getOperand(0)));
1200 return false;
1201 }
1202};
1203
1204template <typename LHS, typename RHS>
1205inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1206 return AnyBinaryOp_match<LHS, RHS>(L, R);
1207}
1208
1209//===----------------------------------------------------------------------===//
1210// Matcher for any unary operator.
1211// TODO fuse unary, binary matcher into n-ary matcher
1212//
1213template <typename OP_t> struct AnyUnaryOp_match {
1214 OP_t X;
1215
1216 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1217
1218 template <typename OpTy> bool match(OpTy *V) const {
1219 if (auto *I = dyn_cast<UnaryOperator>(V))
1220 return X.match(I->getOperand(0));
1221 return false;
1222 }
1223};
1224
1225template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1226 return AnyUnaryOp_match<OP_t>(X);
1227}
1228
1229//===----------------------------------------------------------------------===//
1230// Matchers for specific binary operators.
1231//
1232
1233template <typename LHS_t, typename RHS_t, unsigned Opcode,
1234 bool Commutable = false>
1238
1239 // The evaluation order is always stable, regardless of Commutability.
1240 // The LHS is always matched first.
1241 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1242
1243 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1244 if (V->getValueID() == Value::InstructionVal + Opc) {
1245 auto *I = cast<BinaryOperator>(V);
1246 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1247 (Commutable && L.match(I->getOperand(1)) &&
1248 R.match(I->getOperand(0)));
1249 }
1250 return false;
1251 }
1252
1253 template <typename OpTy> bool match(OpTy *V) const {
1254 return match(Opcode, V);
1255 }
1256};
1257
1258template <typename LHS, typename RHS>
1263
1264template <typename LHS, typename RHS>
1269
1270template <typename LHS, typename RHS>
1275
1276template <typename LHS, typename RHS>
1281
1282template <typename Op_t> struct FNeg_match {
1283 Op_t X;
1284
1285 FNeg_match(const Op_t &Op) : X(Op) {}
1286 template <typename OpTy> bool match(OpTy *V) const {
1287 auto *FPMO = dyn_cast<FPMathOperator>(V);
1288 if (!FPMO)
1289 return false;
1290
1291 if (FPMO->getOpcode() == Instruction::FNeg)
1292 return X.match(FPMO->getOperand(0));
1293
1294 if (FPMO->getOpcode() == Instruction::FSub) {
1295 if (FPMO->hasNoSignedZeros()) {
1296 // With 'nsz', any zero goes.
1297 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1298 return false;
1299 } else {
1300 // Without 'nsz', we need fsub -0.0, X exactly.
1301 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1302 return false;
1303 }
1304
1305 return X.match(FPMO->getOperand(1));
1306 }
1307
1308 return false;
1309 }
1310};
1311
1312/// Match 'fneg X' as 'fsub -0.0, X'.
1313template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1314 return FNeg_match<OpTy>(X);
1315}
1316
1317/// Match 'fneg X' as 'fsub +-0.0, X'.
1318template <typename RHS>
1319inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1320m_FNegNSZ(const RHS &X) {
1321 return m_FSub(m_AnyZeroFP(), X);
1322}
1323
1324template <typename LHS, typename RHS>
1329
1330template <typename LHS, typename RHS>
1335
1336template <typename LHS, typename RHS>
1341
1342template <typename LHS, typename RHS>
1347
1348template <typename LHS, typename RHS>
1353
1354template <typename LHS, typename RHS>
1359
1360template <typename LHS, typename RHS>
1365
1366template <typename LHS, typename RHS>
1371
1372template <typename LHS, typename RHS>
1377
1378template <typename LHS, typename RHS>
1383
1384template <typename LHS, typename RHS>
1389
1390template <typename LHS, typename RHS>
1395
1396template <typename LHS, typename RHS>
1401
1402template <typename LHS, typename RHS>
1407
1408template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1411
1413
1414 template <typename OpTy> bool match(OpTy *V) const {
1415 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1416 if (Op->getOpcode() == Opcode)
1417 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1418 L.match(Op->getOperand(0));
1419 }
1420 // Interpreted as shiftop V, 0
1421 R = 0;
1422 return L.match(V);
1423 }
1424};
1425
1426/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1427template <typename LHS>
1432
1433/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1434template <typename LHS>
1439
1440/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1441template <typename LHS>
1446
1447template <typename LHS_t, typename RHS_t, unsigned Opcode,
1448 unsigned WrapFlags = 0, bool Commutable = false>
1452
1454 : L(LHS), R(RHS) {}
1455
1456 template <typename OpTy> bool match(OpTy *V) const {
1457 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1458 if (Op->getOpcode() != Opcode)
1459 return false;
1461 !Op->hasNoUnsignedWrap())
1462 return false;
1463 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1464 !Op->hasNoSignedWrap())
1465 return false;
1466 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1467 (Commutable && L.match(Op->getOperand(1)) &&
1468 R.match(Op->getOperand(0)));
1469 }
1470 return false;
1471 }
1472};
1473
1474template <typename LHS, typename RHS>
1475inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1477m_NSWAdd(const LHS &L, const RHS &R) {
1478 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1480 R);
1481}
1482template <typename LHS, typename RHS>
1483inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1485m_c_NSWAdd(const LHS &L, const RHS &R) {
1486 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1488 true>(L, R);
1489}
1490template <typename LHS, typename RHS>
1491inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1493m_NSWSub(const LHS &L, const RHS &R) {
1494 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1496 R);
1497}
1498template <typename LHS, typename RHS>
1499inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1501m_NSWMul(const LHS &L, const RHS &R) {
1502 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1504 R);
1505}
1506template <typename LHS, typename RHS>
1507inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1509m_NSWShl(const LHS &L, const RHS &R) {
1510 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1512 R);
1513}
1514
1515template <typename LHS, typename RHS>
1516inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1518m_NUWAdd(const LHS &L, const RHS &R) {
1519 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1521 L, R);
1522}
1523
1524template <typename LHS, typename RHS>
1526 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1527m_c_NUWAdd(const LHS &L, const RHS &R) {
1528 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1530 true>(L, R);
1531}
1532
1533template <typename LHS, typename RHS>
1534inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1536m_NUWSub(const LHS &L, const RHS &R) {
1537 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1539 L, R);
1540}
1541template <typename LHS, typename RHS>
1542inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1544m_NUWMul(const LHS &L, const RHS &R) {
1545 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1547 L, R);
1548}
1549template <typename LHS, typename RHS>
1550inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1552m_NUWShl(const LHS &L, const RHS &R) {
1553 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1555 L, R);
1556}
1557
1558template <typename LHS_t, typename RHS_t, bool Commutable = false>
1560 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1561 unsigned Opcode;
1562
1564 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1565
1566 template <typename OpTy> bool match(OpTy *V) const {
1568 }
1569};
1570
1571/// Matches a specific opcode.
1572template <typename LHS, typename RHS>
1573inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1574 const RHS &R) {
1575 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1576}
1577
1578template <typename LHS, typename RHS, bool Commutable = false>
1582
1583 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1584
1585 template <typename OpTy> bool match(OpTy *V) const {
1586 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1587 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1588 if (!PDI->isDisjoint())
1589 return false;
1590 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1591 (Commutable && L.match(PDI->getOperand(1)) &&
1592 R.match(PDI->getOperand(0)));
1593 }
1594 return false;
1595 }
1596};
1597
1598template <typename LHS, typename RHS>
1600 return DisjointOr_match<LHS, RHS>(L, R);
1601}
1602
1603template <typename LHS, typename RHS>
1605 const RHS &R) {
1607}
1608
1609/// Match either "add" or "or disjoint".
1610template <typename LHS, typename RHS>
1613m_AddLike(const LHS &L, const RHS &R) {
1614 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1615}
1616
1617/// Match either "add nsw" or "or disjoint"
1618template <typename LHS, typename RHS>
1619inline match_combine_or<
1620 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1623m_NSWAddLike(const LHS &L, const RHS &R) {
1624 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1625}
1626
1627/// Match either "add nuw" or "or disjoint"
1628template <typename LHS, typename RHS>
1629inline match_combine_or<
1630 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1633m_NUWAddLike(const LHS &L, const RHS &R) {
1634 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1635}
1636
1637template <typename LHS, typename RHS>
1641
1642 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1643
1644 template <typename OpTy> bool match(OpTy *V) const {
1645 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1646 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1647 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1648 ; // Pass
1649 else if (Op->getOpcode() != Instruction::Xor)
1650 return false;
1651 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1652 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1653 }
1654 return false;
1655 }
1656};
1657
1658/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1659/// Only commutative matcher as the `sub` will need to swap the L and R.
1660template <typename LHS, typename RHS>
1661inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1662 return XorLike_match<LHS, RHS>(L, R);
1663}
1664
1665//===----------------------------------------------------------------------===//
1666// Class that matches a group of binary opcodes.
1667//
1668template <typename LHS_t, typename RHS_t, typename Predicate,
1669 bool Commutable = false>
1670struct BinOpPred_match : Predicate {
1673
1674 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1675
1676 template <typename OpTy> bool match(OpTy *V) const {
1677 if (auto *I = dyn_cast<Instruction>(V))
1678 return this->isOpType(I->getOpcode()) &&
1679 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1680 (Commutable && L.match(I->getOperand(1)) &&
1681 R.match(I->getOperand(0))));
1682 return false;
1683 }
1684};
1685
1687 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1688};
1689
1691 bool isOpType(unsigned Opcode) const {
1692 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1693 }
1694};
1695
1697 bool isOpType(unsigned Opcode) const {
1698 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1699 }
1700};
1701
1703 bool isOpType(unsigned Opcode) const {
1704 return Instruction::isBitwiseLogicOp(Opcode);
1705 }
1706};
1707
1709 bool isOpType(unsigned Opcode) const {
1710 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1711 }
1712};
1713
1715 bool isOpType(unsigned Opcode) const {
1716 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1717 }
1718};
1719
1720/// Matches shift operations.
1721template <typename LHS, typename RHS>
1723 const RHS &R) {
1725}
1726
1727/// Matches logical shift operations.
1728template <typename LHS, typename RHS>
1733
1734/// Matches logical shift operations.
1735template <typename LHS, typename RHS>
1737m_LogicalShift(const LHS &L, const RHS &R) {
1739}
1740
1741/// Matches bitwise logic operations.
1742template <typename LHS, typename RHS>
1744m_BitwiseLogic(const LHS &L, const RHS &R) {
1746}
1747
1748/// Matches bitwise logic operations in either order.
1749template <typename LHS, typename RHS>
1754
1755/// Matches integer division operations.
1756template <typename LHS, typename RHS>
1758 const RHS &R) {
1760}
1761
1762/// Matches integer remainder operations.
1763template <typename LHS, typename RHS>
1765 const RHS &R) {
1767}
1768
1769//===----------------------------------------------------------------------===//
1770// Class that matches exact binary ops.
1771//
1772template <typename SubPattern_t> struct Exact_match {
1773 SubPattern_t SubPattern;
1774
1775 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1776
1777 template <typename OpTy> bool match(OpTy *V) const {
1778 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1779 return PEO->isExact() && SubPattern.match(V);
1780 return false;
1781 }
1782};
1783
1784template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1785 return SubPattern;
1786}
1787
1788//===----------------------------------------------------------------------===//
1789// Matchers for CmpInst classes
1790//
1791
1792template <typename LHS_t, typename RHS_t, typename Class,
1793 bool Commutable = false>
1798
1799 // The evaluation order is always stable, regardless of Commutability.
1800 // The LHS is always matched first.
1802 : Predicate(&Pred), L(LHS), R(RHS) {}
1804 : Predicate(nullptr), L(LHS), R(RHS) {}
1805
1806 template <typename OpTy> bool match(OpTy *V) const {
1807 if (auto *I = dyn_cast<Class>(V)) {
1808 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1809 if (Predicate)
1811 return true;
1812 }
1813 if (Commutable && L.match(I->getOperand(1)) &&
1814 R.match(I->getOperand(0))) {
1815 if (Predicate)
1817 return true;
1818 }
1819 }
1820 return false;
1821 }
1822};
1823
1824template <typename LHS, typename RHS>
1826 const RHS &R) {
1827 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1828}
1829
1830template <typename LHS, typename RHS>
1832 const LHS &L, const RHS &R) {
1833 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1834}
1835
1836template <typename LHS, typename RHS>
1838 const LHS &L, const RHS &R) {
1839 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1840}
1841
1842template <typename LHS, typename RHS>
1845}
1846
1847template <typename LHS, typename RHS>
1850}
1851
1852template <typename LHS, typename RHS>
1855}
1856
1857// Same as CmpClass, but instead of saving Pred as out output variable, match a
1858// specific input pred for equality.
1859template <typename LHS_t, typename RHS_t, typename Class,
1860 bool Commutable = false>
1865
1867 : Predicate(Pred), L(LHS), R(RHS) {}
1868
1869 template <typename OpTy> bool match(OpTy *V) const {
1870 if (auto *I = dyn_cast<Class>(V)) {
1872 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1873 return true;
1874 if constexpr (Commutable) {
1877 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1878 return true;
1879 }
1880 }
1881
1882 return false;
1883 }
1884};
1885
1886template <typename LHS, typename RHS>
1888m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1889 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1890}
1891
1892template <typename LHS, typename RHS>
1894m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1895 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1896}
1897
1898template <typename LHS, typename RHS>
1900m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1902}
1903
1904template <typename LHS, typename RHS>
1906m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1907 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1908}
1909
1910//===----------------------------------------------------------------------===//
1911// Matchers for instructions with a given opcode and number of operands.
1912//
1913
1914/// Matches instructions with Opcode and three operands.
1915template <typename T0, unsigned Opcode> struct OneOps_match {
1917
1918 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1919
1920 template <typename OpTy> bool match(OpTy *V) const {
1921 if (V->getValueID() == Value::InstructionVal + Opcode) {
1922 auto *I = cast<Instruction>(V);
1923 return Op1.match(I->getOperand(0));
1924 }
1925 return false;
1926 }
1927};
1928
1929/// Matches instructions with Opcode and three operands.
1930template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1933
1934 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1935
1936 template <typename OpTy> bool match(OpTy *V) const {
1937 if (V->getValueID() == Value::InstructionVal + Opcode) {
1938 auto *I = cast<Instruction>(V);
1939 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1940 }
1941 return false;
1942 }
1943};
1944
1945/// Matches instructions with Opcode and three operands.
1946template <typename T0, typename T1, typename T2, unsigned Opcode,
1947 bool CommutableOp2Op3 = false>
1952
1953 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1954 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1955
1956 template <typename OpTy> bool match(OpTy *V) const {
1957 if (V->getValueID() == Value::InstructionVal + Opcode) {
1958 auto *I = cast<Instruction>(V);
1959 if (!Op1.match(I->getOperand(0)))
1960 return false;
1961 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1962 return true;
1963 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1964 Op3.match(I->getOperand(1));
1965 }
1966 return false;
1967 }
1968};
1969
1970/// Matches instructions with Opcode and any number of operands
1971template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1972 std::tuple<OperandTypes...> Operands;
1973
1974 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1975
1976 // Operand matching works by recursively calling match_operands, matching the
1977 // operands left to right. The first version is called for each operand but
1978 // the last, for which the second version is called. The second version of
1979 // match_operands is also used to match each individual operand.
1980 template <int Idx, int Last>
1981 std::enable_if_t<Idx != Last, bool>
1985
1986 template <int Idx, int Last>
1987 std::enable_if_t<Idx == Last, bool>
1989 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1990 }
1991
1992 template <typename OpTy> bool match(OpTy *V) const {
1993 if (V->getValueID() == Value::InstructionVal + Opcode) {
1994 auto *I = cast<Instruction>(V);
1995 return I->getNumOperands() == sizeof...(OperandTypes) &&
1996 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1997 }
1998 return false;
1999 }
2000};
2001
2002/// Matches SelectInst.
2003template <typename Cond, typename LHS, typename RHS>
2005m_Select(const Cond &C, const LHS &L, const RHS &R) {
2007}
2008
2009/// This matches a select of two constants, e.g.:
2010/// m_SelectCst<-1, 0>(m_Value(V))
2011template <int64_t L, int64_t R, typename Cond>
2013 Instruction::Select>
2016}
2017
2018/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
2019template <typename LHS, typename RHS>
2020inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
2021m_c_Select(const LHS &L, const RHS &R) {
2022 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
2023 true>(m_Value(), L, R);
2024}
2025
2026/// Matches FreezeInst.
2027template <typename OpTy>
2031
2032/// Matches InsertElementInst.
2033template <typename Val_t, typename Elt_t, typename Idx_t>
2035m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
2037 Val, Elt, Idx);
2038}
2039
2040/// Matches ExtractElementInst.
2041template <typename Val_t, typename Idx_t>
2043m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
2045}
2046
2047/// Matches shuffle.
2048template <typename T0, typename T1, typename T2> struct Shuffle_match {
2052
2053 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
2054 : Op1(Op1), Op2(Op2), Mask(Mask) {}
2055
2056 template <typename OpTy> bool match(OpTy *V) const {
2057 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
2058 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
2059 Mask.match(I->getShuffleMask());
2060 }
2061 return false;
2062 }
2063};
2064
2065struct m_Mask {
2068 bool match(ArrayRef<int> Mask) const {
2069 MaskRef = Mask;
2070 return true;
2071 }
2072};
2073
2075 bool match(ArrayRef<int> Mask) const {
2076 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
2077 }
2078};
2079
2083 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
2084};
2085
2089 bool match(ArrayRef<int> Mask) const {
2090 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2091 if (First == Mask.end())
2092 return false;
2093 SplatIndex = *First;
2094 return all_of(Mask,
2095 [First](int Elem) { return Elem == *First || Elem == -1; });
2096 }
2097};
2098
2099template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2100 PointerOpTy PointerOp;
2101 OffsetOpTy OffsetOp;
2102
2103 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2105
2106 template <typename OpTy> bool match(OpTy *V) const {
2107 auto *GEP = dyn_cast<GEPOperator>(V);
2108 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2109 PointerOp.match(GEP->getPointerOperand()) &&
2110 OffsetOp.match(GEP->idx_begin()->get());
2111 }
2112};
2113
2114/// Matches ShuffleVectorInst independently of mask value.
2115template <typename V1_t, typename V2_t>
2117m_Shuffle(const V1_t &v1, const V2_t &v2) {
2119}
2120
2121template <typename V1_t, typename V2_t, typename Mask_t>
2123m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2125}
2126
2127/// Matches LoadInst.
2128template <typename OpTy>
2132
2133/// Matches StoreInst.
2134template <typename ValueOpTy, typename PointerOpTy>
2136m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2138 PointerOp);
2139}
2140
2141/// Matches GetElementPtrInst.
2142template <typename... OperandTypes>
2143inline auto m_GEP(const OperandTypes &...Ops) {
2144 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2145}
2146
2147/// Matches GEP with i8 source element type
2148template <typename PointerOpTy, typename OffsetOpTy>
2150m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2152}
2153
2154//===----------------------------------------------------------------------===//
2155// Matchers for CastInst classes
2156//
2157
2158template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2159 Op_t Op;
2160
2161 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2162
2163 template <typename OpTy> bool match(OpTy *V) const {
2164 if (auto *O = dyn_cast<Operator>(V))
2165 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2166 return false;
2167 }
2168};
2169
2170template <typename Op_t, typename Class> struct CastInst_match {
2171 Op_t Op;
2172
2173 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2174
2175 template <typename OpTy> bool match(OpTy *V) const {
2176 if (auto *I = dyn_cast<Class>(V))
2177 return Op.match(I->getOperand(0));
2178 return false;
2179 }
2180};
2181
2182template <typename Op_t> struct PtrToIntSameSize_match {
2184 Op_t Op;
2185
2186 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2187 : DL(DL), Op(OpMatch) {}
2188
2189 template <typename OpTy> bool match(OpTy *V) const {
2190 if (auto *O = dyn_cast<Operator>(V))
2191 return O->getOpcode() == Instruction::PtrToInt &&
2192 DL.getTypeSizeInBits(O->getType()) ==
2193 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2194 Op.match(O->getOperand(0));
2195 return false;
2196 }
2197};
2198
2199template <typename Op_t> struct NNegZExt_match {
2200 Op_t Op;
2201
2202 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2203
2204 template <typename OpTy> bool match(OpTy *V) const {
2205 if (auto *I = dyn_cast<ZExtInst>(V))
2206 return I->hasNonNeg() && Op.match(I->getOperand(0));
2207 return false;
2208 }
2209};
2210
2211template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2212 Op_t Op;
2213
2214 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2215
2216 template <typename OpTy> bool match(OpTy *V) const {
2217 if (auto *I = dyn_cast<TruncInst>(V))
2218 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2219 Op.match(I->getOperand(0));
2220 return false;
2221 }
2222};
2223
2224/// Matches BitCast.
2225template <typename OpTy>
2230
2231template <typename Op_t> struct ElementWiseBitCast_match {
2232 Op_t Op;
2233
2234 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2235
2236 template <typename OpTy> bool match(OpTy *V) const {
2237 auto *I = dyn_cast<BitCastInst>(V);
2238 if (!I)
2239 return false;
2240 Type *SrcType = I->getSrcTy();
2241 Type *DstType = I->getType();
2242 // Make sure the bitcast doesn't change between scalar and vector and
2243 // doesn't change the number of vector elements.
2244 if (SrcType->isVectorTy() != DstType->isVectorTy())
2245 return false;
2246 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2247 SrcVecTy && SrcVecTy->getElementCount() !=
2248 cast<VectorType>(DstType)->getElementCount())
2249 return false;
2250 return Op.match(I->getOperand(0));
2251 }
2252};
2253
2254template <typename OpTy>
2258
2259/// Matches PtrToInt.
2260template <typename OpTy>
2265
2266template <typename OpTy>
2271
2272/// Matches PtrToAddr.
2273template <typename OpTy>
2278
2279/// Matches PtrToInt or PtrToAddr.
2280template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2282}
2283
2284/// Matches IntToPtr.
2285template <typename OpTy>
2290
2291/// Matches any cast or self. Used to ignore casts.
2292template <typename OpTy>
2294m_CastOrSelf(const OpTy &Op) {
2296}
2297
2298/// Matches Trunc.
2299template <typename OpTy>
2303
2304/// Matches trunc nuw.
2305template <typename OpTy>
2310
2311/// Matches trunc nsw.
2312template <typename OpTy>
2317
2318template <typename OpTy>
2320m_TruncOrSelf(const OpTy &Op) {
2321 return m_CombineOr(m_Trunc(Op), Op);
2322}
2323
2324/// Matches SExt.
2325template <typename OpTy>
2329
2330/// Matches ZExt.
2331template <typename OpTy>
2335
2336template <typename OpTy>
2338 return NNegZExt_match<OpTy>(Op);
2339}
2340
2341template <typename OpTy>
2343m_ZExtOrSelf(const OpTy &Op) {
2344 return m_CombineOr(m_ZExt(Op), Op);
2345}
2346
2347template <typename OpTy>
2349m_SExtOrSelf(const OpTy &Op) {
2350 return m_CombineOr(m_SExt(Op), Op);
2351}
2352
2353/// Match either "sext" or "zext nneg".
2354template <typename OpTy>
2356m_SExtLike(const OpTy &Op) {
2357 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2358}
2359
2360template <typename OpTy>
2363m_ZExtOrSExt(const OpTy &Op) {
2364 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2365}
2366
2367template <typename OpTy>
2370 OpTy>
2372 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2373}
2374
2375template <typename OpTy>
2378 OpTy>
2381}
2382
2383template <typename OpTy>
2387
2388template <typename OpTy>
2392
2393template <typename OpTy>
2397
2398template <typename OpTy>
2402
2403template <typename OpTy>
2407
2408template <typename OpTy>
2412
2413//===----------------------------------------------------------------------===//
2414// Matchers for control flow.
2415//
2416
2417struct br_match {
2419
2421
2422 template <typename OpTy> bool match(OpTy *V) const {
2423 if (auto *BI = dyn_cast<BranchInst>(V))
2424 if (BI->isUnconditional()) {
2425 Succ = BI->getSuccessor(0);
2426 return true;
2427 }
2428 return false;
2429 }
2430};
2431
2432inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2433
2434template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2436 Cond_t Cond;
2437 TrueBlock_t T;
2438 FalseBlock_t F;
2439
2440 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2441 : Cond(C), T(t), F(f) {}
2442
2443 template <typename OpTy> bool match(OpTy *V) const {
2444 if (auto *BI = dyn_cast<BranchInst>(V))
2445 if (BI->isConditional() && Cond.match(BI->getCondition()))
2446 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2447 return false;
2448 }
2449};
2450
2451template <typename Cond_t>
2457
2458template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2460m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2462}
2463
2464//===----------------------------------------------------------------------===//
2465// Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2466//
2467
2468template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t,
2469 bool Commutable = false>
2471 using PredType = Pred_t;
2474
2475 // The evaluation order is always stable, regardless of Commutability.
2476 // The LHS is always matched first.
2477 MaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2478
2479 template <typename OpTy> bool match(OpTy *V) const {
2480 if (auto *II = dyn_cast<IntrinsicInst>(V)) {
2481 Intrinsic::ID IID = II->getIntrinsicID();
2482 if ((IID == Intrinsic::smax && Pred_t::match(ICmpInst::ICMP_SGT)) ||
2483 (IID == Intrinsic::smin && Pred_t::match(ICmpInst::ICMP_SLT)) ||
2484 (IID == Intrinsic::umax && Pred_t::match(ICmpInst::ICMP_UGT)) ||
2485 (IID == Intrinsic::umin && Pred_t::match(ICmpInst::ICMP_ULT))) {
2486 Value *LHS = II->getOperand(0), *RHS = II->getOperand(1);
2487 return (L.match(LHS) && R.match(RHS)) ||
2488 (Commutable && L.match(RHS) && R.match(LHS));
2489 }
2490 }
2491 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2492 auto *SI = dyn_cast<SelectInst>(V);
2493 if (!SI)
2494 return false;
2495 auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
2496 if (!Cmp)
2497 return false;
2498 // At this point we have a select conditioned on a comparison. Check that
2499 // it is the values returned by the select that are being compared.
2500 auto *TrueVal = SI->getTrueValue();
2501 auto *FalseVal = SI->getFalseValue();
2502 auto *LHS = Cmp->getOperand(0);
2503 auto *RHS = Cmp->getOperand(1);
2504 if ((TrueVal != LHS || FalseVal != RHS) &&
2505 (TrueVal != RHS || FalseVal != LHS))
2506 return false;
2507 typename CmpInst_t::Predicate Pred =
2508 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2509 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2510 if (!Pred_t::match(Pred))
2511 return false;
2512 // It does! Bind the operands.
2513 return (L.match(LHS) && R.match(RHS)) ||
2514 (Commutable && L.match(RHS) && R.match(LHS));
2515 }
2516};
2517
2518/// Helper class for identifying signed max predicates.
2520 static bool match(ICmpInst::Predicate Pred) {
2521 return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE;
2522 }
2523};
2524
2525/// Helper class for identifying signed min predicates.
2527 static bool match(ICmpInst::Predicate Pred) {
2528 return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE;
2529 }
2530};
2531
2532/// Helper class for identifying unsigned max predicates.
2534 static bool match(ICmpInst::Predicate Pred) {
2535 return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE;
2536 }
2537};
2538
2539/// Helper class for identifying unsigned min predicates.
2541 static bool match(ICmpInst::Predicate Pred) {
2542 return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE;
2543 }
2544};
2545
2546/// Helper class for identifying ordered max predicates.
2548 static bool match(FCmpInst::Predicate Pred) {
2549 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2550 }
2551};
2552
2553/// Helper class for identifying ordered min predicates.
2555 static bool match(FCmpInst::Predicate Pred) {
2556 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2557 }
2558};
2559
2560/// Helper class for identifying unordered max predicates.
2562 static bool match(FCmpInst::Predicate Pred) {
2563 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2564 }
2565};
2566
2567/// Helper class for identifying unordered min predicates.
2569 static bool match(FCmpInst::Predicate Pred) {
2570 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2571 }
2572};
2573
2574template <typename LHS, typename RHS>
2579
2580template <typename LHS, typename RHS>
2585
2586template <typename LHS, typename RHS>
2591
2592template <typename LHS, typename RHS>
2597
2598template <typename LHS, typename RHS>
2599inline match_combine_or<
2604m_MaxOrMin(const LHS &L, const RHS &R) {
2605 return m_CombineOr(m_CombineOr(m_SMax(L, R), m_SMin(L, R)),
2606 m_CombineOr(m_UMax(L, R), m_UMin(L, R)));
2607}
2608
2609/// Match an 'ordered' floating point maximum function.
2610/// Floating point has one special value 'NaN'. Therefore, there is no total
2611/// order. However, if we can ignore the 'NaN' value (for example, because of a
2612/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2613/// semantics. In the presence of 'NaN' we have to preserve the original
2614/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2615///
2616/// max(L, R) iff L and R are not NaN
2617/// m_OrdFMax(L, R) = R iff L or R are NaN
2618template <typename LHS, typename RHS>
2623
2624/// Match an 'ordered' floating point minimum function.
2625/// Floating point has one special value 'NaN'. Therefore, there is no total
2626/// order. However, if we can ignore the 'NaN' value (for example, because of a
2627/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2628/// semantics. In the presence of 'NaN' we have to preserve the original
2629/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2630///
2631/// min(L, R) iff L and R are not NaN
2632/// m_OrdFMin(L, R) = R iff L or R are NaN
2633template <typename LHS, typename RHS>
2638
2639/// Match an 'unordered' floating point maximum function.
2640/// Floating point has one special value 'NaN'. Therefore, there is no total
2641/// order. However, if we can ignore the 'NaN' value (for example, because of a
2642/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2643/// semantics. In the presence of 'NaN' we have to preserve the original
2644/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2645///
2646/// max(L, R) iff L and R are not NaN
2647/// m_UnordFMax(L, R) = L iff L or R are NaN
2648template <typename LHS, typename RHS>
2650m_UnordFMax(const LHS &L, const RHS &R) {
2652}
2653
2654/// Match an 'unordered' floating point minimum function.
2655/// Floating point has one special value 'NaN'. Therefore, there is no total
2656/// order. However, if we can ignore the 'NaN' value (for example, because of a
2657/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2658/// semantics. In the presence of 'NaN' we have to preserve the original
2659/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2660///
2661/// min(L, R) iff L and R are not NaN
2662/// m_UnordFMin(L, R) = L iff L or R are NaN
2663template <typename LHS, typename RHS>
2665m_UnordFMin(const LHS &L, const RHS &R) {
2667}
2668
2669/// Match an 'ordered' or 'unordered' floating point maximum function.
2670/// Floating point has one special value 'NaN'. Therefore, there is no total
2671/// order. However, if we can ignore the 'NaN' value (for example, because of a
2672/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2673/// semantics.
2674template <typename LHS, typename RHS>
2681
2682/// Match an 'ordered' or 'unordered' floating point minimum function.
2683/// Floating point has one special value 'NaN'. Therefore, there is no total
2684/// order. However, if we can ignore the 'NaN' value (for example, because of a
2685/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2686/// semantics.
2687template <typename LHS, typename RHS>
2694
2695/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2696/// NOTE: we first match the 'Not' (by matching '-1'),
2697/// and only then match the inner matcher!
2698template <typename ValTy>
2699inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2700m_Not(const ValTy &V) {
2701 return m_c_Xor(m_AllOnes(), V);
2702}
2703
2704template <typename ValTy>
2705inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2706 true>
2707m_NotForbidPoison(const ValTy &V) {
2708 return m_c_Xor(m_AllOnesForbidPoison(), V);
2709}
2710
2711//===----------------------------------------------------------------------===//
2712// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2713// Note that S might be matched to other instructions than AddInst.
2714//
2715
2716template <typename LHS_t, typename RHS_t, typename Sum_t>
2720 Sum_t S;
2721
2722 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2723 : L(L), R(R), S(S) {}
2724
2725 template <typename OpTy> bool match(OpTy *V) const {
2726 Value *ICmpLHS, *ICmpRHS;
2727 CmpPredicate Pred;
2728 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2729 return false;
2730
2731 Value *AddLHS, *AddRHS;
2732 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2733
2734 // (a + b) u< a, (a + b) u< b
2735 if (Pred == ICmpInst::ICMP_ULT)
2736 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2737 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2738
2739 // a >u (a + b), b >u (a + b)
2740 if (Pred == ICmpInst::ICMP_UGT)
2741 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2742 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2743
2744 Value *Op1;
2745 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2746 // (~a) <u b
2747 if (Pred == ICmpInst::ICMP_ULT) {
2748 if (XorExpr.match(ICmpLHS))
2749 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2750 }
2751 // b > u (~a)
2752 if (Pred == ICmpInst::ICMP_UGT) {
2753 if (XorExpr.match(ICmpRHS))
2754 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2755 }
2756
2757 // Match special-case for increment-by-1.
2758 if (Pred == ICmpInst::ICMP_EQ) {
2759 // (a + 1) == 0
2760 // (1 + a) == 0
2761 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2762 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2763 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2764 // 0 == (a + 1)
2765 // 0 == (1 + a)
2766 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2767 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2768 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2769 }
2770
2771 return false;
2772 }
2773};
2774
2775/// Match an icmp instruction checking for unsigned overflow on addition.
2776///
2777/// S is matched to the addition whose result is being checked for overflow, and
2778/// L and R are matched to the LHS and RHS of S.
2779template <typename LHS_t, typename RHS_t, typename Sum_t>
2781m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2783}
2784
2785template <typename Opnd_t> struct Argument_match {
2786 unsigned OpI;
2787 Opnd_t Val;
2788
2789 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2790
2791 template <typename OpTy> bool match(OpTy *V) const {
2792 // FIXME: Should likely be switched to use `CallBase`.
2793 if (const auto *CI = dyn_cast<CallInst>(V))
2794 return Val.match(CI->getArgOperand(OpI));
2795 return false;
2796 }
2797};
2798
2799/// Match an argument.
2800template <unsigned OpI, typename Opnd_t>
2801inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2802 return Argument_match<Opnd_t>(OpI, Op);
2803}
2804
2805/// Intrinsic matchers.
2807 unsigned ID;
2808
2810
2811 template <typename OpTy> bool match(OpTy *V) const {
2812 if (const auto *CI = dyn_cast<CallInst>(V))
2813 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2814 return F->getIntrinsicID() == ID;
2815 return false;
2816 }
2817};
2818
2819/// Intrinsic matches are combinations of ID matchers, and argument
2820/// matchers. Higher arity matcher are defined recursively in terms of and-ing
2821/// them with lower arity matchers. Here's some convenient typedefs for up to
2822/// several arguments, and more can be added as needed
2823template <typename T0 = void, typename T1 = void, typename T2 = void,
2824 typename T3 = void, typename T4 = void, typename T5 = void,
2825 typename T6 = void, typename T7 = void, typename T8 = void,
2826 typename T9 = void, typename T10 = void>
2828template <typename T0> struct m_Intrinsic_Ty<T0> {
2830};
2831template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
2832 using Ty =
2834};
2835template <typename T0, typename T1, typename T2>
2840template <typename T0, typename T1, typename T2, typename T3>
2845
2846template <typename T0, typename T1, typename T2, typename T3, typename T4>
2851
2852template <typename T0, typename T1, typename T2, typename T3, typename T4,
2853 typename T5>
2858
2859/// Match intrinsic calls like this:
2860/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2861template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
2862 return IntrinsicID_match(IntrID);
2863}
2864
2865/// Matches MaskedLoad Intrinsic.
2866template <typename Opnd0, typename Opnd1, typename Opnd2>
2868m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2869 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2870}
2871
2872/// Matches MaskedStore Intrinsic.
2873template <typename Opnd0, typename Opnd1, typename Opnd2>
2875m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2876 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2877}
2878
2879/// Matches MaskedGather Intrinsic.
2880template <typename Opnd0, typename Opnd1, typename Opnd2>
2882m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2883 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2884}
2885
2886template <Intrinsic::ID IntrID, typename T0>
2887inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
2889}
2890
2891template <Intrinsic::ID IntrID, typename T0, typename T1>
2892inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
2893 const T1 &Op1) {
2895}
2896
2897template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
2898inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
2899m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
2900 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
2901}
2902
2903template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2904 typename T3>
2906m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
2907 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
2908}
2909
2910template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2911 typename T3, typename T4>
2913m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
2914 const T4 &Op4) {
2915 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
2916 m_Argument<4>(Op4));
2917}
2918
2919template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
2920 typename T3, typename T4, typename T5>
2922m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
2923 const T4 &Op4, const T5 &Op5) {
2924 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
2925 m_Argument<5>(Op5));
2926}
2927
2928// Helper intrinsic matching specializations.
2929template <typename Opnd0>
2930inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BitReverse(const Opnd0 &Op0) {
2932}
2933
2934template <typename Opnd0>
2935inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BSwap(const Opnd0 &Op0) {
2937}
2938
2939template <typename Opnd0>
2940inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FAbs(const Opnd0 &Op0) {
2941 return m_Intrinsic<Intrinsic::fabs>(Op0);
2942}
2943
2944template <typename Opnd0>
2945inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FCanonicalize(const Opnd0 &Op0) {
2947}
2948
2949template <typename Opnd0, typename Opnd1>
2950inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMinNum(const Opnd0 &Op0,
2951 const Opnd1 &Op1) {
2952 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2953}
2954
2955template <typename Opnd0, typename Opnd1>
2956inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMinimum(const Opnd0 &Op0,
2957 const Opnd1 &Op1) {
2958 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2959}
2960
2961template <typename Opnd0, typename Opnd1>
2963m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2964 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2965}
2966
2967template <typename Opnd0, typename Opnd1>
2968inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMaxNum(const Opnd0 &Op0,
2969 const Opnd1 &Op1) {
2970 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2971}
2972
2973template <typename Opnd0, typename Opnd1>
2974inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMaximum(const Opnd0 &Op0,
2975 const Opnd1 &Op1) {
2976 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2977}
2978
2979template <typename Opnd0, typename Opnd1>
2981m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2982 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2983}
2984
2985template <typename Opnd0, typename Opnd1, typename Opnd2>
2987m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2988 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2989}
2990
2991template <typename Opnd0, typename Opnd1, typename Opnd2>
2993m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2994 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2995}
2996
2997template <typename Opnd0>
2998inline typename m_Intrinsic_Ty<Opnd0>::Ty m_Sqrt(const Opnd0 &Op0) {
2999 return m_Intrinsic<Intrinsic::sqrt>(Op0);
3000}
3001
3002template <typename Opnd0, typename Opnd1>
3003inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_CopySign(const Opnd0 &Op0,
3004 const Opnd1 &Op1) {
3005 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
3006}
3007
3008template <typename Opnd0>
3009inline typename m_Intrinsic_Ty<Opnd0>::Ty m_VecReverse(const Opnd0 &Op0) {
3011}
3012
3013template <typename Opnd0, typename Opnd1, typename Opnd2>
3015m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
3016 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
3017}
3018
3019//===----------------------------------------------------------------------===//
3020// Matchers for two-operands operators with the operators in either order
3021//
3022
3023/// Matches a BinaryOperator with LHS and RHS in either order.
3024template <typename LHS, typename RHS>
3027}
3028
3029/// Matches an ICmp with a predicate over LHS and RHS in either order.
3030/// Swaps the predicate if operands are commuted.
3031template <typename LHS, typename RHS>
3033m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
3035}
3036
3037template <typename LHS, typename RHS>
3042
3043/// Matches a specific opcode with LHS and RHS in either order.
3044template <typename LHS, typename RHS>
3046m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
3047 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
3048}
3049
3050/// Matches a Add with LHS and RHS in either order.
3051template <typename LHS, typename RHS>
3056
3057/// Matches a Mul with LHS and RHS in either order.
3058template <typename LHS, typename RHS>
3063
3064/// Matches an And with LHS and RHS in either order.
3065template <typename LHS, typename RHS>
3070
3071/// Matches an Or with LHS and RHS in either order.
3072template <typename LHS, typename RHS>
3077
3078/// Matches an Xor with LHS and RHS in either order.
3079template <typename LHS, typename RHS>
3084
3085/// Matches a 'Neg' as 'sub 0, V'.
3086template <typename ValTy>
3087inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3088m_Neg(const ValTy &V) {
3089 return m_Sub(m_ZeroInt(), V);
3090}
3091
3092/// Matches a 'Neg' as 'sub nsw 0, V'.
3093template <typename ValTy>
3095 Instruction::Sub,
3097m_NSWNeg(const ValTy &V) {
3098 return m_NSWSub(m_ZeroInt(), V);
3099}
3100
3101/// Matches an SMin with LHS and RHS in either order.
3102template <typename LHS, typename RHS>
3104m_c_SMin(const LHS &L, const RHS &R) {
3106}
3107/// Matches an SMax with LHS and RHS in either order.
3108template <typename LHS, typename RHS>
3110m_c_SMax(const LHS &L, const RHS &R) {
3112}
3113/// Matches a UMin with LHS and RHS in either order.
3114template <typename LHS, typename RHS>
3116m_c_UMin(const LHS &L, const RHS &R) {
3118}
3119/// Matches a UMax with LHS and RHS in either order.
3120template <typename LHS, typename RHS>
3122m_c_UMax(const LHS &L, const RHS &R) {
3124}
3125
3126template <typename LHS, typename RHS>
3127inline match_combine_or<
3132m_c_MaxOrMin(const LHS &L, const RHS &R) {
3133 return m_CombineOr(m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R)),
3134 m_CombineOr(m_c_UMax(L, R), m_c_UMin(L, R)));
3135}
3136
3137template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3141
3142 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3143
3144 template <typename OpTy> bool match(OpTy *V) const {
3145 const auto *II = dyn_cast<IntrinsicInst>(V);
3146 if (!II || II->getIntrinsicID() != IntrID)
3147 return false;
3148 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3149 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3150 }
3151};
3152
3153template <Intrinsic::ID IntrID, typename T0, typename T1>
3155m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3157}
3158
3159/// Matches FAdd with LHS and RHS in either order.
3160template <typename LHS, typename RHS>
3162m_c_FAdd(const LHS &L, const RHS &R) {
3164}
3165
3166/// Matches FMul with LHS and RHS in either order.
3167template <typename LHS, typename RHS>
3169m_c_FMul(const LHS &L, const RHS &R) {
3171}
3172
3173template <typename Opnd_t> struct Signum_match {
3174 Opnd_t Val;
3175 Signum_match(const Opnd_t &V) : Val(V) {}
3176
3177 template <typename OpTy> bool match(OpTy *V) const {
3178 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3179 if (TypeSize == 0)
3180 return false;
3181
3182 unsigned ShiftWidth = TypeSize - 1;
3183 Value *Op;
3184
3185 // This is the representation of signum we match:
3186 //
3187 // signum(x) == (x >> 63) | (-x >>u 63)
3188 //
3189 // An i1 value is its own signum, so it's correct to match
3190 //
3191 // signum(x) == (x >> 0) | (-x >>u 0)
3192 //
3193 // for i1 values.
3194
3195 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3196 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3197 auto Signum = m_c_Or(LHS, RHS);
3198
3199 return Signum.match(V) && Val.match(Op);
3200 }
3201};
3202
3203/// Matches a signum pattern.
3204///
3205/// signum(x) =
3206/// x > 0 -> 1
3207/// x == 0 -> 0
3208/// x < 0 -> -1
3209template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3210 return Signum_match<Val_t>(V);
3211}
3212
3213template <int Ind, typename Opnd_t> struct ExtractValue_match {
3214 Opnd_t Val;
3215 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3216
3217 template <typename OpTy> bool match(OpTy *V) const {
3218 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3219 // If Ind is -1, don't inspect indices
3220 if (Ind != -1 &&
3221 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3222 return false;
3223 return Val.match(I->getAggregateOperand());
3224 }
3225 return false;
3226 }
3227};
3228
3229/// Match a single index ExtractValue instruction.
3230/// For example m_ExtractValue<1>(...)
3231template <int Ind, typename Val_t>
3235
3236/// Match an ExtractValue instruction with any index.
3237/// For example m_ExtractValue(...)
3238template <typename Val_t>
3239inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3240 return ExtractValue_match<-1, Val_t>(V);
3241}
3242
3243/// Matcher for a single index InsertValue instruction.
3244template <int Ind, typename T0, typename T1> struct InsertValue_match {
3247
3248 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3249
3250 template <typename OpTy> bool match(OpTy *V) const {
3251 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3252 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3253 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3254 }
3255 return false;
3256 }
3257};
3258
3259/// Matches a single index InsertValue instruction.
3260template <int Ind, typename Val_t, typename Elt_t>
3262 const Elt_t &Elt) {
3263 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3264}
3265
3266/// Matches a call to `llvm.vscale()`.
3268
3269template <typename Opnd0, typename Opnd1>
3271m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3273}
3274
3275template <typename Opnd>
3279
3280template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3284
3285 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3286
3287 template <typename T> bool match(T *V) const {
3288 auto *I = dyn_cast<Instruction>(V);
3289 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3290 return false;
3291
3292 if (I->getOpcode() == Opcode) {
3293 auto *Op0 = I->getOperand(0);
3294 auto *Op1 = I->getOperand(1);
3295 return (L.match(Op0) && R.match(Op1)) ||
3296 (Commutable && L.match(Op1) && R.match(Op0));
3297 }
3298
3299 if (auto *Select = dyn_cast<SelectInst>(I)) {
3300 auto *Cond = Select->getCondition();
3301 auto *TVal = Select->getTrueValue();
3302 auto *FVal = Select->getFalseValue();
3303
3304 // Don't match a scalar select of bool vectors.
3305 // Transforms expect a single type for operands if this matches.
3306 if (Cond->getType() != Select->getType())
3307 return false;
3308
3309 if (Opcode == Instruction::And) {
3310 auto *C = dyn_cast<Constant>(FVal);
3311 if (C && C->isNullValue())
3312 return (L.match(Cond) && R.match(TVal)) ||
3313 (Commutable && L.match(TVal) && R.match(Cond));
3314 } else {
3315 assert(Opcode == Instruction::Or);
3316 auto *C = dyn_cast<Constant>(TVal);
3317 if (C && C->isOneValue())
3318 return (L.match(Cond) && R.match(FVal)) ||
3319 (Commutable && L.match(FVal) && R.match(Cond));
3320 }
3321 }
3322
3323 return false;
3324 }
3325};
3326
3327/// Matches L && R either in the form of L & R or L ? R : false.
3328/// Note that the latter form is poison-blocking.
3329template <typename LHS, typename RHS>
3334
3335/// Matches L && R where L and R are arbitrary values.
3336inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3337
3338/// Matches L && R with LHS and RHS in either order.
3339template <typename LHS, typename RHS>
3341m_c_LogicalAnd(const LHS &L, const RHS &R) {
3343}
3344
3345/// Matches L || R either in the form of L | R or L ? true : R.
3346/// Note that the latter form is poison-blocking.
3347template <typename LHS, typename RHS>
3352
3353/// Matches L || R where L and R are arbitrary values.
3354inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3355
3356/// Matches L || R with LHS and RHS in either order.
3357template <typename LHS, typename RHS>
3359m_c_LogicalOr(const LHS &L, const RHS &R) {
3361}
3362
3363/// Matches either L && R or L || R,
3364/// either one being in the either binary or logical form.
3365/// Note that the latter form is poison-blocking.
3366template <typename LHS, typename RHS, bool Commutable = false>
3372
3373/// Matches either L && R or L || R where L and R are arbitrary values.
3374inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3375
3376/// Matches either L && R or L || R with LHS and RHS in either order.
3377template <typename LHS, typename RHS>
3378inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3379 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3380}
3381
3382} // end namespace PatternMatch
3383} // end namespace llvm
3384
3385#endif // LLVM_IR_PATTERNMATCH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static constexpr unsigned long long mask(BlockVerifier::State S)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Hexagon Common GEP
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
#define T1
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
Definition APInt.h:1567
static bool isSameValue(const APInt &I1, const APInt &I2, bool SignedCompare=false)
Determine if two APInts have the same value, after zero-extending or sign-extending (if SignedCompare...
Definition APInt.h:555
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
@ ICMP_SLT
signed less than
Definition InstrTypes.h:705
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:706
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:682
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:691
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:680
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:681
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:703
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:690
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:688
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:683
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:704
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:702
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:689
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static LLVM_ABI CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
static LLVM_ABI CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
Base class for aggregate constants (with operands).
Definition Constants.h:413
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1130
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:282
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
static LLVM_ABI 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.
bool isShift() const
A wrapper class for inspecting calls to intrinsic functions.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
'undef' values are things that do not have specified contents.
Definition Constants.h:1445
LLVM Value Representation.
Definition Value.h:75
Base class of all SIMD vector types.
Represents an op.with.overflow intrinsic.
An efficient, type-erasing, non-owning reference to a callable.
@ C
The default llvm calling convention, compatible with C.
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.
class_match< PoisonValue > m_Poison()
Match an arbitrary poison constant.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
ShiftLike_match< LHS, Instruction::LShr > m_LShrOrSelf(const LHS &L, uint64_t &R)
Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
AllowFmf_match< T, FastMathFlags::NoSignedZeros > m_NoSignedZeros(const T &SubPattern)
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
m_Intrinsic_Ty< Opnd0 >::Ty m_FCanonicalize(const Opnd0 &Op0)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
AllowFmf_match< T, FastMathFlags::NoInfs > m_NoInfs(const T &SubPattern)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
auto m_PtrToIntOrAddr(const OpTy &Op)
Matches PtrToInt or PtrToAddr.
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedStore Intrinsic.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap, true > m_c_NSWAdd(const LHS &L, const RHS &R)
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, CastInst >, OpTy > m_CastOrSelf(const OpTy &Op)
Matches any cast or self. Used to ignore casts.
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
CommutativeBinaryIntrinsic_match< IntrID, T0, T1 > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
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.
ap_match< APFloat > m_APFloatForbidPoison(const APFloat *&Res)
Match APFloat while forbidding poison in splat vector constants.
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
br_match m_UnconditionalBr(BasicBlock *&Succ)
CastOperator_match< OpTy, Instruction::PtrToAddr > m_PtrToAddr(const OpTy &Op)
Matches PtrToAddr.
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
bool match(Val *V, const Pattern &P)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
class_match< IntrinsicInst > m_AnyIntrinsic()
Matches any intrinsic call and ignore it.
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
cstval_pred_ty< Predicate, ConstantInt, AllowPoison > cst_pred_ty
specialization of cstval_pred_ty for ConstantInt
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1)
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
constantexpr_match m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
auto m_c_XorLike(const LHS &L, const RHS &R)
Match either (xor L, R), (xor R, L) or (sub nuw R, L) iff R.isMask() Only commutative matcher as the ...
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
ap_match< APFloat > m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
ap_match< APFloat > m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
auto match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
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'.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedLoad Intrinsic.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
auto m_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R, either one being in the either binary or logical form.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
IntrinsicID_match m_VScale()
Matches a call to llvm.vscale().
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< CastInst_match< OpTy, SExtInst >, OpTy > m_SExtOrSelf(const OpTy &Op)
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
match_combine_or< MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty >, MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > > m_OrdOrUnordFMin(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point minimum function.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1)
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1)
CastInst_match< OpTy, FPToUIInst > m_FPToUI(const OpTy &Op)
m_Intrinsic_Ty< Opnd0 >::Ty m_Sqrt(const Opnd0 &Op0)
ShiftLike_match< LHS, Instruction::Shl > m_ShlOrSelf(const LHS &L, uint64_t &R)
Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
SpecificCmpClass_match< LHS, RHS, CmpInst > m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
NoWrapTrunc_match< OpTy, TruncInst::NoSignedWrap > m_NSWTrunc(const OpTy &Op)
Matches trunc nsw.
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
OneUse_match< T > m_OneUse(const T &SubPattern)
NNegZExt_match< OpTy > m_NNegZExt(const OpTy &Op)
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
Splat_match< T > m_ConstantSplat(const T &SubPattern)
Match a constant splat. TODO: Extend this to non-constant splats.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true > m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
auto m_GEP(const OperandTypes &...Ops)
Matches GetElementPtrInst.
ap_match< APInt > m_APIntForbidPoison(const APInt *&Res)
Match APInt while forbidding poison in splat vector constants.
AllowFmf_match< T, FastMathFlags::NoNaNs > m_NoNaNs(const T &SubPattern)
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
cst_pred_ty< is_non_zero_int > m_NonZeroInt()
Match a non-zero integer or a vector with all non-zero elements.
ThreeOps_match< decltype(m_Value()), LHS, RHS, Instruction::Select, true > m_c_Select(const LHS &L, const RHS &R)
Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
class_match< ConstantFP > m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
cstfp_pred_ty< is_nonnan > m_NonNaN()
Match a non-NaN FP constant.
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
AllowFmf_match< T, FastMathFlags::AllowReassoc > m_AllowReassoc(const T &SubPattern)
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
cstfp_pred_ty< is_non_zero_not_denormal_fp > m_NonZeroNotDenormalFP()
Match a floating-point non-zero that is not a denormal.
cst_pred_ty< is_all_ones, false > m_AllOnesForbidPoison()
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_bitwiselogic_op, true > m_c_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations in either order.
class_match< UndefValue > m_UndefValue()
Match an arbitrary UndefValue constant.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
AllowFmf_match< T, FastMathFlags::ApproxFunc > m_ApproxFunc(const T &SubPattern)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
match_immconstant_ty m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
cst_pred_ty< is_negated_power2_or_zero > m_NegatedPower2OrZero()
Match a integer or vector negated power-of-2.
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
ShiftLike_match< LHS, Instruction::AShr > m_AShrOrSelf(const LHS &L, uint64_t &R)
Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
cst_pred_ty< custom_checkfn< APInt > > m_CheckedInt(function_ref< bool(const APInt &)> CheckFn)
Match an integer or vector where CheckFn(ele) for each element is true.
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
SpecificCmpClass_match< LHS, RHS, FCmpInst > m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
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".
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedGather Intrinsic.
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
match_combine_or< MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty >, MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true > m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
match_combine_or< match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true >, MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > >, match_combine_or< MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true >, MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > > > m_c_MaxOrMin(const LHS &L, const RHS &R)
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
cstval_pred_ty< Predicate, ConstantFP, true > cstfp_pred_ty
specialization of cstval_pred_ty for ConstantFP
match_combine_or< CastInst_match< OpTy, SExtInst >, NNegZExt_match< OpTy > > m_SExtLike(const OpTy &Op)
Match either "sext" or "zext nneg".
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
class_match< UnaryOperator > m_UnOp()
Match an arbitrary unary operation and ignore it.
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
cstfp_pred_ty< custom_checkfn< APFloat > > m_CheckedFp(function_ref< bool(const APFloat &)> CheckFn)
Match a float or vector where CheckFn(ele) for each element is true.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap >, DisjointOr_match< LHS, RHS > > m_NSWAddLike(const LHS &L, const RHS &R)
Match either "add nsw" or "or disjoint".
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
Exact_match< T > m_Exact(const T &SubPattern)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
UAddWithOverflow_match< LHS_t, RHS_t, Sum_t > m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Match an icmp instruction checking for unsigned overflow on addition.
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_VecReverse(const Opnd0 &Op0)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
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)
AllowFmf_match< T, FastMathFlags::AllowContract > m_AllowContract(const T &SubPattern)
CastInst_match< OpTy, FPTruncInst > m_FPTrunc(const OpTy &Op)
class_match< BasicBlock > m_BasicBlock()
Match an arbitrary basic block value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap >, DisjointOr_match< LHS, RHS > > m_NUWAddLike(const LHS &L, const RHS &R)
Match either "add nuw" or "or disjoint".
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
SpecificCmpClass_match< LHS, RHS, ICmpInst, true > m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
AllowFmf_match< T, FastMathFlags::AllowReciprocal > m_AllowReciprocal(const T &SubPattern)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, TruncInst > >, OpTy > m_ZExtOrTruncOrSelf(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
m_Intrinsic_Ty< Opnd >::Ty m_Deinterleave2(const Opnd &Op)
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr auto bind_back(FnT &&Fn, BindArgsT &&...BindArgs)
C++23 bind_back.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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:1772
AllowFmf_match(const SubPattern_t &SP)
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Matches instructions with Opcode and any number of operands.
std::enable_if_t< Idx==Last, bool > match_operands(const Instruction *I) const
std::enable_if_t< Idx !=Last, bool > match_operands(const Instruction *I) const
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) const
CastInst_match(const Op_t &OpMatch)
CmpClass_match(CmpPredicate &Pred, const LHS_t &LHS, const RHS_t &RHS)
CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R)
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)
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)
ShiftLike_match(const LHS_t &LHS, uint64_t &RHS)
Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
SpecificCmpClass_match(CmpPredicate Pred, const LHS_t &LHS, const RHS_t &RHS)
Splat_match(const SubPattern_t &SP)
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)
XorLike_match(const LHS &L, const RHS &R)
ap_match(const APTy *&Res, bool AllowPoison)
std::conditional_t< std::is_same_v< APTy, APInt >, ConstantInt, ConstantFP > ConstantTy
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
Check whether the value has the given Class and matches the nested pattern.
bind_and_match_ty(Class *&V, const MatchTy &Match)
bool match(ITy *V) const
bool match(OpTy *V) const
br_match(BasicBlock *&Succ)
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
This helper class is used to match constant scalars, vector splats, and fixed width vectors that sati...
bool isValue(const APTy &C) const
function_ref< bool(const APTy &)> CheckFn
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers.
bool match(ITy *const V) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isOpType(unsigned Opcode) const
bool isValue(const APFloat &C) const
bool isValue(const APFloat &C) const
bool isOpType(unsigned Opcode) const
bool isValue(const APFloat &C) const
bool isOpType(unsigned Opcode) const
bool isOpType(unsigned Opcode) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isOpType(unsigned Opcode) const
bool isOpType(unsigned Opcode) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool match(ITy *V) const
match_combine_and< typename m_Intrinsic_Ty< T0, T1, T2, T3, T4 >::Ty, Argument_match< T5 > > Ty
match_combine_and< typename m_Intrinsic_Ty< T0, T1, T2, T3 >::Ty, Argument_match< T4 > > Ty
match_combine_and< typename m_Intrinsic_Ty< T0, T1, T2 >::Ty, Argument_match< T3 > > Ty
match_combine_and< typename m_Intrinsic_Ty< T0, T1 >::Ty, Argument_match< T2 > > Ty
match_combine_and< typename m_Intrinsic_Ty< T0 >::Ty, Argument_match< T1 > > Ty
match_combine_and< IntrinsicID_match, Argument_match< T0 > > Ty
Intrinsic matches are combinations of ID matchers, and argument matchers.
ArrayRef< int > & MaskRef
m_Mask(ArrayRef< int > &MaskRef)
bool match(ArrayRef< int > Mask) const
bool match(ArrayRef< int > Mask) const
m_SpecificMask(ArrayRef< int > Val)
bool match(ArrayRef< int > Mask) const
bool match(ArrayRef< int > Mask) const
match_combine_and(const LTy &Left, const RTy &Right)
match_combine_or(const LTy &Left, const RTy &Right)
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.
Match a specified floating point value or vector of all elements of that value.
Match a specified integer value or vector of all elements of that value.
Match a specified Value*.
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)