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 an UndefValue, capturing the value if we match.
884
885/// Match a Constant, capturing the value if we match.
887
888/// Match a ConstantInt, capturing the value if we match.
890
891/// Match a ConstantFP, capturing the value if we match.
893
894/// Match a ConstantExpr, capturing the value if we match.
896
897/// Match a basic block value, capturing it if we match.
900 return V;
901}
902
903// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
904// and use m_Unless(m_ConstantExpr).
906 template <typename ITy> static bool isImmConstant(ITy *V) {
907 if (auto *CV = dyn_cast<Constant>(V)) {
908 if (!match(CV, m_ConstantExpr()))
909 return true;
910
911 if (CV->getType()->isVectorTy()) {
912 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
913 if (!match(Splat, m_ConstantExpr())) {
914 return true;
915 }
916 }
917 }
918 }
919 return false;
920 }
921};
922
924 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
925};
926
927/// Match an arbitrary immediate Constant and ignore it.
929
932
934
935 template <typename ITy> bool match(ITy *V) const {
936 if (isImmConstant(V)) {
937 VR = cast<Constant>(V);
938 return true;
939 }
940 return false;
941 }
942};
943
944/// Match an immediate Constant, capturing the value if we match.
948
949/// Matcher for specified Value*.
951 const Value *Val;
952
953 specificval_ty(const Value *V) : Val(V) {}
954
955 template <typename ITy> bool match(ITy *V) const { return V == Val; }
956};
957
958/// Match if we have a specific specified value.
959inline specificval_ty m_Specific(const Value *V) { return V; }
960
961/// Like m_Specific(), but works if the specific value to match is determined
962/// as part of the same match() expression. For example:
963/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
964/// bind X before the pattern match starts.
965/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
966/// whichever value m_Value(X) populated.
967inline match_deferred<Value> m_Deferred(Value *const &V) { return V; }
969 return V;
970}
971
972/// Match a specified floating point value or vector of all elements of
973/// that value.
975 double Val;
976
977 specific_fpval(double V) : Val(V) {}
978
979 template <typename ITy> bool match(ITy *V) const {
980 if (const auto *CFP = dyn_cast<ConstantFP>(V))
981 return CFP->isExactlyValue(Val);
982 if (V->getType()->isVectorTy())
983 if (const auto *C = dyn_cast<Constant>(V))
984 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
985 return CFP->isExactlyValue(Val);
986 return false;
987 }
988};
989
990/// Match a specific floating point value or vector with all elements
991/// equal to the value.
992inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
993
994/// Match a float 1.0 or vector with all elements equal to 1.0.
995inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
996
999
1001
1002 template <typename ITy> bool match(ITy *V) const {
1003 const APInt *ConstInt;
1004 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1005 return false;
1006 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1007 if (!ZExtVal)
1008 return false;
1009 VR = *ZExtVal;
1010 return true;
1011 }
1012};
1013
1014/// Match a specified integer value or vector of all elements of that
1015/// value.
1016template <bool AllowPoison> struct specific_intval {
1017 const APInt &Val;
1018
1019 specific_intval(const APInt &V) : Val(V) {}
1020
1021 template <typename ITy> bool match(ITy *V) const {
1022 const auto *CI = dyn_cast<ConstantInt>(V);
1023 if (!CI && V->getType()->isVectorTy())
1024 if (const auto *C = dyn_cast<Constant>(V))
1025 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1026
1027 return CI && APInt::isSameValue(CI->getValue(), Val);
1028 }
1029};
1030
1031template <bool AllowPoison> struct specific_intval64 {
1033
1035
1036 template <typename ITy> bool match(ITy *V) const {
1037 const auto *CI = dyn_cast<ConstantInt>(V);
1038 if (!CI && V->getType()->isVectorTy())
1039 if (const auto *C = dyn_cast<Constant>(V))
1040 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1041
1042 return CI && CI->getValue() == Val;
1043 }
1044};
1045
1046/// Match a specific integer value or vector with all elements equal to
1047/// the value.
1049 return specific_intval<false>(V);
1050}
1051
1055
1059
1063
1064/// Match a ConstantInt and bind to its value. This does not match
1065/// ConstantInts wider than 64-bits.
1067
1068/// Match a specified basic block value.
1071
1073
1074 template <typename ITy> bool match(ITy *V) const {
1075 const auto *BB = dyn_cast<BasicBlock>(V);
1076 return BB && BB == Val;
1077 }
1078};
1079
1080/// Match a specific basic block value.
1082 return specific_bbval(BB);
1083}
1084
1085/// A commutative-friendly version of m_Specific().
1087 return BB;
1088}
1090m_Deferred(const BasicBlock *const &BB) {
1091 return BB;
1092}
1093
1094//===----------------------------------------------------------------------===//
1095// Matcher for any binary operator.
1096//
1097template <typename LHS_t, typename RHS_t, bool Commutable = false>
1101
1102 // The evaluation order is always stable, regardless of Commutability.
1103 // The LHS is always matched first.
1104 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1105
1106 template <typename OpTy> bool match(OpTy *V) const {
1107 if (auto *I = dyn_cast<BinaryOperator>(V))
1108 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1109 (Commutable && L.match(I->getOperand(1)) &&
1110 R.match(I->getOperand(0)));
1111 return false;
1112 }
1113};
1114
1115template <typename LHS, typename RHS>
1116inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1117 return AnyBinaryOp_match<LHS, RHS>(L, R);
1118}
1119
1120//===----------------------------------------------------------------------===//
1121// Matcher for any unary operator.
1122// TODO fuse unary, binary matcher into n-ary matcher
1123//
1124template <typename OP_t> struct AnyUnaryOp_match {
1125 OP_t X;
1126
1127 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1128
1129 template <typename OpTy> bool match(OpTy *V) const {
1130 if (auto *I = dyn_cast<UnaryOperator>(V))
1131 return X.match(I->getOperand(0));
1132 return false;
1133 }
1134};
1135
1136template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1137 return AnyUnaryOp_match<OP_t>(X);
1138}
1139
1140//===----------------------------------------------------------------------===//
1141// Matchers for specific binary operators.
1142//
1143
1144template <typename LHS_t, typename RHS_t, unsigned Opcode,
1145 bool Commutable = false>
1149
1150 // The evaluation order is always stable, regardless of Commutability.
1151 // The LHS is always matched first.
1152 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1153
1154 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1155 if (V->getValueID() == Value::InstructionVal + Opc) {
1156 auto *I = cast<BinaryOperator>(V);
1157 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1158 (Commutable && L.match(I->getOperand(1)) &&
1159 R.match(I->getOperand(0)));
1160 }
1161 return false;
1162 }
1163
1164 template <typename OpTy> bool match(OpTy *V) const {
1165 return match(Opcode, V);
1166 }
1167};
1168
1169template <typename LHS, typename RHS>
1171 const RHS &R) {
1173}
1174
1175template <typename LHS, typename RHS>
1177 const RHS &R) {
1179}
1180
1181template <typename LHS, typename RHS>
1183 const RHS &R) {
1185}
1186
1187template <typename LHS, typename RHS>
1189 const RHS &R) {
1191}
1192
1193template <typename Op_t> struct FNeg_match {
1194 Op_t X;
1195
1196 FNeg_match(const Op_t &Op) : X(Op) {}
1197 template <typename OpTy> bool match(OpTy *V) const {
1198 auto *FPMO = dyn_cast<FPMathOperator>(V);
1199 if (!FPMO)
1200 return false;
1201
1202 if (FPMO->getOpcode() == Instruction::FNeg)
1203 return X.match(FPMO->getOperand(0));
1204
1205 if (FPMO->getOpcode() == Instruction::FSub) {
1206 if (FPMO->hasNoSignedZeros()) {
1207 // With 'nsz', any zero goes.
1208 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1209 return false;
1210 } else {
1211 // Without 'nsz', we need fsub -0.0, X exactly.
1212 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1213 return false;
1214 }
1215
1216 return X.match(FPMO->getOperand(1));
1217 }
1218
1219 return false;
1220 }
1221};
1222
1223/// Match 'fneg X' as 'fsub -0.0, X'.
1224template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1225 return FNeg_match<OpTy>(X);
1226}
1227
1228/// Match 'fneg X' as 'fsub +-0.0, X'.
1229template <typename RHS>
1230inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1231m_FNegNSZ(const RHS &X) {
1232 return m_FSub(m_AnyZeroFP(), X);
1233}
1234
1235template <typename LHS, typename RHS>
1237 const RHS &R) {
1239}
1240
1241template <typename LHS, typename RHS>
1243 const RHS &R) {
1245}
1246
1247template <typename LHS, typename RHS>
1249 const RHS &R) {
1251}
1252
1253template <typename LHS, typename RHS>
1255 const RHS &R) {
1257}
1258
1259template <typename LHS, typename RHS>
1261 const RHS &R) {
1263}
1264
1265template <typename LHS, typename RHS>
1267 const RHS &R) {
1269}
1270
1271template <typename LHS, typename RHS>
1273 const RHS &R) {
1275}
1276
1277template <typename LHS, typename RHS>
1279 const RHS &R) {
1281}
1282
1283template <typename LHS, typename RHS>
1285 const RHS &R) {
1287}
1288
1289template <typename LHS, typename RHS>
1291 const RHS &R) {
1293}
1294
1295template <typename LHS, typename RHS>
1297 const RHS &R) {
1299}
1300
1301template <typename LHS, typename RHS>
1303 const RHS &R) {
1305}
1306
1307template <typename LHS, typename RHS>
1309 const RHS &R) {
1311}
1312
1313template <typename LHS, typename RHS>
1315 const RHS &R) {
1317}
1318
1319template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1322
1323 ShiftLike_match(const LHS_t &LHS, uint64_t &RHS) : L(LHS), R(RHS) {}
1324
1325 template <typename OpTy> bool match(OpTy *V) const {
1326 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1327 if (Op->getOpcode() == Opcode)
1328 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1329 L.match(Op->getOperand(0));
1330 }
1331 // Interpreted as shiftop V, 0
1332 R = 0;
1333 return L.match(V);
1334 }
1335};
1336
1337/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1338template <typename LHS>
1343
1344/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1345template <typename LHS>
1350
1351/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1352template <typename LHS>
1357
1358template <typename LHS_t, typename RHS_t, unsigned Opcode,
1359 unsigned WrapFlags = 0, bool Commutable = false>
1363
1364 OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
1365 : L(LHS), R(RHS) {}
1366
1367 template <typename OpTy> bool match(OpTy *V) const {
1368 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1369 if (Op->getOpcode() != Opcode)
1370 return false;
1372 !Op->hasNoUnsignedWrap())
1373 return false;
1374 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1375 !Op->hasNoSignedWrap())
1376 return false;
1377 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1378 (Commutable && L.match(Op->getOperand(1)) &&
1379 R.match(Op->getOperand(0)));
1380 }
1381 return false;
1382 }
1383};
1384
1385template <typename LHS, typename RHS>
1386inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1388m_NSWAdd(const LHS &L, const RHS &R) {
1389 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1391 R);
1392}
1393template <typename LHS, typename RHS>
1394inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1396m_c_NSWAdd(const LHS &L, const RHS &R) {
1397 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1399 true>(L, R);
1400}
1401template <typename LHS, typename RHS>
1402inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1404m_NSWSub(const LHS &L, const RHS &R) {
1405 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1407 R);
1408}
1409template <typename LHS, typename RHS>
1410inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1412m_NSWMul(const LHS &L, const RHS &R) {
1413 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1415 R);
1416}
1417template <typename LHS, typename RHS>
1418inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1420m_NSWShl(const LHS &L, const RHS &R) {
1421 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1423 R);
1424}
1425
1426template <typename LHS, typename RHS>
1427inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1429m_NUWAdd(const LHS &L, const RHS &R) {
1430 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1432 L, R);
1433}
1434
1435template <typename LHS, typename RHS>
1437 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1438m_c_NUWAdd(const LHS &L, const RHS &R) {
1439 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1441 true>(L, R);
1442}
1443
1444template <typename LHS, typename RHS>
1445inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1447m_NUWSub(const LHS &L, const RHS &R) {
1448 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1450 L, R);
1451}
1452template <typename LHS, typename RHS>
1453inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1455m_NUWMul(const LHS &L, const RHS &R) {
1456 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1458 L, R);
1459}
1460template <typename LHS, typename RHS>
1461inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1463m_NUWShl(const LHS &L, const RHS &R) {
1464 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1466 L, R);
1467}
1468
1469template <typename LHS_t, typename RHS_t, bool Commutable = false>
1471 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1472 unsigned Opcode;
1473
1474 SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
1475 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1476
1477 template <typename OpTy> bool match(OpTy *V) const {
1479 }
1480};
1481
1482/// Matches a specific opcode.
1483template <typename LHS, typename RHS>
1484inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1485 const RHS &R) {
1486 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1487}
1488
1489template <typename LHS, typename RHS, bool Commutable = false>
1491 LHS L;
1492 RHS R;
1493
1494 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1495
1496 template <typename OpTy> bool match(OpTy *V) const {
1497 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1498 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1499 if (!PDI->isDisjoint())
1500 return false;
1501 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1502 (Commutable && L.match(PDI->getOperand(1)) &&
1503 R.match(PDI->getOperand(0)));
1504 }
1505 return false;
1506 }
1507};
1508
1509template <typename LHS, typename RHS>
1510inline DisjointOr_match<LHS, RHS> m_DisjointOr(const LHS &L, const RHS &R) {
1511 return DisjointOr_match<LHS, RHS>(L, R);
1512}
1513
1514template <typename LHS, typename RHS>
1516 const RHS &R) {
1518}
1519
1520/// Match either "add" or "or disjoint".
1521template <typename LHS, typename RHS>
1524m_AddLike(const LHS &L, const RHS &R) {
1525 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1526}
1527
1528/// Match either "add nsw" or "or disjoint"
1529template <typename LHS, typename RHS>
1530inline match_combine_or<
1531 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1534m_NSWAddLike(const LHS &L, const RHS &R) {
1535 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1536}
1537
1538/// Match either "add nuw" or "or disjoint"
1539template <typename LHS, typename RHS>
1540inline match_combine_or<
1541 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1544m_NUWAddLike(const LHS &L, const RHS &R) {
1545 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1546}
1547
1548template <typename LHS, typename RHS>
1550 LHS L;
1551 RHS R;
1552
1553 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1554
1555 template <typename OpTy> bool match(OpTy *V) const {
1556 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1557 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1558 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1559 ; // Pass
1560 else if (Op->getOpcode() != Instruction::Xor)
1561 return false;
1562 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1563 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1564 }
1565 return false;
1566 }
1567};
1568
1569/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1570/// Only commutative matcher as the `sub` will need to swap the L and R.
1571template <typename LHS, typename RHS>
1572inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1573 return XorLike_match<LHS, RHS>(L, R);
1574}
1575
1576//===----------------------------------------------------------------------===//
1577// Class that matches a group of binary opcodes.
1578//
1579template <typename LHS_t, typename RHS_t, typename Predicate,
1580 bool Commutable = false>
1581struct BinOpPred_match : Predicate {
1584
1585 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1586
1587 template <typename OpTy> bool match(OpTy *V) const {
1588 if (auto *I = dyn_cast<Instruction>(V))
1589 return this->isOpType(I->getOpcode()) &&
1590 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1591 (Commutable && L.match(I->getOperand(1)) &&
1592 R.match(I->getOperand(0))));
1593 return false;
1594 }
1595};
1596
1598 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1599};
1600
1602 bool isOpType(unsigned Opcode) const {
1603 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1604 }
1605};
1606
1608 bool isOpType(unsigned Opcode) const {
1609 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1610 }
1611};
1612
1614 bool isOpType(unsigned Opcode) const {
1615 return Instruction::isBitwiseLogicOp(Opcode);
1616 }
1617};
1618
1620 bool isOpType(unsigned Opcode) const {
1621 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1622 }
1623};
1624
1626 bool isOpType(unsigned Opcode) const {
1627 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1628 }
1629};
1630
1631/// Matches shift operations.
1632template <typename LHS, typename RHS>
1634 const RHS &R) {
1636}
1637
1638/// Matches logical shift operations.
1639template <typename LHS, typename RHS>
1641 const RHS &R) {
1643}
1644
1645/// Matches logical shift operations.
1646template <typename LHS, typename RHS>
1648m_LogicalShift(const LHS &L, const RHS &R) {
1650}
1651
1652/// Matches bitwise logic operations.
1653template <typename LHS, typename RHS>
1655m_BitwiseLogic(const LHS &L, const RHS &R) {
1657}
1658
1659/// Matches bitwise logic operations in either order.
1660template <typename LHS, typename RHS>
1662m_c_BitwiseLogic(const LHS &L, const RHS &R) {
1664}
1665
1666/// Matches integer division operations.
1667template <typename LHS, typename RHS>
1669 const RHS &R) {
1671}
1672
1673/// Matches integer remainder operations.
1674template <typename LHS, typename RHS>
1676 const RHS &R) {
1678}
1679
1680//===----------------------------------------------------------------------===//
1681// Class that matches exact binary ops.
1682//
1683template <typename SubPattern_t> struct Exact_match {
1684 SubPattern_t SubPattern;
1685
1686 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1687
1688 template <typename OpTy> bool match(OpTy *V) const {
1689 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1690 return PEO->isExact() && SubPattern.match(V);
1691 return false;
1692 }
1693};
1694
1695template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1696 return SubPattern;
1697}
1698
1699//===----------------------------------------------------------------------===//
1700// Matchers for CmpInst classes
1701//
1702
1703template <typename LHS_t, typename RHS_t, typename Class,
1704 bool Commutable = false>
1709
1710 // The evaluation order is always stable, regardless of Commutability.
1711 // The LHS is always matched first.
1712 CmpClass_match(CmpPredicate &Pred, const LHS_t &LHS, const RHS_t &RHS)
1713 : Predicate(&Pred), L(LHS), R(RHS) {}
1714 CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
1715 : Predicate(nullptr), L(LHS), R(RHS) {}
1716
1717 template <typename OpTy> bool match(OpTy *V) const {
1718 if (auto *I = dyn_cast<Class>(V)) {
1719 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1720 if (Predicate)
1722 return true;
1723 }
1724 if (Commutable && L.match(I->getOperand(1)) &&
1725 R.match(I->getOperand(0))) {
1726 if (Predicate)
1728 return true;
1729 }
1730 }
1731 return false;
1732 }
1733};
1734
1735template <typename LHS, typename RHS>
1737 const RHS &R) {
1738 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1739}
1740
1741template <typename LHS, typename RHS>
1743 const LHS &L, const RHS &R) {
1744 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1745}
1746
1747template <typename LHS, typename RHS>
1749 const LHS &L, const RHS &R) {
1750 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1751}
1752
1753template <typename LHS, typename RHS>
1754inline CmpClass_match<LHS, RHS, CmpInst> m_Cmp(const LHS &L, const RHS &R) {
1756}
1757
1758template <typename LHS, typename RHS>
1759inline CmpClass_match<LHS, RHS, ICmpInst> m_ICmp(const LHS &L, const RHS &R) {
1761}
1762
1763template <typename LHS, typename RHS>
1764inline CmpClass_match<LHS, RHS, FCmpInst> m_FCmp(const LHS &L, const RHS &R) {
1766}
1767
1768// Same as CmpClass, but instead of saving Pred as out output variable, match a
1769// specific input pred for equality.
1770template <typename LHS_t, typename RHS_t, typename Class,
1771 bool Commutable = false>
1776
1777 SpecificCmpClass_match(CmpPredicate Pred, const LHS_t &LHS, const RHS_t &RHS)
1778 : Predicate(Pred), L(LHS), R(RHS) {}
1779
1780 template <typename OpTy> bool match(OpTy *V) const {
1781 if (auto *I = dyn_cast<Class>(V)) {
1783 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1784 return true;
1785 if constexpr (Commutable) {
1788 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1789 return true;
1790 }
1791 }
1792
1793 return false;
1794 }
1795};
1796
1797template <typename LHS, typename RHS>
1799m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1800 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1801}
1802
1803template <typename LHS, typename RHS>
1805m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1806 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1807}
1808
1809template <typename LHS, typename RHS>
1811m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1813}
1814
1815template <typename LHS, typename RHS>
1817m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1818 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1819}
1820
1821//===----------------------------------------------------------------------===//
1822// Matchers for instructions with a given opcode and number of operands.
1823//
1824
1825/// Matches instructions with Opcode and three operands.
1826template <typename T0, unsigned Opcode> struct OneOps_match {
1828
1829 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1830
1831 template <typename OpTy> bool match(OpTy *V) const {
1832 if (V->getValueID() == Value::InstructionVal + Opcode) {
1833 auto *I = cast<Instruction>(V);
1834 return Op1.match(I->getOperand(0));
1835 }
1836 return false;
1837 }
1838};
1839
1840/// Matches instructions with Opcode and three operands.
1841template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1844
1845 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1846
1847 template <typename OpTy> bool match(OpTy *V) const {
1848 if (V->getValueID() == Value::InstructionVal + Opcode) {
1849 auto *I = cast<Instruction>(V);
1850 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1851 }
1852 return false;
1853 }
1854};
1855
1856/// Matches instructions with Opcode and three operands.
1857template <typename T0, typename T1, typename T2, unsigned Opcode,
1858 bool CommutableOp2Op3 = false>
1863
1864 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1865 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1866
1867 template <typename OpTy> bool match(OpTy *V) const {
1868 if (V->getValueID() == Value::InstructionVal + Opcode) {
1869 auto *I = cast<Instruction>(V);
1870 if (!Op1.match(I->getOperand(0)))
1871 return false;
1872 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1873 return true;
1874 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1875 Op3.match(I->getOperand(1));
1876 }
1877 return false;
1878 }
1879};
1880
1881/// Matches instructions with Opcode and any number of operands
1882template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1883 std::tuple<OperandTypes...> Operands;
1884
1885 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1886
1887 // Operand matching works by recursively calling match_operands, matching the
1888 // operands left to right. The first version is called for each operand but
1889 // the last, for which the second version is called. The second version of
1890 // match_operands is also used to match each individual operand.
1891 template <int Idx, int Last>
1892 std::enable_if_t<Idx != Last, bool>
1896
1897 template <int Idx, int Last>
1898 std::enable_if_t<Idx == Last, bool>
1900 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1901 }
1902
1903 template <typename OpTy> bool match(OpTy *V) const {
1904 if (V->getValueID() == Value::InstructionVal + Opcode) {
1905 auto *I = cast<Instruction>(V);
1906 return I->getNumOperands() == sizeof...(OperandTypes) &&
1907 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1908 }
1909 return false;
1910 }
1911};
1912
1913/// Matches SelectInst.
1914template <typename Cond, typename LHS, typename RHS>
1916m_Select(const Cond &C, const LHS &L, const RHS &R) {
1918}
1919
1920/// This matches a select of two constants, e.g.:
1921/// m_SelectCst<-1, 0>(m_Value(V))
1922template <int64_t L, int64_t R, typename Cond>
1924 Instruction::Select>
1927}
1928
1929/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1930template <typename LHS, typename RHS>
1931inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1932m_c_Select(const LHS &L, const RHS &R) {
1933 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1934 true>(m_Value(), L, R);
1935}
1936
1937/// Matches FreezeInst.
1938template <typename OpTy>
1942
1943/// Matches InsertElementInst.
1944template <typename Val_t, typename Elt_t, typename Idx_t>
1946m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1948 Val, Elt, Idx);
1949}
1950
1951/// Matches ExtractElementInst.
1952template <typename Val_t, typename Idx_t>
1954m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
1956}
1957
1958/// Matches shuffle.
1959template <typename T0, typename T1, typename T2> struct Shuffle_match {
1963
1964 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
1965 : Op1(Op1), Op2(Op2), Mask(Mask) {}
1966
1967 template <typename OpTy> bool match(OpTy *V) const {
1968 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
1969 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1970 Mask.match(I->getShuffleMask());
1971 }
1972 return false;
1973 }
1974};
1975
1976struct m_Mask {
1979 bool match(ArrayRef<int> Mask) const {
1980 MaskRef = Mask;
1981 return true;
1982 }
1983};
1984
1986 bool match(ArrayRef<int> Mask) const {
1987 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
1988 }
1989};
1990
1994 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
1995};
1996
1998 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
1999};
2000
2004 bool match(ArrayRef<int> Mask) const {
2005 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2006 if (First == Mask.end())
2007 return false;
2008 SplatIndex = *First;
2009 return all_of(Mask,
2010 [First](int Elem) { return Elem == *First || Elem == -1; });
2011 }
2012};
2013
2014template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2015 PointerOpTy PointerOp;
2016 OffsetOpTy OffsetOp;
2017
2018 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2020
2021 template <typename OpTy> bool match(OpTy *V) const {
2022 auto *GEP = dyn_cast<GEPOperator>(V);
2023 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2024 PointerOp.match(GEP->getPointerOperand()) &&
2025 OffsetOp.match(GEP->idx_begin()->get());
2026 }
2027};
2028
2029/// Matches ShuffleVectorInst independently of mask value.
2030template <typename V1_t, typename V2_t>
2032m_Shuffle(const V1_t &v1, const V2_t &v2) {
2034}
2035
2036template <typename V1_t, typename V2_t, typename Mask_t>
2038m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2040}
2041
2042/// Matches LoadInst.
2043template <typename OpTy>
2047
2048/// Matches a simple (non-volatile, non-atomic) LoadInst.
2049template <typename OpTy> struct LoadSimple_match {
2051
2053
2054 template <typename ITy> bool match(ITy *V) const {
2055 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2056 }
2057};
2058
2059template <typename OpTy>
2063
2064/// Matches StoreInst.
2065template <typename ValueOpTy, typename PointerOpTy>
2067m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2069 PointerOp);
2070}
2071
2072/// Matches GetElementPtrInst.
2073template <typename... OperandTypes>
2074inline auto m_GEP(const OperandTypes &...Ops) {
2075 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2076}
2077
2078/// Matches GEP with i8 source element type
2079template <typename PointerOpTy, typename OffsetOpTy>
2081m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2083}
2084
2085//===----------------------------------------------------------------------===//
2086// Matchers for CastInst classes
2087//
2088
2089template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2090 Op_t Op;
2091
2092 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2093
2094 template <typename OpTy> bool match(OpTy *V) const {
2095 if (auto *O = dyn_cast<Operator>(V))
2096 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2097 return false;
2098 }
2099};
2100
2101template <typename Op_t, typename Class> struct CastInst_match {
2102 Op_t Op;
2103
2104 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2105
2106 template <typename OpTy> bool match(OpTy *V) const {
2107 if (auto *I = dyn_cast<Class>(V))
2108 return Op.match(I->getOperand(0));
2109 return false;
2110 }
2111};
2112
2113template <typename Op_t> struct PtrToIntSameSize_match {
2115 Op_t Op;
2116
2117 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2118 : DL(DL), Op(OpMatch) {}
2119
2120 template <typename OpTy> bool match(OpTy *V) const {
2121 if (auto *O = dyn_cast<Operator>(V))
2122 return O->getOpcode() == Instruction::PtrToInt &&
2123 DL.getTypeSizeInBits(O->getType()) ==
2124 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2125 Op.match(O->getOperand(0));
2126 return false;
2127 }
2128};
2129
2130template <typename Op_t> struct NNegZExt_match {
2131 Op_t Op;
2132
2133 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2134
2135 template <typename OpTy> bool match(OpTy *V) const {
2136 if (auto *I = dyn_cast<ZExtInst>(V))
2137 return I->hasNonNeg() && Op.match(I->getOperand(0));
2138 return false;
2139 }
2140};
2141
2142template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2143 Op_t Op;
2144
2145 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2146
2147 template <typename OpTy> bool match(OpTy *V) const {
2148 if (auto *I = dyn_cast<TruncInst>(V))
2149 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2150 Op.match(I->getOperand(0));
2151 return false;
2152 }
2153};
2154
2155/// Matches BitCast.
2156template <typename OpTy>
2161
2162template <typename Op_t> struct ElementWiseBitCast_match {
2163 Op_t Op;
2164
2165 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2166
2167 template <typename OpTy> bool match(OpTy *V) const {
2168 auto *I = dyn_cast<BitCastInst>(V);
2169 if (!I)
2170 return false;
2171 Type *SrcType = I->getSrcTy();
2172 Type *DstType = I->getType();
2173 // Make sure the bitcast doesn't change between scalar and vector and
2174 // doesn't change the number of vector elements.
2175 if (SrcType->isVectorTy() != DstType->isVectorTy())
2176 return false;
2177 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2178 SrcVecTy && SrcVecTy->getElementCount() !=
2179 cast<VectorType>(DstType)->getElementCount())
2180 return false;
2181 return Op.match(I->getOperand(0));
2182 }
2183};
2184
2185template <typename OpTy>
2189
2190/// Matches PtrToInt.
2191template <typename OpTy>
2196
2197template <typename OpTy>
2202
2203/// Matches PtrToAddr.
2204template <typename OpTy>
2209
2210/// Matches PtrToInt or PtrToAddr.
2211template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2213}
2214
2215/// Matches IntToPtr.
2216template <typename OpTy>
2221
2222/// Matches any cast or self. Used to ignore casts.
2223template <typename OpTy>
2228
2229/// Matches Trunc.
2230template <typename OpTy>
2234
2235/// Matches trunc nuw.
2236template <typename OpTy>
2241
2242/// Matches trunc nsw.
2243template <typename OpTy>
2248
2249template <typename OpTy>
2252 return m_CombineOr(m_Trunc(Op), Op);
2253}
2254
2255/// Matches SExt.
2256template <typename OpTy>
2260
2261/// Matches ZExt.
2262template <typename OpTy>
2266
2267template <typename OpTy>
2269 return NNegZExt_match<OpTy>(Op);
2270}
2271
2272template <typename OpTy>
2275 return m_CombineOr(m_ZExt(Op), Op);
2276}
2277
2278template <typename OpTy>
2281 return m_CombineOr(m_SExt(Op), Op);
2282}
2283
2284/// Match either "sext" or "zext nneg".
2285template <typename OpTy>
2288 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2289}
2290
2291template <typename OpTy>
2295 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2296}
2297
2298template <typename OpTy>
2301 OpTy>
2303 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2304}
2305
2306template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2307 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2308}
2309
2310template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2314
2316 : Pred(P), L(Left), R(Right) {}
2317
2318 template <typename OpTy> bool match(OpTy *V) const {
2319 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2320 return true;
2321 Value *A;
2322 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2323 if (V->getType()->isIntOrIntVectorTy(1) &&
2324 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2325 R.match(ConstantInt::getNullValue(A->getType()))) {
2327 return true;
2328 }
2329 return false;
2330 }
2331};
2332
2333template <typename LHS, typename RHS>
2335 const RHS &R) {
2336 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2337}
2338
2339template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2340 CondTy Cond;
2343
2344 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2345 : Cond(C), TrueC(TC), FalseC(FC) {}
2346
2347 template <typename OpTy> bool match(OpTy *V) const {
2348 // select(Cond, TrueC, FalseC) — captures both constants directly
2350 return true;
2351
2352 Type *Ty = V->getType();
2353 Value *CondV = nullptr;
2354
2355 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2356 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2357 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2358 TrueC.match(ConstantInt::get(Ty, 1)) &&
2359 FalseC.match(ConstantInt::get(Ty, 0)))
2360 return true;
2361
2362 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2363 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2364 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2365 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2366 FalseC.match(ConstantInt::get(Ty, 0)))
2367 return true;
2368
2369 return false;
2370 }
2371};
2372
2373/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2374/// select i1 Cond, TrueC, FalseC
2375/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2376/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2377///
2378/// The condition is matched against \p Cond, and the true/false constants
2379/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2380/// constants are bound to \p TrueC and \p FalseC via their matchers.
2381template <typename CondTy, typename LTy, typename RTy>
2383m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2384 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2385}
2386
2387template <typename OpTy>
2391
2392template <typename OpTy>
2396
2397template <typename OpTy>
2400m_IToFP(const OpTy &Op) {
2401 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2402}
2403
2404template <typename OpTy>
2408
2409template <typename OpTy>
2413
2414template <typename OpTy>
2417m_FPToI(const OpTy &Op) {
2418 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2419}
2420
2421template <typename OpTy>
2425
2426template <typename OpTy>
2430
2431//===----------------------------------------------------------------------===//
2432// Matchers for control flow.
2433//
2434
2435struct br_match {
2437
2439
2440 template <typename OpTy> bool match(OpTy *V) const {
2441 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2442 Succ = BI->getSuccessor();
2443 return true;
2444 }
2445 return false;
2446 }
2447};
2448
2449inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2450
2451template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2453 Cond_t Cond;
2454 TrueBlock_t T;
2455 FalseBlock_t F;
2456
2457 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2458 : Cond(C), T(t), F(f) {}
2459
2460 template <typename OpTy> bool match(OpTy *V) const {
2461 if (auto *BI = dyn_cast<CondBrInst>(V))
2462 if (Cond.match(BI->getCondition()))
2463 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2464 return false;
2465 }
2466};
2467
2468template <typename Cond_t>
2474
2475template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2477m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2479}
2480
2481//===----------------------------------------------------------------------===//
2482// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2483//
2484
2485template <typename LHS_t, typename RHS_t, typename Pred_t>
2487 using PredType = Pred_t;
2490
2491 // The evaluation order is always stable, regardless of Commutability.
2492 // The LHS is always matched first.
2493 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2494
2495 template <typename OpTy> bool match(OpTy *V) const {
2496 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2497 auto *SI = dyn_cast<SelectInst>(V);
2498 if (!SI)
2499 return false;
2500 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2501 if (!Cmp)
2502 return false;
2503 // At this point we have a select conditioned on a comparison. Check that
2504 // it is the values returned by the select that are being compared.
2505 auto *TrueVal = SI->getTrueValue();
2506 auto *FalseVal = SI->getFalseValue();
2507 auto *LHS = Cmp->getOperand(0);
2508 auto *RHS = Cmp->getOperand(1);
2509 if ((TrueVal != LHS || FalseVal != RHS) &&
2510 (TrueVal != RHS || FalseVal != LHS))
2511 return false;
2512 FCmpInst::Predicate Pred =
2513 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2514 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2515 if (!Pred_t::match(Pred))
2516 return false;
2517 // It does! Bind the operands.
2518 return L.match(LHS) && R.match(RHS);
2519 }
2520};
2521
2522/// Helper class for identifying ordered max predicates.
2524 static bool match(FCmpInst::Predicate Pred) {
2525 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2526 }
2527};
2528
2529/// Helper class for identifying ordered min predicates.
2531 static bool match(FCmpInst::Predicate Pred) {
2532 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2533 }
2534};
2535
2536/// Helper class for identifying unordered max predicates.
2538 static bool match(FCmpInst::Predicate Pred) {
2539 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2540 }
2541};
2542
2543/// Helper class for identifying unordered min predicates.
2545 static bool match(FCmpInst::Predicate Pred) {
2546 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2547 }
2548};
2549
2550/// Match an 'ordered' floating point maximum function.
2551/// Floating point has one special value 'NaN'. Therefore, there is no total
2552/// order. However, if we can ignore the 'NaN' value (for example, because of a
2553/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2554/// semantics. In the presence of 'NaN' we have to preserve the original
2555/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2556///
2557/// max(L, R) iff L and R are not NaN
2558/// m_OrdFMax(L, R) = R iff L or R are NaN
2559template <typename LHS, typename RHS>
2561 const RHS &R) {
2563}
2564
2565/// Match an 'ordered' floating point minimum function.
2566/// Floating point has one special value 'NaN'. Therefore, there is no total
2567/// order. However, if we can ignore the 'NaN' value (for example, because of a
2568/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2569/// semantics. In the presence of 'NaN' we have to preserve the original
2570/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2571///
2572/// min(L, R) iff L and R are not NaN
2573/// m_OrdFMin(L, R) = R iff L or R are NaN
2574template <typename LHS, typename RHS>
2576 const RHS &R) {
2578}
2579
2580/// Match an 'unordered' floating point maximum function.
2581/// Floating point has one special value 'NaN'. Therefore, there is no total
2582/// order. However, if we can ignore the 'NaN' value (for example, because of a
2583/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2584/// semantics. In the presence of 'NaN' we have to preserve the original
2585/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2586///
2587/// max(L, R) iff L and R are not NaN
2588/// m_UnordFMax(L, R) = L iff L or R are NaN
2589template <typename LHS, typename RHS>
2591 const RHS &R) {
2593}
2594
2595/// Match an 'unordered' floating point minimum function.
2596/// Floating point has one special value 'NaN'. Therefore, there is no total
2597/// order. However, if we can ignore the 'NaN' value (for example, because of a
2598/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2599/// semantics. In the presence of 'NaN' we have to preserve the original
2600/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2601///
2602/// min(L, R) iff L and R are not NaN
2603/// m_UnordFMin(L, R) = L iff L or R are NaN
2604template <typename LHS, typename RHS>
2606 const RHS &R) {
2608}
2609
2610/// Match an 'ordered' or 'unordered' floating point maximum function.
2611/// Floating point has one special value 'NaN'. Therefore, there is no total
2612/// order. However, if we can ignore the 'NaN' value (for example, because of a
2613/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2614/// semantics.
2615template <typename LHS, typename RHS>
2618m_OrdOrUnordFMax(const LHS &L, const RHS &R) {
2621}
2622
2623/// Match an 'ordered' or 'unordered' floating point minimum function.
2624/// Floating point has one special value 'NaN'. Therefore, there is no total
2625/// order. However, if we can ignore the 'NaN' value (for example, because of a
2626/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2627/// semantics.
2628template <typename LHS, typename RHS>
2631m_OrdOrUnordFMin(const LHS &L, const RHS &R) {
2634}
2635
2636/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2637/// NOTE: we first match the 'Not' (by matching '-1'),
2638/// and only then match the inner matcher!
2639template <typename ValTy>
2640inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2641m_Not(const ValTy &V) {
2642 return m_c_Xor(m_AllOnes(), V);
2643}
2644
2645template <typename ValTy>
2646inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2647 true>
2648m_NotForbidPoison(const ValTy &V) {
2649 return m_c_Xor(m_AllOnesForbidPoison(), V);
2650}
2651
2652//===----------------------------------------------------------------------===//
2653// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2654// Note that S might be matched to other instructions than AddInst.
2655//
2656
2657template <typename LHS_t, typename RHS_t, typename Sum_t>
2661 Sum_t S;
2662
2663 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2664 : L(L), R(R), S(S) {}
2665
2666 template <typename OpTy> bool match(OpTy *V) const {
2667 Value *ICmpLHS, *ICmpRHS;
2668 CmpPredicate Pred;
2669 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2670 return false;
2671
2672 Value *AddLHS, *AddRHS;
2673 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2674
2675 // (a + b) u< a, (a + b) u< b
2676 if (Pred == ICmpInst::ICMP_ULT)
2677 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2678 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2679
2680 // a >u (a + b), b >u (a + b)
2681 if (Pred == ICmpInst::ICMP_UGT)
2682 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2683 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2684
2685 Value *Op1;
2686 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2687 // (~a) <u b
2688 if (Pred == ICmpInst::ICMP_ULT) {
2689 if (XorExpr.match(ICmpLHS))
2690 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2691 }
2692 // b > u (~a)
2693 if (Pred == ICmpInst::ICMP_UGT) {
2694 if (XorExpr.match(ICmpRHS))
2695 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2696 }
2697
2698 // Match special-case for increment-by-1.
2699 if (Pred == ICmpInst::ICMP_EQ) {
2700 // (a + 1) == 0
2701 // (1 + a) == 0
2702 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2703 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2704 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2705 // 0 == (a + 1)
2706 // 0 == (1 + a)
2707 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2708 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2709 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2710 }
2711
2712 return false;
2713 }
2714};
2715
2716/// Match an icmp instruction checking for unsigned overflow on addition.
2717///
2718/// S is matched to the addition whose result is being checked for overflow, and
2719/// L and R are matched to the LHS and RHS of S.
2720template <typename LHS_t, typename RHS_t, typename Sum_t>
2722m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2724}
2725
2726template <typename Opnd_t> struct Argument_match {
2727 unsigned OpI;
2728 Opnd_t Val;
2729
2730 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2731
2732 template <typename OpTy> bool match(OpTy *V) const {
2733 // FIXME: Should likely be switched to use `CallBase`.
2734 if (const auto *CI = dyn_cast<CallInst>(V))
2735 return Val.match(CI->getArgOperand(OpI));
2736 return false;
2737 }
2738};
2739
2740/// Match an argument.
2741template <unsigned OpI, typename Opnd_t>
2742inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2743 return Argument_match<Opnd_t>(OpI, Op);
2744}
2745
2746/// Intrinsic matchers.
2748 unsigned ID;
2749
2751
2752 template <typename OpTy> bool match(OpTy *V) const {
2753 if (const auto *CI = dyn_cast<CallInst>(V))
2754 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2755 return F->getIntrinsicID() == ID;
2756 return false;
2757 }
2758};
2759
2760/// Match intrinsic calls with any of the given IDs.
2761template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2762 template <typename OpTy> bool match(OpTy *V) const {
2763 if (const auto *CI = dyn_cast<CallInst>(V))
2764 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2765 Intrinsic::ID ID = F->getIntrinsicID();
2766 return ((ID == IntrIDs) || ...);
2767 }
2768 return false;
2769 }
2770};
2771
2773 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2774 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2775 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2776 }
2777};
2778
2779/// Match intrinsic calls like this:
2780/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2781template <Intrinsic::ID IntrID, typename... Ts>
2782inline auto m_Intrinsic(const Ts &...Ops) {
2784 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2785}
2786
2787/// Match intrinsic calls with any of the given IDs like this:
2788/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2789/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2790/// because it performs the CallInst/Function cast only once.
2791template <Intrinsic::ID... IntrIDs>
2793 return IntrinsicIDs_match<IntrIDs...>();
2794}
2795
2796/// Matches MaskedLoad Intrinsic.
2797template <typename Opnd0, typename Opnd1, typename Opnd2>
2798inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2799 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2800}
2801
2802/// Matches MaskedStore Intrinsic.
2803template <typename Opnd0, typename Opnd1, typename Opnd2>
2804inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2805 const Opnd2 &Op2) {
2806 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2807}
2808
2809/// Matches MaskedGather Intrinsic.
2810template <typename Opnd0, typename Opnd1, typename Opnd2>
2811inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2812 const Opnd2 &Op2) {
2813 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2814}
2815
2816// Helper intrinsic matching specializations.
2817template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2819}
2820
2821template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2823}
2824template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2826}
2827
2828template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2829 return m_Intrinsic<Intrinsic::fabs>(Op0);
2830}
2831
2832template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2834}
2835
2836template <typename Opnd0, typename Opnd1>
2837inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2838 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2839}
2840
2841template <typename Opnd0, typename Opnd1>
2842inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2843 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2844}
2845
2846template <typename Opnd0, typename Opnd1>
2847inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2848 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2849}
2850
2851template <typename Opnd0, typename Opnd1>
2852inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2853 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2854}
2855
2856template <typename Opnd0, typename Opnd1>
2857inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2858 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2859}
2860
2861template <typename Opnd0, typename Opnd1>
2862inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2863 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2864}
2865
2866template <typename Opnd0, typename Opnd1>
2867inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2868 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2869 m_UMin(Op0, Op1));
2870}
2871
2872template <typename Opnd0, typename Opnd1>
2873inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2874 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2875}
2876
2877template <typename Opnd0, typename Opnd1>
2878inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2879 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2880}
2881
2882template <typename Opnd0, typename Opnd1>
2883inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2884 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2885}
2886
2887template <typename Opnd0, typename Opnd1>
2888inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2889 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2890}
2891
2892template <typename Opnd0, typename Opnd1>
2893inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2894 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2895}
2896
2897template <typename Opnd0, typename Opnd1>
2898inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2899 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2900}
2901
2902template <typename Opnd0, typename Opnd1>
2903inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2904 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2905}
2906
2907template <typename Opnd0, typename Opnd1>
2908inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2909 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2910}
2911
2912template <typename Opnd0, typename Opnd1, typename Opnd2>
2913inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2914 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2915}
2916
2917template <typename Opnd0, typename Opnd1, typename Opnd2>
2918inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2919 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2920}
2921
2922template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2923 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2924}
2925
2926template <typename Opnd0, typename Opnd1>
2927inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2928 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2929}
2930
2931template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
2933}
2934
2935template <typename Opnd0, typename Opnd1, typename Opnd2>
2936inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
2937 const Opnd2 &Op2) {
2938 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
2939}
2940
2941//===----------------------------------------------------------------------===//
2942// Matchers for two-operands operators with the operators in either order
2943//
2944
2945/// Matches a BinaryOperator with LHS and RHS in either order.
2946template <typename LHS, typename RHS>
2947inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) {
2949}
2950
2951/// Matches an ICmp with a predicate over LHS and RHS in either order.
2952/// Swaps the predicate if operands are commuted.
2953template <typename LHS, typename RHS>
2955m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
2957}
2958
2959template <typename LHS, typename RHS>
2961 const RHS &R) {
2963}
2964
2965/// Matches a specific opcode with LHS and RHS in either order.
2966template <typename LHS, typename RHS>
2968m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
2969 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
2970}
2971
2972/// Matches a Add with LHS and RHS in either order.
2973template <typename LHS, typename RHS>
2978
2979/// Matches a Mul with LHS and RHS in either order.
2980template <typename LHS, typename RHS>
2985
2986/// Matches an And with LHS and RHS in either order.
2987template <typename LHS, typename RHS>
2992
2993/// Matches an Or with LHS and RHS in either order.
2994template <typename LHS, typename RHS>
2996 const RHS &R) {
2998}
2999
3000/// Matches an Xor with LHS and RHS in either order.
3001template <typename LHS, typename RHS>
3006
3007/// Matches a 'Neg' as 'sub 0, V'.
3008template <typename ValTy>
3009inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3010m_Neg(const ValTy &V) {
3011 return m_Sub(m_ZeroInt(), V);
3012}
3013
3014/// Matches a 'Neg' as 'sub nsw 0, V'.
3015template <typename ValTy>
3017 Instruction::Sub,
3019m_NSWNeg(const ValTy &V) {
3020 return m_NSWSub(m_ZeroInt(), V);
3021}
3022
3023template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3025 LHS L;
3026 RHS R;
3027
3028 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3029
3030 template <typename OpTy> bool match(OpTy *V) const {
3031 const auto *II = dyn_cast<IntrinsicInst>(V);
3032 if (!II || II->getIntrinsicID() != IntrID)
3033 return false;
3034 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3035 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3036 }
3037};
3038
3039template <Intrinsic::ID IntrID, typename T0, typename T1>
3041m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3043}
3044
3045/// Matches an SMin with LHS and RHS in either order.
3046template <typename LHS, typename RHS>
3047inline auto m_c_SMin(const LHS &L, const RHS &R) {
3048 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3049}
3050/// Matches an SMax with LHS and RHS in either order.
3051template <typename LHS, typename RHS>
3052inline auto m_c_SMax(const LHS &L, const RHS &R) {
3053 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3054}
3055/// Matches a UMin with LHS and RHS in either order.
3056template <typename LHS, typename RHS>
3057inline auto m_c_UMin(const LHS &L, const RHS &R) {
3058 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3059}
3060/// Matches a UMax with LHS and RHS in either order.
3061template <typename LHS, typename RHS>
3062inline auto m_c_UMax(const LHS &L, const RHS &R) {
3063 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3064}
3065
3066template <typename LHS, typename RHS>
3067inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3068 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3069 m_c_UMin(L, R));
3070}
3071
3072/// Matches FAdd with LHS and RHS in either order.
3073template <typename LHS, typename RHS>
3075m_c_FAdd(const LHS &L, const RHS &R) {
3077}
3078
3079/// Matches FMul with LHS and RHS in either order.
3080template <typename LHS, typename RHS>
3082m_c_FMul(const LHS &L, const RHS &R) {
3084}
3085
3086template <typename Opnd_t> struct Signum_match {
3087 Opnd_t Val;
3088 Signum_match(const Opnd_t &V) : Val(V) {}
3089
3090 template <typename OpTy> bool match(OpTy *V) const {
3091 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3092 if (TypeSize == 0)
3093 return false;
3094
3095 unsigned ShiftWidth = TypeSize - 1;
3096 Value *Op;
3097
3098 // This is the representation of signum we match:
3099 //
3100 // signum(x) == (x >> 63) | (-x >>u 63)
3101 //
3102 // An i1 value is its own signum, so it's correct to match
3103 //
3104 // signum(x) == (x >> 0) | (-x >>u 0)
3105 //
3106 // for i1 values.
3107
3108 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3109 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3110 auto Signum = m_c_Or(LHS, RHS);
3111
3112 return Signum.match(V) && Val.match(Op);
3113 }
3114};
3115
3116/// Matches a signum pattern.
3117///
3118/// signum(x) =
3119/// x > 0 -> 1
3120/// x == 0 -> 0
3121/// x < 0 -> -1
3122template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3123 return Signum_match<Val_t>(V);
3124}
3125
3126template <int Ind, typename Opnd_t> struct ExtractValue_match {
3127 Opnd_t Val;
3128 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3129
3130 template <typename OpTy> bool match(OpTy *V) const {
3131 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3132 // If Ind is -1, don't inspect indices
3133 if (Ind != -1 &&
3134 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3135 return false;
3136 return Val.match(I->getAggregateOperand());
3137 }
3138 return false;
3139 }
3140};
3141
3142/// Match a single index ExtractValue instruction.
3143/// For example m_ExtractValue<1>(...)
3144template <int Ind, typename Val_t>
3148
3149/// Match an ExtractValue instruction with any index.
3150/// For example m_ExtractValue(...)
3151template <typename Val_t>
3152inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3153 return ExtractValue_match<-1, Val_t>(V);
3154}
3155
3156/// Matcher for a single index InsertValue instruction.
3157template <int Ind, typename T0, typename T1> struct InsertValue_match {
3160
3161 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3162
3163 template <typename OpTy> bool match(OpTy *V) const {
3164 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3165 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3166 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3167 }
3168 return false;
3169 }
3170};
3171
3172/// Matches a single index InsertValue instruction.
3173template <int Ind, typename Val_t, typename Elt_t>
3175 const Elt_t &Elt) {
3176 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3177}
3178
3179/// Matches a call to `llvm.vscale()`.
3180inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3181
3182template <typename Opnd0, typename Opnd1>
3183inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3185}
3186
3187template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3189}
3190
3191template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3193 LHS L;
3194 RHS R;
3195
3196 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3197
3198 template <typename T> bool match(T *V) const {
3199 auto *I = dyn_cast<Instruction>(V);
3200 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3201 return false;
3202
3203 if (I->getOpcode() == Opcode) {
3204 auto *Op0 = I->getOperand(0);
3205 auto *Op1 = I->getOperand(1);
3206 return (L.match(Op0) && R.match(Op1)) ||
3207 (Commutable && L.match(Op1) && R.match(Op0));
3208 }
3209
3210 if (auto *Select = dyn_cast<SelectInst>(I)) {
3211 auto *Cond = Select->getCondition();
3212 auto *TVal = Select->getTrueValue();
3213 auto *FVal = Select->getFalseValue();
3214
3215 // Don't match a scalar select of bool vectors.
3216 // Transforms expect a single type for operands if this matches.
3217 if (Cond->getType() != Select->getType())
3218 return false;
3219
3220 if (Opcode == Instruction::And) {
3221 auto *C = dyn_cast<Constant>(FVal);
3222 if (C && C->isNullValue())
3223 return (L.match(Cond) && R.match(TVal)) ||
3224 (Commutable && L.match(TVal) && R.match(Cond));
3225 } else {
3226 assert(Opcode == Instruction::Or);
3227 auto *C = dyn_cast<Constant>(TVal);
3228 if (C && C->isOneValue())
3229 return (L.match(Cond) && R.match(FVal)) ||
3230 (Commutable && L.match(FVal) && R.match(Cond));
3231 }
3232 }
3233
3234 return false;
3235 }
3236};
3237
3238/// Matches L && R either in the form of L & R or L ? R : false.
3239/// Note that the latter form is poison-blocking.
3240template <typename LHS, typename RHS>
3242 const RHS &R) {
3244}
3245
3246/// Matches L && R where L and R are arbitrary values.
3247inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3248
3249/// Matches L && R with LHS and RHS in either order.
3250template <typename LHS, typename RHS>
3252m_c_LogicalAnd(const LHS &L, const RHS &R) {
3254}
3255
3256/// Matches L || R either in the form of L | R or L ? true : R.
3257/// Note that the latter form is poison-blocking.
3258template <typename LHS, typename RHS>
3260 const RHS &R) {
3262}
3263
3264/// Matches L || R where L and R are arbitrary values.
3265inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3266
3267/// Matches L || R with LHS and RHS in either order.
3268template <typename LHS, typename RHS>
3270m_c_LogicalOr(const LHS &L, const RHS &R) {
3272}
3273
3274/// Matches either L && R or L || R,
3275/// either one being in the either binary or logical form.
3276/// Note that the latter form is poison-blocking.
3277template <typename LHS, typename RHS, bool Commutable = false>
3283
3284/// Matches either L && R or L || R where L and R are arbitrary values.
3285inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3286
3287/// Matches either L && R or L || R with LHS and RHS in either order.
3288template <typename LHS, typename RHS>
3289inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3290 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3291}
3292
3293} // end namespace PatternMatch
3294} // end namespace llvm
3295
3296#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.
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)