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> 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 (FPMO->getOpcode() == Instruction::FSub) {
1255 if (FPMO->hasNoSignedZeros()) {
1256 // With 'nsz', any zero goes.
1257 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1258 return false;
1259 } else {
1260 // Without 'nsz', we need fsub -0.0, X exactly.
1261 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1262 return false;
1263 }
1264
1265 return X.match(FPMO->getOperand(1));
1266 }
1267
1268 return false;
1269 }
1270};
1271
1272/// Match 'fneg X' as 'fsub -0.0, X'.
1273template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1274 return FNeg_match<OpTy>(X);
1275}
1276
1277/// Match 'fneg X' as 'fsub +-0.0, X'.
1278template <typename RHS>
1279inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1280m_FNegNSZ(const RHS &X) {
1281 return m_FSub(m_AnyZeroFP(), X);
1282}
1283
1284template <typename LHS, typename RHS>
1289
1290template <typename LHS, typename RHS>
1295
1296template <typename LHS, typename RHS>
1301
1302template <typename LHS, typename RHS>
1307
1308template <typename LHS, typename RHS>
1313
1314template <typename LHS, typename RHS>
1319
1320template <typename LHS, typename RHS>
1325
1326template <typename LHS, typename RHS>
1331
1332template <typename LHS, typename RHS>
1337
1338template <typename LHS, typename RHS>
1343
1344template <typename LHS, typename RHS>
1349
1350template <typename LHS, typename RHS>
1355
1356template <typename LHS, typename RHS>
1361
1362template <typename LHS, typename RHS>
1367
1368template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1371
1373
1374 template <typename OpTy> bool match(OpTy *V) const {
1375 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1376 if (Op->getOpcode() == Opcode)
1377 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1378 L.match(Op->getOperand(0));
1379 }
1380 // Interpreted as shiftop V, 0
1381 R = 0;
1382 return L.match(V);
1383 }
1384};
1385
1386/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1387template <typename LHS>
1392
1393/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1394template <typename LHS>
1399
1400/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1401template <typename LHS>
1406
1407template <typename LHS_t, typename RHS_t, unsigned Opcode,
1408 unsigned WrapFlags = 0, bool Commutable = false>
1412
1414 : L(LHS), R(RHS) {}
1415
1416 template <typename OpTy> bool match(OpTy *V) const {
1417 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1418 if (Op->getOpcode() != Opcode)
1419 return false;
1421 !Op->hasNoUnsignedWrap())
1422 return false;
1423 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1424 !Op->hasNoSignedWrap())
1425 return false;
1426 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1427 (Commutable && L.match(Op->getOperand(1)) &&
1428 R.match(Op->getOperand(0)));
1429 }
1430 return false;
1431 }
1432};
1433
1434template <typename LHS, typename RHS>
1435inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1437m_NSWAdd(const LHS &L, const RHS &R) {
1438 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1440 R);
1441}
1442template <typename LHS, typename RHS>
1443inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1445m_c_NSWAdd(const LHS &L, const RHS &R) {
1446 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1448 true>(L, R);
1449}
1450template <typename LHS, typename RHS>
1451inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1453m_NSWSub(const LHS &L, const RHS &R) {
1454 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1456 R);
1457}
1458template <typename LHS, typename RHS>
1459inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1461m_NSWMul(const LHS &L, const RHS &R) {
1462 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1464 R);
1465}
1466template <typename LHS, typename RHS>
1467inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1469m_NSWShl(const LHS &L, const RHS &R) {
1470 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1472 R);
1473}
1474
1475template <typename LHS, typename RHS>
1476inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1478m_NUWAdd(const LHS &L, const RHS &R) {
1479 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1481 L, R);
1482}
1483
1484template <typename LHS, typename RHS>
1486 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1487m_c_NUWAdd(const LHS &L, const RHS &R) {
1488 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1490 true>(L, R);
1491}
1492
1493template <typename LHS, typename RHS>
1494inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1496m_NUWSub(const LHS &L, const RHS &R) {
1497 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1499 L, R);
1500}
1501template <typename LHS, typename RHS>
1502inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1504m_NUWMul(const LHS &L, const RHS &R) {
1505 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1507 L, R);
1508}
1509template <typename LHS, typename RHS>
1510inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1512m_NUWShl(const LHS &L, const RHS &R) {
1513 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1515 L, R);
1516}
1517
1518template <typename LHS_t, typename RHS_t, bool Commutable = false>
1520 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1521 unsigned Opcode;
1522
1524 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1525
1526 template <typename OpTy> bool match(OpTy *V) const {
1528 }
1529};
1530
1531/// Matches a specific opcode.
1532template <typename LHS, typename RHS>
1533inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1534 const RHS &R) {
1535 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1536}
1537
1538template <typename LHS, typename RHS, bool Commutable = false>
1542
1543 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1544
1545 template <typename OpTy> bool match(OpTy *V) const {
1546 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1547 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1548 if (!PDI->isDisjoint())
1549 return false;
1550 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1551 (Commutable && L.match(PDI->getOperand(1)) &&
1552 R.match(PDI->getOperand(0)));
1553 }
1554 return false;
1555 }
1556};
1557
1558template <typename LHS, typename RHS>
1560 return DisjointOr_match<LHS, RHS>(L, R);
1561}
1562
1563template <typename LHS, typename RHS>
1565 const RHS &R) {
1567}
1568
1569/// Match either "add" or "or disjoint".
1570template <typename LHS, typename RHS>
1573m_AddLike(const LHS &L, const RHS &R) {
1574 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1575}
1576
1577/// Match either "add nsw" or "or disjoint"
1578template <typename LHS, typename RHS>
1579inline match_combine_or<
1580 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1583m_NSWAddLike(const LHS &L, const RHS &R) {
1584 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1585}
1586
1587/// Match either "add nuw" or "or disjoint"
1588template <typename LHS, typename RHS>
1589inline match_combine_or<
1590 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1593m_NUWAddLike(const LHS &L, const RHS &R) {
1594 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1595}
1596
1597template <typename LHS, typename RHS>
1601
1602 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1603
1604 template <typename OpTy> bool match(OpTy *V) const {
1605 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1606 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1607 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1608 ; // Pass
1609 else if (Op->getOpcode() != Instruction::Xor)
1610 return false;
1611 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1612 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1613 }
1614 return false;
1615 }
1616};
1617
1618/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1619/// Only commutative matcher as the `sub` will need to swap the L and R.
1620template <typename LHS, typename RHS>
1621inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1622 return XorLike_match<LHS, RHS>(L, R);
1623}
1624
1625//===----------------------------------------------------------------------===//
1626// Class that matches a group of binary opcodes.
1627//
1628template <typename LHS_t, typename RHS_t, typename Predicate,
1629 bool Commutable = false>
1630struct BinOpPred_match : Predicate {
1633
1634 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1635
1636 template <typename OpTy> bool match(OpTy *V) const {
1637 if (auto *I = dyn_cast<Instruction>(V))
1638 return this->isOpType(I->getOpcode()) &&
1639 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1640 (Commutable && L.match(I->getOperand(1)) &&
1641 R.match(I->getOperand(0))));
1642 return false;
1643 }
1644};
1645
1647 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1648};
1649
1651 bool isOpType(unsigned Opcode) const {
1652 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1653 }
1654};
1655
1657 bool isOpType(unsigned Opcode) const {
1658 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1659 }
1660};
1661
1663 bool isOpType(unsigned Opcode) const {
1664 return Instruction::isBitwiseLogicOp(Opcode);
1665 }
1666};
1667
1669 bool isOpType(unsigned Opcode) const {
1670 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1671 }
1672};
1673
1675 bool isOpType(unsigned Opcode) const {
1676 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1677 }
1678};
1679
1680/// Matches shift operations.
1681template <typename LHS, typename RHS>
1683 const RHS &R) {
1685}
1686
1687/// Matches logical shift operations.
1688template <typename LHS, typename RHS>
1693
1694/// Matches logical shift operations.
1695template <typename LHS, typename RHS>
1697m_LogicalShift(const LHS &L, const RHS &R) {
1699}
1700
1701/// Matches bitwise logic operations.
1702template <typename LHS, typename RHS>
1704m_BitwiseLogic(const LHS &L, const RHS &R) {
1706}
1707
1708/// Matches bitwise logic operations in either order.
1709template <typename LHS, typename RHS>
1714
1715/// Matches integer division operations.
1716template <typename LHS, typename RHS>
1718 const RHS &R) {
1720}
1721
1722/// Matches integer remainder operations.
1723template <typename LHS, typename RHS>
1725 const RHS &R) {
1727}
1728
1729//===----------------------------------------------------------------------===//
1730// Class that matches exact binary ops.
1731//
1732template <typename SubPattern_t> struct Exact_match {
1733 SubPattern_t SubPattern;
1734
1735 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1736
1737 template <typename OpTy> bool match(OpTy *V) const {
1738 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1739 return PEO->isExact() && SubPattern.match(V);
1740 return false;
1741 }
1742};
1743
1744template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1745 return SubPattern;
1746}
1747
1748//===----------------------------------------------------------------------===//
1749// Matchers for CmpInst classes
1750//
1751
1752template <typename LHS_t, typename RHS_t, typename Class,
1753 bool Commutable = false>
1758
1759 // The evaluation order is always stable, regardless of Commutability.
1760 // The LHS is always matched first.
1762 : Predicate(&Pred), L(LHS), R(RHS) {}
1764 : Predicate(nullptr), L(LHS), R(RHS) {}
1765
1766 template <typename OpTy> bool match(OpTy *V) const {
1767 if (auto *I = dyn_cast<Class>(V)) {
1768 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1769 if (Predicate)
1771 return true;
1772 }
1773 if (Commutable && L.match(I->getOperand(1)) &&
1774 R.match(I->getOperand(0))) {
1775 if (Predicate)
1777 return true;
1778 }
1779 }
1780 return false;
1781 }
1782};
1783
1784template <typename LHS, typename RHS>
1786 const RHS &R) {
1787 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1788}
1789
1790template <typename LHS, typename RHS>
1792 const LHS &L, const RHS &R) {
1793 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1794}
1795
1796template <typename LHS, typename RHS>
1798 const LHS &L, const RHS &R) {
1799 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1800}
1801
1802template <typename LHS, typename RHS>
1805}
1806
1807template <typename LHS, typename RHS>
1810}
1811
1812template <typename LHS, typename RHS>
1815}
1816
1817// Same as CmpClass, but instead of saving Pred as out output variable, match a
1818// specific input pred for equality.
1819template <typename LHS_t, typename RHS_t, typename Class,
1820 bool Commutable = false>
1825
1827 : Predicate(Pred), L(LHS), R(RHS) {}
1828
1829 template <typename OpTy> bool match(OpTy *V) const {
1830 if (auto *I = dyn_cast<Class>(V)) {
1832 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1833 return true;
1834 if constexpr (Commutable) {
1837 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1838 return true;
1839 }
1840 }
1841
1842 return false;
1843 }
1844};
1845
1846template <typename LHS, typename RHS>
1848m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1849 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1850}
1851
1852template <typename LHS, typename RHS>
1854m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1855 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1856}
1857
1858template <typename LHS, typename RHS>
1860m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1862}
1863
1864template <typename LHS, typename RHS>
1866m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1867 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1868}
1869
1870//===----------------------------------------------------------------------===//
1871// Matchers for instructions with a given opcode and number of operands.
1872//
1873
1874/// Matches instructions with Opcode and three operands.
1875template <typename T0, unsigned Opcode> struct OneOps_match {
1877
1878 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1879
1880 template <typename OpTy> bool match(OpTy *V) const {
1881 if (V->getValueID() == Value::InstructionVal + Opcode) {
1882 auto *I = cast<Instruction>(V);
1883 return Op1.match(I->getOperand(0));
1884 }
1885 return false;
1886 }
1887};
1888
1889/// Matches instructions with Opcode and three operands.
1890template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1893
1894 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1895
1896 template <typename OpTy> bool match(OpTy *V) const {
1897 if (V->getValueID() == Value::InstructionVal + Opcode) {
1898 auto *I = cast<Instruction>(V);
1899 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1900 }
1901 return false;
1902 }
1903};
1904
1905/// Matches instructions with Opcode and three operands.
1906template <typename T0, typename T1, typename T2, unsigned Opcode,
1907 bool CommutableOp2Op3 = false>
1912
1913 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1914 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1915
1916 template <typename OpTy> bool match(OpTy *V) const {
1917 if (V->getValueID() == Value::InstructionVal + Opcode) {
1918 auto *I = cast<Instruction>(V);
1919 if (!Op1.match(I->getOperand(0)))
1920 return false;
1921 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1922 return true;
1923 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1924 Op3.match(I->getOperand(1));
1925 }
1926 return false;
1927 }
1928};
1929
1930/// Matches instructions with Opcode and any number of operands
1931template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1932 std::tuple<OperandTypes...> Operands;
1933
1934 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1935
1936 // Operand matching works by recursively calling match_operands, matching the
1937 // operands left to right. The first version is called for each operand but
1938 // the last, for which the second version is called. The second version of
1939 // match_operands is also used to match each individual operand.
1940 template <int Idx, int Last>
1941 std::enable_if_t<Idx != Last, bool>
1945
1946 template <int Idx, int Last>
1947 std::enable_if_t<Idx == Last, bool>
1949 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1950 }
1951
1952 template <typename OpTy> bool match(OpTy *V) const {
1953 if (V->getValueID() == Value::InstructionVal + Opcode) {
1954 auto *I = cast<Instruction>(V);
1955 return I->getNumOperands() == sizeof...(OperandTypes) &&
1956 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1957 }
1958 return false;
1959 }
1960};
1961
1962/// Matches SelectInst.
1963template <typename Cond, typename LHS, typename RHS>
1965m_Select(const Cond &C, const LHS &L, const RHS &R) {
1967}
1968
1969/// This matches a select of two constants, e.g.:
1970/// m_SelectCst<-1, 0>(m_Value(V))
1971template <int64_t L, int64_t R, typename Cond>
1973 Instruction::Select>
1976}
1977
1978/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1979template <typename LHS, typename RHS>
1980inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1981m_c_Select(const LHS &L, const RHS &R) {
1982 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1983 true>(m_Value(), L, R);
1984}
1985
1986/// Matches FreezeInst.
1987template <typename OpTy>
1991
1992/// Matches InsertElementInst.
1993template <typename Val_t, typename Elt_t, typename Idx_t>
1995m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1997 Val, Elt, Idx);
1998}
1999
2000/// Matches ExtractElementInst.
2001template <typename Val_t, typename Idx_t>
2003m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
2005}
2006
2007/// Matches shuffle.
2008template <typename T0, typename T1, typename T2> struct Shuffle_match {
2012
2013 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
2014 : Op1(Op1), Op2(Op2), Mask(Mask) {}
2015
2016 template <typename OpTy> bool match(OpTy *V) const {
2017 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
2018 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
2019 Mask.match(I->getShuffleMask());
2020 }
2021 return false;
2022 }
2023};
2024
2025struct m_Mask {
2028 bool match(ArrayRef<int> Mask) const {
2029 MaskRef = Mask;
2030 return true;
2031 }
2032};
2033
2035 bool match(ArrayRef<int> Mask) const {
2036 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
2037 }
2038};
2039
2043 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
2044};
2045
2047 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
2048};
2049
2053 bool match(ArrayRef<int> Mask) const {
2054 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2055 if (First == Mask.end())
2056 return false;
2057 SplatIndex = *First;
2058 return all_of(Mask,
2059 [First](int Elem) { return Elem == *First || Elem == -1; });
2060 }
2061};
2062
2063template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2064 PointerOpTy PointerOp;
2065 OffsetOpTy OffsetOp;
2066
2067 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2069
2070 template <typename OpTy> bool match(OpTy *V) const {
2071 auto *GEP = dyn_cast<GEPOperator>(V);
2072 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2073 PointerOp.match(GEP->getPointerOperand()) &&
2074 OffsetOp.match(GEP->idx_begin()->get());
2075 }
2076};
2077
2078/// Matches ShuffleVectorInst independently of mask value.
2079template <typename V1_t, typename V2_t>
2081m_Shuffle(const V1_t &v1, const V2_t &v2) {
2083}
2084
2085template <typename V1_t, typename V2_t, typename Mask_t>
2087m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2089}
2090
2091/// Matches LoadInst.
2092template <typename OpTy>
2096
2097/// Matches a simple (non-volatile, non-atomic) LoadInst.
2098template <typename OpTy> struct LoadSimple_match {
2100
2102
2103 template <typename ITy> bool match(ITy *V) const {
2104 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2105 }
2106};
2107
2108template <typename OpTy>
2112
2113/// Matches StoreInst.
2114template <typename ValueOpTy, typename PointerOpTy>
2116m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2118 PointerOp);
2119}
2120
2121/// Matches GetElementPtrInst.
2122template <typename... OperandTypes>
2123inline auto m_GEP(const OperandTypes &...Ops) {
2124 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2125}
2126
2127/// Matches GEP with i8 source element type
2128template <typename PointerOpTy, typename OffsetOpTy>
2130m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2132}
2133
2134//===----------------------------------------------------------------------===//
2135// Matchers for CastInst classes
2136//
2137
2138template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2139 Op_t Op;
2140
2141 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2142
2143 template <typename OpTy> bool match(OpTy *V) const {
2144 if (auto *O = dyn_cast<Operator>(V))
2145 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2146 return false;
2147 }
2148};
2149
2150template <typename Op_t, typename Class> struct CastInst_match {
2151 Op_t Op;
2152
2153 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2154
2155 template <typename OpTy> bool match(OpTy *V) const {
2156 if (auto *I = dyn_cast<Class>(V))
2157 return Op.match(I->getOperand(0));
2158 return false;
2159 }
2160};
2161
2162template <typename Op_t> struct PtrToIntSameSize_match {
2164 Op_t Op;
2165
2166 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2167 : DL(DL), Op(OpMatch) {}
2168
2169 template <typename OpTy> bool match(OpTy *V) const {
2170 if (auto *O = dyn_cast<Operator>(V))
2171 return O->getOpcode() == Instruction::PtrToInt &&
2172 DL.getTypeSizeInBits(O->getType()) ==
2173 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2174 Op.match(O->getOperand(0));
2175 return false;
2176 }
2177};
2178
2179template <typename Op_t> struct NNegZExt_match {
2180 Op_t Op;
2181
2182 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2183
2184 template <typename OpTy> bool match(OpTy *V) const {
2185 if (auto *I = dyn_cast<ZExtInst>(V))
2186 return I->hasNonNeg() && Op.match(I->getOperand(0));
2187 return false;
2188 }
2189};
2190
2191template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2192 Op_t Op;
2193
2194 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2195
2196 template <typename OpTy> bool match(OpTy *V) const {
2197 if (auto *I = dyn_cast<TruncInst>(V))
2198 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2199 Op.match(I->getOperand(0));
2200 return false;
2201 }
2202};
2203
2204/// Matches BitCast.
2205template <typename OpTy>
2210
2211template <typename Op_t> struct ElementWiseBitCast_match {
2212 Op_t Op;
2213
2214 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2215
2216 template <typename OpTy> bool match(OpTy *V) const {
2217 auto *I = dyn_cast<BitCastInst>(V);
2218 if (!I)
2219 return false;
2220 Type *SrcType = I->getSrcTy();
2221 Type *DstType = I->getType();
2222 // Make sure the bitcast doesn't change between scalar and vector and
2223 // doesn't change the number of vector elements.
2224 if (SrcType->isVectorTy() != DstType->isVectorTy())
2225 return false;
2226 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2227 SrcVecTy && SrcVecTy->getElementCount() !=
2228 cast<VectorType>(DstType)->getElementCount())
2229 return false;
2230 return Op.match(I->getOperand(0));
2231 }
2232};
2233
2234template <typename OpTy>
2238
2239/// Matches PtrToInt.
2240template <typename OpTy>
2245
2246template <typename OpTy>
2251
2252/// Matches PtrToAddr.
2253template <typename OpTy>
2258
2259/// Matches PtrToInt or PtrToAddr.
2260template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2262}
2263
2264/// Matches IntToPtr.
2265template <typename OpTy>
2270
2271/// Matches any cast or self. Used to ignore casts.
2272template <typename OpTy>
2277
2278/// Matches Trunc.
2279template <typename OpTy>
2283
2284/// Matches trunc nuw.
2285template <typename OpTy>
2290
2291/// Matches trunc nsw.
2292template <typename OpTy>
2297
2298template <typename OpTy>
2301 return m_CombineOr(m_Trunc(Op), Op);
2302}
2303
2304/// Matches SExt.
2305template <typename OpTy>
2309
2310/// Matches ZExt.
2311template <typename OpTy>
2315
2316template <typename OpTy>
2318 return NNegZExt_match<OpTy>(Op);
2319}
2320
2321template <typename OpTy>
2324 return m_CombineOr(m_ZExt(Op), Op);
2325}
2326
2327template <typename OpTy>
2330 return m_CombineOr(m_SExt(Op), Op);
2331}
2332
2333/// Match either "sext" or "zext nneg".
2334template <typename OpTy>
2337 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2338}
2339
2340template <typename OpTy>
2344 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2345}
2346
2347template <typename OpTy>
2350 OpTy>
2352 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2353}
2354
2355template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2356 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2357}
2358
2359template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2363
2365 : Pred(P), L(Left), R(Right) {}
2366
2367 template <typename OpTy> bool match(OpTy *V) const {
2368 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2369 return true;
2370 Value *A;
2371 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2372 if (V->getType()->isIntOrIntVectorTy(1) &&
2373 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2374 R.match(ConstantInt::getNullValue(A->getType()))) {
2376 return true;
2377 }
2378 return false;
2379 }
2380};
2381
2382template <typename LHS, typename RHS>
2384 const RHS &R) {
2385 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2386}
2387
2388template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2389 CondTy Cond;
2392
2393 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2394 : Cond(C), TrueC(TC), FalseC(FC) {}
2395
2396 template <typename OpTy> bool match(OpTy *V) const {
2397 // select(Cond, TrueC, FalseC) — captures both constants directly
2399 return true;
2400
2401 Type *Ty = V->getType();
2402 Value *CondV = nullptr;
2403
2404 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2405 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2406 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2407 TrueC.match(ConstantInt::get(Ty, 1)) &&
2408 FalseC.match(ConstantInt::get(Ty, 0)))
2409 return true;
2410
2411 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2412 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2413 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2414 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2415 FalseC.match(ConstantInt::get(Ty, 0)))
2416 return true;
2417
2418 return false;
2419 }
2420};
2421
2422/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2423/// select i1 Cond, TrueC, FalseC
2424/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2425/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2426///
2427/// The condition is matched against \p Cond, and the true/false constants
2428/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2429/// constants are bound to \p TrueC and \p FalseC via their matchers.
2430template <typename CondTy, typename LTy, typename RTy>
2432m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2433 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2434}
2435
2436template <typename OpTy>
2440
2441template <typename OpTy>
2445
2446template <typename OpTy>
2449m_IToFP(const OpTy &Op) {
2450 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2451}
2452
2453template <typename OpTy>
2457
2458template <typename OpTy>
2462
2463template <typename OpTy>
2466m_FPToI(const OpTy &Op) {
2467 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2468}
2469
2470template <typename OpTy>
2474
2475template <typename OpTy>
2479
2480//===----------------------------------------------------------------------===//
2481// Matchers for control flow.
2482//
2483
2484struct br_match {
2486
2488
2489 template <typename OpTy> bool match(OpTy *V) const {
2490 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2491 Succ = BI->getSuccessor();
2492 return true;
2493 }
2494 return false;
2495 }
2496};
2497
2498inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2499
2500template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2502 Cond_t Cond;
2503 TrueBlock_t T;
2504 FalseBlock_t F;
2505
2506 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2507 : Cond(C), T(t), F(f) {}
2508
2509 template <typename OpTy> bool match(OpTy *V) const {
2510 if (auto *BI = dyn_cast<CondBrInst>(V))
2511 if (Cond.match(BI->getCondition()))
2512 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2513 return false;
2514 }
2515};
2516
2517template <typename Cond_t>
2523
2524template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2526m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2528}
2529
2530//===----------------------------------------------------------------------===//
2531// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2532//
2533
2534template <typename LHS_t, typename RHS_t, typename Pred_t>
2536 using PredType = Pred_t;
2539
2540 // The evaluation order is always stable, regardless of Commutability.
2541 // The LHS is always matched first.
2542 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2543
2544 template <typename OpTy> bool match(OpTy *V) const {
2545 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2546 auto *SI = dyn_cast<SelectInst>(V);
2547 if (!SI)
2548 return false;
2549 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2550 if (!Cmp)
2551 return false;
2552 // At this point we have a select conditioned on a comparison. Check that
2553 // it is the values returned by the select that are being compared.
2554 auto *TrueVal = SI->getTrueValue();
2555 auto *FalseVal = SI->getFalseValue();
2556 auto *LHS = Cmp->getOperand(0);
2557 auto *RHS = Cmp->getOperand(1);
2558 if ((TrueVal != LHS || FalseVal != RHS) &&
2559 (TrueVal != RHS || FalseVal != LHS))
2560 return false;
2561 FCmpInst::Predicate Pred =
2562 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2563 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2564 if (!Pred_t::match(Pred))
2565 return false;
2566 // It does! Bind the operands.
2567 return L.match(LHS) && R.match(RHS);
2568 }
2569};
2570
2571/// Helper class for identifying ordered max predicates.
2573 static bool match(FCmpInst::Predicate Pred) {
2574 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2575 }
2576};
2577
2578/// Helper class for identifying ordered min predicates.
2580 static bool match(FCmpInst::Predicate Pred) {
2581 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2582 }
2583};
2584
2585/// Helper class for identifying unordered max predicates.
2587 static bool match(FCmpInst::Predicate Pred) {
2588 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2589 }
2590};
2591
2592/// Helper class for identifying unordered min predicates.
2594 static bool match(FCmpInst::Predicate Pred) {
2595 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2596 }
2597};
2598
2599/// Match an 'ordered' floating point maximum function.
2600/// Floating point has one special value 'NaN'. Therefore, there is no total
2601/// order. However, if we can ignore the 'NaN' value (for example, because of a
2602/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2603/// semantics. In the presence of 'NaN' we have to preserve the original
2604/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2605///
2606/// max(L, R) iff L and R are not NaN
2607/// m_OrdFMax(L, R) = R iff L or R are NaN
2608template <typename LHS, typename RHS>
2610 const RHS &R) {
2612}
2613
2614/// Match an 'ordered' floating point minimum function.
2615/// Floating point has one special value 'NaN'. Therefore, there is no total
2616/// order. However, if we can ignore the 'NaN' value (for example, because of a
2617/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2618/// semantics. In the presence of 'NaN' we have to preserve the original
2619/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2620///
2621/// min(L, R) iff L and R are not NaN
2622/// m_OrdFMin(L, R) = R iff L or R are NaN
2623template <typename LHS, typename RHS>
2625 const RHS &R) {
2627}
2628
2629/// Match an 'unordered' floating point maximum function.
2630/// Floating point has one special value 'NaN'. Therefore, there is no total
2631/// order. However, if we can ignore the 'NaN' value (for example, because of a
2632/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2633/// semantics. In the presence of 'NaN' we have to preserve the original
2634/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2635///
2636/// max(L, R) iff L and R are not NaN
2637/// m_UnordFMax(L, R) = L iff L or R are NaN
2638template <typename LHS, typename RHS>
2643
2644/// Match an 'unordered' floating point minimum function.
2645/// Floating point has one special value 'NaN'. Therefore, there is no total
2646/// order. However, if we can ignore the 'NaN' value (for example, because of a
2647/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2648/// semantics. In the presence of 'NaN' we have to preserve the original
2649/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2650///
2651/// min(L, R) iff L and R are not NaN
2652/// m_UnordFMin(L, R) = L iff L or R are NaN
2653template <typename LHS, typename RHS>
2658
2659/// Match an 'ordered' or 'unordered' floating point maximum function.
2660/// Floating point has one special value 'NaN'. Therefore, there is no total
2661/// order. However, if we can ignore the 'NaN' value (for example, because of a
2662/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2663/// semantics.
2664template <typename LHS, typename RHS>
2671
2672/// Match an 'ordered' or 'unordered' floating point minimum function.
2673/// Floating point has one special value 'NaN'. Therefore, there is no total
2674/// order. However, if we can ignore the 'NaN' value (for example, because of a
2675/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2676/// semantics.
2677template <typename LHS, typename RHS>
2684
2685/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2686/// NOTE: we first match the 'Not' (by matching '-1'),
2687/// and only then match the inner matcher!
2688template <typename ValTy>
2689inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2690m_Not(const ValTy &V) {
2691 return m_c_Xor(m_AllOnes(), V);
2692}
2693
2694template <typename ValTy>
2695inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2696 true>
2697m_NotForbidPoison(const ValTy &V) {
2698 return m_c_Xor(m_AllOnesForbidPoison(), V);
2699}
2700
2701//===----------------------------------------------------------------------===//
2702// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2703// Note that S might be matched to other instructions than AddInst.
2704//
2705
2706template <typename LHS_t, typename RHS_t, typename Sum_t>
2710 Sum_t S;
2711
2712 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2713 : L(L), R(R), S(S) {}
2714
2715 template <typename OpTy> bool match(OpTy *V) const {
2716 Value *ICmpLHS, *ICmpRHS;
2717 CmpPredicate Pred;
2718 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2719 return false;
2720
2721 Value *AddLHS, *AddRHS;
2722 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2723
2724 // (a + b) u< a, (a + b) u< b
2725 if (Pred == ICmpInst::ICMP_ULT)
2726 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2727 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2728
2729 // a >u (a + b), b >u (a + b)
2730 if (Pred == ICmpInst::ICMP_UGT)
2731 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2732 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2733
2734 Value *Op1;
2735 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2736 // (~a) <u b
2737 if (Pred == ICmpInst::ICMP_ULT) {
2738 if (XorExpr.match(ICmpLHS))
2739 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2740 }
2741 // b > u (~a)
2742 if (Pred == ICmpInst::ICMP_UGT) {
2743 if (XorExpr.match(ICmpRHS))
2744 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2745 }
2746
2747 // Match special-case for increment-by-1.
2748 if (Pred == ICmpInst::ICMP_EQ) {
2749 // (a + 1) == 0
2750 // (1 + a) == 0
2751 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2752 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2753 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2754 // 0 == (a + 1)
2755 // 0 == (1 + a)
2756 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2757 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2758 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2759 }
2760
2761 return false;
2762 }
2763};
2764
2765/// Match an icmp instruction checking for unsigned overflow on addition.
2766///
2767/// S is matched to the addition whose result is being checked for overflow, and
2768/// L and R are matched to the LHS and RHS of S.
2769template <typename LHS_t, typename RHS_t, typename Sum_t>
2771m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2773}
2774
2775template <typename Opnd_t> struct Argument_match {
2776 unsigned OpI;
2777 Opnd_t Val;
2778
2779 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2780
2781 template <typename OpTy> bool match(OpTy *V) const {
2782 // FIXME: Should likely be switched to use `CallBase`.
2783 if (const auto *CI = dyn_cast<CallInst>(V))
2784 return Val.match(CI->getArgOperand(OpI));
2785 return false;
2786 }
2787};
2788
2789/// Match an argument.
2790template <unsigned OpI, typename Opnd_t>
2791inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2792 return Argument_match<Opnd_t>(OpI, Op);
2793}
2794
2795/// Intrinsic matchers.
2797 unsigned ID;
2798
2800
2801 template <typename OpTy> bool match(OpTy *V) const {
2802 if (const auto *CI = dyn_cast<CallInst>(V))
2803 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2804 return F->getIntrinsicID() == ID;
2805 return false;
2806 }
2807};
2808
2809/// Match intrinsic calls with any of the given IDs.
2810template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2811 template <typename OpTy> bool match(OpTy *V) const {
2812 if (const auto *CI = dyn_cast<CallInst>(V))
2813 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2814 Intrinsic::ID ID = F->getIntrinsicID();
2815 return ((ID == IntrIDs) || ...);
2816 }
2817 return false;
2818 }
2819};
2820
2822 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2823 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2824 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2825 }
2826};
2827
2828/// Match intrinsic calls like this:
2829/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2830template <Intrinsic::ID IntrID, typename... Ts>
2831inline auto m_Intrinsic(const Ts &...Ops) {
2833 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2834}
2835
2836/// Match intrinsic calls with any of the given IDs like this:
2837/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2838/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2839/// because it performs the CallInst/Function cast only once.
2840template <Intrinsic::ID... IntrIDs>
2842 return IntrinsicIDs_match<IntrIDs...>();
2843}
2844
2845/// Matches MaskedLoad Intrinsic.
2846template <typename Opnd0, typename Opnd1, typename Opnd2>
2847inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2848 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2849}
2850
2851/// Matches MaskedStore Intrinsic.
2852template <typename Opnd0, typename Opnd1, typename Opnd2>
2853inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2854 const Opnd2 &Op2) {
2855 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2856}
2857
2858/// Matches MaskedGather Intrinsic.
2859template <typename Opnd0, typename Opnd1, typename Opnd2>
2860inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2861 const Opnd2 &Op2) {
2862 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2863}
2864
2865// Helper intrinsic matching specializations.
2866template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2868}
2869
2870template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2872}
2873template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2875}
2876
2877template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2878 return m_Intrinsic<Intrinsic::fabs>(Op0);
2879}
2880
2881template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2883}
2884
2885template <typename Opnd0, typename Opnd1>
2886inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2887 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2888}
2889
2890template <typename Opnd0, typename Opnd1>
2891inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2892 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2893}
2894
2895template <typename Opnd0, typename Opnd1>
2896inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2897 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2898}
2899
2900template <typename Opnd0, typename Opnd1>
2901inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2902 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2903}
2904
2905template <typename Opnd0, typename Opnd1>
2906inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2907 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2908}
2909
2910template <typename Opnd0, typename Opnd1>
2911inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2912 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2913}
2914
2915template <typename Opnd0, typename Opnd1>
2916inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2917 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2918 m_UMin(Op0, Op1));
2919}
2920
2921template <typename Opnd0, typename Opnd1>
2922inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2923 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2924}
2925
2926template <typename Opnd0, typename Opnd1>
2927inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2928 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2929}
2930
2931template <typename Opnd0, typename Opnd1>
2932inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2933 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2934}
2935
2936template <typename Opnd0, typename Opnd1>
2937inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2938 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2939}
2940
2941template <typename Opnd0, typename Opnd1>
2942inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2943 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2944}
2945
2946template <typename Opnd0, typename Opnd1>
2947inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2948 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2949}
2950
2951template <typename Opnd0, typename Opnd1>
2952inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2953 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2954}
2955
2956template <typename Opnd0, typename Opnd1>
2957inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2958 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2959}
2960
2961template <typename Opnd0, typename Opnd1, typename Opnd2>
2962inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2963 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2964}
2965
2966template <typename Opnd0, typename Opnd1, typename Opnd2>
2967inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2968 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2969}
2970
2971template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2972 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2973}
2974
2975template <typename Opnd0, typename Opnd1>
2976inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2977 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2978}
2979
2980template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
2982}
2983
2984template <typename Opnd0, typename Opnd1, typename Opnd2>
2985inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
2986 const Opnd2 &Op2) {
2987 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
2988}
2989
2990//===----------------------------------------------------------------------===//
2991// Matchers for two-operands operators with the operators in either order
2992//
2993
2994/// Matches a BinaryOperator with LHS and RHS in either order.
2995template <typename LHS, typename RHS>
2998}
2999
3000/// Matches an ICmp with a predicate over LHS and RHS in either order.
3001/// Swaps the predicate if operands are commuted.
3002template <typename LHS, typename RHS>
3004m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
3006}
3007
3008template <typename LHS, typename RHS>
3013
3014template <typename LHS, typename RHS>
3016 const RHS &R) {
3018}
3019
3020/// Matches a specific opcode with LHS and RHS in either order.
3021template <typename LHS, typename RHS>
3023m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
3024 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
3025}
3026
3027/// Matches a Add with LHS and RHS in either order.
3028template <typename LHS, typename RHS>
3033
3034/// Matches a Mul with LHS and RHS in either order.
3035template <typename LHS, typename RHS>
3040
3041/// Matches an And with LHS and RHS in either order.
3042template <typename LHS, typename RHS>
3047
3048/// Matches an Or with LHS and RHS in either order.
3049template <typename LHS, typename RHS>
3054
3055/// Matches an Xor with LHS and RHS in either order.
3056template <typename LHS, typename RHS>
3061
3062/// Matches a 'Neg' as 'sub 0, V'.
3063template <typename ValTy>
3064inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3065m_Neg(const ValTy &V) {
3066 return m_Sub(m_ZeroInt(), V);
3067}
3068
3069/// Matches a 'Neg' as 'sub nsw 0, V'.
3070template <typename ValTy>
3072 Instruction::Sub,
3074m_NSWNeg(const ValTy &V) {
3075 return m_NSWSub(m_ZeroInt(), V);
3076}
3077
3078template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3082
3083 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3084
3085 template <typename OpTy> bool match(OpTy *V) const {
3086 const auto *II = dyn_cast<IntrinsicInst>(V);
3087 if (!II || II->getIntrinsicID() != IntrID)
3088 return false;
3089 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3090 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3091 }
3092};
3093
3094template <Intrinsic::ID IntrID, typename T0, typename T1>
3096m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3098}
3099
3100/// Matches an SMin with LHS and RHS in either order.
3101template <typename LHS, typename RHS>
3102inline auto m_c_SMin(const LHS &L, const RHS &R) {
3103 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3104}
3105/// Matches an SMax with LHS and RHS in either order.
3106template <typename LHS, typename RHS>
3107inline auto m_c_SMax(const LHS &L, const RHS &R) {
3108 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3109}
3110/// Matches a UMin with LHS and RHS in either order.
3111template <typename LHS, typename RHS>
3112inline auto m_c_UMin(const LHS &L, const RHS &R) {
3113 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3114}
3115/// Matches a UMax with LHS and RHS in either order.
3116template <typename LHS, typename RHS>
3117inline auto m_c_UMax(const LHS &L, const RHS &R) {
3118 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3119}
3120
3121template <typename LHS, typename RHS>
3122inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3123 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3124 m_c_UMin(L, R));
3125}
3126
3127/// Matches FAdd with LHS and RHS in either order.
3128template <typename LHS, typename RHS>
3130m_c_FAdd(const LHS &L, const RHS &R) {
3132}
3133
3134/// Matches FMul with LHS and RHS in either order.
3135template <typename LHS, typename RHS>
3137m_c_FMul(const LHS &L, const RHS &R) {
3139}
3140
3141template <typename Opnd_t> struct Signum_match {
3142 Opnd_t Val;
3143 Signum_match(const Opnd_t &V) : Val(V) {}
3144
3145 template <typename OpTy> bool match(OpTy *V) const {
3146 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3147 if (TypeSize == 0)
3148 return false;
3149
3150 unsigned ShiftWidth = TypeSize - 1;
3151 Value *Op;
3152
3153 // This is the representation of signum we match:
3154 //
3155 // signum(x) == (x >> 63) | (-x >>u 63)
3156 //
3157 // An i1 value is its own signum, so it's correct to match
3158 //
3159 // signum(x) == (x >> 0) | (-x >>u 0)
3160 //
3161 // for i1 values.
3162
3163 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3164 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3165 auto Signum = m_c_Or(LHS, RHS);
3166
3167 return Signum.match(V) && Val.match(Op);
3168 }
3169};
3170
3171/// Matches a signum pattern.
3172///
3173/// signum(x) =
3174/// x > 0 -> 1
3175/// x == 0 -> 0
3176/// x < 0 -> -1
3177template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3178 return Signum_match<Val_t>(V);
3179}
3180
3181template <int Ind, typename Opnd_t> struct ExtractValue_match {
3182 Opnd_t Val;
3183 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3184
3185 template <typename OpTy> bool match(OpTy *V) const {
3186 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3187 // If Ind is -1, don't inspect indices
3188 if (Ind != -1 &&
3189 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3190 return false;
3191 return Val.match(I->getAggregateOperand());
3192 }
3193 return false;
3194 }
3195};
3196
3197/// Match a single index ExtractValue instruction.
3198/// For example m_ExtractValue<1>(...)
3199template <int Ind, typename Val_t>
3203
3204/// Match an ExtractValue instruction with any index.
3205/// For example m_ExtractValue(...)
3206template <typename Val_t>
3207inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3208 return ExtractValue_match<-1, Val_t>(V);
3209}
3210
3211/// Matcher for a single index InsertValue instruction.
3212template <int Ind, typename T0, typename T1> struct InsertValue_match {
3215
3216 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3217
3218 template <typename OpTy> bool match(OpTy *V) const {
3219 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3220 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3221 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3222 }
3223 return false;
3224 }
3225};
3226
3227/// Matches a single index InsertValue instruction.
3228template <int Ind, typename Val_t, typename Elt_t>
3230 const Elt_t &Elt) {
3231 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3232}
3233
3234/// Matches a call to `llvm.vscale()`.
3235inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3236
3237template <typename Opnd0, typename Opnd1>
3238inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3240}
3241
3242template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3244}
3245
3246template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3250
3251 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3252
3253 template <typename T> bool match(T *V) const {
3254 auto *I = dyn_cast<Instruction>(V);
3255 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3256 return false;
3257
3258 if (I->getOpcode() == Opcode) {
3259 auto *Op0 = I->getOperand(0);
3260 auto *Op1 = I->getOperand(1);
3261 return (L.match(Op0) && R.match(Op1)) ||
3262 (Commutable && L.match(Op1) && R.match(Op0));
3263 }
3264
3265 if (auto *Select = dyn_cast<SelectInst>(I)) {
3266 auto *Cond = Select->getCondition();
3267 auto *TVal = Select->getTrueValue();
3268 auto *FVal = Select->getFalseValue();
3269
3270 // Don't match a scalar select of bool vectors.
3271 // Transforms expect a single type for operands if this matches.
3272 if (Cond->getType() != Select->getType())
3273 return false;
3274
3275 if (Opcode == Instruction::And) {
3276 auto *C = dyn_cast<Constant>(FVal);
3277 if (C && C->isNullValue())
3278 return (L.match(Cond) && R.match(TVal)) ||
3279 (Commutable && L.match(TVal) && R.match(Cond));
3280 } else {
3281 assert(Opcode == Instruction::Or);
3282 auto *C = dyn_cast<Constant>(TVal);
3283 if (C && C->isOneValue())
3284 return (L.match(Cond) && R.match(FVal)) ||
3285 (Commutable && L.match(FVal) && R.match(Cond));
3286 }
3287 }
3288
3289 return false;
3290 }
3291};
3292
3293/// Matches L && R either in the form of L & R or L ? R : false.
3294/// Note that the latter form is poison-blocking.
3295template <typename LHS, typename RHS>
3300
3301/// Matches L && R where L and R are arbitrary values.
3302inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3303
3304/// Matches L && R with LHS and RHS in either order.
3305template <typename LHS, typename RHS>
3307m_c_LogicalAnd(const LHS &L, const RHS &R) {
3309}
3310
3311/// Matches L || R either in the form of L | R or L ? true : R.
3312/// Note that the latter form is poison-blocking.
3313template <typename LHS, typename RHS>
3318
3319/// Matches L || R where L and R are arbitrary values.
3320inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3321
3322/// Matches L || R with LHS and RHS in either order.
3323template <typename LHS, typename RHS>
3325m_c_LogicalOr(const LHS &L, const RHS &R) {
3327}
3328
3329/// Matches either L && R or L || R,
3330/// either one being in the either binary or logical form.
3331/// Note that the latter form is poison-blocking.
3332template <typename LHS, typename RHS, bool Commutable = false>
3338
3339/// Matches either L && R or L || R where L and R are arbitrary values.
3340inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3341
3342/// Matches either L && R or L || R with LHS and RHS in either order.
3343template <typename LHS, typename RHS>
3344inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3345 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3346}
3347
3348} // end namespace PatternMatch
3349} // end namespace llvm
3350
3351#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:857
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:215
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)
const SmallVectorImpl< MachineOperand > & 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:43
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.
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)
Match 'fneg X' as 'fsub +-0.0, X'.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, CastInst >, OpTy > m_CastOrSelf(const OpTy &Op)
Matches any cast or self. Used to ignore casts.
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
CommutativeBinaryIntrinsic_match< IntrID, T0, T1 > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
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.
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)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
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.
AllowFmf_match< T, FastMathFlags::AllowReciprocal > m_AllowReciprocal(const T &SubPattern)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
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)