LLVM 24.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"
46#include <cstdint>
47#include <utility>
48
49namespace llvm {
50namespace PatternMatch {
51
52using namespace llvm::PatternMatchHelpers;
53
54template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
55 return P.match(V);
56}
57
58/// A match functor that can be used as a UnaryPredicate in functional
59/// algorithms like all_of.
60template <typename Val = const Value, typename Pattern>
61auto match_fn(const Pattern &P) {
63}
64
65template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
66 return P.match(Mask);
67}
68
69template <typename SubPattern_t> struct OneUse_match {
70 SubPattern_t SubPattern;
71
72 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
73
74 template <typename OpTy> bool match(OpTy *V) const {
75 return V->hasOneUse() && SubPattern.match(V);
76 }
77};
78
79template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
80 return SubPattern;
81}
82
83template <typename SubPattern_t, int Flag> struct AllowFmf_match {
84 SubPattern_t SubPattern;
86
87 AllowFmf_match(const SubPattern_t &SP) : SubPattern(SP), FMF(Flag) {}
88
89 template <typename OpTy> bool match(OpTy *V) const {
90 auto *I = dyn_cast<FPMathOperator>(V);
91 return I && ((I->getFastMathFlags() & FMF) == FMF) && SubPattern.match(I);
92 }
93};
94
95template <typename T>
97m_AllowReassoc(const T &SubPattern) {
98 return SubPattern;
99}
100
101template <typename T>
103m_AllowReciprocal(const T &SubPattern) {
104 return SubPattern;
105}
106
107template <typename T>
109m_AllowContract(const T &SubPattern) {
110 return SubPattern;
111}
112
113template <typename T>
115m_ApproxFunc(const T &SubPattern) {
116 return SubPattern;
117}
118
119template <typename T>
121 return SubPattern;
122}
123
124template <typename T>
126 return SubPattern;
127}
128
129template <typename T>
131m_NoSignedZeros(const T &SubPattern) {
132 return SubPattern;
133}
134
135/// Match an arbitrary value and ignore it.
136inline auto m_Value() { return m_Isa<Value>(); }
137
138/// Match an arbitrary unary operation and ignore it.
139inline auto m_UnOp() { return m_Isa<UnaryOperator>(); }
140
141/// Match an arbitrary binary operation and ignore it.
142inline auto m_BinOp() { return m_Isa<BinaryOperator>(); }
143
144/// Matches any compare instruction and ignore it.
145inline auto m_Cmp() { return m_Isa<CmpInst>(); }
146
147/// Matches any intrinsic call and ignore it.
148inline auto m_AnyIntrinsic() { return m_Isa<IntrinsicInst>(); }
149
151private:
152 LLVM_ABI static bool checkAggregate(const ConstantAggregate *CA);
153
154public:
155 static bool check(const Value *V) {
156 if (isa<UndefValue>(V))
157 return true;
158 if (const auto *CA = dyn_cast<ConstantAggregate>(V))
159 return checkAggregate(CA);
160 return false;
161 }
162 template <typename ITy> bool match(ITy *V) const { return check(V); }
163};
164
165/// Match an arbitrary undef constant. This matches poison as well.
166/// If this is an aggregate and contains a non-aggregate element that is
167/// neither undef nor poison, the aggregate is not matched.
168inline auto m_Undef() { return undef_match(); }
169
170/// Match an arbitrary UndefValue constant.
171inline auto m_UndefValue() { return m_Isa<UndefValue>(); }
172
173/// Match an arbitrary poison constant.
174inline auto m_Poison() { return m_Isa<PoisonValue>(); }
175
176/// Match an arbitrary Constant and ignore it.
177inline auto m_Constant() { return m_Isa<Constant>(); }
178
179/// Match an arbitrary ConstantInt and ignore it.
180inline auto m_ConstantInt() { return m_Isa<ConstantInt>(); }
181
182/// Match an arbitrary ConstantFP and ignore it.
183inline auto m_ConstantFP() { return m_Isa<ConstantFP>(); }
184
185template <typename SPTy> struct ContainsMatchingVectorElement_match {
188
189 template <typename ITy> bool match(ITy *V) const {
190 auto *C = dyn_cast<Constant>(V);
191 return C && C->containsMatchingVectorElement(
192 [&](Constant *E) { return SubPattern.match(E); });
193 }
194};
195
196/// Match a vector constant where at least one of its elements matches the
197/// subpattern. Scalable vector constants are not matched. Any bindings in the
198/// subpattern will be bound to the first match.
199template <typename SPTy>
201m_ContainsMatchingVectorElement(const SPTy &SubPattern) {
202 return SubPattern;
203}
204
205/// Match a constant expression or a constant that contains a constant
206/// expression.
211
212template <typename SubPattern_t> struct Splat_match {
213 SubPattern_t SubPattern;
214 Splat_match(const SubPattern_t &SP) : SubPattern(SP) {}
215
216 template <typename OpTy> bool match(OpTy *V) const {
217 if (auto *C = dyn_cast<Constant>(V)) {
218 auto *Splat = C->getSplatValue();
219 return Splat ? SubPattern.match(Splat) : false;
220 }
221
222 auto *Shuffle = dyn_cast<ShuffleVectorInst>(V);
223 if (!Shuffle || !Shuffle->isZeroEltSplat())
224 return false;
225
226 // Look for an insertelement.
227 auto *Insert = dyn_cast<InsertElementInst>(Shuffle->getOperand(0));
228 if (!Insert)
229 return false;
230
231 Value *SplatElt = Insert->getOperand(1);
232 ConstantInt *Idx = dyn_cast<ConstantInt>(Insert->getOperand(2));
233 if (!Idx || !Idx->isZero())
234 return false;
235
236 return SubPattern.match(SplatElt);
237 }
238};
239
240/// Match a vector splat. May be a constant splat or a shufflevector of the
241/// first element.
242template <typename T> inline Splat_match<T> m_Splat(const T &SubPattern) {
243 return SubPattern;
244}
245
246/// Match an arbitrary basic block value and ignore it.
247inline auto m_BasicBlock() { return m_Isa<BasicBlock>(); }
248
249template <typename APTy> struct ap_match {
250 static_assert(std::is_same_v<APTy, APInt> || std::is_same_v<APTy, APFloat>);
252 std::conditional_t<std::is_same_v<APTy, APInt>, ConstantInt, ConstantFP>;
253
254 const APTy *&Res;
256
257 ap_match(const APTy *&Res, bool AllowPoison)
259
260 template <typename ITy> bool match(ITy *V) const {
261 if (auto *CI = dyn_cast<ConstantTy>(V)) {
262 Res = &CI->getValue();
263 return true;
264 }
265 if (V->getType()->isVectorTy())
266 if (const auto *C = dyn_cast<Constant>(V))
267 if (auto *CI =
268 dyn_cast_or_null<ConstantTy>(C->getSplatValue(AllowPoison))) {
269 Res = &CI->getValue();
270 return true;
271 }
272 return false;
273 }
274};
275
276/// Match a ConstantInt or splatted ConstantVector, binding the
277/// specified pointer to the contained APInt.
278inline ap_match<APInt> m_APInt(const APInt *&Res) {
279 // Forbid poison by default to maintain previous behavior.
280 return ap_match<APInt>(Res, /* AllowPoison */ false);
281}
282
283/// Match APInt while allowing poison in splat vector constants.
285 return ap_match<APInt>(Res, /* AllowPoison */ true);
286}
287
288/// Match APInt while forbidding poison in splat vector constants.
290 return ap_match<APInt>(Res, /* AllowPoison */ false);
291}
292
293/// Match a ConstantFP or splatted ConstantVector, binding the
294/// specified pointer to the contained APFloat.
296 // Forbid undefs by default to maintain previous behavior.
297 return ap_match<APFloat>(Res, /* AllowPoison */ false);
298}
299
300/// Match APFloat while allowing poison in splat vector constants.
302 return ap_match<APFloat>(Res, /* AllowPoison */ true);
303}
304
305/// Match APFloat while forbidding poison in splat vector constants.
307 return ap_match<APFloat>(Res, /* AllowPoison */ false);
308}
309
310template <int64_t Val> struct constantint_match {
311 template <typename ITy> bool match(ITy *V) const {
312 if (const auto *CI = dyn_cast<ConstantInt>(V)) {
313 const APInt &CIV = CI->getValue();
314 if (Val >= 0)
315 return CIV == static_cast<uint64_t>(Val);
316 // If Val is negative, and CI is shorter than it, truncate to the right
317 // number of bits. If it is larger, then we have to sign extend. Just
318 // compare their negated values.
319 return -CIV == -Val;
320 }
321 return false;
322 }
323};
324
325/// Match a ConstantInt with a specific value.
326template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
327 return constantint_match<Val>();
328}
329
330/// This helper class is used to match constant scalars, vector splats,
331/// and fixed width vectors that satisfy a specified predicate.
332/// For fixed width vector constants, poison elements are ignored if AllowPoison
333/// is true.
334template <typename Predicate, typename ConstantVal, bool AllowPoison>
335struct cstval_pred_ty : public Predicate {
336private:
337 bool matchVector(const Value *V) const {
338 if (const auto *C = dyn_cast<Constant>(V)) {
339 if (const auto *CV = dyn_cast_or_null<ConstantVal>(C->getSplatValue()))
340 return this->isValue(CV->getValue());
341
342 // Number of elements of a scalable vector unknown at compile time
343 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
344 if (!FVTy)
345 return false;
346
347 // Non-splat vector constant: check each element for a match.
348 unsigned NumElts = FVTy->getNumElements();
349 assert(NumElts != 0 && "Constant vector with no elements?");
350 bool HasNonPoisonElements = false;
351 for (unsigned i = 0; i != NumElts; ++i) {
352 Constant *Elt = C->getAggregateElement(i);
353 if (!Elt)
354 return false;
355 if (AllowPoison && isa<PoisonValue>(Elt))
356 continue;
357 auto *CV = dyn_cast<ConstantVal>(Elt);
358 if (!CV || !this->isValue(CV->getValue()))
359 return false;
360 HasNonPoisonElements = true;
361 }
362 return HasNonPoisonElements;
363 }
364 return false;
365 }
366
367public:
368 const Constant **Res = nullptr;
369 template <typename ITy> bool match_impl(ITy *V) const {
370 if (const auto *CV = dyn_cast<ConstantVal>(V))
371 return this->isValue(CV->getValue());
372 if (isa<VectorType>(V->getType()))
373 return matchVector(V);
374 return false;
375 }
376
377 template <typename ITy> bool match(ITy *V) const {
378 if (this->match_impl(V)) {
379 if (Res)
380 *Res = cast<Constant>(V);
381 return true;
382 }
383 return false;
384 }
385};
386
387/// specialization of cstval_pred_ty for ConstantInt
388template <typename Predicate, bool AllowPoison = true>
390
391/// specialization of cstval_pred_ty for ConstantFP
392template <typename Predicate>
394 /*AllowPoison=*/true>;
395
396/// This helper class is used to match scalar and vector constants that
397/// satisfy a specified predicate, and bind them to an APInt.
398template <typename Predicate> struct api_pred_ty : public Predicate {
399 const APInt *&Res;
400
401 api_pred_ty(const APInt *&R) : Res(R) {}
402
403 template <typename ITy> bool match(ITy *V) const {
404 if (const auto *CI = dyn_cast<ConstantInt>(V))
405 if (this->isValue(CI->getValue())) {
406 Res = &CI->getValue();
407 return true;
408 }
409 if (V->getType()->isVectorTy())
410 if (const auto *C = dyn_cast<Constant>(V))
411 if (auto *CI = dyn_cast_or_null<ConstantInt>(
412 C->getSplatValue(/*AllowPoison=*/true)))
413 if (this->isValue(CI->getValue())) {
414 Res = &CI->getValue();
415 return true;
416 }
417
418 return false;
419 }
420};
421
422/// This helper class is used to match scalar and vector constants that
423/// satisfy a specified predicate, and bind them to an APFloat.
424/// Poison is allowed in splat vector constants.
425template <typename Predicate> struct apf_pred_ty : public Predicate {
426 const APFloat *&Res;
427
428 apf_pred_ty(const APFloat *&R) : Res(R) {}
429
430 template <typename ITy> bool match(ITy *V) const {
431 if (const auto *CI = dyn_cast<ConstantFP>(V))
432 if (this->isValue(CI->getValue())) {
433 Res = &CI->getValue();
434 return true;
435 }
436 if (V->getType()->isVectorTy())
437 if (const auto *C = dyn_cast<Constant>(V))
438 if (auto *CI = dyn_cast_or_null<ConstantFP>(
439 C->getSplatValue(/* AllowPoison */ true)))
440 if (this->isValue(CI->getValue())) {
441 Res = &CI->getValue();
442 return true;
443 }
444
445 return false;
446 }
447};
448
449///////////////////////////////////////////////////////////////////////////////
450//
451// Encapsulate constant value queries for use in templated predicate matchers.
452// This allows checking if constants match using compound predicates and works
453// with vector constants, possibly with relaxed constraints. For example, ignore
454// undef values.
455//
456///////////////////////////////////////////////////////////////////////////////
457
458template <typename APTy> struct custom_checkfn {
459 function_ref<bool(const APTy &)> CheckFn;
460 bool isValue(const APTy &C) const { return CheckFn(C); }
461};
462
463/// Match an integer or vector where CheckFn(ele) for each element is true.
464/// For vectors, poison elements are assumed to match.
466m_CheckedInt(function_ref<bool(const APInt &)> CheckFn) {
467 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}};
468}
469
471m_CheckedInt(const Constant *&V, function_ref<bool(const APInt &)> CheckFn) {
472 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}, &V};
473}
474
475/// Match a float or vector where CheckFn(ele) for each element is true.
476/// For vectors, poison elements are assumed to match.
478m_CheckedFp(function_ref<bool(const APFloat &)> CheckFn) {
479 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}};
480}
481
483m_CheckedFp(const Constant *&V, function_ref<bool(const APFloat &)> CheckFn) {
484 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}, &V};
485}
486
488 bool isValue(const APInt &C) const { return true; }
489};
490/// Match an integer or vector with any integral constant.
491/// For vectors, this includes constants with undefined elements.
495
497 bool isValue(const APInt &C) const { return C.isShiftedMask(); }
498};
499
503
505 bool isValue(const APInt &C) const { return C.isAllOnes(); }
506};
507/// Match an integer or vector with all bits set.
508/// For vectors, this includes constants with undefined elements.
512
516
517inline auto m_AllOnesOrPoison() { return m_CombineOr(m_AllOnes(), m_Poison()); }
518
520 bool isValue(const APInt &C) const { return C.isMaxSignedValue(); }
521};
522/// Match an integer or vector with values having all bits except for the high
523/// bit set (0x7f...).
524/// For vectors, this includes constants with undefined elements.
529 return V;
530}
531
533 bool isValue(const APInt &C) const { return C.isNegative(); }
534};
535/// Match an integer or vector of negative values.
536/// For vectors, this includes constants with undefined elements.
540inline api_pred_ty<is_negative> m_Negative(const APInt *&V) { return V; }
541
543 bool isValue(const APInt &C) const { return C.isNonNegative(); }
544};
545/// Match an integer or vector of non-negative values.
546/// For vectors, this includes constants with undefined elements.
550inline api_pred_ty<is_nonnegative> m_NonNegative(const APInt *&V) { return V; }
551
553 bool isValue(const APInt &C) const { return C.isStrictlyPositive(); }
554};
555/// Match an integer or vector of strictly positive values.
556/// For vectors, this includes constants with undefined elements.
561 return V;
562}
563
565 bool isValue(const APInt &C) const { return C.isNonPositive(); }
566};
567/// Match an integer or vector of non-positive values.
568/// For vectors, this includes constants with undefined elements.
572inline api_pred_ty<is_nonpositive> m_NonPositive(const APInt *&V) { return V; }
573
574struct is_one {
575 bool isValue(const APInt &C) const { return C.isOne(); }
576};
577/// Match an integer 1 or a vector with all elements equal to 1.
578/// For vectors, this includes constants with undefined elements.
580
582 bool isValue(const APInt &C) const { return C.isZero(); }
583};
584/// Match an integer 0 or a vector with all elements equal to 0.
585/// For vectors, this includes constants with undefined elements.
589
591 bool isValue(const APInt &C) const { return !C.isZero(); }
592};
593/// Match a non-zero integer or a vector with all non-zero elements.
594/// For vectors, this includes constants with undefined elements.
598
599template <bool AllowPoison> struct is_zero {
600 template <typename ITy> bool match(ITy *V) const {
601 auto *C = dyn_cast<Constant>(V);
602 // FIXME: this should be able to do something for scalable vectors
603 return C && (C->isNullValue() ||
605 }
606};
607/// Match any null constant or a vector with all elements equal to 0.
608/// For vectors, this includes constants with undefined elements.
609inline is_zero<true> m_Zero() { return is_zero<true>(); }
611
612inline auto m_ZeroOrPoison() { return m_CombineOr(m_Zero(), m_Poison()); }
613
614struct is_power2 {
615 bool isValue(const APInt &C) const { return C.isPowerOf2(); }
616};
617/// Match an integer or vector power-of-2.
618/// For vectors, this includes constants with undefined elements.
620inline api_pred_ty<is_power2> m_Power2(const APInt *&V) { return V; }
621
623 bool isValue(const APInt &C) const { return C.isNegatedPowerOf2(); }
624};
625/// Match a integer or vector negated power-of-2.
626/// For vectors, this includes constants with undefined elements.
631 return V;
632}
633
635 bool isValue(const APInt &C) const { return !C || C.isNegatedPowerOf2(); }
636};
637/// Match a integer or vector negated power-of-2.
638/// For vectors, this includes constants with undefined elements.
644 return V;
645}
646
648 bool isValue(const APInt &C) const { return !C || C.isPowerOf2(); }
649};
650/// Match an integer or vector of 0 or power-of-2 values.
651/// For vectors, this includes constants with undefined elements.
656 return V;
657}
658
660 bool isValue(const APInt &C) const { return C.isSignMask(); }
661};
662/// Match an integer or vector with only the sign bit(s) set.
663/// For vectors, this includes constants with undefined elements.
667
669 bool isValue(const APInt &C) const { return C.isMask(); }
670};
671/// Match an integer or vector with only the low bit(s) set.
672/// For vectors, this includes constants with undefined elements.
676inline api_pred_ty<is_lowbit_mask> m_LowBitMask(const APInt *&V) { return V; }
677
679 bool isValue(const APInt &C) const { return !C || C.isMask(); }
680};
681/// Match an integer or vector with only the low bit(s) set.
682/// For vectors, this includes constants with undefined elements.
687 return V;
688}
689
692 const APInt *Thr;
693 bool isValue(const APInt &C) const {
694 return ICmpInst::compare(C, *Thr, Pred);
695 }
696};
697/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
698/// to Threshold. For vectors, this includes constants with undefined elements.
702 P.Pred = Predicate;
703 P.Thr = &Threshold;
704 return P;
705}
706
707/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
708/// to Threshold. For vectors, this includes constants with undefined elements.
711 const APInt &Threshold) {
713 P.Pred = Predicate;
714 P.Thr = &Threshold;
715 return P;
716}
717
718struct is_nan {
719 bool isValue(const APFloat &C) const { return C.isNaN(); }
720};
721/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
722/// For vectors, this includes constants with undefined elements.
724
725struct is_nonnan {
726 bool isValue(const APFloat &C) const { return !C.isNaN(); }
727};
728/// Match a non-NaN FP constant.
729/// For vectors, this includes constants with undefined elements.
733
734struct is_inf {
735 bool isValue(const APFloat &C) const { return C.isInfinity(); }
736};
737/// Match a positive or negative infinity FP constant.
738/// For vectors, this includes constants with undefined elements.
740
741template <bool IsNegative> struct is_signed_inf {
742 bool isValue(const APFloat &C) const {
743 return C.isInfinity() && IsNegative == C.isNegative();
744 }
745};
746
747/// Match a positive infinity FP constant.
748/// For vectors, this includes constants with undefined elements.
752
753/// Match a negative infinity FP constant.
754/// For vectors, this includes constants with undefined elements.
758
759struct is_noninf {
760 bool isValue(const APFloat &C) const { return !C.isInfinity(); }
761};
762/// Match a non-infinity FP constant, i.e. finite or NaN.
763/// For vectors, this includes constants with undefined elements.
767
768struct is_finite {
769 bool isValue(const APFloat &C) const { return C.isFinite(); }
770};
771/// Match a finite FP constant, i.e. not infinity or NaN.
772/// For vectors, this includes constants with undefined elements.
776inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
777
779 bool isValue(const APFloat &C) const { return C.isFiniteNonZero(); }
780};
781/// Match a finite non-zero FP constant.
782/// For vectors, this includes constants with undefined elements.
787 return V;
788}
789
791 bool isValue(const APFloat &C) const { return C.isZero(); }
792};
793/// Match a floating-point negative zero or positive zero.
794/// For vectors, this includes constants with undefined elements.
798
800 bool isValue(const APFloat &C) const { return C.isPosZero(); }
801};
802/// Match a floating-point positive zero.
803/// For vectors, this includes constants with undefined elements.
807
809 bool isValue(const APFloat &C) const { return C.isNegZero(); }
810};
811/// Match a floating-point negative zero.
812/// For vectors, this includes constants with undefined elements.
816
818 bool isValue(const APFloat &C) const { return C.isNonZero(); }
819};
820/// Match a floating-point non-zero.
821/// For vectors, this includes constants with undefined elements.
825
827 bool isValue(const APFloat &C) const {
828 return !C.isDenormal() && C.isNonZero();
829 }
830};
831
832/// Match a floating-point non-zero that is not a denormal.
833/// For vectors, this includes constants with undefined elements.
837
838///////////////////////////////////////////////////////////////////////////////
839
840/// Match a value, capturing it if we match.
841inline match_bind<Value> m_Value(Value *&V) { return V; }
842inline match_bind<const Value> m_Value(const Value *&V) { return V; }
843
844/// Match against the nested pattern, and capture the value if we match.
845template <typename Pattern> inline auto m_Value(Value *&V, const Pattern &P) {
846 return m_CombineAnd(P, match_bind<Value>(V));
847}
848
849/// Match against the nested pattern, and capture the value if we match.
850template <typename Pattern>
851inline auto m_Value(const Value *&V, const Pattern &P) {
853}
854
855/// Match an instruction, capturing it if we match.
858 return I;
859}
860
861/// Match against the nested pattern, and capture the instruction if we match.
862template <typename Pattern>
863inline auto m_Instruction(Instruction *&I, const Pattern &P) {
865}
866template <typename Pattern>
867inline auto m_Instruction(const Instruction *&I, const Pattern &P) {
869}
870
871/// Match a unary operator, capturing it if we match.
874 return I;
875}
876/// Match a binary operator, capturing it if we match.
879 return I;
880}
881/// Match any intrinsic call, capturing it if we match.
886/// Match a with overflow intrinsic, capturing it if we match.
892 return I;
893}
894
895/// Match a PHI node, capturing it if we match.
896inline match_bind<PHINode> m_Phi(PHINode *&PN) { return PN; }
897
898/// Match an UndefValue, capturing the value if we match.
900
901/// Match a Constant, capturing the value if we match.
903
904/// Match a ConstantInt, capturing the value if we match.
906
907/// Match a ConstantFP, capturing the value if we match.
909
910/// Match a ConstantExpr, capturing the value if we match.
912
913/// Match a basic block value, capturing it if we match.
916 return V;
917}
918
919// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
920// and use m_Unless(m_ConstantExpr).
922 template <typename ITy> static bool isImmConstant(ITy *V) {
923 if (auto *CV = dyn_cast<Constant>(V)) {
924 if (!match(CV, m_ConstantExpr()))
925 return true;
926
927 if (CV->getType()->isVectorTy()) {
928 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
929 if (!match(Splat, m_ConstantExpr())) {
930 return true;
931 }
932 }
933 }
934 }
935 return false;
936 }
937};
938
940 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
941};
942
943/// Match an arbitrary immediate Constant and ignore it.
945
948
950
951 template <typename ITy> bool match(ITy *V) const {
952 if (isImmConstant(V)) {
953 VR = cast<Constant>(V);
954 return true;
955 }
956 return false;
957 }
958};
959
960/// Match an immediate Constant, capturing the value if we match.
964
965/// Matcher for specified Value*.
967 const Value *Val;
968
969 specificval_ty(const Value *V) : Val(V) {}
970
971 template <typename ITy> bool match(ITy *V) const { return V == Val; }
972};
973
974/// Match if we have a specific specified value.
975inline specificval_ty m_Specific(const Value *V) { return V; }
976
977/// Like m_Specific(), but works if the specific value to match is determined
978/// as part of the same match() expression. For example:
979/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
980/// bind X before the pattern match starts.
981/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
982/// whichever value m_Value(X) populated.
983inline match_deferred<Value> m_Deferred(Value *const &V) { return V; }
985 return V;
986}
987
988/// Match a specified floating point value or vector of all elements of
989/// that value.
991 double Val;
992
993 specific_fpval(double V) : Val(V) {}
994
995 template <typename ITy> bool match(ITy *V) const {
996 if (const auto *CFP = dyn_cast<ConstantFP>(V))
997 return CFP->isExactlyValue(Val);
998 if (V->getType()->isVectorTy())
999 if (const auto *C = dyn_cast<Constant>(V))
1000 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
1001 return CFP->isExactlyValue(Val);
1002 return false;
1003 }
1004};
1005
1006/// Match a specific floating point value or vector with all elements
1007/// equal to the value.
1008inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
1009
1010/// Match a float 1.0 or vector with all elements equal to 1.0.
1011inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
1012
1015
1017
1018 template <typename ITy> bool match(ITy *V) const {
1019 const APInt *ConstInt;
1020 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1021 return false;
1022 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1023 if (!ZExtVal)
1024 return false;
1025 VR = *ZExtVal;
1026 return true;
1027 }
1028};
1029
1030/// Match a specified integer value or vector of all elements of that
1031/// value.
1032template <bool AllowPoison> struct specific_intval {
1033 const APInt &Val;
1034
1035 specific_intval(const APInt &V) : Val(V) {}
1036
1037 template <typename ITy> bool match(ITy *V) const {
1038 const auto *CI = dyn_cast<ConstantInt>(V);
1039 if (!CI && V->getType()->isVectorTy())
1040 if (const auto *C = dyn_cast<Constant>(V))
1041 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1042
1043 return CI && APInt::isSameValue(CI->getValue(), Val);
1044 }
1045};
1046
1047template <bool AllowPoison> struct specific_intval64 {
1049
1051
1052 template <typename ITy> bool match(ITy *V) const {
1053 const auto *CI = dyn_cast<ConstantInt>(V);
1054 if (!CI && V->getType()->isVectorTy())
1055 if (const auto *C = dyn_cast<Constant>(V))
1056 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1057
1058 return CI && CI->getValue() == Val;
1059 }
1060};
1061
1062/// Match a specific integer value or vector with all elements equal to
1063/// the value.
1065 return specific_intval<false>(V);
1066}
1067
1071
1075
1079
1080/// Match a ConstantInt and bind to its value. This does not match
1081/// ConstantInts wider than 64-bits.
1083
1084/// Match a specified basic block value.
1087
1089
1090 template <typename ITy> bool match(ITy *V) const {
1091 const auto *BB = dyn_cast<BasicBlock>(V);
1092 return BB && BB == Val;
1093 }
1094};
1095
1096/// Match a specific basic block value.
1098 return specific_bbval(BB);
1099}
1100
1101/// A commutative-friendly version of m_Specific().
1103 return BB;
1104}
1106m_Deferred(const BasicBlock *const &BB) {
1107 return BB;
1108}
1109
1110template <typename Pattern> struct SpecificType_match {
1113
1115
1116 template <typename ITy> bool match(ITy *V) const {
1117 return V->getType() == RefTy && P.match(V);
1118 }
1119};
1120
1121// Explicit deduction guide.
1122template <typename Pattern>
1125
1126/// Match a value of a specific type.
1127template <typename Pattern>
1128inline auto m_SpecificType(Type *RefTy, const Pattern &P) {
1129 return SpecificType_match<Pattern>(RefTy, P);
1130}
1131inline auto m_SpecificType(Type *RefTy) {
1132 return m_SpecificType(RefTy, m_Value());
1133}
1134
1135/// Match a value of a specific type, capturing it if we match.
1136inline auto m_SpecificType(Type *RefTy, Value *&V) {
1137 return m_SpecificType(RefTy, m_Value(V));
1138}
1139inline auto m_SpecificType(Type *RefTy, const Value *&V) {
1140 return m_SpecificType(RefTy, m_Value(V));
1141}
1142
1143//===----------------------------------------------------------------------===//
1144// Matcher for any binary operator.
1145//
1146template <typename LHS_t, typename RHS_t, bool Commutable = false>
1150
1151 // The evaluation order is always stable, regardless of Commutability.
1152 // The LHS is always matched first.
1153 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1154
1155 template <typename OpTy> bool match(OpTy *V) const {
1156 if (auto *I = dyn_cast<BinaryOperator>(V))
1157 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1158 (Commutable && L.match(I->getOperand(1)) &&
1159 R.match(I->getOperand(0)));
1160 return false;
1161 }
1162};
1163
1164template <typename LHS, typename RHS>
1165inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1166 return AnyBinaryOp_match<LHS, RHS>(L, R);
1167}
1168
1169//===----------------------------------------------------------------------===//
1170// Matcher for any unary operator.
1171// TODO fuse unary, binary matcher into n-ary matcher
1172//
1173template <typename OP_t> struct AnyUnaryOp_match {
1174 OP_t X;
1175
1176 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1177
1178 template <typename OpTy> bool match(OpTy *V) const {
1179 if (auto *I = dyn_cast<UnaryOperator>(V))
1180 return X.match(I->getOperand(0));
1181 return false;
1182 }
1183};
1184
1185template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1186 return AnyUnaryOp_match<OP_t>(X);
1187}
1188
1189//===----------------------------------------------------------------------===//
1190// Matchers for specific binary operators.
1191//
1192
1193template <typename LHS_t, typename RHS_t, unsigned Opcode,
1194 bool Commutable = false>
1198
1199 // The evaluation order is always stable, regardless of Commutability.
1200 // The LHS is always matched first.
1201 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1202
1203 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1204 if (V->getValueID() == Value::InstructionVal + Opc) {
1205 auto *I = cast<BinaryOperator>(V);
1206 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1207 (Commutable && L.match(I->getOperand(1)) &&
1208 R.match(I->getOperand(0)));
1209 }
1210 return false;
1211 }
1212
1213 template <typename OpTy> bool match(OpTy *V) const {
1214 return match(Opcode, V);
1215 }
1216};
1217
1218template <typename LHS, typename RHS>
1223
1224template <typename LHS, typename RHS>
1229
1230template <typename LHS, typename RHS>
1235
1236template <typename LHS, typename RHS>
1241
1242template <typename Op_t, bool AllowFSubNegZero = false> struct FNeg_match {
1243 Op_t X;
1244
1245 FNeg_match(const Op_t &Op) : X(Op) {}
1246 template <typename OpTy> bool match(OpTy *V) const {
1247 auto *FPMO = dyn_cast<FPMathOperator>(V);
1248 if (!FPMO)
1249 return false;
1250
1251 if (FPMO->getOpcode() == Instruction::FNeg)
1252 return X.match(FPMO->getOperand(0));
1253
1254 if constexpr (AllowFSubNegZero) {
1255 if (FPMO->getOpcode() == Instruction::FSub) {
1256 if (FPMO->hasNoSignedZeros()) {
1257 // With 'nsz', any zero goes.
1258 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1259 return false;
1260 } else {
1261 // Without 'nsz', we need fsub -0.0, X exactly.
1262 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1263 return false;
1264 }
1265
1266 return X.match(FPMO->getOperand(1));
1267 }
1268 }
1269
1270 return false;
1271 }
1272};
1273
1274/// Match fneg X only
1275template <typename OpTy> inline FNeg_match<OpTy, false> m_FNeg(const OpTy &X) {
1276 return FNeg_match<OpTy, false>(X);
1277}
1278
1279/// Match fneg X or fsub -0.0, X.
1280template <typename OpTy>
1284
1285template <typename RHS>
1286inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1287m_FNegNSZ(const RHS &X) {
1288 return m_FSub(m_AnyZeroFP(), X);
1289}
1290
1291template <typename LHS, typename RHS>
1296
1297template <typename LHS, typename RHS>
1302
1303template <typename LHS, typename RHS>
1308
1309template <typename LHS, typename RHS>
1314
1315template <typename LHS, typename RHS>
1320
1321template <typename LHS, typename RHS>
1326
1327template <typename LHS, typename RHS>
1332
1333template <typename LHS, typename RHS>
1338
1339template <typename LHS, typename RHS>
1344
1345template <typename LHS, typename RHS>
1350
1351template <typename LHS, typename RHS>
1356
1357template <typename LHS, typename RHS>
1362
1363template <typename LHS, typename RHS>
1368
1369template <typename LHS, typename RHS>
1374
1375template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1378
1380
1381 template <typename OpTy> bool match(OpTy *V) const {
1382 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1383 if (Op->getOpcode() == Opcode)
1384 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1385 L.match(Op->getOperand(0));
1386 }
1387 // Interpreted as shiftop V, 0
1388 R = 0;
1389 return L.match(V);
1390 }
1391};
1392
1393/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1394template <typename LHS>
1399
1400/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1401template <typename LHS>
1406
1407/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1408template <typename LHS>
1413
1414template <typename LHS_t, typename RHS_t, unsigned Opcode,
1415 unsigned WrapFlags = 0, bool Commutable = false>
1419
1421 : L(LHS), R(RHS) {}
1422
1423 template <typename OpTy> bool match(OpTy *V) const {
1424 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1425 if (Op->getOpcode() != Opcode)
1426 return false;
1428 !Op->hasNoUnsignedWrap())
1429 return false;
1430 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1431 !Op->hasNoSignedWrap())
1432 return false;
1433 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1434 (Commutable && L.match(Op->getOperand(1)) &&
1435 R.match(Op->getOperand(0)));
1436 }
1437 return false;
1438 }
1439};
1440
1441template <typename LHS, typename RHS>
1442inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1444m_NSWAdd(const LHS &L, const RHS &R) {
1445 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1447 R);
1448}
1449template <typename LHS, typename RHS>
1450inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1452m_c_NSWAdd(const LHS &L, const RHS &R) {
1453 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1455 true>(L, R);
1456}
1457template <typename LHS, typename RHS>
1458inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1460m_NSWSub(const LHS &L, const RHS &R) {
1461 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1463 R);
1464}
1465template <typename LHS, typename RHS>
1466inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1468m_NSWMul(const LHS &L, const RHS &R) {
1469 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1471 R);
1472}
1473template <typename LHS, typename RHS>
1474inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1476m_NSWShl(const LHS &L, const RHS &R) {
1477 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1479 R);
1480}
1481
1482template <typename LHS, typename RHS>
1483inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1485m_NUWAdd(const LHS &L, const RHS &R) {
1486 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1488 L, R);
1489}
1490
1491template <typename LHS, typename RHS>
1493 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1494m_c_NUWAdd(const LHS &L, const RHS &R) {
1495 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1497 true>(L, R);
1498}
1499
1500template <typename LHS, typename RHS>
1501inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1503m_NUWSub(const LHS &L, const RHS &R) {
1504 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1506 L, R);
1507}
1508template <typename LHS, typename RHS>
1509inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1511m_NUWMul(const LHS &L, const RHS &R) {
1512 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1514 L, R);
1515}
1516template <typename LHS, typename RHS>
1517inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1519m_NUWShl(const LHS &L, const RHS &R) {
1520 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1522 L, R);
1523}
1524
1525template <typename LHS_t, typename RHS_t, bool Commutable = false>
1527 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1528 unsigned Opcode;
1529
1531 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1532
1533 template <typename OpTy> bool match(OpTy *V) const {
1535 }
1536};
1537
1538/// Matches a specific opcode.
1539template <typename LHS, typename RHS>
1540inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1541 const RHS &R) {
1542 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1543}
1544
1545template <typename LHS, typename RHS, bool Commutable = false>
1549
1550 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1551
1552 template <typename OpTy> bool match(OpTy *V) const {
1553 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1554 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1555 if (!PDI->isDisjoint())
1556 return false;
1557 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1558 (Commutable && L.match(PDI->getOperand(1)) &&
1559 R.match(PDI->getOperand(0)));
1560 }
1561 return false;
1562 }
1563};
1564
1565template <typename LHS, typename RHS>
1567 return DisjointOr_match<LHS, RHS>(L, R);
1568}
1569
1570template <typename LHS, typename RHS>
1572 const RHS &R) {
1574}
1575
1576/// Match either "add" or "or disjoint".
1577template <typename LHS, typename RHS>
1580m_AddLike(const LHS &L, const RHS &R) {
1581 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1582}
1583
1584/// Match either "add nsw" or "or disjoint"
1585template <typename LHS, typename RHS>
1586inline match_combine_or<
1587 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1590m_NSWAddLike(const LHS &L, const RHS &R) {
1591 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1592}
1593
1594/// Match either "add nuw" or "or disjoint"
1595template <typename LHS, typename RHS>
1596inline match_combine_or<
1597 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1600m_NUWAddLike(const LHS &L, const RHS &R) {
1601 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1602}
1603
1604template <typename LHS, typename RHS>
1608
1609 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1610
1611 template <typename OpTy> bool match(OpTy *V) const {
1612 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1613 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1614 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1615 ; // Pass
1616 else if (Op->getOpcode() != Instruction::Xor)
1617 return false;
1618 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1619 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1620 }
1621 return false;
1622 }
1623};
1624
1625/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1626/// Only commutative matcher as the `sub` will need to swap the L and R.
1627template <typename LHS, typename RHS>
1628inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1629 return XorLike_match<LHS, RHS>(L, R);
1630}
1631
1632//===----------------------------------------------------------------------===//
1633// Class that matches a group of binary opcodes.
1634//
1635template <typename LHS_t, typename RHS_t, typename Predicate,
1636 bool Commutable = false>
1637struct BinOpPred_match : Predicate {
1640
1641 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1642
1643 template <typename OpTy> bool match(OpTy *V) const {
1644 if (auto *I = dyn_cast<Instruction>(V))
1645 return this->isOpType(I->getOpcode()) &&
1646 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1647 (Commutable && L.match(I->getOperand(1)) &&
1648 R.match(I->getOperand(0))));
1649 return false;
1650 }
1651};
1652
1654 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1655};
1656
1658 bool isOpType(unsigned Opcode) const {
1659 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1660 }
1661};
1662
1664 bool isOpType(unsigned Opcode) const {
1665 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1666 }
1667};
1668
1670 bool isOpType(unsigned Opcode) const {
1671 return Instruction::isBitwiseLogicOp(Opcode);
1672 }
1673};
1674
1676 bool isOpType(unsigned Opcode) const {
1677 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1678 }
1679};
1680
1682 bool isOpType(unsigned Opcode) const {
1683 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1684 }
1685};
1686
1687/// Matches shift operations.
1688template <typename LHS, typename RHS>
1690 const RHS &R) {
1692}
1693
1694/// Matches logical shift operations.
1695template <typename LHS, typename RHS>
1700
1701/// Matches logical shift operations.
1702template <typename LHS, typename RHS>
1704m_LogicalShift(const LHS &L, const RHS &R) {
1706}
1707
1708/// Matches bitwise logic operations.
1709template <typename LHS, typename RHS>
1711m_BitwiseLogic(const LHS &L, const RHS &R) {
1713}
1714
1715/// Matches bitwise logic operations in either order.
1716template <typename LHS, typename RHS>
1721
1722/// Matches integer division operations.
1723template <typename LHS, typename RHS>
1725 const RHS &R) {
1727}
1728
1729/// Matches integer remainder operations.
1730template <typename LHS, typename RHS>
1732 const RHS &R) {
1734}
1735
1736//===----------------------------------------------------------------------===//
1737// Class that matches exact binary ops.
1738//
1739template <typename SubPattern_t> struct Exact_match {
1740 SubPattern_t SubPattern;
1741
1742 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1743
1744 template <typename OpTy> bool match(OpTy *V) const {
1745 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1746 return PEO->isExact() && SubPattern.match(V);
1747 return false;
1748 }
1749};
1750
1751template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1752 return SubPattern;
1753}
1754
1755//===----------------------------------------------------------------------===//
1756// Matchers for CmpInst classes
1757//
1758
1759template <typename LHS_t, typename RHS_t, typename Class,
1760 bool Commutable = false>
1765
1766 // The evaluation order is always stable, regardless of Commutability.
1767 // The LHS is always matched first.
1769 : Predicate(&Pred), L(LHS), R(RHS) {}
1771 : Predicate(nullptr), L(LHS), R(RHS) {}
1772
1773 template <typename OpTy> bool match(OpTy *V) const {
1774 if (auto *I = dyn_cast<Class>(V)) {
1775 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1776 if (Predicate)
1778 return true;
1779 }
1780 if (Commutable && L.match(I->getOperand(1)) &&
1781 R.match(I->getOperand(0))) {
1782 if (Predicate)
1784 return true;
1785 }
1786 }
1787 return false;
1788 }
1789};
1790
1791template <typename LHS, typename RHS>
1793 const RHS &R) {
1794 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1795}
1796
1797template <typename LHS, typename RHS>
1799 const LHS &L, const RHS &R) {
1800 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1801}
1802
1803template <typename LHS, typename RHS>
1805 const LHS &L, const RHS &R) {
1806 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1807}
1808
1809template <typename LHS, typename RHS>
1812}
1813
1814template <typename LHS, typename RHS>
1817}
1818
1819template <typename LHS, typename RHS>
1822}
1823
1824// Same as CmpClass, but instead of saving Pred as out output variable, match a
1825// specific input pred for equality.
1826template <typename LHS_t, typename RHS_t, typename Class,
1827 bool Commutable = false>
1832
1834 : Predicate(Pred), L(LHS), R(RHS) {}
1835
1836 template <typename OpTy> bool match(OpTy *V) const {
1837 if (auto *I = dyn_cast<Class>(V)) {
1839 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1840 return true;
1841 if constexpr (Commutable) {
1844 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1845 return true;
1846 }
1847 }
1848
1849 return false;
1850 }
1851};
1852
1853template <typename LHS, typename RHS>
1855m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1856 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1857}
1858
1859template <typename LHS, typename RHS>
1861m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1862 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1863}
1864
1865template <typename LHS, typename RHS>
1867m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1869}
1870
1871template <typename LHS, typename RHS>
1873m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1874 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1875}
1876
1877//===----------------------------------------------------------------------===//
1878// Matchers for instructions with a given opcode and number of operands.
1879//
1880
1881/// Matches instructions with Opcode and three operands.
1882template <typename T0, unsigned Opcode> struct OneOps_match {
1884
1885 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1886
1887 template <typename OpTy> bool match(OpTy *V) const {
1888 if (V->getValueID() == Value::InstructionVal + Opcode) {
1889 auto *I = cast<Instruction>(V);
1890 return Op1.match(I->getOperand(0));
1891 }
1892 return false;
1893 }
1894};
1895
1896/// Matches instructions with Opcode and three operands.
1897template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1900
1901 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1902
1903 template <typename OpTy> bool match(OpTy *V) const {
1904 if (V->getValueID() == Value::InstructionVal + Opcode) {
1905 auto *I = cast<Instruction>(V);
1906 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1907 }
1908 return false;
1909 }
1910};
1911
1912/// Matches instructions with Opcode and three operands.
1913template <typename T0, typename T1, typename T2, unsigned Opcode,
1914 bool CommutableOp2Op3 = false>
1919
1920 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1921 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1922
1923 template <typename OpTy> bool match(OpTy *V) const {
1924 if (V->getValueID() == Value::InstructionVal + Opcode) {
1925 auto *I = cast<Instruction>(V);
1926 if (!Op1.match(I->getOperand(0)))
1927 return false;
1928 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1929 return true;
1930 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1931 Op3.match(I->getOperand(1));
1932 }
1933 return false;
1934 }
1935};
1936
1937/// Matches instructions with Opcode and any number of operands
1938template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1939 std::tuple<OperandTypes...> Operands;
1940
1941 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1942
1943 // Operand matching works by recursively calling match_operands, matching the
1944 // operands left to right. The first version is called for each operand but
1945 // the last, for which the second version is called. The second version of
1946 // match_operands is also used to match each individual operand.
1947 template <int Idx, int Last>
1948 std::enable_if_t<Idx != Last, bool>
1952
1953 template <int Idx, int Last>
1954 std::enable_if_t<Idx == Last, bool>
1956 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1957 }
1958
1959 template <typename OpTy> bool match(OpTy *V) const {
1960 if (V->getValueID() == Value::InstructionVal + Opcode) {
1961 auto *I = cast<Instruction>(V);
1962 return I->getNumOperands() == sizeof...(OperandTypes) &&
1963 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1964 }
1965 return false;
1966 }
1967};
1968
1969/// Matches SelectInst.
1970template <typename Cond, typename LHS, typename RHS>
1972m_Select(const Cond &C, const LHS &L, const RHS &R) {
1974}
1975
1976/// This matches a select of two constants, e.g.:
1977/// m_SelectCst<-1, 0>(m_Value(V))
1978template <int64_t L, int64_t R, typename Cond>
1980 Instruction::Select>
1983}
1984
1985/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1986template <typename LHS, typename RHS>
1987inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1988m_c_Select(const LHS &L, const RHS &R) {
1989 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1990 true>(m_Value(), L, R);
1991}
1992
1993/// Matches FreezeInst.
1994template <typename OpTy>
1998
1999/// Matches InsertElementInst.
2000template <typename Val_t, typename Elt_t, typename Idx_t>
2002m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
2004 Val, Elt, Idx);
2005}
2006
2007/// Matches ExtractElementInst.
2008template <typename Val_t, typename Idx_t>
2010m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
2012}
2013
2014/// Matches BitInsertInst.
2015template <typename Base_t, typename Val_t, typename Off_t>
2017m_BitInsert(const Base_t &Base, const Val_t &Val, const Off_t &Off) {
2019 Off);
2020}
2021
2022/// Matches BitExtractInst.
2023template <typename Src_t, typename Off_t>
2025m_BitExtract(const Src_t &Src, const Off_t &Off) {
2027}
2028
2029/// Matches shuffle.
2030template <typename T0, typename T1, typename T2> struct Shuffle_match {
2034
2035 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
2036 : Op1(Op1), Op2(Op2), Mask(Mask) {}
2037
2038 template <typename OpTy> bool match(OpTy *V) const {
2039 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
2040 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
2041 Mask.match(I->getShuffleMask());
2042 }
2043 return false;
2044 }
2045};
2046
2047struct m_Mask {
2050 bool match(ArrayRef<int> Mask) const {
2051 MaskRef = Mask;
2052 return true;
2053 }
2054};
2055
2057 bool match(ArrayRef<int> Mask) const {
2058 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
2059 }
2060};
2061
2065 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
2066};
2067
2069 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
2070};
2071
2075 bool match(ArrayRef<int> Mask) const {
2076 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2077 if (First == Mask.end())
2078 return false;
2079 SplatIndex = *First;
2080 return all_of(Mask,
2081 [First](int Elem) { return Elem == *First || Elem == -1; });
2082 }
2083};
2084
2085template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2086 PointerOpTy PointerOp;
2087 OffsetOpTy OffsetOp;
2088
2089 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2091
2092 template <typename OpTy> bool match(OpTy *V) const {
2093 auto *GEP = dyn_cast<GEPOperator>(V);
2094 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2095 PointerOp.match(GEP->getPointerOperand()) &&
2096 OffsetOp.match(GEP->idx_begin()->get());
2097 }
2098};
2099
2100/// Matches ShuffleVectorInst independently of mask value.
2101template <typename V1_t, typename V2_t>
2103m_Shuffle(const V1_t &v1, const V2_t &v2) {
2105}
2106
2107template <typename V1_t, typename V2_t, typename Mask_t>
2109m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2111}
2112
2113/// Matches LoadInst.
2114template <typename OpTy>
2118
2119/// Matches a simple (non-volatile, non-atomic) LoadInst.
2120template <typename OpTy> struct LoadSimple_match {
2122
2124
2125 template <typename ITy> bool match(ITy *V) const {
2126 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2127 }
2128};
2129
2130template <typename OpTy>
2134
2135/// Matches StoreInst.
2136template <typename ValueOpTy, typename PointerOpTy>
2138m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2140 PointerOp);
2141}
2142
2143/// Matches GetElementPtrInst.
2144template <typename... OperandTypes>
2145inline auto m_GEP(const OperandTypes &...Ops) {
2146 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2147}
2148
2149/// Matches GEP with i8 source element type
2150template <typename PointerOpTy, typename OffsetOpTy>
2152m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2154}
2155
2156//===----------------------------------------------------------------------===//
2157// Matchers for CastInst classes
2158//
2159
2160template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2161 Op_t Op;
2162
2163 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2164
2165 template <typename OpTy> bool match(OpTy *V) const {
2166 if (auto *O = dyn_cast<Operator>(V))
2167 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2168 return false;
2169 }
2170};
2171
2172template <typename Op_t, typename Class> struct CastInst_match {
2173 Op_t Op;
2174
2175 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2176
2177 template <typename OpTy> bool match(OpTy *V) const {
2178 if (auto *I = dyn_cast<Class>(V))
2179 return Op.match(I->getOperand(0));
2180 return false;
2181 }
2182};
2183
2184template <typename Op_t> struct PtrToIntSameSize_match {
2186 Op_t Op;
2187
2188 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2189 : DL(DL), Op(OpMatch) {}
2190
2191 template <typename OpTy> bool match(OpTy *V) const {
2192 if (auto *O = dyn_cast<Operator>(V))
2193 return O->getOpcode() == Instruction::PtrToInt &&
2194 DL.getTypeSizeInBits(O->getType()) ==
2195 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2196 Op.match(O->getOperand(0));
2197 return false;
2198 }
2199};
2200
2201template <typename Op_t> struct NNegZExt_match {
2202 Op_t Op;
2203
2204 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2205
2206 template <typename OpTy> bool match(OpTy *V) const {
2207 if (auto *I = dyn_cast<ZExtInst>(V))
2208 return I->hasNonNeg() && Op.match(I->getOperand(0));
2209 return false;
2210 }
2211};
2212
2213template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2214 Op_t Op;
2215
2216 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2217
2218 template <typename OpTy> bool match(OpTy *V) const {
2219 if (auto *I = dyn_cast<TruncInst>(V))
2220 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2221 Op.match(I->getOperand(0));
2222 return false;
2223 }
2224};
2225
2226/// Matches BitCast.
2227template <typename OpTy>
2232
2233template <typename Op_t> struct ElementWiseBitCast_match {
2234 Op_t Op;
2235
2236 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2237
2238 template <typename OpTy> bool match(OpTy *V) const {
2239 auto *I = dyn_cast<BitCastInst>(V);
2240 if (!I)
2241 return false;
2242 Type *SrcType = I->getSrcTy();
2243 Type *DstType = I->getType();
2244 // Make sure the bitcast doesn't change between scalar and vector and
2245 // doesn't change the number of vector elements.
2246 if (SrcType->isVectorTy() != DstType->isVectorTy())
2247 return false;
2248 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2249 SrcVecTy && SrcVecTy->getElementCount() !=
2250 cast<VectorType>(DstType)->getElementCount())
2251 return false;
2252 return Op.match(I->getOperand(0));
2253 }
2254};
2255
2256template <typename OpTy>
2260
2261/// Matches PtrToInt.
2262template <typename OpTy>
2267
2268template <typename OpTy>
2273
2274/// Matches PtrToAddr.
2275template <typename OpTy>
2280
2281/// Matches PtrToInt or PtrToAddr.
2282template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2284}
2285
2286/// Matches IntToPtr.
2287template <typename OpTy>
2292
2293/// Matches any cast or self. Used to ignore casts.
2294template <typename OpTy>
2299
2300/// Matches Trunc.
2301template <typename OpTy>
2305
2306/// Matches trunc nuw.
2307template <typename OpTy>
2312
2313/// Matches trunc nsw.
2314template <typename OpTy>
2319
2320template <typename OpTy>
2323 return m_CombineOr(m_Trunc(Op), Op);
2324}
2325
2326/// Matches SExt.
2327template <typename OpTy>
2331
2332/// Matches ZExt.
2333template <typename OpTy>
2337
2338template <typename OpTy>
2340 return NNegZExt_match<OpTy>(Op);
2341}
2342
2343template <typename OpTy>
2346 return m_CombineOr(m_ZExt(Op), Op);
2347}
2348
2349template <typename OpTy>
2352 return m_CombineOr(m_SExt(Op), Op);
2353}
2354
2355/// Match either "sext" or "zext nneg".
2356template <typename OpTy>
2359 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2360}
2361
2362template <typename OpTy>
2366 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2367}
2368
2369template <typename OpTy>
2372 OpTy>
2374 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2375}
2376
2377template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2378 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2379}
2380
2381template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2385
2387 : Pred(P), L(Left), R(Right) {}
2388
2389 template <typename OpTy> bool match(OpTy *V) const {
2390 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2391 return true;
2392 Value *A;
2393 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2394 if (V->getType()->isIntOrIntVectorTy(1) &&
2395 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2396 R.match(ConstantInt::getNullValue(A->getType()))) {
2398 return true;
2399 }
2400 return false;
2401 }
2402};
2403
2404template <typename LHS, typename RHS>
2406 const RHS &R) {
2407 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2408}
2409
2410template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2411 CondTy Cond;
2414
2415 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2416 : Cond(C), TrueC(TC), FalseC(FC) {}
2417
2418 template <typename OpTy> bool match(OpTy *V) const {
2419 // select(Cond, TrueC, FalseC) — captures both constants directly
2421 return true;
2422
2423 Type *Ty = V->getType();
2424 Value *CondV = nullptr;
2425
2426 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2427 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2428 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2429 TrueC.match(ConstantInt::get(Ty, 1)) &&
2430 FalseC.match(ConstantInt::get(Ty, 0)))
2431 return true;
2432
2433 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2434 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2435 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2436 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2437 FalseC.match(ConstantInt::get(Ty, 0)))
2438 return true;
2439
2440 return false;
2441 }
2442};
2443
2444/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2445/// select i1 Cond, TrueC, FalseC
2446/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2447/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2448///
2449/// The condition is matched against \p Cond, and the true/false constants
2450/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2451/// constants are bound to \p TrueC and \p FalseC via their matchers.
2452template <typename CondTy, typename LTy, typename RTy>
2454m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2455 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2456}
2457
2458template <typename OpTy>
2462
2463template <typename OpTy>
2467
2468template <typename OpTy>
2471m_IToFP(const OpTy &Op) {
2472 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2473}
2474
2475template <typename OpTy>
2479
2480template <typename OpTy>
2484
2485template <typename OpTy>
2488m_FPToI(const OpTy &Op) {
2489 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2490}
2491
2492template <typename OpTy>
2496
2497template <typename OpTy>
2501
2502//===----------------------------------------------------------------------===//
2503// Matchers for control flow.
2504//
2505
2506struct br_match {
2508
2510
2511 template <typename OpTy> bool match(OpTy *V) const {
2512 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2513 Succ = BI->getSuccessor();
2514 return true;
2515 }
2516 return false;
2517 }
2518};
2519
2520inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2521
2522template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2524 Cond_t Cond;
2525 TrueBlock_t T;
2526 FalseBlock_t F;
2527
2528 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2529 : Cond(C), T(t), F(f) {}
2530
2531 template <typename OpTy> bool match(OpTy *V) const {
2532 if (auto *BI = dyn_cast<CondBrInst>(V))
2533 if (Cond.match(BI->getCondition()))
2534 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2535 return false;
2536 }
2537};
2538
2539template <typename Cond_t>
2545
2546template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2548m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2550}
2551
2552//===----------------------------------------------------------------------===//
2553// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2554//
2555
2556template <typename LHS_t, typename RHS_t, typename Pred_t>
2558 using PredType = Pred_t;
2561
2562 // The evaluation order is always stable, regardless of Commutability.
2563 // The LHS is always matched first.
2564 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2565
2566 template <typename OpTy> bool match(OpTy *V) const {
2567 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2568 auto *SI = dyn_cast<SelectInst>(V);
2569 if (!SI)
2570 return false;
2571 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2572 if (!Cmp)
2573 return false;
2574 // At this point we have a select conditioned on a comparison. Check that
2575 // it is the values returned by the select that are being compared.
2576 auto *TrueVal = SI->getTrueValue();
2577 auto *FalseVal = SI->getFalseValue();
2578 auto *LHS = Cmp->getOperand(0);
2579 auto *RHS = Cmp->getOperand(1);
2580 if ((TrueVal != LHS || FalseVal != RHS) &&
2581 (TrueVal != RHS || FalseVal != LHS))
2582 return false;
2583 FCmpInst::Predicate Pred =
2584 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2585 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2586 if (!Pred_t::match(Pred))
2587 return false;
2588 // It does! Bind the operands.
2589 return L.match(LHS) && R.match(RHS);
2590 }
2591};
2592
2593/// Helper class for identifying ordered max predicates.
2595 static bool match(FCmpInst::Predicate Pred) {
2596 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2597 }
2598};
2599
2600/// Helper class for identifying ordered min predicates.
2602 static bool match(FCmpInst::Predicate Pred) {
2603 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2604 }
2605};
2606
2607/// Helper class for identifying unordered max predicates.
2609 static bool match(FCmpInst::Predicate Pred) {
2610 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2611 }
2612};
2613
2614/// Helper class for identifying unordered min predicates.
2616 static bool match(FCmpInst::Predicate Pred) {
2617 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2618 }
2619};
2620
2621/// Match an 'ordered' floating point maximum function.
2622/// Floating point has one special value 'NaN'. Therefore, there is no total
2623/// order. However, if we can ignore the 'NaN' value (for example, because of a
2624/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2625/// semantics. In the presence of 'NaN' we have to preserve the original
2626/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2627///
2628/// max(L, R) iff L and R are not NaN
2629/// m_OrdFMax(L, R) = R iff L or R are NaN
2630template <typename LHS, typename RHS>
2632 const RHS &R) {
2634}
2635
2636/// Match an 'ordered' floating point minimum function.
2637/// Floating point has one special value 'NaN'. Therefore, there is no total
2638/// order. However, if we can ignore the 'NaN' value (for example, because of a
2639/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2640/// semantics. In the presence of 'NaN' we have to preserve the original
2641/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2642///
2643/// min(L, R) iff L and R are not NaN
2644/// m_OrdFMin(L, R) = R iff L or R are NaN
2645template <typename LHS, typename RHS>
2647 const RHS &R) {
2649}
2650
2651/// Match an 'unordered' floating point maximum function.
2652/// Floating point has one special value 'NaN'. Therefore, there is no total
2653/// order. However, if we can ignore the 'NaN' value (for example, because of a
2654/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2655/// semantics. In the presence of 'NaN' we have to preserve the original
2656/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2657///
2658/// max(L, R) iff L and R are not NaN
2659/// m_UnordFMax(L, R) = L iff L or R are NaN
2660template <typename LHS, typename RHS>
2665
2666/// Match an 'unordered' floating point minimum function.
2667/// Floating point has one special value 'NaN'. Therefore, there is no total
2668/// order. However, if we can ignore the 'NaN' value (for example, because of a
2669/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2670/// semantics. In the presence of 'NaN' we have to preserve the original
2671/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2672///
2673/// min(L, R) iff L and R are not NaN
2674/// m_UnordFMin(L, R) = L iff L or R are NaN
2675template <typename LHS, typename RHS>
2680
2681/// Match an 'ordered' or 'unordered' floating point maximum function.
2682/// Floating point has one special value 'NaN'. Therefore, there is no total
2683/// order. However, if we can ignore the 'NaN' value (for example, because of a
2684/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2685/// semantics.
2686template <typename LHS, typename RHS>
2693
2694/// Match an 'ordered' or 'unordered' floating point minimum function.
2695/// Floating point has one special value 'NaN'. Therefore, there is no total
2696/// order. However, if we can ignore the 'NaN' value (for example, because of a
2697/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2698/// semantics.
2699template <typename LHS, typename RHS>
2706
2707/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2708/// NOTE: we first match the 'Not' (by matching '-1'),
2709/// and only then match the inner matcher!
2710template <typename ValTy>
2711inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2712m_Not(const ValTy &V) {
2713 return m_c_Xor(m_AllOnes(), V);
2714}
2715
2716template <typename ValTy>
2717inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2718 true>
2719m_NotForbidPoison(const ValTy &V) {
2720 return m_c_Xor(m_AllOnesForbidPoison(), V);
2721}
2722
2723//===----------------------------------------------------------------------===//
2724// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2725// Note that S might be matched to other instructions than AddInst.
2726//
2727
2728template <typename LHS_t, typename RHS_t, typename Sum_t>
2732 Sum_t S;
2733
2734 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2735 : L(L), R(R), S(S) {}
2736
2737 template <typename OpTy> bool match(OpTy *V) const {
2738 Value *ICmpLHS, *ICmpRHS;
2739 CmpPredicate Pred;
2740 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2741 return false;
2742
2743 Value *AddLHS, *AddRHS;
2744 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2745
2746 // (a + b) u< a, (a + b) u< b
2747 if (Pred == ICmpInst::ICMP_ULT)
2748 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2749 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2750
2751 // a >u (a + b), b >u (a + b)
2752 if (Pred == ICmpInst::ICMP_UGT)
2753 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2754 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2755
2756 Value *Op1;
2757 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2758 // (~a) <u b
2759 if (Pred == ICmpInst::ICMP_ULT) {
2760 if (XorExpr.match(ICmpLHS))
2761 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2762 }
2763 // b > u (~a)
2764 if (Pred == ICmpInst::ICMP_UGT) {
2765 if (XorExpr.match(ICmpRHS))
2766 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2767 }
2768
2769 // Match special-case for increment-by-1.
2770 if (Pred == ICmpInst::ICMP_EQ) {
2771 // (a + 1) == 0
2772 // (1 + a) == 0
2773 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2774 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2775 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2776 // 0 == (a + 1)
2777 // 0 == (1 + a)
2778 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2779 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2780 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2781 }
2782
2783 return false;
2784 }
2785};
2786
2787/// Match an icmp instruction checking for unsigned overflow on addition.
2788///
2789/// S is matched to the addition whose result is being checked for overflow, and
2790/// L and R are matched to the LHS and RHS of S.
2791template <typename LHS_t, typename RHS_t, typename Sum_t>
2793m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2795}
2796
2797template <typename Opnd_t> struct Argument_match {
2798 unsigned OpI;
2799 Opnd_t Val;
2800
2801 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2802
2803 template <typename OpTy> bool match(OpTy *V) const {
2804 // FIXME: Should likely be switched to use `CallBase`.
2805 if (const auto *CI = dyn_cast<CallInst>(V))
2806 return Val.match(CI->getArgOperand(OpI));
2807 return false;
2808 }
2809};
2810
2811/// Match an argument.
2812template <unsigned OpI, typename Opnd_t>
2813inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2814 return Argument_match<Opnd_t>(OpI, Op);
2815}
2816
2817/// Intrinsic matchers.
2819 unsigned ID;
2820
2822
2823 template <typename OpTy> bool match(OpTy *V) const {
2824 if (const auto *CI = dyn_cast<CallInst>(V))
2825 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2826 return F->getIntrinsicID() == ID;
2827 return false;
2828 }
2829};
2830
2831/// Match intrinsic calls with any of the given IDs.
2832template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2833 template <typename OpTy> bool match(OpTy *V) const {
2834 if (const auto *CI = dyn_cast<CallInst>(V))
2835 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2836 Intrinsic::ID ID = F->getIntrinsicID();
2837 return ((ID == IntrIDs) || ...);
2838 }
2839 return false;
2840 }
2841};
2842
2844 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2845 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2846 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2847 }
2848};
2849
2850/// Match intrinsic calls like this:
2851/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2852template <Intrinsic::ID IntrID, typename... Ts>
2853inline auto m_Intrinsic(const Ts &...Ops) {
2855 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2856}
2857
2858/// Match intrinsic calls with any of the given IDs like this:
2859/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2860/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2861/// because it performs the CallInst/Function cast only once.
2862template <Intrinsic::ID... IntrIDs>
2864 return IntrinsicIDs_match<IntrIDs...>();
2865}
2866
2867/// Matches MaskedLoad Intrinsic.
2868template <typename Opnd0, typename Opnd1, typename Opnd2>
2869inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2870 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2871}
2872
2873/// Matches MaskedStore Intrinsic.
2874template <typename Opnd0, typename Opnd1, typename Opnd2>
2875inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2876 const Opnd2 &Op2) {
2877 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2878}
2879
2880/// Matches MaskedGather Intrinsic.
2881template <typename Opnd0, typename Opnd1, typename Opnd2>
2882inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2883 const Opnd2 &Op2) {
2884 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2885}
2886
2887// Helper intrinsic matching specializations.
2888template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2890}
2891
2892template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2894}
2895template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2897}
2898
2899template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2900 return m_Intrinsic<Intrinsic::fabs>(Op0);
2901}
2902
2903template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2905}
2906
2907template <typename Opnd0, typename Opnd1>
2908inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2909 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2910}
2911
2912template <typename Opnd0, typename Opnd1>
2913inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2914 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2915}
2916
2917template <typename Opnd0, typename Opnd1>
2918inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2919 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2920}
2921
2922template <typename Opnd0, typename Opnd1>
2923inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2924 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2925}
2926
2927template <typename Opnd0, typename Opnd1>
2928inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2929 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2930}
2931
2932template <typename Opnd0, typename Opnd1>
2933inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2934 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2935}
2936
2937template <typename Opnd0, typename Opnd1>
2938inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2939 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2940 m_UMin(Op0, Op1));
2941}
2942
2943template <typename Opnd0, typename Opnd1>
2944inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2945 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2946}
2947
2948template <typename Opnd0, typename Opnd1>
2949inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2950 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2951}
2952
2953template <typename Opnd0, typename Opnd1>
2954inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2955 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2956}
2957
2958template <typename Opnd0, typename Opnd1>
2959inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2960 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2961}
2962
2963template <typename Opnd0, typename Opnd1>
2964inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2965 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2966}
2967
2968template <typename Opnd0, typename Opnd1>
2969inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2970 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2971}
2972
2973template <typename Opnd0, typename Opnd1>
2974inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2975 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2976}
2977
2978template <typename Opnd0, typename Opnd1>
2979inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2980 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2981}
2982
2983template <typename Opnd0, typename Opnd1, typename Opnd2>
2984inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2985 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2986}
2987
2988template <typename Opnd0, typename Opnd1, typename Opnd2>
2989inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2990 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2991}
2992
2993template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2994 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2995}
2996
2997template <typename Opnd0, typename Opnd1>
2998inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2999 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
3000}
3001
3002template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
3004}
3005
3006template <typename Opnd0, typename Opnd1, typename Opnd2>
3007inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
3008 const Opnd2 &Op2) {
3009 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
3010}
3011
3012//===----------------------------------------------------------------------===//
3013// Matchers for two-operands operators with the operators in either order
3014//
3015
3016/// Matches a BinaryOperator with LHS and RHS in either order.
3017template <typename LHS, typename RHS>
3020}
3021
3022/// Matches an ICmp with a predicate over LHS and RHS in either order.
3023/// Swaps the predicate if operands are commuted.
3024template <typename LHS, typename RHS>
3026m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
3028}
3029
3030template <typename LHS, typename RHS>
3035
3036template <typename LHS, typename RHS>
3038 const RHS &R) {
3040}
3041
3042/// Matches a specific opcode with LHS and RHS in either order.
3043template <typename LHS, typename RHS>
3045m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
3046 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
3047}
3048
3049/// Matches a Add with LHS and RHS in either order.
3050template <typename LHS, typename RHS>
3055
3056/// Matches a Mul with LHS and RHS in either order.
3057template <typename LHS, typename RHS>
3062
3063/// Matches an And with LHS and RHS in either order.
3064template <typename LHS, typename RHS>
3069
3070/// Matches an Or with LHS and RHS in either order.
3071template <typename LHS, typename RHS>
3076
3077/// Matches an Xor with LHS and RHS in either order.
3078template <typename LHS, typename RHS>
3083
3084/// Matches a 'Neg' as 'sub 0, V'.
3085template <typename ValTy>
3086inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3087m_Neg(const ValTy &V) {
3088 return m_Sub(m_ZeroInt(), V);
3089}
3090
3091/// Matches a 'Neg' as 'sub nsw 0, V'.
3092template <typename ValTy>
3094 Instruction::Sub,
3096m_NSWNeg(const ValTy &V) {
3097 return m_NSWSub(m_ZeroInt(), V);
3098}
3099
3100template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3104
3105 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3106
3107 template <typename OpTy> bool match(OpTy *V) const {
3108 const auto *II = dyn_cast<IntrinsicInst>(V);
3109 if (!II || II->getIntrinsicID() != IntrID)
3110 return false;
3111 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3112 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3113 }
3114};
3115
3116template <Intrinsic::ID IntrID, typename T0, typename T1>
3118m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3120}
3121
3122/// Matches an SMin with LHS and RHS in either order.
3123template <typename LHS, typename RHS>
3124inline auto m_c_SMin(const LHS &L, const RHS &R) {
3125 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3126}
3127/// Matches an SMax with LHS and RHS in either order.
3128template <typename LHS, typename RHS>
3129inline auto m_c_SMax(const LHS &L, const RHS &R) {
3130 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3131}
3132/// Matches a UMin with LHS and RHS in either order.
3133template <typename LHS, typename RHS>
3134inline auto m_c_UMin(const LHS &L, const RHS &R) {
3135 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3136}
3137/// Matches a UMax with LHS and RHS in either order.
3138template <typename LHS, typename RHS>
3139inline auto m_c_UMax(const LHS &L, const RHS &R) {
3140 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3141}
3142
3143template <typename LHS, typename RHS>
3144inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3145 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3146 m_c_UMin(L, R));
3147}
3148
3149/// Matches FAdd with LHS and RHS in either order.
3150template <typename LHS, typename RHS>
3152m_c_FAdd(const LHS &L, const RHS &R) {
3154}
3155
3156/// Matches FMul with LHS and RHS in either order.
3157template <typename LHS, typename RHS>
3159m_c_FMul(const LHS &L, const RHS &R) {
3161}
3162
3163template <typename Opnd_t> struct Signum_match {
3164 Opnd_t Val;
3165 Signum_match(const Opnd_t &V) : Val(V) {}
3166
3167 template <typename OpTy> bool match(OpTy *V) const {
3168 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3169 if (TypeSize == 0)
3170 return false;
3171
3172 unsigned ShiftWidth = TypeSize - 1;
3173 Value *Op;
3174
3175 // This is the representation of signum we match:
3176 //
3177 // signum(x) == (x >> 63) | (-x >>u 63)
3178 //
3179 // An i1 value is its own signum, so it's correct to match
3180 //
3181 // signum(x) == (x >> 0) | (-x >>u 0)
3182 //
3183 // for i1 values.
3184
3185 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3186 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3187 auto Signum = m_c_Or(LHS, RHS);
3188
3189 return Signum.match(V) && Val.match(Op);
3190 }
3191};
3192
3193/// Matches a signum pattern.
3194///
3195/// signum(x) =
3196/// x > 0 -> 1
3197/// x == 0 -> 0
3198/// x < 0 -> -1
3199template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3200 return Signum_match<Val_t>(V);
3201}
3202
3203template <int Ind, typename Opnd_t> struct ExtractValue_match {
3204 Opnd_t Val;
3205 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3206
3207 template <typename OpTy> bool match(OpTy *V) const {
3208 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3209 // If Ind is -1, don't inspect indices
3210 if (Ind != -1 &&
3211 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3212 return false;
3213 return Val.match(I->getAggregateOperand());
3214 }
3215 return false;
3216 }
3217};
3218
3219/// Match a single index ExtractValue instruction.
3220/// For example m_ExtractValue<1>(...)
3221template <int Ind, typename Val_t>
3225
3226/// Match an ExtractValue instruction with any index.
3227/// For example m_ExtractValue(...)
3228template <typename Val_t>
3229inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3230 return ExtractValue_match<-1, Val_t>(V);
3231}
3232
3233/// Matcher for a single index InsertValue instruction.
3234template <int Ind, typename T0, typename T1> struct InsertValue_match {
3237
3238 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3239
3240 template <typename OpTy> bool match(OpTy *V) const {
3241 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3242 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3243 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3244 }
3245 return false;
3246 }
3247};
3248
3249/// Matches a single index InsertValue instruction.
3250template <int Ind, typename Val_t, typename Elt_t>
3252 const Elt_t &Elt) {
3253 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3254}
3255
3256/// Matches a call to `llvm.vscale()`.
3257inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3258
3259template <typename Opnd0, typename Opnd1>
3260inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3262}
3263
3264template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3266}
3267
3268template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3272
3273 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3274
3275 template <typename T> bool match(T *V) const {
3276 auto *I = dyn_cast<Instruction>(V);
3277 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3278 return false;
3279
3280 if (I->getOpcode() == Opcode) {
3281 auto *Op0 = I->getOperand(0);
3282 auto *Op1 = I->getOperand(1);
3283 return (L.match(Op0) && R.match(Op1)) ||
3284 (Commutable && L.match(Op1) && R.match(Op0));
3285 }
3286
3287 if (auto *Select = dyn_cast<SelectInst>(I)) {
3288 auto *Cond = Select->getCondition();
3289 auto *TVal = Select->getTrueValue();
3290 auto *FVal = Select->getFalseValue();
3291
3292 // Don't match a scalar select of bool vectors.
3293 // Transforms expect a single type for operands if this matches.
3294 if (Cond->getType() != Select->getType())
3295 return false;
3296
3297 if (Opcode == Instruction::And) {
3298 auto *C = dyn_cast<Constant>(FVal);
3299 if (C && C->isNullValue())
3300 return (L.match(Cond) && R.match(TVal)) ||
3301 (Commutable && L.match(TVal) && R.match(Cond));
3302 } else {
3303 assert(Opcode == Instruction::Or);
3304 auto *C = dyn_cast<Constant>(TVal);
3305 if (C && C->isOneValue())
3306 return (L.match(Cond) && R.match(FVal)) ||
3307 (Commutable && L.match(FVal) && R.match(Cond));
3308 }
3309 }
3310
3311 return false;
3312 }
3313};
3314
3315/// Matches L && R either in the form of L & R or L ? R : false.
3316/// Note that the latter form is poison-blocking.
3317template <typename LHS, typename RHS>
3322
3323/// Matches L && R where L and R are arbitrary values.
3324inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3325
3326/// Matches L && R with LHS and RHS in either order.
3327template <typename LHS, typename RHS>
3329m_c_LogicalAnd(const LHS &L, const RHS &R) {
3331}
3332
3333/// Matches L || R either in the form of L | R or L ? true : R.
3334/// Note that the latter form is poison-blocking.
3335template <typename LHS, typename RHS>
3340
3341/// Matches L || R where L and R are arbitrary values.
3342inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3343
3344/// Matches L || R with LHS and RHS in either order.
3345template <typename LHS, typename RHS>
3347m_c_LogicalOr(const LHS &L, const RHS &R) {
3349}
3350
3351/// Matches either L && R or L || R,
3352/// either one being in the either binary or logical form.
3353/// Note that the latter form is poison-blocking.
3354template <typename LHS, typename RHS, bool Commutable = false>
3360
3361/// Matches either L && R or L || R where L and R are arbitrary values.
3362inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3363
3364/// Matches either L && R or L || R with LHS and RHS in either order.
3365template <typename LHS, typename RHS>
3366inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3367 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3368}
3369
3370} // end namespace PatternMatch
3371} // end namespace llvm
3372
3373#endif // LLVM_IR_PATTERNMATCH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
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
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
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
uint64_t IntrinsicInst * II
#define P(N)
SmallVector< MachineOperand, 4 > Cond
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:1572
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:550
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:740
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
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:565
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1316
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
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:44
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
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.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
'undef' values are things that do not have specified contents.
Definition Constants.h:1657
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
Base class of all SIMD vector types.
Represents an op.with.overflow intrinsic.
An efficient, type-erasing, non-owning reference to a callable.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
match_combine_and< Ty... > m_CombineAnd(const Ty &...Ps)
Combine pattern matchers matching all of Ps patterns.
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.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
match_bind< PHINode > m_Phi(PHINode *&PN)
Match a PHI node, capturing it if we match.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
auto m_BSwap(const Opnd0 &Op0)
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)
auto m_Cmp()
Matches any compare instruction and ignore it.
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
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)
auto m_BitReverse(const Opnd0 &Op0)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
auto m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
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.
FNeg_match< OpTy, false > m_FNeg(const OpTy &X)
Match fneg X only.
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
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.
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)
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)
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
auto m_Poison()
Match an arbitrary poison constant.
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.
auto m_Sqrt(const Opnd0 &Op0)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
auto m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
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)
LoadSimple_match< OpTy > m_LoadSimple(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.
match_bind< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1)
match_deferred< 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()...
cstval_pred_ty< Predicate, ConstantInt, AllowPoison > cst_pred_ty
specialization of cstval_pred_ty for ConstantInt
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)
cstfp_pred_ty< is_signed_inf< true > > m_NegInf()
Match a negative infinity FP constant.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
auto m_c_XorLike(const LHS &L, const RHS &R)
Match either (xor L, R), (xor R, L) or (sub nuw R, L) iff R.isMask() Only commutative matcher as the ...
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
CmpClass_match< LHS, RHS, CmpInst, true > m_c_Cmp(const LHS &L, const RHS &R)
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'.
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.
FMaxMin_match< LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1)
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.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
auto m_BinOp()
Match an arbitrary binary operation and ignore it.
auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< CastInst_match< OpTy, SExtInst >, OpTy > m_SExtOrSelf(const OpTy &Op)
FMaxMin_match< LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
auto m_BasicBlock()
Match an arbitrary basic block value and ignore it.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
auto m_CopySign(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_or< CastInst_match< OpTy, UIToFPInst >, CastInst_match< OpTy, SIToFPInst > > m_IToFP(const OpTy &Op)
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1)
ICmpLike_match< LHS, RHS > m_ICmpLike(CmpPredicate &Pred, const LHS &L, const RHS &R)
CastInst_match< OpTy, FPToUIInst > m_FPToUI(const OpTy &Op)
auto m_Value()
Match an arbitrary value and ignore it.
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).
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)
auto m_Ctpop(const Opnd0 &Op0)
auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1)
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)
auto m_SpecificType(Type *RefTy, const Pattern &P)
Match a value of a specific type.
auto m_UndefValue()
Match an arbitrary UndefValue constant.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
auto m_Constant()
Match an arbitrary Constant and ignore it.
ContainsMatchingVectorElement_match< SPTy > m_ContainsMatchingVectorElement(const SPTy &SubPattern)
Match a vector constant where at least one of its elements matches the subpattern.
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)
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
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.
auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedGather Intrinsic.
auto m_VScale()
Matches a call to llvm.vscale().
FMaxMin_match< LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
match_combine_or< CastInst_match< OpTy, FPToUIInst >, CastInst_match< OpTy, FPToSIInst > > m_FPToI(const OpTy &Op)
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)
match_bind< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
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)
auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1)
FMaxMin_match< LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1)
Splat_match< T > m_Splat(const T &SubPattern)
Match a vector splat.
auto m_AnyIntrinsic()
Matches any intrinsic call and ignore it.
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()
match_combine_or< FMaxMin_match< LHS, RHS, ofmin_pred_ty >, FMaxMin_match< LHS, RHS, ufmin_pred_ty > > m_OrdOrUnordFMin(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point minimum function.
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)
auto m_FCanonicalize(const Opnd0 &Op0)
is_zero< false > m_ZeroForbidPoison()
is_zero< true > m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op, true > m_c_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations in either order.
auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
AllowFmf_match< T, FastMathFlags::ApproxFunc > m_ApproxFunc(const T &SubPattern)
auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< icmp_pred_with_threshold, false > m_SpecificInt_ICMP_ForbidPoison(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
SpecificType_match(const Type *, const Pattern &) -> SpecificType_match< Pattern >
cstfp_pred_ty< is_signed_inf< false > > m_PosInf()
Match a positive infinity FP constant.
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_ZExtOrTruncOrSelf(const OpTy &Op)
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.
SelectLike_match< CondTy, LTy, RTy > m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC)
Matches a value that behaves like a boolean-controlled select, i.e.
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
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".
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
cstval_pred_ty< Predicate, ConstantFP, true > cstfp_pred_ty
specialization of cstval_pred_ty for ConstantFP
auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
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.
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
auto m_Deinterleave2(const Opnd &Op)
auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedStore Intrinsic.
auto m_c_MaxOrMin(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.
auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedLoad Intrinsic.
FNeg_match< OpTy, true > m_FNegOrFSubNegZero(const OpTy &X)
Match fneg X or fsub -0.0, X.
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
auto m_FAbs(const Opnd0 &Op0)
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".
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.
match_combine_or< FMaxMin_match< LHS, RHS, ofmax_pred_ty >, FMaxMin_match< LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
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)
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.
auto m_UnOp()
Match an arbitrary unary operation and ignore it.
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)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
auto m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
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))
auto m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
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)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
auto m_FMaxNum(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.
auto m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
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'.
auto m_VecReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
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.
auto m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
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)
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.
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
TwoOps_match< Src_t, Off_t, Instruction::BitExtract > m_BitExtract(const Src_t &Src, const Off_t &Off)
Matches BitExtractInst.
AllowFmf_match< T, FastMathFlags::AllowReciprocal > m_AllowReciprocal(const T &SubPattern)
ThreeOps_match< Base_t, Val_t, Off_t, Instruction::BitInsert > m_BitInsert(const Base_t &Base, const Val_t &Val, const Off_t &Off)
Matches BitInsertInst.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
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.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1755
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:1788
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2182
Matcher to bind the captured value.
Matcher for a specific value, but stores a reference to the value, not the value itself.
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)
FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
ICmpLike_match(CmpPredicate &P, const LHS_t &Left, const RHS_t &Right)
Matcher for a single index InsertValue instruction.
InsertValue_match(const T0 &Op0, const T1 &Op1)
IntrinsicID_match(Intrinsic::ID IntrID)
Match intrinsic calls with any of the given IDs.
static auto impl(std::index_sequence< Is... >, const Ts &...Ops)
Matches a simple (non-volatile, non-atomic) LoadInst.
OneOps_match< OpTy, Instruction::Load > Base
LogicalOp_match(const LHS &L, const RHS &R)
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)
SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
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)
SpecificType_match(Type *RefTy, const Pattern &P)
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,...
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
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 APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool match(ITy *V) const
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
bool match(ArrayRef< int > Mask) const
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)
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.
Matcher for 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)
static bool check(const Value *V)