LLVM 23.0.0git
PatternMatch.h
Go to the documentation of this file.
1//===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides a simple and efficient mechanism for performing general
10// tree-based pattern matches on the LLVM IR. The power of these routines is
11// that it allows you to write concise patterns that are expressive and easy to
12// understand. The other major advantage of this is that it allows you to
13// trivially capture/bind elements in the pattern to variables. For example,
14// you can do something like this:
15//
16// Value *Exp = ...
17// Value *X, *Y; ConstantInt *C1, *C2; // (X & C1) | (Y & C2)
18// if (match(Exp, m_Or(m_And(m_Value(X), m_ConstantInt(C1)),
19// m_And(m_Value(Y), m_ConstantInt(C2))))) {
20// ... Pattern is matched and variables are bound ...
21// }
22//
23// This is primarily useful to things like the instruction combiner, but can
24// also be useful for static analysis tools or code generators.
25//
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_IR_PATTERNMATCH_H
29#define LLVM_IR_PATTERNMATCH_H
30
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/APInt.h"
33#include "llvm/IR/Constant.h"
34#include "llvm/IR/Constants.h"
35#include "llvm/IR/DataLayout.h"
36#include "llvm/IR/FMF.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
41#include "llvm/IR/Intrinsics.h"
42#include "llvm/IR/Operator.h"
43#include "llvm/IR/Value.h"
46#include <cstdint>
47#include <utility>
48
49using namespace llvm::PatternMatchHelpers;
50
51namespace llvm {
52namespace PatternMatch {
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 // TODO: Extend to other cases (e.g. shufflevectors).
222 return false;
223 }
224};
225
226/// Match a constant splat. TODO: Extend this to non-constant splats.
227template <typename T>
228inline Splat_match<T> m_ConstantSplat(const T &SubPattern) {
229 return SubPattern;
230}
231
232/// Match an arbitrary basic block value and ignore it.
233inline auto m_BasicBlock() { return m_Isa<BasicBlock>(); }
234
235/// Inverting matcher
236template <typename Ty> struct match_unless {
237 Ty M;
238
239 match_unless(const Ty &Matcher) : M(Matcher) {}
240
241 template <typename ITy> bool match(ITy *V) const { return !M.match(V); }
242};
243
244/// Match if the inner matcher does *NOT* match.
245template <typename Ty> inline match_unless<Ty> m_Unless(const Ty &M) {
246 return match_unless<Ty>(M);
247}
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.
698m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold) {
700 P.Pred = Predicate;
701 P.Thr = &Threshold;
702 return P;
703}
704
705struct is_nan {
706 bool isValue(const APFloat &C) const { return C.isNaN(); }
707};
708/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
709/// For vectors, this includes constants with undefined elements.
711
712struct is_nonnan {
713 bool isValue(const APFloat &C) const { return !C.isNaN(); }
714};
715/// Match a non-NaN FP constant.
716/// For vectors, this includes constants with undefined elements.
720
721struct is_inf {
722 bool isValue(const APFloat &C) const { return C.isInfinity(); }
723};
724/// Match a positive or negative infinity FP constant.
725/// For vectors, this includes constants with undefined elements.
727
728template <bool IsNegative> struct is_signed_inf {
729 bool isValue(const APFloat &C) const {
730 return C.isInfinity() && IsNegative == C.isNegative();
731 }
732};
733
734/// Match a positive infinity FP constant.
735/// For vectors, this includes constants with undefined elements.
739
740/// Match a negative infinity FP constant.
741/// For vectors, this includes constants with undefined elements.
745
746struct is_noninf {
747 bool isValue(const APFloat &C) const { return !C.isInfinity(); }
748};
749/// Match a non-infinity FP constant, i.e. finite or NaN.
750/// For vectors, this includes constants with undefined elements.
754
755struct is_finite {
756 bool isValue(const APFloat &C) const { return C.isFinite(); }
757};
758/// Match a finite FP constant, i.e. not infinity or NaN.
759/// For vectors, this includes constants with undefined elements.
763inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
764
766 bool isValue(const APFloat &C) const { return C.isFiniteNonZero(); }
767};
768/// Match a finite non-zero FP constant.
769/// For vectors, this includes constants with undefined elements.
774 return V;
775}
776
778 bool isValue(const APFloat &C) const { return C.isZero(); }
779};
780/// Match a floating-point negative zero or positive zero.
781/// For vectors, this includes constants with undefined elements.
785
787 bool isValue(const APFloat &C) const { return C.isPosZero(); }
788};
789/// Match a floating-point positive zero.
790/// For vectors, this includes constants with undefined elements.
794
796 bool isValue(const APFloat &C) const { return C.isNegZero(); }
797};
798/// Match a floating-point negative zero.
799/// For vectors, this includes constants with undefined elements.
803
805 bool isValue(const APFloat &C) const { return C.isNonZero(); }
806};
807/// Match a floating-point non-zero.
808/// For vectors, this includes constants with undefined elements.
812
814 bool isValue(const APFloat &C) const {
815 return !C.isDenormal() && C.isNonZero();
816 }
817};
818
819/// Match a floating-point non-zero that is not a denormal.
820/// For vectors, this includes constants with undefined elements.
824
825///////////////////////////////////////////////////////////////////////////////
826
827/// Match a value, capturing it if we match.
828inline match_bind<Value> m_Value(Value *&V) { return V; }
829inline match_bind<const Value> m_Value(const Value *&V) { return V; }
830
831/// Match against the nested pattern, and capture the value if we match.
832template <typename Pattern> inline auto m_Value(Value *&V, const Pattern &P) {
833 return m_CombineAnd(P, match_bind<Value>(V));
834}
835
836/// Match against the nested pattern, and capture the value if we match.
837template <typename Pattern>
838inline auto m_Value(const Value *&V, const Pattern &P) {
840}
841
842/// Match an instruction, capturing it if we match.
845 return I;
846}
847
848/// Match against the nested pattern, and capture the instruction if we match.
849template <typename Pattern>
850inline auto m_Instruction(Instruction *&I, const Pattern &P) {
852}
853template <typename Pattern>
854inline auto m_Instruction(const Instruction *&I, const Pattern &P) {
856}
857
858/// Match a unary operator, capturing it if we match.
861 return I;
862}
863/// Match a binary operator, capturing it if we match.
866 return I;
867}
868/// Match any intrinsic call, capturing it if we match.
873/// Match a with overflow intrinsic, capturing it if we match.
879 return I;
880}
881
882/// Match a PHI node, capturing it if we match.
883inline match_bind<PHINode> m_Phi(PHINode *&PN) { return PN; }
884
885/// Match an UndefValue, capturing the value if we match.
887
888/// Match a Constant, capturing the value if we match.
890
891/// Match a ConstantInt, capturing the value if we match.
893
894/// Match a ConstantFP, capturing the value if we match.
896
897/// Match a ConstantExpr, capturing the value if we match.
899
900/// Match a basic block value, capturing it if we match.
903 return V;
904}
905
906// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
907// and use m_Unless(m_ConstantExpr).
909 template <typename ITy> static bool isImmConstant(ITy *V) {
910 if (auto *CV = dyn_cast<Constant>(V)) {
911 if (!match(CV, m_ConstantExpr()))
912 return true;
913
914 if (CV->getType()->isVectorTy()) {
915 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
916 if (!match(Splat, m_ConstantExpr())) {
917 return true;
918 }
919 }
920 }
921 }
922 return false;
923 }
924};
925
927 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
928};
929
930/// Match an arbitrary immediate Constant and ignore it.
932
935
937
938 template <typename ITy> bool match(ITy *V) const {
939 if (isImmConstant(V)) {
940 VR = cast<Constant>(V);
941 return true;
942 }
943 return false;
944 }
945};
946
947/// Match an immediate Constant, capturing the value if we match.
951
952/// Matcher for specified Value*.
954 const Value *Val;
955
956 specificval_ty(const Value *V) : Val(V) {}
957
958 template <typename ITy> bool match(ITy *V) const { return V == Val; }
959};
960
961/// Match if we have a specific specified value.
962inline specificval_ty m_Specific(const Value *V) { return V; }
963
964/// Like m_Specific(), but works if the specific value to match is determined
965/// as part of the same match() expression. For example:
966/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
967/// bind X before the pattern match starts.
968/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
969/// whichever value m_Value(X) populated.
970inline match_deferred<Value> m_Deferred(Value *const &V) { return V; }
972 return V;
973}
974
975/// Match a specified floating point value or vector of all elements of
976/// that value.
978 double Val;
979
980 specific_fpval(double V) : Val(V) {}
981
982 template <typename ITy> bool match(ITy *V) const {
983 if (const auto *CFP = dyn_cast<ConstantFP>(V))
984 return CFP->isExactlyValue(Val);
985 if (V->getType()->isVectorTy())
986 if (const auto *C = dyn_cast<Constant>(V))
987 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
988 return CFP->isExactlyValue(Val);
989 return false;
990 }
991};
992
993/// Match a specific floating point value or vector with all elements
994/// equal to the value.
995inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
996
997/// Match a float 1.0 or vector with all elements equal to 1.0.
998inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
999
1002
1004
1005 template <typename ITy> bool match(ITy *V) const {
1006 const APInt *ConstInt;
1007 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1008 return false;
1009 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1010 if (!ZExtVal)
1011 return false;
1012 VR = *ZExtVal;
1013 return true;
1014 }
1015};
1016
1017/// Match a specified integer value or vector of all elements of that
1018/// value.
1019template <bool AllowPoison> struct specific_intval {
1020 const APInt &Val;
1021
1022 specific_intval(const APInt &V) : Val(V) {}
1023
1024 template <typename ITy> bool match(ITy *V) const {
1025 const auto *CI = dyn_cast<ConstantInt>(V);
1026 if (!CI && V->getType()->isVectorTy())
1027 if (const auto *C = dyn_cast<Constant>(V))
1028 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1029
1030 return CI && APInt::isSameValue(CI->getValue(), Val);
1031 }
1032};
1033
1034template <bool AllowPoison> struct specific_intval64 {
1036
1038
1039 template <typename ITy> bool match(ITy *V) const {
1040 const auto *CI = dyn_cast<ConstantInt>(V);
1041 if (!CI && V->getType()->isVectorTy())
1042 if (const auto *C = dyn_cast<Constant>(V))
1043 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1044
1045 return CI && CI->getValue() == Val;
1046 }
1047};
1048
1049/// Match a specific integer value or vector with all elements equal to
1050/// the value.
1052 return specific_intval<false>(V);
1053}
1054
1058
1062
1066
1067/// Match a ConstantInt and bind to its value. This does not match
1068/// ConstantInts wider than 64-bits.
1070
1071/// Match a specified basic block value.
1074
1076
1077 template <typename ITy> bool match(ITy *V) const {
1078 const auto *BB = dyn_cast<BasicBlock>(V);
1079 return BB && BB == Val;
1080 }
1081};
1082
1083/// Match a specific basic block value.
1085 return specific_bbval(BB);
1086}
1087
1088/// A commutative-friendly version of m_Specific().
1090 return BB;
1091}
1093m_Deferred(const BasicBlock *const &BB) {
1094 return BB;
1095}
1096
1097//===----------------------------------------------------------------------===//
1098// Matcher for any binary operator.
1099//
1100template <typename LHS_t, typename RHS_t, bool Commutable = false>
1104
1105 // The evaluation order is always stable, regardless of Commutability.
1106 // The LHS is always matched first.
1107 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1108
1109 template <typename OpTy> bool match(OpTy *V) const {
1110 if (auto *I = dyn_cast<BinaryOperator>(V))
1111 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1112 (Commutable && L.match(I->getOperand(1)) &&
1113 R.match(I->getOperand(0)));
1114 return false;
1115 }
1116};
1117
1118template <typename LHS, typename RHS>
1119inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1120 return AnyBinaryOp_match<LHS, RHS>(L, R);
1121}
1122
1123//===----------------------------------------------------------------------===//
1124// Matcher for any unary operator.
1125// TODO fuse unary, binary matcher into n-ary matcher
1126//
1127template <typename OP_t> struct AnyUnaryOp_match {
1128 OP_t X;
1129
1130 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1131
1132 template <typename OpTy> bool match(OpTy *V) const {
1133 if (auto *I = dyn_cast<UnaryOperator>(V))
1134 return X.match(I->getOperand(0));
1135 return false;
1136 }
1137};
1138
1139template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1140 return AnyUnaryOp_match<OP_t>(X);
1141}
1142
1143//===----------------------------------------------------------------------===//
1144// Matchers for specific binary operators.
1145//
1146
1147template <typename LHS_t, typename RHS_t, unsigned Opcode,
1148 bool Commutable = false>
1152
1153 // The evaluation order is always stable, regardless of Commutability.
1154 // The LHS is always matched first.
1155 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1156
1157 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1158 if (V->getValueID() == Value::InstructionVal + Opc) {
1159 auto *I = cast<BinaryOperator>(V);
1160 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1161 (Commutable && L.match(I->getOperand(1)) &&
1162 R.match(I->getOperand(0)));
1163 }
1164 return false;
1165 }
1166
1167 template <typename OpTy> bool match(OpTy *V) const {
1168 return match(Opcode, V);
1169 }
1170};
1171
1172template <typename LHS, typename RHS>
1174 const RHS &R) {
1176}
1177
1178template <typename LHS, typename RHS>
1180 const RHS &R) {
1182}
1183
1184template <typename LHS, typename RHS>
1186 const RHS &R) {
1188}
1189
1190template <typename LHS, typename RHS>
1192 const RHS &R) {
1194}
1195
1196template <typename Op_t> struct FNeg_match {
1197 Op_t X;
1198
1199 FNeg_match(const Op_t &Op) : X(Op) {}
1200 template <typename OpTy> bool match(OpTy *V) const {
1201 auto *FPMO = dyn_cast<FPMathOperator>(V);
1202 if (!FPMO)
1203 return false;
1204
1205 if (FPMO->getOpcode() == Instruction::FNeg)
1206 return X.match(FPMO->getOperand(0));
1207
1208 if (FPMO->getOpcode() == Instruction::FSub) {
1209 if (FPMO->hasNoSignedZeros()) {
1210 // With 'nsz', any zero goes.
1211 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1212 return false;
1213 } else {
1214 // Without 'nsz', we need fsub -0.0, X exactly.
1215 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1216 return false;
1217 }
1218
1219 return X.match(FPMO->getOperand(1));
1220 }
1221
1222 return false;
1223 }
1224};
1225
1226/// Match 'fneg X' as 'fsub -0.0, X'.
1227template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1228 return FNeg_match<OpTy>(X);
1229}
1230
1231/// Match 'fneg X' as 'fsub +-0.0, X'.
1232template <typename RHS>
1233inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1234m_FNegNSZ(const RHS &X) {
1235 return m_FSub(m_AnyZeroFP(), X);
1236}
1237
1238template <typename LHS, typename RHS>
1240 const RHS &R) {
1242}
1243
1244template <typename LHS, typename RHS>
1246 const RHS &R) {
1248}
1249
1250template <typename LHS, typename RHS>
1252 const RHS &R) {
1254}
1255
1256template <typename LHS, typename RHS>
1258 const RHS &R) {
1260}
1261
1262template <typename LHS, typename RHS>
1264 const RHS &R) {
1266}
1267
1268template <typename LHS, typename RHS>
1270 const RHS &R) {
1272}
1273
1274template <typename LHS, typename RHS>
1276 const RHS &R) {
1278}
1279
1280template <typename LHS, typename RHS>
1282 const RHS &R) {
1284}
1285
1286template <typename LHS, typename RHS>
1288 const RHS &R) {
1290}
1291
1292template <typename LHS, typename RHS>
1294 const RHS &R) {
1296}
1297
1298template <typename LHS, typename RHS>
1300 const RHS &R) {
1302}
1303
1304template <typename LHS, typename RHS>
1306 const RHS &R) {
1308}
1309
1310template <typename LHS, typename RHS>
1312 const RHS &R) {
1314}
1315
1316template <typename LHS, typename RHS>
1318 const RHS &R) {
1320}
1321
1322template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1325
1326 ShiftLike_match(const LHS_t &LHS, uint64_t &RHS) : L(LHS), R(RHS) {}
1327
1328 template <typename OpTy> bool match(OpTy *V) const {
1329 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1330 if (Op->getOpcode() == Opcode)
1331 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1332 L.match(Op->getOperand(0));
1333 }
1334 // Interpreted as shiftop V, 0
1335 R = 0;
1336 return L.match(V);
1337 }
1338};
1339
1340/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1341template <typename LHS>
1346
1347/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1348template <typename LHS>
1353
1354/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1355template <typename LHS>
1360
1361template <typename LHS_t, typename RHS_t, unsigned Opcode,
1362 unsigned WrapFlags = 0, bool Commutable = false>
1366
1367 OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
1368 : L(LHS), R(RHS) {}
1369
1370 template <typename OpTy> bool match(OpTy *V) const {
1371 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1372 if (Op->getOpcode() != Opcode)
1373 return false;
1375 !Op->hasNoUnsignedWrap())
1376 return false;
1377 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1378 !Op->hasNoSignedWrap())
1379 return false;
1380 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1381 (Commutable && L.match(Op->getOperand(1)) &&
1382 R.match(Op->getOperand(0)));
1383 }
1384 return false;
1385 }
1386};
1387
1388template <typename LHS, typename RHS>
1389inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1391m_NSWAdd(const LHS &L, const RHS &R) {
1392 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1394 R);
1395}
1396template <typename LHS, typename RHS>
1397inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1399m_c_NSWAdd(const LHS &L, const RHS &R) {
1400 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1402 true>(L, R);
1403}
1404template <typename LHS, typename RHS>
1405inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1407m_NSWSub(const LHS &L, const RHS &R) {
1408 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1410 R);
1411}
1412template <typename LHS, typename RHS>
1413inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1415m_NSWMul(const LHS &L, const RHS &R) {
1416 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1418 R);
1419}
1420template <typename LHS, typename RHS>
1421inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1423m_NSWShl(const LHS &L, const RHS &R) {
1424 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1426 R);
1427}
1428
1429template <typename LHS, typename RHS>
1430inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1432m_NUWAdd(const LHS &L, const RHS &R) {
1433 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1435 L, R);
1436}
1437
1438template <typename LHS, typename RHS>
1440 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1441m_c_NUWAdd(const LHS &L, const RHS &R) {
1442 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1444 true>(L, R);
1445}
1446
1447template <typename LHS, typename RHS>
1448inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1450m_NUWSub(const LHS &L, const RHS &R) {
1451 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1453 L, R);
1454}
1455template <typename LHS, typename RHS>
1456inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1458m_NUWMul(const LHS &L, const RHS &R) {
1459 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1461 L, R);
1462}
1463template <typename LHS, typename RHS>
1464inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1466m_NUWShl(const LHS &L, const RHS &R) {
1467 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1469 L, R);
1470}
1471
1472template <typename LHS_t, typename RHS_t, bool Commutable = false>
1474 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1475 unsigned Opcode;
1476
1477 SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
1478 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1479
1480 template <typename OpTy> bool match(OpTy *V) const {
1482 }
1483};
1484
1485/// Matches a specific opcode.
1486template <typename LHS, typename RHS>
1487inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1488 const RHS &R) {
1489 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1490}
1491
1492template <typename LHS, typename RHS, bool Commutable = false>
1494 LHS L;
1495 RHS R;
1496
1497 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1498
1499 template <typename OpTy> bool match(OpTy *V) const {
1500 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1501 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1502 if (!PDI->isDisjoint())
1503 return false;
1504 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1505 (Commutable && L.match(PDI->getOperand(1)) &&
1506 R.match(PDI->getOperand(0)));
1507 }
1508 return false;
1509 }
1510};
1511
1512template <typename LHS, typename RHS>
1513inline DisjointOr_match<LHS, RHS> m_DisjointOr(const LHS &L, const RHS &R) {
1514 return DisjointOr_match<LHS, RHS>(L, R);
1515}
1516
1517template <typename LHS, typename RHS>
1519 const RHS &R) {
1521}
1522
1523/// Match either "add" or "or disjoint".
1524template <typename LHS, typename RHS>
1527m_AddLike(const LHS &L, const RHS &R) {
1528 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1529}
1530
1531/// Match either "add nsw" or "or disjoint"
1532template <typename LHS, typename RHS>
1533inline match_combine_or<
1534 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1537m_NSWAddLike(const LHS &L, const RHS &R) {
1538 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1539}
1540
1541/// Match either "add nuw" or "or disjoint"
1542template <typename LHS, typename RHS>
1543inline match_combine_or<
1544 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1547m_NUWAddLike(const LHS &L, const RHS &R) {
1548 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1549}
1550
1551template <typename LHS, typename RHS>
1553 LHS L;
1554 RHS R;
1555
1556 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1557
1558 template <typename OpTy> bool match(OpTy *V) const {
1559 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1560 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1561 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1562 ; // Pass
1563 else if (Op->getOpcode() != Instruction::Xor)
1564 return false;
1565 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1566 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1567 }
1568 return false;
1569 }
1570};
1571
1572/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1573/// Only commutative matcher as the `sub` will need to swap the L and R.
1574template <typename LHS, typename RHS>
1575inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1576 return XorLike_match<LHS, RHS>(L, R);
1577}
1578
1579//===----------------------------------------------------------------------===//
1580// Class that matches a group of binary opcodes.
1581//
1582template <typename LHS_t, typename RHS_t, typename Predicate,
1583 bool Commutable = false>
1584struct BinOpPred_match : Predicate {
1587
1588 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1589
1590 template <typename OpTy> bool match(OpTy *V) const {
1591 if (auto *I = dyn_cast<Instruction>(V))
1592 return this->isOpType(I->getOpcode()) &&
1593 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1594 (Commutable && L.match(I->getOperand(1)) &&
1595 R.match(I->getOperand(0))));
1596 return false;
1597 }
1598};
1599
1601 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1602};
1603
1605 bool isOpType(unsigned Opcode) const {
1606 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1607 }
1608};
1609
1611 bool isOpType(unsigned Opcode) const {
1612 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1613 }
1614};
1615
1617 bool isOpType(unsigned Opcode) const {
1618 return Instruction::isBitwiseLogicOp(Opcode);
1619 }
1620};
1621
1623 bool isOpType(unsigned Opcode) const {
1624 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1625 }
1626};
1627
1629 bool isOpType(unsigned Opcode) const {
1630 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1631 }
1632};
1633
1634/// Matches shift operations.
1635template <typename LHS, typename RHS>
1637 const RHS &R) {
1639}
1640
1641/// Matches logical shift operations.
1642template <typename LHS, typename RHS>
1644 const RHS &R) {
1646}
1647
1648/// Matches logical shift operations.
1649template <typename LHS, typename RHS>
1651m_LogicalShift(const LHS &L, const RHS &R) {
1653}
1654
1655/// Matches bitwise logic operations.
1656template <typename LHS, typename RHS>
1658m_BitwiseLogic(const LHS &L, const RHS &R) {
1660}
1661
1662/// Matches bitwise logic operations in either order.
1663template <typename LHS, typename RHS>
1665m_c_BitwiseLogic(const LHS &L, const RHS &R) {
1667}
1668
1669/// Matches integer division operations.
1670template <typename LHS, typename RHS>
1672 const RHS &R) {
1674}
1675
1676/// Matches integer remainder operations.
1677template <typename LHS, typename RHS>
1679 const RHS &R) {
1681}
1682
1683//===----------------------------------------------------------------------===//
1684// Class that matches exact binary ops.
1685//
1686template <typename SubPattern_t> struct Exact_match {
1687 SubPattern_t SubPattern;
1688
1689 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1690
1691 template <typename OpTy> bool match(OpTy *V) const {
1692 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1693 return PEO->isExact() && SubPattern.match(V);
1694 return false;
1695 }
1696};
1697
1698template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1699 return SubPattern;
1700}
1701
1702//===----------------------------------------------------------------------===//
1703// Matchers for CmpInst classes
1704//
1705
1706template <typename LHS_t, typename RHS_t, typename Class,
1707 bool Commutable = false>
1712
1713 // The evaluation order is always stable, regardless of Commutability.
1714 // The LHS is always matched first.
1715 CmpClass_match(CmpPredicate &Pred, const LHS_t &LHS, const RHS_t &RHS)
1716 : Predicate(&Pred), L(LHS), R(RHS) {}
1717 CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
1718 : Predicate(nullptr), L(LHS), R(RHS) {}
1719
1720 template <typename OpTy> bool match(OpTy *V) const {
1721 if (auto *I = dyn_cast<Class>(V)) {
1722 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1723 if (Predicate)
1725 return true;
1726 }
1727 if (Commutable && L.match(I->getOperand(1)) &&
1728 R.match(I->getOperand(0))) {
1729 if (Predicate)
1731 return true;
1732 }
1733 }
1734 return false;
1735 }
1736};
1737
1738template <typename LHS, typename RHS>
1740 const RHS &R) {
1741 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1742}
1743
1744template <typename LHS, typename RHS>
1746 const LHS &L, const RHS &R) {
1747 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1748}
1749
1750template <typename LHS, typename RHS>
1752 const LHS &L, const RHS &R) {
1753 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1754}
1755
1756template <typename LHS, typename RHS>
1757inline CmpClass_match<LHS, RHS, CmpInst> m_Cmp(const LHS &L, const RHS &R) {
1759}
1760
1761template <typename LHS, typename RHS>
1762inline CmpClass_match<LHS, RHS, ICmpInst> m_ICmp(const LHS &L, const RHS &R) {
1764}
1765
1766template <typename LHS, typename RHS>
1767inline CmpClass_match<LHS, RHS, FCmpInst> m_FCmp(const LHS &L, const RHS &R) {
1769}
1770
1771// Same as CmpClass, but instead of saving Pred as out output variable, match a
1772// specific input pred for equality.
1773template <typename LHS_t, typename RHS_t, typename Class,
1774 bool Commutable = false>
1779
1780 SpecificCmpClass_match(CmpPredicate Pred, const LHS_t &LHS, const RHS_t &RHS)
1781 : Predicate(Pred), L(LHS), R(RHS) {}
1782
1783 template <typename OpTy> bool match(OpTy *V) const {
1784 if (auto *I = dyn_cast<Class>(V)) {
1786 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1787 return true;
1788 if constexpr (Commutable) {
1791 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1792 return true;
1793 }
1794 }
1795
1796 return false;
1797 }
1798};
1799
1800template <typename LHS, typename RHS>
1802m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1803 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1804}
1805
1806template <typename LHS, typename RHS>
1808m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1809 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1810}
1811
1812template <typename LHS, typename RHS>
1814m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1816}
1817
1818template <typename LHS, typename RHS>
1820m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1821 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1822}
1823
1824//===----------------------------------------------------------------------===//
1825// Matchers for instructions with a given opcode and number of operands.
1826//
1827
1828/// Matches instructions with Opcode and three operands.
1829template <typename T0, unsigned Opcode> struct OneOps_match {
1831
1832 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1833
1834 template <typename OpTy> bool match(OpTy *V) const {
1835 if (V->getValueID() == Value::InstructionVal + Opcode) {
1836 auto *I = cast<Instruction>(V);
1837 return Op1.match(I->getOperand(0));
1838 }
1839 return false;
1840 }
1841};
1842
1843/// Matches instructions with Opcode and three operands.
1844template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1847
1848 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1849
1850 template <typename OpTy> bool match(OpTy *V) const {
1851 if (V->getValueID() == Value::InstructionVal + Opcode) {
1852 auto *I = cast<Instruction>(V);
1853 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1854 }
1855 return false;
1856 }
1857};
1858
1859/// Matches instructions with Opcode and three operands.
1860template <typename T0, typename T1, typename T2, unsigned Opcode,
1861 bool CommutableOp2Op3 = false>
1866
1867 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1868 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1869
1870 template <typename OpTy> bool match(OpTy *V) const {
1871 if (V->getValueID() == Value::InstructionVal + Opcode) {
1872 auto *I = cast<Instruction>(V);
1873 if (!Op1.match(I->getOperand(0)))
1874 return false;
1875 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1876 return true;
1877 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1878 Op3.match(I->getOperand(1));
1879 }
1880 return false;
1881 }
1882};
1883
1884/// Matches instructions with Opcode and any number of operands
1885template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1886 std::tuple<OperandTypes...> Operands;
1887
1888 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1889
1890 // Operand matching works by recursively calling match_operands, matching the
1891 // operands left to right. The first version is called for each operand but
1892 // the last, for which the second version is called. The second version of
1893 // match_operands is also used to match each individual operand.
1894 template <int Idx, int Last>
1895 std::enable_if_t<Idx != Last, bool>
1899
1900 template <int Idx, int Last>
1901 std::enable_if_t<Idx == Last, bool>
1903 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1904 }
1905
1906 template <typename OpTy> bool match(OpTy *V) const {
1907 if (V->getValueID() == Value::InstructionVal + Opcode) {
1908 auto *I = cast<Instruction>(V);
1909 return I->getNumOperands() == sizeof...(OperandTypes) &&
1910 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1911 }
1912 return false;
1913 }
1914};
1915
1916/// Matches SelectInst.
1917template <typename Cond, typename LHS, typename RHS>
1919m_Select(const Cond &C, const LHS &L, const RHS &R) {
1921}
1922
1923/// This matches a select of two constants, e.g.:
1924/// m_SelectCst<-1, 0>(m_Value(V))
1925template <int64_t L, int64_t R, typename Cond>
1927 Instruction::Select>
1930}
1931
1932/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1933template <typename LHS, typename RHS>
1934inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1935m_c_Select(const LHS &L, const RHS &R) {
1936 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1937 true>(m_Value(), L, R);
1938}
1939
1940/// Matches FreezeInst.
1941template <typename OpTy>
1945
1946/// Matches InsertElementInst.
1947template <typename Val_t, typename Elt_t, typename Idx_t>
1949m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1951 Val, Elt, Idx);
1952}
1953
1954/// Matches ExtractElementInst.
1955template <typename Val_t, typename Idx_t>
1957m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
1959}
1960
1961/// Matches shuffle.
1962template <typename T0, typename T1, typename T2> struct Shuffle_match {
1966
1967 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
1968 : Op1(Op1), Op2(Op2), Mask(Mask) {}
1969
1970 template <typename OpTy> bool match(OpTy *V) const {
1971 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
1972 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1973 Mask.match(I->getShuffleMask());
1974 }
1975 return false;
1976 }
1977};
1978
1979struct m_Mask {
1982 bool match(ArrayRef<int> Mask) const {
1983 MaskRef = Mask;
1984 return true;
1985 }
1986};
1987
1989 bool match(ArrayRef<int> Mask) const {
1990 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
1991 }
1992};
1993
1997 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
1998};
1999
2001 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
2002};
2003
2007 bool match(ArrayRef<int> Mask) const {
2008 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2009 if (First == Mask.end())
2010 return false;
2011 SplatIndex = *First;
2012 return all_of(Mask,
2013 [First](int Elem) { return Elem == *First || Elem == -1; });
2014 }
2015};
2016
2017template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2018 PointerOpTy PointerOp;
2019 OffsetOpTy OffsetOp;
2020
2021 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2023
2024 template <typename OpTy> bool match(OpTy *V) const {
2025 auto *GEP = dyn_cast<GEPOperator>(V);
2026 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2027 PointerOp.match(GEP->getPointerOperand()) &&
2028 OffsetOp.match(GEP->idx_begin()->get());
2029 }
2030};
2031
2032/// Matches ShuffleVectorInst independently of mask value.
2033template <typename V1_t, typename V2_t>
2035m_Shuffle(const V1_t &v1, const V2_t &v2) {
2037}
2038
2039template <typename V1_t, typename V2_t, typename Mask_t>
2041m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2043}
2044
2045/// Matches LoadInst.
2046template <typename OpTy>
2050
2051/// Matches a simple (non-volatile, non-atomic) LoadInst.
2052template <typename OpTy> struct LoadSimple_match {
2054
2056
2057 template <typename ITy> bool match(ITy *V) const {
2058 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2059 }
2060};
2061
2062template <typename OpTy>
2066
2067/// Matches StoreInst.
2068template <typename ValueOpTy, typename PointerOpTy>
2070m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2072 PointerOp);
2073}
2074
2075/// Matches GetElementPtrInst.
2076template <typename... OperandTypes>
2077inline auto m_GEP(const OperandTypes &...Ops) {
2078 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2079}
2080
2081/// Matches GEP with i8 source element type
2082template <typename PointerOpTy, typename OffsetOpTy>
2084m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2086}
2087
2088//===----------------------------------------------------------------------===//
2089// Matchers for CastInst classes
2090//
2091
2092template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2093 Op_t Op;
2094
2095 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2096
2097 template <typename OpTy> bool match(OpTy *V) const {
2098 if (auto *O = dyn_cast<Operator>(V))
2099 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2100 return false;
2101 }
2102};
2103
2104template <typename Op_t, typename Class> struct CastInst_match {
2105 Op_t Op;
2106
2107 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2108
2109 template <typename OpTy> bool match(OpTy *V) const {
2110 if (auto *I = dyn_cast<Class>(V))
2111 return Op.match(I->getOperand(0));
2112 return false;
2113 }
2114};
2115
2116template <typename Op_t> struct PtrToIntSameSize_match {
2118 Op_t Op;
2119
2120 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2121 : DL(DL), Op(OpMatch) {}
2122
2123 template <typename OpTy> bool match(OpTy *V) const {
2124 if (auto *O = dyn_cast<Operator>(V))
2125 return O->getOpcode() == Instruction::PtrToInt &&
2126 DL.getTypeSizeInBits(O->getType()) ==
2127 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2128 Op.match(O->getOperand(0));
2129 return false;
2130 }
2131};
2132
2133template <typename Op_t> struct NNegZExt_match {
2134 Op_t Op;
2135
2136 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2137
2138 template <typename OpTy> bool match(OpTy *V) const {
2139 if (auto *I = dyn_cast<ZExtInst>(V))
2140 return I->hasNonNeg() && Op.match(I->getOperand(0));
2141 return false;
2142 }
2143};
2144
2145template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2146 Op_t Op;
2147
2148 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2149
2150 template <typename OpTy> bool match(OpTy *V) const {
2151 if (auto *I = dyn_cast<TruncInst>(V))
2152 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2153 Op.match(I->getOperand(0));
2154 return false;
2155 }
2156};
2157
2158/// Matches BitCast.
2159template <typename OpTy>
2164
2165template <typename Op_t> struct ElementWiseBitCast_match {
2166 Op_t Op;
2167
2168 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2169
2170 template <typename OpTy> bool match(OpTy *V) const {
2171 auto *I = dyn_cast<BitCastInst>(V);
2172 if (!I)
2173 return false;
2174 Type *SrcType = I->getSrcTy();
2175 Type *DstType = I->getType();
2176 // Make sure the bitcast doesn't change between scalar and vector and
2177 // doesn't change the number of vector elements.
2178 if (SrcType->isVectorTy() != DstType->isVectorTy())
2179 return false;
2180 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2181 SrcVecTy && SrcVecTy->getElementCount() !=
2182 cast<VectorType>(DstType)->getElementCount())
2183 return false;
2184 return Op.match(I->getOperand(0));
2185 }
2186};
2187
2188template <typename OpTy>
2192
2193/// Matches PtrToInt.
2194template <typename OpTy>
2199
2200template <typename OpTy>
2205
2206/// Matches PtrToAddr.
2207template <typename OpTy>
2212
2213/// Matches PtrToInt or PtrToAddr.
2214template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2216}
2217
2218/// Matches IntToPtr.
2219template <typename OpTy>
2224
2225/// Matches any cast or self. Used to ignore casts.
2226template <typename OpTy>
2231
2232/// Matches Trunc.
2233template <typename OpTy>
2237
2238/// Matches trunc nuw.
2239template <typename OpTy>
2244
2245/// Matches trunc nsw.
2246template <typename OpTy>
2251
2252template <typename OpTy>
2255 return m_CombineOr(m_Trunc(Op), Op);
2256}
2257
2258/// Matches SExt.
2259template <typename OpTy>
2263
2264/// Matches ZExt.
2265template <typename OpTy>
2269
2270template <typename OpTy>
2272 return NNegZExt_match<OpTy>(Op);
2273}
2274
2275template <typename OpTy>
2278 return m_CombineOr(m_ZExt(Op), Op);
2279}
2280
2281template <typename OpTy>
2284 return m_CombineOr(m_SExt(Op), Op);
2285}
2286
2287/// Match either "sext" or "zext nneg".
2288template <typename OpTy>
2291 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2292}
2293
2294template <typename OpTy>
2298 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2299}
2300
2301template <typename OpTy>
2304 OpTy>
2306 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2307}
2308
2309template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2310 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2311}
2312
2313template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2317
2319 : Pred(P), L(Left), R(Right) {}
2320
2321 template <typename OpTy> bool match(OpTy *V) const {
2322 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2323 return true;
2324 Value *A;
2325 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2326 if (V->getType()->isIntOrIntVectorTy(1) &&
2327 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2328 R.match(ConstantInt::getNullValue(A->getType()))) {
2330 return true;
2331 }
2332 return false;
2333 }
2334};
2335
2336template <typename LHS, typename RHS>
2338 const RHS &R) {
2339 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2340}
2341
2342template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2343 CondTy Cond;
2346
2347 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2348 : Cond(C), TrueC(TC), FalseC(FC) {}
2349
2350 template <typename OpTy> bool match(OpTy *V) const {
2351 // select(Cond, TrueC, FalseC) — captures both constants directly
2353 return true;
2354
2355 Type *Ty = V->getType();
2356 Value *CondV = nullptr;
2357
2358 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2359 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2360 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2361 TrueC.match(ConstantInt::get(Ty, 1)) &&
2362 FalseC.match(ConstantInt::get(Ty, 0)))
2363 return true;
2364
2365 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2366 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2367 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2368 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2369 FalseC.match(ConstantInt::get(Ty, 0)))
2370 return true;
2371
2372 return false;
2373 }
2374};
2375
2376/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2377/// select i1 Cond, TrueC, FalseC
2378/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2379/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2380///
2381/// The condition is matched against \p Cond, and the true/false constants
2382/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2383/// constants are bound to \p TrueC and \p FalseC via their matchers.
2384template <typename CondTy, typename LTy, typename RTy>
2386m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2387 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2388}
2389
2390template <typename OpTy>
2394
2395template <typename OpTy>
2399
2400template <typename OpTy>
2403m_IToFP(const OpTy &Op) {
2404 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2405}
2406
2407template <typename OpTy>
2411
2412template <typename OpTy>
2416
2417template <typename OpTy>
2420m_FPToI(const OpTy &Op) {
2421 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2422}
2423
2424template <typename OpTy>
2428
2429template <typename OpTy>
2433
2434//===----------------------------------------------------------------------===//
2435// Matchers for control flow.
2436//
2437
2438struct br_match {
2440
2442
2443 template <typename OpTy> bool match(OpTy *V) const {
2444 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2445 Succ = BI->getSuccessor();
2446 return true;
2447 }
2448 return false;
2449 }
2450};
2451
2452inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2453
2454template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2456 Cond_t Cond;
2457 TrueBlock_t T;
2458 FalseBlock_t F;
2459
2460 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2461 : Cond(C), T(t), F(f) {}
2462
2463 template <typename OpTy> bool match(OpTy *V) const {
2464 if (auto *BI = dyn_cast<CondBrInst>(V))
2465 if (Cond.match(BI->getCondition()))
2466 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2467 return false;
2468 }
2469};
2470
2471template <typename Cond_t>
2477
2478template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2480m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2482}
2483
2484//===----------------------------------------------------------------------===//
2485// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2486//
2487
2488template <typename LHS_t, typename RHS_t, typename Pred_t>
2490 using PredType = Pred_t;
2493
2494 // The evaluation order is always stable, regardless of Commutability.
2495 // The LHS is always matched first.
2496 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2497
2498 template <typename OpTy> bool match(OpTy *V) const {
2499 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2500 auto *SI = dyn_cast<SelectInst>(V);
2501 if (!SI)
2502 return false;
2503 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2504 if (!Cmp)
2505 return false;
2506 // At this point we have a select conditioned on a comparison. Check that
2507 // it is the values returned by the select that are being compared.
2508 auto *TrueVal = SI->getTrueValue();
2509 auto *FalseVal = SI->getFalseValue();
2510 auto *LHS = Cmp->getOperand(0);
2511 auto *RHS = Cmp->getOperand(1);
2512 if ((TrueVal != LHS || FalseVal != RHS) &&
2513 (TrueVal != RHS || FalseVal != LHS))
2514 return false;
2515 FCmpInst::Predicate Pred =
2516 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2517 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2518 if (!Pred_t::match(Pred))
2519 return false;
2520 // It does! Bind the operands.
2521 return L.match(LHS) && R.match(RHS);
2522 }
2523};
2524
2525/// Helper class for identifying ordered max predicates.
2527 static bool match(FCmpInst::Predicate Pred) {
2528 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2529 }
2530};
2531
2532/// Helper class for identifying ordered min predicates.
2534 static bool match(FCmpInst::Predicate Pred) {
2535 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2536 }
2537};
2538
2539/// Helper class for identifying unordered max predicates.
2541 static bool match(FCmpInst::Predicate Pred) {
2542 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2543 }
2544};
2545
2546/// Helper class for identifying unordered min predicates.
2548 static bool match(FCmpInst::Predicate Pred) {
2549 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2550 }
2551};
2552
2553/// Match an 'ordered' floating point maximum function.
2554/// Floating point has one special value 'NaN'. Therefore, there is no total
2555/// order. However, if we can ignore the 'NaN' value (for example, because of a
2556/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2557/// semantics. In the presence of 'NaN' we have to preserve the original
2558/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2559///
2560/// max(L, R) iff L and R are not NaN
2561/// m_OrdFMax(L, R) = R iff L or R are NaN
2562template <typename LHS, typename RHS>
2564 const RHS &R) {
2566}
2567
2568/// Match an 'ordered' floating point minimum function.
2569/// Floating point has one special value 'NaN'. Therefore, there is no total
2570/// order. However, if we can ignore the 'NaN' value (for example, because of a
2571/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2572/// semantics. In the presence of 'NaN' we have to preserve the original
2573/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2574///
2575/// min(L, R) iff L and R are not NaN
2576/// m_OrdFMin(L, R) = R iff L or R are NaN
2577template <typename LHS, typename RHS>
2579 const RHS &R) {
2581}
2582
2583/// Match an 'unordered' floating point maximum function.
2584/// Floating point has one special value 'NaN'. Therefore, there is no total
2585/// order. However, if we can ignore the 'NaN' value (for example, because of a
2586/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2587/// semantics. In the presence of 'NaN' we have to preserve the original
2588/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2589///
2590/// max(L, R) iff L and R are not NaN
2591/// m_UnordFMax(L, R) = L iff L or R are NaN
2592template <typename LHS, typename RHS>
2594 const RHS &R) {
2596}
2597
2598/// Match an 'unordered' floating point minimum function.
2599/// Floating point has one special value 'NaN'. Therefore, there is no total
2600/// order. However, if we can ignore the 'NaN' value (for example, because of a
2601/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2602/// semantics. In the presence of 'NaN' we have to preserve the original
2603/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2604///
2605/// min(L, R) iff L and R are not NaN
2606/// m_UnordFMin(L, R) = L iff L or R are NaN
2607template <typename LHS, typename RHS>
2609 const RHS &R) {
2611}
2612
2613/// Match an 'ordered' or 'unordered' floating point maximum function.
2614/// Floating point has one special value 'NaN'. Therefore, there is no total
2615/// order. However, if we can ignore the 'NaN' value (for example, because of a
2616/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2617/// semantics.
2618template <typename LHS, typename RHS>
2621m_OrdOrUnordFMax(const LHS &L, const RHS &R) {
2624}
2625
2626/// Match an 'ordered' or 'unordered' floating point minimum function.
2627/// Floating point has one special value 'NaN'. Therefore, there is no total
2628/// order. However, if we can ignore the 'NaN' value (for example, because of a
2629/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2630/// semantics.
2631template <typename LHS, typename RHS>
2634m_OrdOrUnordFMin(const LHS &L, const RHS &R) {
2637}
2638
2639/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2640/// NOTE: we first match the 'Not' (by matching '-1'),
2641/// and only then match the inner matcher!
2642template <typename ValTy>
2643inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2644m_Not(const ValTy &V) {
2645 return m_c_Xor(m_AllOnes(), V);
2646}
2647
2648template <typename ValTy>
2649inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2650 true>
2651m_NotForbidPoison(const ValTy &V) {
2652 return m_c_Xor(m_AllOnesForbidPoison(), V);
2653}
2654
2655//===----------------------------------------------------------------------===//
2656// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2657// Note that S might be matched to other instructions than AddInst.
2658//
2659
2660template <typename LHS_t, typename RHS_t, typename Sum_t>
2664 Sum_t S;
2665
2666 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2667 : L(L), R(R), S(S) {}
2668
2669 template <typename OpTy> bool match(OpTy *V) const {
2670 Value *ICmpLHS, *ICmpRHS;
2671 CmpPredicate Pred;
2672 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2673 return false;
2674
2675 Value *AddLHS, *AddRHS;
2676 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2677
2678 // (a + b) u< a, (a + b) u< b
2679 if (Pred == ICmpInst::ICMP_ULT)
2680 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2681 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2682
2683 // a >u (a + b), b >u (a + b)
2684 if (Pred == ICmpInst::ICMP_UGT)
2685 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2686 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2687
2688 Value *Op1;
2689 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2690 // (~a) <u b
2691 if (Pred == ICmpInst::ICMP_ULT) {
2692 if (XorExpr.match(ICmpLHS))
2693 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2694 }
2695 // b > u (~a)
2696 if (Pred == ICmpInst::ICMP_UGT) {
2697 if (XorExpr.match(ICmpRHS))
2698 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2699 }
2700
2701 // Match special-case for increment-by-1.
2702 if (Pred == ICmpInst::ICMP_EQ) {
2703 // (a + 1) == 0
2704 // (1 + a) == 0
2705 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2706 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2707 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2708 // 0 == (a + 1)
2709 // 0 == (1 + a)
2710 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2711 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2712 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2713 }
2714
2715 return false;
2716 }
2717};
2718
2719/// Match an icmp instruction checking for unsigned overflow on addition.
2720///
2721/// S is matched to the addition whose result is being checked for overflow, and
2722/// L and R are matched to the LHS and RHS of S.
2723template <typename LHS_t, typename RHS_t, typename Sum_t>
2725m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2727}
2728
2729template <typename Opnd_t> struct Argument_match {
2730 unsigned OpI;
2731 Opnd_t Val;
2732
2733 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2734
2735 template <typename OpTy> bool match(OpTy *V) const {
2736 // FIXME: Should likely be switched to use `CallBase`.
2737 if (const auto *CI = dyn_cast<CallInst>(V))
2738 return Val.match(CI->getArgOperand(OpI));
2739 return false;
2740 }
2741};
2742
2743/// Match an argument.
2744template <unsigned OpI, typename Opnd_t>
2745inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2746 return Argument_match<Opnd_t>(OpI, Op);
2747}
2748
2749/// Intrinsic matchers.
2751 unsigned ID;
2752
2754
2755 template <typename OpTy> bool match(OpTy *V) const {
2756 if (const auto *CI = dyn_cast<CallInst>(V))
2757 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2758 return F->getIntrinsicID() == ID;
2759 return false;
2760 }
2761};
2762
2763/// Match intrinsic calls with any of the given IDs.
2764template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2765 template <typename OpTy> bool match(OpTy *V) const {
2766 if (const auto *CI = dyn_cast<CallInst>(V))
2767 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2768 Intrinsic::ID ID = F->getIntrinsicID();
2769 return ((ID == IntrIDs) || ...);
2770 }
2771 return false;
2772 }
2773};
2774
2776 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2777 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2778 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2779 }
2780};
2781
2782/// Match intrinsic calls like this:
2783/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2784template <Intrinsic::ID IntrID, typename... Ts>
2785inline auto m_Intrinsic(const Ts &...Ops) {
2787 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2788}
2789
2790/// Match intrinsic calls with any of the given IDs like this:
2791/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2792/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2793/// because it performs the CallInst/Function cast only once.
2794template <Intrinsic::ID... IntrIDs>
2796 return IntrinsicIDs_match<IntrIDs...>();
2797}
2798
2799/// Matches MaskedLoad Intrinsic.
2800template <typename Opnd0, typename Opnd1, typename Opnd2>
2801inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2802 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2803}
2804
2805/// Matches MaskedStore Intrinsic.
2806template <typename Opnd0, typename Opnd1, typename Opnd2>
2807inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2808 const Opnd2 &Op2) {
2809 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2810}
2811
2812/// Matches MaskedGather Intrinsic.
2813template <typename Opnd0, typename Opnd1, typename Opnd2>
2814inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2815 const Opnd2 &Op2) {
2816 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2817}
2818
2819// Helper intrinsic matching specializations.
2820template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2822}
2823
2824template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2826}
2827template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2829}
2830
2831template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2832 return m_Intrinsic<Intrinsic::fabs>(Op0);
2833}
2834
2835template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2837}
2838
2839template <typename Opnd0, typename Opnd1>
2840inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2841 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2842}
2843
2844template <typename Opnd0, typename Opnd1>
2845inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2846 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2847}
2848
2849template <typename Opnd0, typename Opnd1>
2850inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2851 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2852}
2853
2854template <typename Opnd0, typename Opnd1>
2855inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2856 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2857}
2858
2859template <typename Opnd0, typename Opnd1>
2860inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2861 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2862}
2863
2864template <typename Opnd0, typename Opnd1>
2865inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2866 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2867}
2868
2869template <typename Opnd0, typename Opnd1>
2870inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2871 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2872 m_UMin(Op0, Op1));
2873}
2874
2875template <typename Opnd0, typename Opnd1>
2876inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2877 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2878}
2879
2880template <typename Opnd0, typename Opnd1>
2881inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2882 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2883}
2884
2885template <typename Opnd0, typename Opnd1>
2886inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2887 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2888}
2889
2890template <typename Opnd0, typename Opnd1>
2891inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2892 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2893}
2894
2895template <typename Opnd0, typename Opnd1>
2896inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2897 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2898}
2899
2900template <typename Opnd0, typename Opnd1>
2901inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2902 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2903}
2904
2905template <typename Opnd0, typename Opnd1>
2906inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2907 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2908}
2909
2910template <typename Opnd0, typename Opnd1>
2911inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2912 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2913}
2914
2915template <typename Opnd0, typename Opnd1, typename Opnd2>
2916inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2917 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2918}
2919
2920template <typename Opnd0, typename Opnd1, typename Opnd2>
2921inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2922 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2923}
2924
2925template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2926 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2927}
2928
2929template <typename Opnd0, typename Opnd1>
2930inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2931 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2932}
2933
2934template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
2936}
2937
2938template <typename Opnd0, typename Opnd1, typename Opnd2>
2939inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
2940 const Opnd2 &Op2) {
2941 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
2942}
2943
2944//===----------------------------------------------------------------------===//
2945// Matchers for two-operands operators with the operators in either order
2946//
2947
2948/// Matches a BinaryOperator with LHS and RHS in either order.
2949template <typename LHS, typename RHS>
2950inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) {
2952}
2953
2954/// Matches an ICmp with a predicate over LHS and RHS in either order.
2955/// Swaps the predicate if operands are commuted.
2956template <typename LHS, typename RHS>
2958m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
2960}
2961
2962template <typename LHS, typename RHS>
2964 const RHS &R) {
2966}
2967
2968/// Matches a specific opcode with LHS and RHS in either order.
2969template <typename LHS, typename RHS>
2971m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
2972 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
2973}
2974
2975/// Matches a Add with LHS and RHS in either order.
2976template <typename LHS, typename RHS>
2981
2982/// Matches a Mul with LHS and RHS in either order.
2983template <typename LHS, typename RHS>
2988
2989/// Matches an And with LHS and RHS in either order.
2990template <typename LHS, typename RHS>
2995
2996/// Matches an Or with LHS and RHS in either order.
2997template <typename LHS, typename RHS>
2999 const RHS &R) {
3001}
3002
3003/// Matches an Xor with LHS and RHS in either order.
3004template <typename LHS, typename RHS>
3009
3010/// Matches a 'Neg' as 'sub 0, V'.
3011template <typename ValTy>
3012inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3013m_Neg(const ValTy &V) {
3014 return m_Sub(m_ZeroInt(), V);
3015}
3016
3017/// Matches a 'Neg' as 'sub nsw 0, V'.
3018template <typename ValTy>
3020 Instruction::Sub,
3022m_NSWNeg(const ValTy &V) {
3023 return m_NSWSub(m_ZeroInt(), V);
3024}
3025
3026template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3028 LHS L;
3029 RHS R;
3030
3031 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3032
3033 template <typename OpTy> bool match(OpTy *V) const {
3034 const auto *II = dyn_cast<IntrinsicInst>(V);
3035 if (!II || II->getIntrinsicID() != IntrID)
3036 return false;
3037 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3038 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3039 }
3040};
3041
3042template <Intrinsic::ID IntrID, typename T0, typename T1>
3044m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3046}
3047
3048/// Matches an SMin with LHS and RHS in either order.
3049template <typename LHS, typename RHS>
3050inline auto m_c_SMin(const LHS &L, const RHS &R) {
3051 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3052}
3053/// Matches an SMax with LHS and RHS in either order.
3054template <typename LHS, typename RHS>
3055inline auto m_c_SMax(const LHS &L, const RHS &R) {
3056 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3057}
3058/// Matches a UMin with LHS and RHS in either order.
3059template <typename LHS, typename RHS>
3060inline auto m_c_UMin(const LHS &L, const RHS &R) {
3061 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3062}
3063/// Matches a UMax with LHS and RHS in either order.
3064template <typename LHS, typename RHS>
3065inline auto m_c_UMax(const LHS &L, const RHS &R) {
3066 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3067}
3068
3069template <typename LHS, typename RHS>
3070inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3071 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3072 m_c_UMin(L, R));
3073}
3074
3075/// Matches FAdd with LHS and RHS in either order.
3076template <typename LHS, typename RHS>
3078m_c_FAdd(const LHS &L, const RHS &R) {
3080}
3081
3082/// Matches FMul with LHS and RHS in either order.
3083template <typename LHS, typename RHS>
3085m_c_FMul(const LHS &L, const RHS &R) {
3087}
3088
3089template <typename Opnd_t> struct Signum_match {
3090 Opnd_t Val;
3091 Signum_match(const Opnd_t &V) : Val(V) {}
3092
3093 template <typename OpTy> bool match(OpTy *V) const {
3094 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3095 if (TypeSize == 0)
3096 return false;
3097
3098 unsigned ShiftWidth = TypeSize - 1;
3099 Value *Op;
3100
3101 // This is the representation of signum we match:
3102 //
3103 // signum(x) == (x >> 63) | (-x >>u 63)
3104 //
3105 // An i1 value is its own signum, so it's correct to match
3106 //
3107 // signum(x) == (x >> 0) | (-x >>u 0)
3108 //
3109 // for i1 values.
3110
3111 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3112 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3113 auto Signum = m_c_Or(LHS, RHS);
3114
3115 return Signum.match(V) && Val.match(Op);
3116 }
3117};
3118
3119/// Matches a signum pattern.
3120///
3121/// signum(x) =
3122/// x > 0 -> 1
3123/// x == 0 -> 0
3124/// x < 0 -> -1
3125template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3126 return Signum_match<Val_t>(V);
3127}
3128
3129template <int Ind, typename Opnd_t> struct ExtractValue_match {
3130 Opnd_t Val;
3131 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3132
3133 template <typename OpTy> bool match(OpTy *V) const {
3134 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3135 // If Ind is -1, don't inspect indices
3136 if (Ind != -1 &&
3137 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3138 return false;
3139 return Val.match(I->getAggregateOperand());
3140 }
3141 return false;
3142 }
3143};
3144
3145/// Match a single index ExtractValue instruction.
3146/// For example m_ExtractValue<1>(...)
3147template <int Ind, typename Val_t>
3151
3152/// Match an ExtractValue instruction with any index.
3153/// For example m_ExtractValue(...)
3154template <typename Val_t>
3155inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3156 return ExtractValue_match<-1, Val_t>(V);
3157}
3158
3159/// Matcher for a single index InsertValue instruction.
3160template <int Ind, typename T0, typename T1> struct InsertValue_match {
3163
3164 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3165
3166 template <typename OpTy> bool match(OpTy *V) const {
3167 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3168 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3169 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3170 }
3171 return false;
3172 }
3173};
3174
3175/// Matches a single index InsertValue instruction.
3176template <int Ind, typename Val_t, typename Elt_t>
3178 const Elt_t &Elt) {
3179 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3180}
3181
3182/// Matches a call to `llvm.vscale()`.
3183inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3184
3185template <typename Opnd0, typename Opnd1>
3186inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3188}
3189
3190template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3192}
3193
3194template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3196 LHS L;
3197 RHS R;
3198
3199 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3200
3201 template <typename T> bool match(T *V) const {
3202 auto *I = dyn_cast<Instruction>(V);
3203 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3204 return false;
3205
3206 if (I->getOpcode() == Opcode) {
3207 auto *Op0 = I->getOperand(0);
3208 auto *Op1 = I->getOperand(1);
3209 return (L.match(Op0) && R.match(Op1)) ||
3210 (Commutable && L.match(Op1) && R.match(Op0));
3211 }
3212
3213 if (auto *Select = dyn_cast<SelectInst>(I)) {
3214 auto *Cond = Select->getCondition();
3215 auto *TVal = Select->getTrueValue();
3216 auto *FVal = Select->getFalseValue();
3217
3218 // Don't match a scalar select of bool vectors.
3219 // Transforms expect a single type for operands if this matches.
3220 if (Cond->getType() != Select->getType())
3221 return false;
3222
3223 if (Opcode == Instruction::And) {
3224 auto *C = dyn_cast<Constant>(FVal);
3225 if (C && C->isNullValue())
3226 return (L.match(Cond) && R.match(TVal)) ||
3227 (Commutable && L.match(TVal) && R.match(Cond));
3228 } else {
3229 assert(Opcode == Instruction::Or);
3230 auto *C = dyn_cast<Constant>(TVal);
3231 if (C && C->isOneValue())
3232 return (L.match(Cond) && R.match(FVal)) ||
3233 (Commutable && L.match(FVal) && R.match(Cond));
3234 }
3235 }
3236
3237 return false;
3238 }
3239};
3240
3241/// Matches L && R either in the form of L & R or L ? R : false.
3242/// Note that the latter form is poison-blocking.
3243template <typename LHS, typename RHS>
3245 const RHS &R) {
3247}
3248
3249/// Matches L && R where L and R are arbitrary values.
3250inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3251
3252/// Matches L && R with LHS and RHS in either order.
3253template <typename LHS, typename RHS>
3255m_c_LogicalAnd(const LHS &L, const RHS &R) {
3257}
3258
3259/// Matches L || R either in the form of L | R or L ? true : R.
3260/// Note that the latter form is poison-blocking.
3261template <typename LHS, typename RHS>
3263 const RHS &R) {
3265}
3266
3267/// Matches L || R where L and R are arbitrary values.
3268inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3269
3270/// Matches L || R with LHS and RHS in either order.
3271template <typename LHS, typename RHS>
3273m_c_LogicalOr(const LHS &L, const RHS &R) {
3275}
3276
3277/// Matches either L && R or L || R,
3278/// either one being in the either binary or logical form.
3279/// Note that the latter form is poison-blocking.
3280template <typename LHS, typename RHS, bool Commutable = false>
3286
3287/// Matches either L && R or L || R where L and R are arbitrary values.
3288inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3289
3290/// Matches either L && R or L || R with LHS and RHS in either order.
3291template <typename LHS, typename RHS>
3292inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3293 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3294}
3295
3296} // end namespace PatternMatch
3297} // end namespace llvm
3298
3299#endif // LLVM_IR_PATTERNMATCH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#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
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
Class for arbitrary precision integers.
Definition APInt.h:78
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
Definition APInt.h:1577
static bool isSameValue(const APInt &I1, const APInt &I2, bool SignedCompare=false)
Determine if two APInts have the same value, after zero-extending or sign-extending (if SignedCompare...
Definition APInt.h:555
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static LLVM_ABI CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
static LLVM_ABI CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
Base class for aggregate constants (with operands).
Definition Constants.h:565
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1316
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
bool isShift() const
A wrapper class for inspecting calls to intrinsic functions.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:263
'undef' values are things that do not have specified contents.
Definition Constants.h:1631
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
Base class of all SIMD vector types.
Represents an op.with.overflow intrinsic.
An efficient, type-erasing, non-owning reference to a callable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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)
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_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'.
Splat_match< T > m_ConstantSplat(const T &SubPattern)
Match a constant splat. TODO: Extend this to non-constant splats.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
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)
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)
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.
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
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:1739
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
constexpr auto bind_back(FnT &&Fn, BindArgsT &&...BindArgs)
C++23 bind_back.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
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:2166
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)
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)