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
599struct 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() || cst_pred_ty<is_zero_int>().match(C));
604 }
605};
606/// Match any null constant or a vector with all elements equal to 0.
607/// For vectors, this includes constants with undefined elements.
608inline is_zero m_Zero() { return is_zero(); }
609
610inline auto m_ZeroOrPoison() { return m_CombineOr(m_Zero(), m_Poison()); }
611
612struct is_power2 {
613 bool isValue(const APInt &C) const { return C.isPowerOf2(); }
614};
615/// Match an integer or vector power-of-2.
616/// For vectors, this includes constants with undefined elements.
618inline api_pred_ty<is_power2> m_Power2(const APInt *&V) { return V; }
619
621 bool isValue(const APInt &C) const { return C.isNegatedPowerOf2(); }
622};
623/// Match a integer or vector negated power-of-2.
624/// For vectors, this includes constants with undefined elements.
629 return V;
630}
631
633 bool isValue(const APInt &C) const { return !C || C.isNegatedPowerOf2(); }
634};
635/// Match a integer or vector negated power-of-2.
636/// For vectors, this includes constants with undefined elements.
642 return V;
643}
644
646 bool isValue(const APInt &C) const { return !C || C.isPowerOf2(); }
647};
648/// Match an integer or vector of 0 or power-of-2 values.
649/// For vectors, this includes constants with undefined elements.
654 return V;
655}
656
658 bool isValue(const APInt &C) const { return C.isSignMask(); }
659};
660/// Match an integer or vector with only the sign bit(s) set.
661/// For vectors, this includes constants with undefined elements.
665
667 bool isValue(const APInt &C) const { return C.isMask(); }
668};
669/// Match an integer or vector with only the low bit(s) set.
670/// For vectors, this includes constants with undefined elements.
674inline api_pred_ty<is_lowbit_mask> m_LowBitMask(const APInt *&V) { return V; }
675
677 bool isValue(const APInt &C) const { return !C || C.isMask(); }
678};
679/// Match an integer or vector with only the low bit(s) set.
680/// For vectors, this includes constants with undefined elements.
685 return V;
686}
687
690 const APInt *Thr;
691 bool isValue(const APInt &C) const {
692 return ICmpInst::compare(C, *Thr, Pred);
693 }
694};
695/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
696/// to Threshold. For vectors, this includes constants with undefined elements.
700 P.Pred = Predicate;
701 P.Thr = &Threshold;
702 return P;
703}
704
705/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
706/// to Threshold. For vectors, this includes constants with undefined elements.
709 const APInt &Threshold) {
711 P.Pred = Predicate;
712 P.Thr = &Threshold;
713 return P;
714}
715
716struct is_nan {
717 bool isValue(const APFloat &C) const { return C.isNaN(); }
718};
719/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
720/// For vectors, this includes constants with undefined elements.
722
723struct is_nonnan {
724 bool isValue(const APFloat &C) const { return !C.isNaN(); }
725};
726/// Match a non-NaN FP constant.
727/// For vectors, this includes constants with undefined elements.
731
732struct is_inf {
733 bool isValue(const APFloat &C) const { return C.isInfinity(); }
734};
735/// Match a positive or negative infinity FP constant.
736/// For vectors, this includes constants with undefined elements.
738
739template <bool IsNegative> struct is_signed_inf {
740 bool isValue(const APFloat &C) const {
741 return C.isInfinity() && IsNegative == C.isNegative();
742 }
743};
744
745/// Match a positive infinity FP constant.
746/// For vectors, this includes constants with undefined elements.
750
751/// Match a negative infinity FP constant.
752/// For vectors, this includes constants with undefined elements.
756
757struct is_noninf {
758 bool isValue(const APFloat &C) const { return !C.isInfinity(); }
759};
760/// Match a non-infinity FP constant, i.e. finite or NaN.
761/// For vectors, this includes constants with undefined elements.
765
766struct is_finite {
767 bool isValue(const APFloat &C) const { return C.isFinite(); }
768};
769/// Match a finite FP constant, i.e. not infinity or NaN.
770/// For vectors, this includes constants with undefined elements.
774inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
775
777 bool isValue(const APFloat &C) const { return C.isFiniteNonZero(); }
778};
779/// Match a finite non-zero FP constant.
780/// For vectors, this includes constants with undefined elements.
785 return V;
786}
787
789 bool isValue(const APFloat &C) const { return C.isZero(); }
790};
791/// Match a floating-point negative zero or positive zero.
792/// For vectors, this includes constants with undefined elements.
796
798 bool isValue(const APFloat &C) const { return C.isPosZero(); }
799};
800/// Match a floating-point positive zero.
801/// For vectors, this includes constants with undefined elements.
805
807 bool isValue(const APFloat &C) const { return C.isNegZero(); }
808};
809/// Match a floating-point negative zero.
810/// For vectors, this includes constants with undefined elements.
814
816 bool isValue(const APFloat &C) const { return C.isNonZero(); }
817};
818/// Match a floating-point non-zero.
819/// For vectors, this includes constants with undefined elements.
823
825 bool isValue(const APFloat &C) const {
826 return !C.isDenormal() && C.isNonZero();
827 }
828};
829
830/// Match a floating-point non-zero that is not a denormal.
831/// For vectors, this includes constants with undefined elements.
835
836///////////////////////////////////////////////////////////////////////////////
837
838/// Match a value, capturing it if we match.
839inline match_bind<Value> m_Value(Value *&V) { return V; }
840inline match_bind<const Value> m_Value(const Value *&V) { return V; }
841
842/// Match against the nested pattern, and capture the value if we match.
843template <typename Pattern> inline auto m_Value(Value *&V, const Pattern &P) {
844 return m_CombineAnd(P, match_bind<Value>(V));
845}
846
847/// Match against the nested pattern, and capture the value if we match.
848template <typename Pattern>
849inline auto m_Value(const Value *&V, const Pattern &P) {
851}
852
853/// Match an instruction, capturing it if we match.
856 return I;
857}
858
859/// Match against the nested pattern, and capture the instruction if we match.
860template <typename Pattern>
861inline auto m_Instruction(Instruction *&I, const Pattern &P) {
863}
864template <typename Pattern>
865inline auto m_Instruction(const Instruction *&I, const Pattern &P) {
867}
868
869/// Match a unary operator, capturing it if we match.
872 return I;
873}
874/// Match a binary operator, capturing it if we match.
877 return I;
878}
879/// Match any intrinsic call, capturing it if we match.
884/// Match a with overflow intrinsic, capturing it if we match.
890 return I;
891}
892
893/// Match a PHI node, capturing it if we match.
894inline match_bind<PHINode> m_Phi(PHINode *&PN) { return PN; }
895
896/// Match an UndefValue, capturing the value if we match.
898
899/// Match a Constant, capturing the value if we match.
901
902/// Match a ConstantInt, capturing the value if we match.
904
905/// Match a ConstantFP, capturing the value if we match.
907
908/// Match a ConstantExpr, capturing the value if we match.
910
911/// Match a basic block value, capturing it if we match.
914 return V;
915}
916
917// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
918// and use m_Unless(m_ConstantExpr).
920 template <typename ITy> static bool isImmConstant(ITy *V) {
921 if (auto *CV = dyn_cast<Constant>(V)) {
922 if (!match(CV, m_ConstantExpr()))
923 return true;
924
925 if (CV->getType()->isVectorTy()) {
926 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
927 if (!match(Splat, m_ConstantExpr())) {
928 return true;
929 }
930 }
931 }
932 }
933 return false;
934 }
935};
936
938 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
939};
940
941/// Match an arbitrary immediate Constant and ignore it.
943
946
948
949 template <typename ITy> bool match(ITy *V) const {
950 if (isImmConstant(V)) {
951 VR = cast<Constant>(V);
952 return true;
953 }
954 return false;
955 }
956};
957
958/// Match an immediate Constant, capturing the value if we match.
962
963/// Matcher for specified Value*.
965 const Value *Val;
966
967 specificval_ty(const Value *V) : Val(V) {}
968
969 template <typename ITy> bool match(ITy *V) const { return V == Val; }
970};
971
972/// Match if we have a specific specified value.
973inline specificval_ty m_Specific(const Value *V) { return V; }
974
975/// Like m_Specific(), but works if the specific value to match is determined
976/// as part of the same match() expression. For example:
977/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
978/// bind X before the pattern match starts.
979/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
980/// whichever value m_Value(X) populated.
981inline match_deferred<Value> m_Deferred(Value *const &V) { return V; }
983 return V;
984}
985
986/// Match a specified floating point value or vector of all elements of
987/// that value.
989 double Val;
990
991 specific_fpval(double V) : Val(V) {}
992
993 template <typename ITy> bool match(ITy *V) const {
994 if (const auto *CFP = dyn_cast<ConstantFP>(V))
995 return CFP->isExactlyValue(Val);
996 if (V->getType()->isVectorTy())
997 if (const auto *C = dyn_cast<Constant>(V))
998 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
999 return CFP->isExactlyValue(Val);
1000 return false;
1001 }
1002};
1003
1004/// Match a specific floating point value or vector with all elements
1005/// equal to the value.
1006inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
1007
1008/// Match a float 1.0 or vector with all elements equal to 1.0.
1009inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
1010
1013
1015
1016 template <typename ITy> bool match(ITy *V) const {
1017 const APInt *ConstInt;
1018 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1019 return false;
1020 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1021 if (!ZExtVal)
1022 return false;
1023 VR = *ZExtVal;
1024 return true;
1025 }
1026};
1027
1028/// Match a specified integer value or vector of all elements of that
1029/// value.
1030template <bool AllowPoison> struct specific_intval {
1031 const APInt &Val;
1032
1033 specific_intval(const APInt &V) : Val(V) {}
1034
1035 template <typename ITy> bool match(ITy *V) const {
1036 const auto *CI = dyn_cast<ConstantInt>(V);
1037 if (!CI && V->getType()->isVectorTy())
1038 if (const auto *C = dyn_cast<Constant>(V))
1039 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1040
1041 return CI && APInt::isSameValue(CI->getValue(), Val);
1042 }
1043};
1044
1045template <bool AllowPoison> struct specific_intval64 {
1047
1049
1050 template <typename ITy> bool match(ITy *V) const {
1051 const auto *CI = dyn_cast<ConstantInt>(V);
1052 if (!CI && V->getType()->isVectorTy())
1053 if (const auto *C = dyn_cast<Constant>(V))
1054 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1055
1056 return CI && CI->getValue() == Val;
1057 }
1058};
1059
1060/// Match a specific integer value or vector with all elements equal to
1061/// the value.
1063 return specific_intval<false>(V);
1064}
1065
1069
1073
1077
1078/// Match a ConstantInt and bind to its value. This does not match
1079/// ConstantInts wider than 64-bits.
1081
1082/// Match a specified basic block value.
1085
1087
1088 template <typename ITy> bool match(ITy *V) const {
1089 const auto *BB = dyn_cast<BasicBlock>(V);
1090 return BB && BB == Val;
1091 }
1092};
1093
1094/// Match a specific basic block value.
1096 return specific_bbval(BB);
1097}
1098
1099/// A commutative-friendly version of m_Specific().
1101 return BB;
1102}
1104m_Deferred(const BasicBlock *const &BB) {
1105 return BB;
1106}
1107
1108template <typename Pattern> struct SpecificType_match {
1111
1113
1114 template <typename ITy> bool match(ITy *V) const {
1115 return V->getType() == RefTy && P.match(V);
1116 }
1117};
1118
1119// Explicit deduction guide.
1120template <typename Pattern>
1123
1124/// Match a value of a specific type.
1125template <typename Pattern>
1126inline auto m_SpecificType(Type *RefTy, const Pattern &P) {
1127 return SpecificType_match<Pattern>(RefTy, P);
1128}
1129inline auto m_SpecificType(Type *RefTy) {
1130 return m_SpecificType(RefTy, m_Value());
1131}
1132
1133/// Match a value of a specific type, capturing it if we match.
1134inline auto m_SpecificType(Type *RefTy, Value *&V) {
1135 return m_SpecificType(RefTy, m_Value(V));
1136}
1137inline auto m_SpecificType(Type *RefTy, const Value *&V) {
1138 return m_SpecificType(RefTy, m_Value(V));
1139}
1140
1141//===----------------------------------------------------------------------===//
1142// Matcher for any binary operator.
1143//
1144template <typename LHS_t, typename RHS_t, bool Commutable = false>
1148
1149 // The evaluation order is always stable, regardless of Commutability.
1150 // The LHS is always matched first.
1151 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1152
1153 template <typename OpTy> bool match(OpTy *V) const {
1154 if (auto *I = dyn_cast<BinaryOperator>(V))
1155 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1156 (Commutable && L.match(I->getOperand(1)) &&
1157 R.match(I->getOperand(0)));
1158 return false;
1159 }
1160};
1161
1162template <typename LHS, typename RHS>
1163inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1164 return AnyBinaryOp_match<LHS, RHS>(L, R);
1165}
1166
1167//===----------------------------------------------------------------------===//
1168// Matcher for any unary operator.
1169// TODO fuse unary, binary matcher into n-ary matcher
1170//
1171template <typename OP_t> struct AnyUnaryOp_match {
1172 OP_t X;
1173
1174 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1175
1176 template <typename OpTy> bool match(OpTy *V) const {
1177 if (auto *I = dyn_cast<UnaryOperator>(V))
1178 return X.match(I->getOperand(0));
1179 return false;
1180 }
1181};
1182
1183template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1184 return AnyUnaryOp_match<OP_t>(X);
1185}
1186
1187//===----------------------------------------------------------------------===//
1188// Matchers for specific binary operators.
1189//
1190
1191template <typename LHS_t, typename RHS_t, unsigned Opcode,
1192 bool Commutable = false>
1196
1197 // The evaluation order is always stable, regardless of Commutability.
1198 // The LHS is always matched first.
1199 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1200
1201 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1202 if (V->getValueID() == Value::InstructionVal + Opc) {
1203 auto *I = cast<BinaryOperator>(V);
1204 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1205 (Commutable && L.match(I->getOperand(1)) &&
1206 R.match(I->getOperand(0)));
1207 }
1208 return false;
1209 }
1210
1211 template <typename OpTy> bool match(OpTy *V) const {
1212 return match(Opcode, V);
1213 }
1214};
1215
1216template <typename LHS, typename RHS>
1221
1222template <typename LHS, typename RHS>
1227
1228template <typename LHS, typename RHS>
1233
1234template <typename LHS, typename RHS>
1239
1240template <typename Op_t> struct FNeg_match {
1241 Op_t X;
1242
1243 FNeg_match(const Op_t &Op) : X(Op) {}
1244 template <typename OpTy> bool match(OpTy *V) const {
1245 auto *FPMO = dyn_cast<FPMathOperator>(V);
1246 if (!FPMO)
1247 return false;
1248
1249 if (FPMO->getOpcode() == Instruction::FNeg)
1250 return X.match(FPMO->getOperand(0));
1251
1252 if (FPMO->getOpcode() == Instruction::FSub) {
1253 if (FPMO->hasNoSignedZeros()) {
1254 // With 'nsz', any zero goes.
1255 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1256 return false;
1257 } else {
1258 // Without 'nsz', we need fsub -0.0, X exactly.
1259 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1260 return false;
1261 }
1262
1263 return X.match(FPMO->getOperand(1));
1264 }
1265
1266 return false;
1267 }
1268};
1269
1270/// Match 'fneg X' as 'fsub -0.0, X'.
1271template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1272 return FNeg_match<OpTy>(X);
1273}
1274
1275/// Match 'fneg X' as 'fsub +-0.0, X'.
1276template <typename RHS>
1277inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1278m_FNegNSZ(const RHS &X) {
1279 return m_FSub(m_AnyZeroFP(), X);
1280}
1281
1282template <typename LHS, typename RHS>
1287
1288template <typename LHS, typename RHS>
1293
1294template <typename LHS, typename RHS>
1299
1300template <typename LHS, typename RHS>
1305
1306template <typename LHS, typename RHS>
1311
1312template <typename LHS, typename RHS>
1317
1318template <typename LHS, typename RHS>
1323
1324template <typename LHS, typename RHS>
1329
1330template <typename LHS, typename RHS>
1335
1336template <typename LHS, typename RHS>
1341
1342template <typename LHS, typename RHS>
1347
1348template <typename LHS, typename RHS>
1353
1354template <typename LHS, typename RHS>
1359
1360template <typename LHS, typename RHS>
1365
1366template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1369
1371
1372 template <typename OpTy> bool match(OpTy *V) const {
1373 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1374 if (Op->getOpcode() == Opcode)
1375 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1376 L.match(Op->getOperand(0));
1377 }
1378 // Interpreted as shiftop V, 0
1379 R = 0;
1380 return L.match(V);
1381 }
1382};
1383
1384/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1385template <typename LHS>
1390
1391/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1392template <typename LHS>
1397
1398/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1399template <typename LHS>
1404
1405template <typename LHS_t, typename RHS_t, unsigned Opcode,
1406 unsigned WrapFlags = 0, bool Commutable = false>
1410
1412 : L(LHS), R(RHS) {}
1413
1414 template <typename OpTy> bool match(OpTy *V) const {
1415 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1416 if (Op->getOpcode() != Opcode)
1417 return false;
1419 !Op->hasNoUnsignedWrap())
1420 return false;
1421 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1422 !Op->hasNoSignedWrap())
1423 return false;
1424 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1425 (Commutable && L.match(Op->getOperand(1)) &&
1426 R.match(Op->getOperand(0)));
1427 }
1428 return false;
1429 }
1430};
1431
1432template <typename LHS, typename RHS>
1433inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1435m_NSWAdd(const LHS &L, const RHS &R) {
1436 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1438 R);
1439}
1440template <typename LHS, typename RHS>
1441inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1443m_c_NSWAdd(const LHS &L, const RHS &R) {
1444 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1446 true>(L, R);
1447}
1448template <typename LHS, typename RHS>
1449inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1451m_NSWSub(const LHS &L, const RHS &R) {
1452 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1454 R);
1455}
1456template <typename LHS, typename RHS>
1457inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1459m_NSWMul(const LHS &L, const RHS &R) {
1460 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1462 R);
1463}
1464template <typename LHS, typename RHS>
1465inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1467m_NSWShl(const LHS &L, const RHS &R) {
1468 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1470 R);
1471}
1472
1473template <typename LHS, typename RHS>
1474inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1476m_NUWAdd(const LHS &L, const RHS &R) {
1477 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1479 L, R);
1480}
1481
1482template <typename LHS, typename RHS>
1484 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1485m_c_NUWAdd(const LHS &L, const RHS &R) {
1486 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1488 true>(L, R);
1489}
1490
1491template <typename LHS, typename RHS>
1492inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1494m_NUWSub(const LHS &L, const RHS &R) {
1495 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1497 L, R);
1498}
1499template <typename LHS, typename RHS>
1500inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1502m_NUWMul(const LHS &L, const RHS &R) {
1503 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1505 L, R);
1506}
1507template <typename LHS, typename RHS>
1508inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1510m_NUWShl(const LHS &L, const RHS &R) {
1511 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1513 L, R);
1514}
1515
1516template <typename LHS_t, typename RHS_t, bool Commutable = false>
1518 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1519 unsigned Opcode;
1520
1522 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1523
1524 template <typename OpTy> bool match(OpTy *V) const {
1526 }
1527};
1528
1529/// Matches a specific opcode.
1530template <typename LHS, typename RHS>
1531inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1532 const RHS &R) {
1533 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1534}
1535
1536template <typename LHS, typename RHS, bool Commutable = false>
1540
1541 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1542
1543 template <typename OpTy> bool match(OpTy *V) const {
1544 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1545 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1546 if (!PDI->isDisjoint())
1547 return false;
1548 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1549 (Commutable && L.match(PDI->getOperand(1)) &&
1550 R.match(PDI->getOperand(0)));
1551 }
1552 return false;
1553 }
1554};
1555
1556template <typename LHS, typename RHS>
1558 return DisjointOr_match<LHS, RHS>(L, R);
1559}
1560
1561template <typename LHS, typename RHS>
1563 const RHS &R) {
1565}
1566
1567/// Match either "add" or "or disjoint".
1568template <typename LHS, typename RHS>
1571m_AddLike(const LHS &L, const RHS &R) {
1572 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1573}
1574
1575/// Match either "add nsw" or "or disjoint"
1576template <typename LHS, typename RHS>
1577inline match_combine_or<
1578 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1581m_NSWAddLike(const LHS &L, const RHS &R) {
1582 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1583}
1584
1585/// Match either "add nuw" or "or disjoint"
1586template <typename LHS, typename RHS>
1587inline match_combine_or<
1588 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1591m_NUWAddLike(const LHS &L, const RHS &R) {
1592 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1593}
1594
1595template <typename LHS, typename RHS>
1599
1600 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1601
1602 template <typename OpTy> bool match(OpTy *V) const {
1603 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1604 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1605 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1606 ; // Pass
1607 else if (Op->getOpcode() != Instruction::Xor)
1608 return false;
1609 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1610 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1611 }
1612 return false;
1613 }
1614};
1615
1616/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1617/// Only commutative matcher as the `sub` will need to swap the L and R.
1618template <typename LHS, typename RHS>
1619inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1620 return XorLike_match<LHS, RHS>(L, R);
1621}
1622
1623//===----------------------------------------------------------------------===//
1624// Class that matches a group of binary opcodes.
1625//
1626template <typename LHS_t, typename RHS_t, typename Predicate,
1627 bool Commutable = false>
1628struct BinOpPred_match : Predicate {
1631
1632 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1633
1634 template <typename OpTy> bool match(OpTy *V) const {
1635 if (auto *I = dyn_cast<Instruction>(V))
1636 return this->isOpType(I->getOpcode()) &&
1637 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1638 (Commutable && L.match(I->getOperand(1)) &&
1639 R.match(I->getOperand(0))));
1640 return false;
1641 }
1642};
1643
1645 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1646};
1647
1649 bool isOpType(unsigned Opcode) const {
1650 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1651 }
1652};
1653
1655 bool isOpType(unsigned Opcode) const {
1656 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1657 }
1658};
1659
1661 bool isOpType(unsigned Opcode) const {
1662 return Instruction::isBitwiseLogicOp(Opcode);
1663 }
1664};
1665
1667 bool isOpType(unsigned Opcode) const {
1668 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1669 }
1670};
1671
1673 bool isOpType(unsigned Opcode) const {
1674 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1675 }
1676};
1677
1678/// Matches shift operations.
1679template <typename LHS, typename RHS>
1681 const RHS &R) {
1683}
1684
1685/// Matches logical shift operations.
1686template <typename LHS, typename RHS>
1691
1692/// Matches logical shift operations.
1693template <typename LHS, typename RHS>
1695m_LogicalShift(const LHS &L, const RHS &R) {
1697}
1698
1699/// Matches bitwise logic operations.
1700template <typename LHS, typename RHS>
1702m_BitwiseLogic(const LHS &L, const RHS &R) {
1704}
1705
1706/// Matches bitwise logic operations in either order.
1707template <typename LHS, typename RHS>
1712
1713/// Matches integer division operations.
1714template <typename LHS, typename RHS>
1716 const RHS &R) {
1718}
1719
1720/// Matches integer remainder operations.
1721template <typename LHS, typename RHS>
1723 const RHS &R) {
1725}
1726
1727//===----------------------------------------------------------------------===//
1728// Class that matches exact binary ops.
1729//
1730template <typename SubPattern_t> struct Exact_match {
1731 SubPattern_t SubPattern;
1732
1733 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1734
1735 template <typename OpTy> bool match(OpTy *V) const {
1736 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1737 return PEO->isExact() && SubPattern.match(V);
1738 return false;
1739 }
1740};
1741
1742template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1743 return SubPattern;
1744}
1745
1746//===----------------------------------------------------------------------===//
1747// Matchers for CmpInst classes
1748//
1749
1750template <typename LHS_t, typename RHS_t, typename Class,
1751 bool Commutable = false>
1756
1757 // The evaluation order is always stable, regardless of Commutability.
1758 // The LHS is always matched first.
1760 : Predicate(&Pred), L(LHS), R(RHS) {}
1762 : Predicate(nullptr), L(LHS), R(RHS) {}
1763
1764 template <typename OpTy> bool match(OpTy *V) const {
1765 if (auto *I = dyn_cast<Class>(V)) {
1766 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1767 if (Predicate)
1769 return true;
1770 }
1771 if (Commutable && L.match(I->getOperand(1)) &&
1772 R.match(I->getOperand(0))) {
1773 if (Predicate)
1775 return true;
1776 }
1777 }
1778 return false;
1779 }
1780};
1781
1782template <typename LHS, typename RHS>
1784 const RHS &R) {
1785 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1786}
1787
1788template <typename LHS, typename RHS>
1790 const LHS &L, const RHS &R) {
1791 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1792}
1793
1794template <typename LHS, typename RHS>
1796 const LHS &L, const RHS &R) {
1797 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1798}
1799
1800template <typename LHS, typename RHS>
1803}
1804
1805template <typename LHS, typename RHS>
1808}
1809
1810template <typename LHS, typename RHS>
1813}
1814
1815// Same as CmpClass, but instead of saving Pred as out output variable, match a
1816// specific input pred for equality.
1817template <typename LHS_t, typename RHS_t, typename Class,
1818 bool Commutable = false>
1823
1825 : Predicate(Pred), L(LHS), R(RHS) {}
1826
1827 template <typename OpTy> bool match(OpTy *V) const {
1828 if (auto *I = dyn_cast<Class>(V)) {
1830 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1831 return true;
1832 if constexpr (Commutable) {
1835 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1836 return true;
1837 }
1838 }
1839
1840 return false;
1841 }
1842};
1843
1844template <typename LHS, typename RHS>
1846m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1847 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1848}
1849
1850template <typename LHS, typename RHS>
1852m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1853 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1854}
1855
1856template <typename LHS, typename RHS>
1858m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1860}
1861
1862template <typename LHS, typename RHS>
1864m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1865 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1866}
1867
1868//===----------------------------------------------------------------------===//
1869// Matchers for instructions with a given opcode and number of operands.
1870//
1871
1872/// Matches instructions with Opcode and three operands.
1873template <typename T0, unsigned Opcode> struct OneOps_match {
1875
1876 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1877
1878 template <typename OpTy> bool match(OpTy *V) const {
1879 if (V->getValueID() == Value::InstructionVal + Opcode) {
1880 auto *I = cast<Instruction>(V);
1881 return Op1.match(I->getOperand(0));
1882 }
1883 return false;
1884 }
1885};
1886
1887/// Matches instructions with Opcode and three operands.
1888template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1891
1892 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1893
1894 template <typename OpTy> bool match(OpTy *V) const {
1895 if (V->getValueID() == Value::InstructionVal + Opcode) {
1896 auto *I = cast<Instruction>(V);
1897 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1898 }
1899 return false;
1900 }
1901};
1902
1903/// Matches instructions with Opcode and three operands.
1904template <typename T0, typename T1, typename T2, unsigned Opcode,
1905 bool CommutableOp2Op3 = false>
1910
1911 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1912 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1913
1914 template <typename OpTy> bool match(OpTy *V) const {
1915 if (V->getValueID() == Value::InstructionVal + Opcode) {
1916 auto *I = cast<Instruction>(V);
1917 if (!Op1.match(I->getOperand(0)))
1918 return false;
1919 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1920 return true;
1921 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1922 Op3.match(I->getOperand(1));
1923 }
1924 return false;
1925 }
1926};
1927
1928/// Matches instructions with Opcode and any number of operands
1929template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1930 std::tuple<OperandTypes...> Operands;
1931
1932 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1933
1934 // Operand matching works by recursively calling match_operands, matching the
1935 // operands left to right. The first version is called for each operand but
1936 // the last, for which the second version is called. The second version of
1937 // match_operands is also used to match each individual operand.
1938 template <int Idx, int Last>
1939 std::enable_if_t<Idx != Last, bool>
1943
1944 template <int Idx, int Last>
1945 std::enable_if_t<Idx == Last, bool>
1947 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1948 }
1949
1950 template <typename OpTy> bool match(OpTy *V) const {
1951 if (V->getValueID() == Value::InstructionVal + Opcode) {
1952 auto *I = cast<Instruction>(V);
1953 return I->getNumOperands() == sizeof...(OperandTypes) &&
1954 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1955 }
1956 return false;
1957 }
1958};
1959
1960/// Matches SelectInst.
1961template <typename Cond, typename LHS, typename RHS>
1963m_Select(const Cond &C, const LHS &L, const RHS &R) {
1965}
1966
1967/// This matches a select of two constants, e.g.:
1968/// m_SelectCst<-1, 0>(m_Value(V))
1969template <int64_t L, int64_t R, typename Cond>
1971 Instruction::Select>
1974}
1975
1976/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1977template <typename LHS, typename RHS>
1978inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1979m_c_Select(const LHS &L, const RHS &R) {
1980 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1981 true>(m_Value(), L, R);
1982}
1983
1984/// Matches FreezeInst.
1985template <typename OpTy>
1989
1990/// Matches InsertElementInst.
1991template <typename Val_t, typename Elt_t, typename Idx_t>
1993m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1995 Val, Elt, Idx);
1996}
1997
1998/// Matches ExtractElementInst.
1999template <typename Val_t, typename Idx_t>
2001m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
2003}
2004
2005/// Matches shuffle.
2006template <typename T0, typename T1, typename T2> struct Shuffle_match {
2010
2011 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
2012 : Op1(Op1), Op2(Op2), Mask(Mask) {}
2013
2014 template <typename OpTy> bool match(OpTy *V) const {
2015 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
2016 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
2017 Mask.match(I->getShuffleMask());
2018 }
2019 return false;
2020 }
2021};
2022
2023struct m_Mask {
2026 bool match(ArrayRef<int> Mask) const {
2027 MaskRef = Mask;
2028 return true;
2029 }
2030};
2031
2033 bool match(ArrayRef<int> Mask) const {
2034 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
2035 }
2036};
2037
2041 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
2042};
2043
2045 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
2046};
2047
2051 bool match(ArrayRef<int> Mask) const {
2052 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2053 if (First == Mask.end())
2054 return false;
2055 SplatIndex = *First;
2056 return all_of(Mask,
2057 [First](int Elem) { return Elem == *First || Elem == -1; });
2058 }
2059};
2060
2061template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2062 PointerOpTy PointerOp;
2063 OffsetOpTy OffsetOp;
2064
2065 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2067
2068 template <typename OpTy> bool match(OpTy *V) const {
2069 auto *GEP = dyn_cast<GEPOperator>(V);
2070 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2071 PointerOp.match(GEP->getPointerOperand()) &&
2072 OffsetOp.match(GEP->idx_begin()->get());
2073 }
2074};
2075
2076/// Matches ShuffleVectorInst independently of mask value.
2077template <typename V1_t, typename V2_t>
2079m_Shuffle(const V1_t &v1, const V2_t &v2) {
2081}
2082
2083template <typename V1_t, typename V2_t, typename Mask_t>
2085m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2087}
2088
2089/// Matches LoadInst.
2090template <typename OpTy>
2094
2095/// Matches a simple (non-volatile, non-atomic) LoadInst.
2096template <typename OpTy> struct LoadSimple_match {
2098
2100
2101 template <typename ITy> bool match(ITy *V) const {
2102 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2103 }
2104};
2105
2106template <typename OpTy>
2110
2111/// Matches StoreInst.
2112template <typename ValueOpTy, typename PointerOpTy>
2114m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2116 PointerOp);
2117}
2118
2119/// Matches GetElementPtrInst.
2120template <typename... OperandTypes>
2121inline auto m_GEP(const OperandTypes &...Ops) {
2122 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2123}
2124
2125/// Matches GEP with i8 source element type
2126template <typename PointerOpTy, typename OffsetOpTy>
2128m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2130}
2131
2132//===----------------------------------------------------------------------===//
2133// Matchers for CastInst classes
2134//
2135
2136template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2137 Op_t Op;
2138
2139 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2140
2141 template <typename OpTy> bool match(OpTy *V) const {
2142 if (auto *O = dyn_cast<Operator>(V))
2143 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2144 return false;
2145 }
2146};
2147
2148template <typename Op_t, typename Class> struct CastInst_match {
2149 Op_t Op;
2150
2151 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2152
2153 template <typename OpTy> bool match(OpTy *V) const {
2154 if (auto *I = dyn_cast<Class>(V))
2155 return Op.match(I->getOperand(0));
2156 return false;
2157 }
2158};
2159
2160template <typename Op_t> struct PtrToIntSameSize_match {
2162 Op_t Op;
2163
2164 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2165 : DL(DL), Op(OpMatch) {}
2166
2167 template <typename OpTy> bool match(OpTy *V) const {
2168 if (auto *O = dyn_cast<Operator>(V))
2169 return O->getOpcode() == Instruction::PtrToInt &&
2170 DL.getTypeSizeInBits(O->getType()) ==
2171 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2172 Op.match(O->getOperand(0));
2173 return false;
2174 }
2175};
2176
2177template <typename Op_t> struct NNegZExt_match {
2178 Op_t Op;
2179
2180 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2181
2182 template <typename OpTy> bool match(OpTy *V) const {
2183 if (auto *I = dyn_cast<ZExtInst>(V))
2184 return I->hasNonNeg() && Op.match(I->getOperand(0));
2185 return false;
2186 }
2187};
2188
2189template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2190 Op_t Op;
2191
2192 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2193
2194 template <typename OpTy> bool match(OpTy *V) const {
2195 if (auto *I = dyn_cast<TruncInst>(V))
2196 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2197 Op.match(I->getOperand(0));
2198 return false;
2199 }
2200};
2201
2202/// Matches BitCast.
2203template <typename OpTy>
2208
2209template <typename Op_t> struct ElementWiseBitCast_match {
2210 Op_t Op;
2211
2212 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2213
2214 template <typename OpTy> bool match(OpTy *V) const {
2215 auto *I = dyn_cast<BitCastInst>(V);
2216 if (!I)
2217 return false;
2218 Type *SrcType = I->getSrcTy();
2219 Type *DstType = I->getType();
2220 // Make sure the bitcast doesn't change between scalar and vector and
2221 // doesn't change the number of vector elements.
2222 if (SrcType->isVectorTy() != DstType->isVectorTy())
2223 return false;
2224 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2225 SrcVecTy && SrcVecTy->getElementCount() !=
2226 cast<VectorType>(DstType)->getElementCount())
2227 return false;
2228 return Op.match(I->getOperand(0));
2229 }
2230};
2231
2232template <typename OpTy>
2236
2237/// Matches PtrToInt.
2238template <typename OpTy>
2243
2244template <typename OpTy>
2249
2250/// Matches PtrToAddr.
2251template <typename OpTy>
2256
2257/// Matches PtrToInt or PtrToAddr.
2258template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2260}
2261
2262/// Matches IntToPtr.
2263template <typename OpTy>
2268
2269/// Matches any cast or self. Used to ignore casts.
2270template <typename OpTy>
2275
2276/// Matches Trunc.
2277template <typename OpTy>
2281
2282/// Matches trunc nuw.
2283template <typename OpTy>
2288
2289/// Matches trunc nsw.
2290template <typename OpTy>
2295
2296template <typename OpTy>
2299 return m_CombineOr(m_Trunc(Op), Op);
2300}
2301
2302/// Matches SExt.
2303template <typename OpTy>
2307
2308/// Matches ZExt.
2309template <typename OpTy>
2313
2314template <typename OpTy>
2316 return NNegZExt_match<OpTy>(Op);
2317}
2318
2319template <typename OpTy>
2322 return m_CombineOr(m_ZExt(Op), Op);
2323}
2324
2325template <typename OpTy>
2328 return m_CombineOr(m_SExt(Op), Op);
2329}
2330
2331/// Match either "sext" or "zext nneg".
2332template <typename OpTy>
2335 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2336}
2337
2338template <typename OpTy>
2342 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2343}
2344
2345template <typename OpTy>
2348 OpTy>
2350 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2351}
2352
2353template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2354 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2355}
2356
2357template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2361
2363 : Pred(P), L(Left), R(Right) {}
2364
2365 template <typename OpTy> bool match(OpTy *V) const {
2366 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2367 return true;
2368 Value *A;
2369 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2370 if (V->getType()->isIntOrIntVectorTy(1) &&
2371 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2372 R.match(ConstantInt::getNullValue(A->getType()))) {
2374 return true;
2375 }
2376 return false;
2377 }
2378};
2379
2380template <typename LHS, typename RHS>
2382 const RHS &R) {
2383 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2384}
2385
2386template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2387 CondTy Cond;
2390
2391 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2392 : Cond(C), TrueC(TC), FalseC(FC) {}
2393
2394 template <typename OpTy> bool match(OpTy *V) const {
2395 // select(Cond, TrueC, FalseC) — captures both constants directly
2397 return true;
2398
2399 Type *Ty = V->getType();
2400 Value *CondV = nullptr;
2401
2402 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2403 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2404 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2405 TrueC.match(ConstantInt::get(Ty, 1)) &&
2406 FalseC.match(ConstantInt::get(Ty, 0)))
2407 return true;
2408
2409 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2410 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2411 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2412 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2413 FalseC.match(ConstantInt::get(Ty, 0)))
2414 return true;
2415
2416 return false;
2417 }
2418};
2419
2420/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2421/// select i1 Cond, TrueC, FalseC
2422/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2423/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2424///
2425/// The condition is matched against \p Cond, and the true/false constants
2426/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2427/// constants are bound to \p TrueC and \p FalseC via their matchers.
2428template <typename CondTy, typename LTy, typename RTy>
2430m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2431 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2432}
2433
2434template <typename OpTy>
2438
2439template <typename OpTy>
2443
2444template <typename OpTy>
2447m_IToFP(const OpTy &Op) {
2448 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2449}
2450
2451template <typename OpTy>
2455
2456template <typename OpTy>
2460
2461template <typename OpTy>
2464m_FPToI(const OpTy &Op) {
2465 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2466}
2467
2468template <typename OpTy>
2472
2473template <typename OpTy>
2477
2478//===----------------------------------------------------------------------===//
2479// Matchers for control flow.
2480//
2481
2482struct br_match {
2484
2486
2487 template <typename OpTy> bool match(OpTy *V) const {
2488 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2489 Succ = BI->getSuccessor();
2490 return true;
2491 }
2492 return false;
2493 }
2494};
2495
2496inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2497
2498template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2500 Cond_t Cond;
2501 TrueBlock_t T;
2502 FalseBlock_t F;
2503
2504 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2505 : Cond(C), T(t), F(f) {}
2506
2507 template <typename OpTy> bool match(OpTy *V) const {
2508 if (auto *BI = dyn_cast<CondBrInst>(V))
2509 if (Cond.match(BI->getCondition()))
2510 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2511 return false;
2512 }
2513};
2514
2515template <typename Cond_t>
2521
2522template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2524m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2526}
2527
2528//===----------------------------------------------------------------------===//
2529// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2530//
2531
2532template <typename LHS_t, typename RHS_t, typename Pred_t>
2534 using PredType = Pred_t;
2537
2538 // The evaluation order is always stable, regardless of Commutability.
2539 // The LHS is always matched first.
2540 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2541
2542 template <typename OpTy> bool match(OpTy *V) const {
2543 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2544 auto *SI = dyn_cast<SelectInst>(V);
2545 if (!SI)
2546 return false;
2547 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2548 if (!Cmp)
2549 return false;
2550 // At this point we have a select conditioned on a comparison. Check that
2551 // it is the values returned by the select that are being compared.
2552 auto *TrueVal = SI->getTrueValue();
2553 auto *FalseVal = SI->getFalseValue();
2554 auto *LHS = Cmp->getOperand(0);
2555 auto *RHS = Cmp->getOperand(1);
2556 if ((TrueVal != LHS || FalseVal != RHS) &&
2557 (TrueVal != RHS || FalseVal != LHS))
2558 return false;
2559 FCmpInst::Predicate Pred =
2560 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2561 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2562 if (!Pred_t::match(Pred))
2563 return false;
2564 // It does! Bind the operands.
2565 return L.match(LHS) && R.match(RHS);
2566 }
2567};
2568
2569/// Helper class for identifying ordered max predicates.
2571 static bool match(FCmpInst::Predicate Pred) {
2572 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2573 }
2574};
2575
2576/// Helper class for identifying ordered min predicates.
2578 static bool match(FCmpInst::Predicate Pred) {
2579 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2580 }
2581};
2582
2583/// Helper class for identifying unordered max predicates.
2585 static bool match(FCmpInst::Predicate Pred) {
2586 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2587 }
2588};
2589
2590/// Helper class for identifying unordered min predicates.
2592 static bool match(FCmpInst::Predicate Pred) {
2593 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2594 }
2595};
2596
2597/// Match an 'ordered' floating point maximum function.
2598/// Floating point has one special value 'NaN'. Therefore, there is no total
2599/// order. However, if we can ignore the 'NaN' value (for example, because of a
2600/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2601/// semantics. In the presence of 'NaN' we have to preserve the original
2602/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2603///
2604/// max(L, R) iff L and R are not NaN
2605/// m_OrdFMax(L, R) = R iff L or R are NaN
2606template <typename LHS, typename RHS>
2608 const RHS &R) {
2610}
2611
2612/// Match an 'ordered' floating point minimum function.
2613/// Floating point has one special value 'NaN'. Therefore, there is no total
2614/// order. However, if we can ignore the 'NaN' value (for example, because of a
2615/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2616/// semantics. In the presence of 'NaN' we have to preserve the original
2617/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2618///
2619/// min(L, R) iff L and R are not NaN
2620/// m_OrdFMin(L, R) = R iff L or R are NaN
2621template <typename LHS, typename RHS>
2623 const RHS &R) {
2625}
2626
2627/// Match an 'unordered' floating point maximum function.
2628/// Floating point has one special value 'NaN'. Therefore, there is no total
2629/// order. However, if we can ignore the 'NaN' value (for example, because of a
2630/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2631/// semantics. In the presence of 'NaN' we have to preserve the original
2632/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2633///
2634/// max(L, R) iff L and R are not NaN
2635/// m_UnordFMax(L, R) = L iff L or R are NaN
2636template <typename LHS, typename RHS>
2641
2642/// Match an 'unordered' floating point minimum function.
2643/// Floating point has one special value 'NaN'. Therefore, there is no total
2644/// order. However, if we can ignore the 'NaN' value (for example, because of a
2645/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2646/// semantics. In the presence of 'NaN' we have to preserve the original
2647/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2648///
2649/// min(L, R) iff L and R are not NaN
2650/// m_UnordFMin(L, R) = L iff L or R are NaN
2651template <typename LHS, typename RHS>
2656
2657/// Match an 'ordered' or 'unordered' floating point maximum function.
2658/// Floating point has one special value 'NaN'. Therefore, there is no total
2659/// order. However, if we can ignore the 'NaN' value (for example, because of a
2660/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2661/// semantics.
2662template <typename LHS, typename RHS>
2669
2670/// Match an 'ordered' or 'unordered' floating point minimum function.
2671/// Floating point has one special value 'NaN'. Therefore, there is no total
2672/// order. However, if we can ignore the 'NaN' value (for example, because of a
2673/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2674/// semantics.
2675template <typename LHS, typename RHS>
2682
2683/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2684/// NOTE: we first match the 'Not' (by matching '-1'),
2685/// and only then match the inner matcher!
2686template <typename ValTy>
2687inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2688m_Not(const ValTy &V) {
2689 return m_c_Xor(m_AllOnes(), V);
2690}
2691
2692template <typename ValTy>
2693inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2694 true>
2695m_NotForbidPoison(const ValTy &V) {
2696 return m_c_Xor(m_AllOnesForbidPoison(), V);
2697}
2698
2699//===----------------------------------------------------------------------===//
2700// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2701// Note that S might be matched to other instructions than AddInst.
2702//
2703
2704template <typename LHS_t, typename RHS_t, typename Sum_t>
2708 Sum_t S;
2709
2710 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2711 : L(L), R(R), S(S) {}
2712
2713 template <typename OpTy> bool match(OpTy *V) const {
2714 Value *ICmpLHS, *ICmpRHS;
2715 CmpPredicate Pred;
2716 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2717 return false;
2718
2719 Value *AddLHS, *AddRHS;
2720 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2721
2722 // (a + b) u< a, (a + b) u< b
2723 if (Pred == ICmpInst::ICMP_ULT)
2724 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2725 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2726
2727 // a >u (a + b), b >u (a + b)
2728 if (Pred == ICmpInst::ICMP_UGT)
2729 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2730 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2731
2732 Value *Op1;
2733 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2734 // (~a) <u b
2735 if (Pred == ICmpInst::ICMP_ULT) {
2736 if (XorExpr.match(ICmpLHS))
2737 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2738 }
2739 // b > u (~a)
2740 if (Pred == ICmpInst::ICMP_UGT) {
2741 if (XorExpr.match(ICmpRHS))
2742 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2743 }
2744
2745 // Match special-case for increment-by-1.
2746 if (Pred == ICmpInst::ICMP_EQ) {
2747 // (a + 1) == 0
2748 // (1 + a) == 0
2749 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2750 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2751 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2752 // 0 == (a + 1)
2753 // 0 == (1 + a)
2754 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2755 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2756 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2757 }
2758
2759 return false;
2760 }
2761};
2762
2763/// Match an icmp instruction checking for unsigned overflow on addition.
2764///
2765/// S is matched to the addition whose result is being checked for overflow, and
2766/// L and R are matched to the LHS and RHS of S.
2767template <typename LHS_t, typename RHS_t, typename Sum_t>
2769m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2771}
2772
2773template <typename Opnd_t> struct Argument_match {
2774 unsigned OpI;
2775 Opnd_t Val;
2776
2777 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2778
2779 template <typename OpTy> bool match(OpTy *V) const {
2780 // FIXME: Should likely be switched to use `CallBase`.
2781 if (const auto *CI = dyn_cast<CallInst>(V))
2782 return Val.match(CI->getArgOperand(OpI));
2783 return false;
2784 }
2785};
2786
2787/// Match an argument.
2788template <unsigned OpI, typename Opnd_t>
2789inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2790 return Argument_match<Opnd_t>(OpI, Op);
2791}
2792
2793/// Intrinsic matchers.
2795 unsigned ID;
2796
2798
2799 template <typename OpTy> bool match(OpTy *V) const {
2800 if (const auto *CI = dyn_cast<CallInst>(V))
2801 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2802 return F->getIntrinsicID() == ID;
2803 return false;
2804 }
2805};
2806
2807/// Match intrinsic calls with any of the given IDs.
2808template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2809 template <typename OpTy> bool match(OpTy *V) const {
2810 if (const auto *CI = dyn_cast<CallInst>(V))
2811 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2812 Intrinsic::ID ID = F->getIntrinsicID();
2813 return ((ID == IntrIDs) || ...);
2814 }
2815 return false;
2816 }
2817};
2818
2820 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2821 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2822 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2823 }
2824};
2825
2826/// Match intrinsic calls like this:
2827/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2828template <Intrinsic::ID IntrID, typename... Ts>
2829inline auto m_Intrinsic(const Ts &...Ops) {
2831 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2832}
2833
2834/// Match intrinsic calls with any of the given IDs like this:
2835/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2836/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2837/// because it performs the CallInst/Function cast only once.
2838template <Intrinsic::ID... IntrIDs>
2840 return IntrinsicIDs_match<IntrIDs...>();
2841}
2842
2843/// Matches MaskedLoad Intrinsic.
2844template <typename Opnd0, typename Opnd1, typename Opnd2>
2845inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2846 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2847}
2848
2849/// Matches MaskedStore Intrinsic.
2850template <typename Opnd0, typename Opnd1, typename Opnd2>
2851inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2852 const Opnd2 &Op2) {
2853 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2854}
2855
2856/// Matches MaskedGather Intrinsic.
2857template <typename Opnd0, typename Opnd1, typename Opnd2>
2858inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2859 const Opnd2 &Op2) {
2860 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2861}
2862
2863// Helper intrinsic matching specializations.
2864template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2866}
2867
2868template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2870}
2871template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2873}
2874
2875template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2876 return m_Intrinsic<Intrinsic::fabs>(Op0);
2877}
2878
2879template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2881}
2882
2883template <typename Opnd0, typename Opnd1>
2884inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2885 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2886}
2887
2888template <typename Opnd0, typename Opnd1>
2889inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2890 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2891}
2892
2893template <typename Opnd0, typename Opnd1>
2894inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2895 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2896}
2897
2898template <typename Opnd0, typename Opnd1>
2899inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2900 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2901}
2902
2903template <typename Opnd0, typename Opnd1>
2904inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2905 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2906}
2907
2908template <typename Opnd0, typename Opnd1>
2909inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2910 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2911}
2912
2913template <typename Opnd0, typename Opnd1>
2914inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2915 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2916 m_UMin(Op0, Op1));
2917}
2918
2919template <typename Opnd0, typename Opnd1>
2920inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2921 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2922}
2923
2924template <typename Opnd0, typename Opnd1>
2925inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2926 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2927}
2928
2929template <typename Opnd0, typename Opnd1>
2930inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2931 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2932}
2933
2934template <typename Opnd0, typename Opnd1>
2935inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2936 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2937}
2938
2939template <typename Opnd0, typename Opnd1>
2940inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2941 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2942}
2943
2944template <typename Opnd0, typename Opnd1>
2945inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2946 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2947}
2948
2949template <typename Opnd0, typename Opnd1>
2950inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2951 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2952}
2953
2954template <typename Opnd0, typename Opnd1>
2955inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2956 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2957}
2958
2959template <typename Opnd0, typename Opnd1, typename Opnd2>
2960inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2961 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2962}
2963
2964template <typename Opnd0, typename Opnd1, typename Opnd2>
2965inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2966 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2967}
2968
2969template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2970 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2971}
2972
2973template <typename Opnd0, typename Opnd1>
2974inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2975 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2976}
2977
2978template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
2980}
2981
2982template <typename Opnd0, typename Opnd1, typename Opnd2>
2983inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
2984 const Opnd2 &Op2) {
2985 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
2986}
2987
2988//===----------------------------------------------------------------------===//
2989// Matchers for two-operands operators with the operators in either order
2990//
2991
2992/// Matches a BinaryOperator with LHS and RHS in either order.
2993template <typename LHS, typename RHS>
2996}
2997
2998/// Matches an ICmp with a predicate over LHS and RHS in either order.
2999/// Swaps the predicate if operands are commuted.
3000template <typename LHS, typename RHS>
3002m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
3004}
3005
3006template <typename LHS, typename RHS>
3011
3012template <typename LHS, typename RHS>
3014 const RHS &R) {
3016}
3017
3018/// Matches a specific opcode with LHS and RHS in either order.
3019template <typename LHS, typename RHS>
3021m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
3022 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
3023}
3024
3025/// Matches a Add with LHS and RHS in either order.
3026template <typename LHS, typename RHS>
3031
3032/// Matches a Mul with LHS and RHS in either order.
3033template <typename LHS, typename RHS>
3038
3039/// Matches an And with LHS and RHS in either order.
3040template <typename LHS, typename RHS>
3045
3046/// Matches an Or with LHS and RHS in either order.
3047template <typename LHS, typename RHS>
3052
3053/// Matches an Xor with LHS and RHS in either order.
3054template <typename LHS, typename RHS>
3059
3060/// Matches a 'Neg' as 'sub 0, V'.
3061template <typename ValTy>
3062inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3063m_Neg(const ValTy &V) {
3064 return m_Sub(m_ZeroInt(), V);
3065}
3066
3067/// Matches a 'Neg' as 'sub nsw 0, V'.
3068template <typename ValTy>
3070 Instruction::Sub,
3072m_NSWNeg(const ValTy &V) {
3073 return m_NSWSub(m_ZeroInt(), V);
3074}
3075
3076template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3080
3081 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3082
3083 template <typename OpTy> bool match(OpTy *V) const {
3084 const auto *II = dyn_cast<IntrinsicInst>(V);
3085 if (!II || II->getIntrinsicID() != IntrID)
3086 return false;
3087 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3088 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3089 }
3090};
3091
3092template <Intrinsic::ID IntrID, typename T0, typename T1>
3094m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3096}
3097
3098/// Matches an SMin with LHS and RHS in either order.
3099template <typename LHS, typename RHS>
3100inline auto m_c_SMin(const LHS &L, const RHS &R) {
3101 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3102}
3103/// Matches an SMax with LHS and RHS in either order.
3104template <typename LHS, typename RHS>
3105inline auto m_c_SMax(const LHS &L, const RHS &R) {
3106 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3107}
3108/// Matches a UMin with LHS and RHS in either order.
3109template <typename LHS, typename RHS>
3110inline auto m_c_UMin(const LHS &L, const RHS &R) {
3111 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3112}
3113/// Matches a UMax with LHS and RHS in either order.
3114template <typename LHS, typename RHS>
3115inline auto m_c_UMax(const LHS &L, const RHS &R) {
3116 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3117}
3118
3119template <typename LHS, typename RHS>
3120inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3121 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3122 m_c_UMin(L, R));
3123}
3124
3125/// Matches FAdd with LHS and RHS in either order.
3126template <typename LHS, typename RHS>
3128m_c_FAdd(const LHS &L, const RHS &R) {
3130}
3131
3132/// Matches FMul with LHS and RHS in either order.
3133template <typename LHS, typename RHS>
3135m_c_FMul(const LHS &L, const RHS &R) {
3137}
3138
3139template <typename Opnd_t> struct Signum_match {
3140 Opnd_t Val;
3141 Signum_match(const Opnd_t &V) : Val(V) {}
3142
3143 template <typename OpTy> bool match(OpTy *V) const {
3144 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3145 if (TypeSize == 0)
3146 return false;
3147
3148 unsigned ShiftWidth = TypeSize - 1;
3149 Value *Op;
3150
3151 // This is the representation of signum we match:
3152 //
3153 // signum(x) == (x >> 63) | (-x >>u 63)
3154 //
3155 // An i1 value is its own signum, so it's correct to match
3156 //
3157 // signum(x) == (x >> 0) | (-x >>u 0)
3158 //
3159 // for i1 values.
3160
3161 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3162 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3163 auto Signum = m_c_Or(LHS, RHS);
3164
3165 return Signum.match(V) && Val.match(Op);
3166 }
3167};
3168
3169/// Matches a signum pattern.
3170///
3171/// signum(x) =
3172/// x > 0 -> 1
3173/// x == 0 -> 0
3174/// x < 0 -> -1
3175template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3176 return Signum_match<Val_t>(V);
3177}
3178
3179template <int Ind, typename Opnd_t> struct ExtractValue_match {
3180 Opnd_t Val;
3181 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3182
3183 template <typename OpTy> bool match(OpTy *V) const {
3184 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3185 // If Ind is -1, don't inspect indices
3186 if (Ind != -1 &&
3187 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3188 return false;
3189 return Val.match(I->getAggregateOperand());
3190 }
3191 return false;
3192 }
3193};
3194
3195/// Match a single index ExtractValue instruction.
3196/// For example m_ExtractValue<1>(...)
3197template <int Ind, typename Val_t>
3201
3202/// Match an ExtractValue instruction with any index.
3203/// For example m_ExtractValue(...)
3204template <typename Val_t>
3205inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3206 return ExtractValue_match<-1, Val_t>(V);
3207}
3208
3209/// Matcher for a single index InsertValue instruction.
3210template <int Ind, typename T0, typename T1> struct InsertValue_match {
3213
3214 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3215
3216 template <typename OpTy> bool match(OpTy *V) const {
3217 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3218 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3219 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3220 }
3221 return false;
3222 }
3223};
3224
3225/// Matches a single index InsertValue instruction.
3226template <int Ind, typename Val_t, typename Elt_t>
3228 const Elt_t &Elt) {
3229 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3230}
3231
3232/// Matches a call to `llvm.vscale()`.
3233inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3234
3235template <typename Opnd0, typename Opnd1>
3236inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3238}
3239
3240template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3242}
3243
3244template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3248
3249 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3250
3251 template <typename T> bool match(T *V) const {
3252 auto *I = dyn_cast<Instruction>(V);
3253 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3254 return false;
3255
3256 if (I->getOpcode() == Opcode) {
3257 auto *Op0 = I->getOperand(0);
3258 auto *Op1 = I->getOperand(1);
3259 return (L.match(Op0) && R.match(Op1)) ||
3260 (Commutable && L.match(Op1) && R.match(Op0));
3261 }
3262
3263 if (auto *Select = dyn_cast<SelectInst>(I)) {
3264 auto *Cond = Select->getCondition();
3265 auto *TVal = Select->getTrueValue();
3266 auto *FVal = Select->getFalseValue();
3267
3268 // Don't match a scalar select of bool vectors.
3269 // Transforms expect a single type for operands if this matches.
3270 if (Cond->getType() != Select->getType())
3271 return false;
3272
3273 if (Opcode == Instruction::And) {
3274 auto *C = dyn_cast<Constant>(FVal);
3275 if (C && C->isNullValue())
3276 return (L.match(Cond) && R.match(TVal)) ||
3277 (Commutable && L.match(TVal) && R.match(Cond));
3278 } else {
3279 assert(Opcode == Instruction::Or);
3280 auto *C = dyn_cast<Constant>(TVal);
3281 if (C && C->isOneValue())
3282 return (L.match(Cond) && R.match(FVal)) ||
3283 (Commutable && L.match(FVal) && R.match(Cond));
3284 }
3285 }
3286
3287 return false;
3288 }
3289};
3290
3291/// Matches L && R either in the form of L & R or L ? R : false.
3292/// Note that the latter form is poison-blocking.
3293template <typename LHS, typename RHS>
3298
3299/// Matches L && R where L and R are arbitrary values.
3300inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3301
3302/// Matches L && R with LHS and RHS in either order.
3303template <typename LHS, typename RHS>
3305m_c_LogicalAnd(const LHS &L, const RHS &R) {
3307}
3308
3309/// Matches L || R either in the form of L | R or L ? true : R.
3310/// Note that the latter form is poison-blocking.
3311template <typename LHS, typename RHS>
3316
3317/// Matches L || R where L and R are arbitrary values.
3318inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3319
3320/// Matches L || R with LHS and RHS in either order.
3321template <typename LHS, typename RHS>
3323m_c_LogicalOr(const LHS &L, const RHS &R) {
3325}
3326
3327/// Matches either L && R or L || R,
3328/// either one being in the either binary or logical form.
3329/// Note that the latter form is poison-blocking.
3330template <typename LHS, typename RHS, bool Commutable = false>
3336
3337/// Matches either L && R or L || R where L and R are arbitrary values.
3338inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3339
3340/// Matches either L && R or L || R with LHS and RHS in either order.
3341template <typename LHS, typename RHS>
3342inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3343 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3344}
3345
3346} // end namespace PatternMatch
3347} // end namespace llvm
3348
3349#endif // LLVM_IR_PATTERNMATCH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned 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
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition Constants.h:219
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)
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.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap >, DisjointOr_match< LHS, RHS > > m_NUWAddLike(const LHS &L, const RHS &R)
Match either "add nuw" or "or disjoint".
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
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)