LLVM 24.0.0git
PatternMatch.h
Go to the documentation of this file.
1//===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides a simple and efficient mechanism for performing general
10// tree-based pattern matches on the LLVM IR. The power of these routines is
11// that it allows you to write concise patterns that are expressive and easy to
12// understand. The other major advantage of this is that it allows you to
13// trivially capture/bind elements in the pattern to variables. For example,
14// you can do something like this:
15//
16// Value *Exp = ...
17// Value *X, *Y; ConstantInt *C1, *C2; // (X & C1) | (Y & C2)
18// if (match(Exp, m_Or(m_And(m_Value(X), m_ConstantInt(C1)),
19// m_And(m_Value(Y), m_ConstantInt(C2))))) {
20// ... Pattern is matched and variables are bound ...
21// }
22//
23// This is primarily useful to things like the instruction combiner, but can
24// also be useful for static analysis tools or code generators.
25//
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_IR_PATTERNMATCH_H
29#define LLVM_IR_PATTERNMATCH_H
30
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/APInt.h"
33#include "llvm/IR/Constant.h"
34#include "llvm/IR/Constants.h"
35#include "llvm/IR/DataLayout.h"
36#include "llvm/IR/FMF.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
41#include "llvm/IR/Intrinsics.h"
42#include "llvm/IR/Operator.h"
43#include "llvm/IR/Value.h"
46#include <cstdint>
47#include <utility>
48
49using namespace llvm::PatternMatchHelpers;
50
51namespace llvm {
52namespace PatternMatch {
53
54template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
55 return P.match(V);
56}
57
58/// A match functor that can be used as a UnaryPredicate in functional
59/// algorithms like all_of.
60template <typename Val = const Value, typename Pattern>
61auto match_fn(const Pattern &P) {
63}
64
65template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
66 return P.match(Mask);
67}
68
69template <typename SubPattern_t> struct OneUse_match {
70 SubPattern_t SubPattern;
71
72 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
73
74 template <typename OpTy> bool match(OpTy *V) const {
75 return V->hasOneUse() && SubPattern.match(V);
76 }
77};
78
79template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
80 return SubPattern;
81}
82
83template <typename SubPattern_t, int Flag> struct AllowFmf_match {
84 SubPattern_t SubPattern;
86
87 AllowFmf_match(const SubPattern_t &SP) : SubPattern(SP), FMF(Flag) {}
88
89 template <typename OpTy> bool match(OpTy *V) const {
90 auto *I = dyn_cast<FPMathOperator>(V);
91 return I && ((I->getFastMathFlags() & FMF) == FMF) && SubPattern.match(I);
92 }
93};
94
95template <typename T>
97m_AllowReassoc(const T &SubPattern) {
98 return SubPattern;
99}
100
101template <typename T>
103m_AllowReciprocal(const T &SubPattern) {
104 return SubPattern;
105}
106
107template <typename T>
109m_AllowContract(const T &SubPattern) {
110 return SubPattern;
111}
112
113template <typename T>
115m_ApproxFunc(const T &SubPattern) {
116 return SubPattern;
117}
118
119template <typename T>
121 return SubPattern;
122}
123
124template <typename T>
126 return SubPattern;
127}
128
129template <typename T>
131m_NoSignedZeros(const T &SubPattern) {
132 return SubPattern;
133}
134
135/// Match an arbitrary value and ignore it.
136inline auto m_Value() { return m_Isa<Value>(); }
137
138/// Match an arbitrary unary operation and ignore it.
139inline auto m_UnOp() { return m_Isa<UnaryOperator>(); }
140
141/// Match an arbitrary binary operation and ignore it.
142inline auto m_BinOp() { return m_Isa<BinaryOperator>(); }
143
144/// Matches any compare instruction and ignore it.
145inline auto m_Cmp() { return m_Isa<CmpInst>(); }
146
147/// Matches any intrinsic call and ignore it.
148inline auto m_AnyIntrinsic() { return m_Isa<IntrinsicInst>(); }
149
151private:
152 LLVM_ABI static bool checkAggregate(const ConstantAggregate *CA);
153
154public:
155 static bool check(const Value *V) {
156 if (isa<UndefValue>(V))
157 return true;
158 if (const auto *CA = dyn_cast<ConstantAggregate>(V))
159 return checkAggregate(CA);
160 return false;
161 }
162 template <typename ITy> bool match(ITy *V) const { return check(V); }
163};
164
165/// Match an arbitrary undef constant. This matches poison as well.
166/// If this is an aggregate and contains a non-aggregate element that is
167/// neither undef nor poison, the aggregate is not matched.
168inline auto m_Undef() { return undef_match(); }
169
170/// Match an arbitrary UndefValue constant.
171inline auto m_UndefValue() { return m_Isa<UndefValue>(); }
172
173/// Match an arbitrary poison constant.
174inline auto m_Poison() { return m_Isa<PoisonValue>(); }
175
176/// Match an arbitrary Constant and ignore it.
177inline auto m_Constant() { return m_Isa<Constant>(); }
178
179/// Match an arbitrary ConstantInt and ignore it.
180inline auto m_ConstantInt() { return m_Isa<ConstantInt>(); }
181
182/// Match an arbitrary ConstantFP and ignore it.
183inline auto m_ConstantFP() { return m_Isa<ConstantFP>(); }
184
185template <typename SPTy> struct ContainsMatchingVectorElement_match {
188
189 template <typename ITy> bool match(ITy *V) const {
190 auto *C = dyn_cast<Constant>(V);
191 return C && C->containsMatchingVectorElement(
192 [&](Constant *E) { return SubPattern.match(E); });
193 }
194};
195
196/// Match a vector constant where at least one of its elements matches the
197/// subpattern. Scalable vector constants are not matched. Any bindings in the
198/// subpattern will be bound to the first match.
199template <typename SPTy>
201m_ContainsMatchingVectorElement(const SPTy &SubPattern) {
202 return SubPattern;
203}
204
205/// Match a constant expression or a constant that contains a constant
206/// expression.
211
212template <typename SubPattern_t> struct Splat_match {
213 SubPattern_t SubPattern;
214 Splat_match(const SubPattern_t &SP) : SubPattern(SP) {}
215
216 template <typename OpTy> bool match(OpTy *V) const {
217 if (auto *C = dyn_cast<Constant>(V)) {
218 auto *Splat = C->getSplatValue();
219 return Splat ? SubPattern.match(Splat) : false;
220 }
221 // TODO: Extend to other cases (e.g. shufflevectors).
222 return false;
223 }
224};
225
226/// Match a constant splat. TODO: Extend this to non-constant splats.
227template <typename T>
228inline Splat_match<T> m_ConstantSplat(const T &SubPattern) {
229 return SubPattern;
230}
231
232/// Match an arbitrary basic block value and ignore it.
233inline auto m_BasicBlock() { return m_Isa<BasicBlock>(); }
234
235/// Inverting matcher
236template <typename Ty> struct match_unless {
237 Ty M;
238
239 match_unless(const Ty &Matcher) : M(Matcher) {}
240
241 template <typename ITy> bool match(ITy *V) const { return !M.match(V); }
242};
243
244/// Match if the inner matcher does *NOT* match.
245template <typename Ty> inline match_unless<Ty> m_Unless(const Ty &M) {
246 return match_unless<Ty>(M);
247}
248
249template <typename APTy> struct ap_match {
250 static_assert(std::is_same_v<APTy, APInt> || std::is_same_v<APTy, APFloat>);
252 std::conditional_t<std::is_same_v<APTy, APInt>, ConstantInt, ConstantFP>;
253
254 const APTy *&Res;
256
257 ap_match(const APTy *&Res, bool AllowPoison)
259
260 template <typename ITy> bool match(ITy *V) const {
261 if (auto *CI = dyn_cast<ConstantTy>(V)) {
262 Res = &CI->getValue();
263 return true;
264 }
265 if (V->getType()->isVectorTy())
266 if (const auto *C = dyn_cast<Constant>(V))
267 if (auto *CI =
268 dyn_cast_or_null<ConstantTy>(C->getSplatValue(AllowPoison))) {
269 Res = &CI->getValue();
270 return true;
271 }
272 return false;
273 }
274};
275
276/// Match a ConstantInt or splatted ConstantVector, binding the
277/// specified pointer to the contained APInt.
278inline ap_match<APInt> m_APInt(const APInt *&Res) {
279 // Forbid poison by default to maintain previous behavior.
280 return ap_match<APInt>(Res, /* AllowPoison */ false);
281}
282
283/// Match APInt while allowing poison in splat vector constants.
285 return ap_match<APInt>(Res, /* AllowPoison */ true);
286}
287
288/// Match APInt while forbidding poison in splat vector constants.
290 return ap_match<APInt>(Res, /* AllowPoison */ false);
291}
292
293/// Match a ConstantFP or splatted ConstantVector, binding the
294/// specified pointer to the contained APFloat.
296 // Forbid undefs by default to maintain previous behavior.
297 return ap_match<APFloat>(Res, /* AllowPoison */ false);
298}
299
300/// Match APFloat while allowing poison in splat vector constants.
302 return ap_match<APFloat>(Res, /* AllowPoison */ true);
303}
304
305/// Match APFloat while forbidding poison in splat vector constants.
307 return ap_match<APFloat>(Res, /* AllowPoison */ false);
308}
309
310template <int64_t Val> struct constantint_match {
311 template <typename ITy> bool match(ITy *V) const {
312 if (const auto *CI = dyn_cast<ConstantInt>(V)) {
313 const APInt &CIV = CI->getValue();
314 if (Val >= 0)
315 return CIV == static_cast<uint64_t>(Val);
316 // If Val is negative, and CI is shorter than it, truncate to the right
317 // number of bits. If it is larger, then we have to sign extend. Just
318 // compare their negated values.
319 return -CIV == -Val;
320 }
321 return false;
322 }
323};
324
325/// Match a ConstantInt with a specific value.
326template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
327 return constantint_match<Val>();
328}
329
330/// This helper class is used to match constant scalars, vector splats,
331/// and fixed width vectors that satisfy a specified predicate.
332/// For fixed width vector constants, poison elements are ignored if AllowPoison
333/// is true.
334template <typename Predicate, typename ConstantVal, bool AllowPoison>
335struct cstval_pred_ty : public Predicate {
336private:
337 bool matchVector(const Value *V) const {
338 if (const auto *C = dyn_cast<Constant>(V)) {
339 if (const auto *CV = dyn_cast_or_null<ConstantVal>(C->getSplatValue()))
340 return this->isValue(CV->getValue());
341
342 // Number of elements of a scalable vector unknown at compile time
343 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
344 if (!FVTy)
345 return false;
346
347 // Non-splat vector constant: check each element for a match.
348 unsigned NumElts = FVTy->getNumElements();
349 assert(NumElts != 0 && "Constant vector with no elements?");
350 bool HasNonPoisonElements = false;
351 for (unsigned i = 0; i != NumElts; ++i) {
352 Constant *Elt = C->getAggregateElement(i);
353 if (!Elt)
354 return false;
355 if (AllowPoison && isa<PoisonValue>(Elt))
356 continue;
357 auto *CV = dyn_cast<ConstantVal>(Elt);
358 if (!CV || !this->isValue(CV->getValue()))
359 return false;
360 HasNonPoisonElements = true;
361 }
362 return HasNonPoisonElements;
363 }
364 return false;
365 }
366
367public:
368 const Constant **Res = nullptr;
369 template <typename ITy> bool match_impl(ITy *V) const {
370 if (const auto *CV = dyn_cast<ConstantVal>(V))
371 return this->isValue(CV->getValue());
372 if (isa<VectorType>(V->getType()))
373 return matchVector(V);
374 return false;
375 }
376
377 template <typename ITy> bool match(ITy *V) const {
378 if (this->match_impl(V)) {
379 if (Res)
380 *Res = cast<Constant>(V);
381 return true;
382 }
383 return false;
384 }
385};
386
387/// specialization of cstval_pred_ty for ConstantInt
388template <typename Predicate, bool AllowPoison = true>
390
391/// specialization of cstval_pred_ty for ConstantFP
392template <typename Predicate>
394 /*AllowPoison=*/true>;
395
396/// This helper class is used to match scalar and vector constants that
397/// satisfy a specified predicate, and bind them to an APInt.
398template <typename Predicate> struct api_pred_ty : public Predicate {
399 const APInt *&Res;
400
401 api_pred_ty(const APInt *&R) : Res(R) {}
402
403 template <typename ITy> bool match(ITy *V) const {
404 if (const auto *CI = dyn_cast<ConstantInt>(V))
405 if (this->isValue(CI->getValue())) {
406 Res = &CI->getValue();
407 return true;
408 }
409 if (V->getType()->isVectorTy())
410 if (const auto *C = dyn_cast<Constant>(V))
411 if (auto *CI = dyn_cast_or_null<ConstantInt>(
412 C->getSplatValue(/*AllowPoison=*/true)))
413 if (this->isValue(CI->getValue())) {
414 Res = &CI->getValue();
415 return true;
416 }
417
418 return false;
419 }
420};
421
422/// This helper class is used to match scalar and vector constants that
423/// satisfy a specified predicate, and bind them to an APFloat.
424/// Poison is allowed in splat vector constants.
425template <typename Predicate> struct apf_pred_ty : public Predicate {
426 const APFloat *&Res;
427
428 apf_pred_ty(const APFloat *&R) : Res(R) {}
429
430 template <typename ITy> bool match(ITy *V) const {
431 if (const auto *CI = dyn_cast<ConstantFP>(V))
432 if (this->isValue(CI->getValue())) {
433 Res = &CI->getValue();
434 return true;
435 }
436 if (V->getType()->isVectorTy())
437 if (const auto *C = dyn_cast<Constant>(V))
438 if (auto *CI = dyn_cast_or_null<ConstantFP>(
439 C->getSplatValue(/* AllowPoison */ true)))
440 if (this->isValue(CI->getValue())) {
441 Res = &CI->getValue();
442 return true;
443 }
444
445 return false;
446 }
447};
448
449///////////////////////////////////////////////////////////////////////////////
450//
451// Encapsulate constant value queries for use in templated predicate matchers.
452// This allows checking if constants match using compound predicates and works
453// with vector constants, possibly with relaxed constraints. For example, ignore
454// undef values.
455//
456///////////////////////////////////////////////////////////////////////////////
457
458template <typename APTy> struct custom_checkfn {
459 function_ref<bool(const APTy &)> CheckFn;
460 bool isValue(const APTy &C) const { return CheckFn(C); }
461};
462
463/// Match an integer or vector where CheckFn(ele) for each element is true.
464/// For vectors, poison elements are assumed to match.
466m_CheckedInt(function_ref<bool(const APInt &)> CheckFn) {
467 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}};
468}
469
471m_CheckedInt(const Constant *&V, function_ref<bool(const APInt &)> CheckFn) {
472 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}, &V};
473}
474
475/// Match a float or vector where CheckFn(ele) for each element is true.
476/// For vectors, poison elements are assumed to match.
478m_CheckedFp(function_ref<bool(const APFloat &)> CheckFn) {
479 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}};
480}
481
483m_CheckedFp(const Constant *&V, function_ref<bool(const APFloat &)> CheckFn) {
484 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}, &V};
485}
486
488 bool isValue(const APInt &C) const { return true; }
489};
490/// Match an integer or vector with any integral constant.
491/// For vectors, this includes constants with undefined elements.
495
497 bool isValue(const APInt &C) const { return C.isShiftedMask(); }
498};
499
503
505 bool isValue(const APInt &C) const { return C.isAllOnes(); }
506};
507/// Match an integer or vector with all bits set.
508/// For vectors, this includes constants with undefined elements.
512
516
517inline auto m_AllOnesOrPoison() { return m_CombineOr(m_AllOnes(), m_Poison()); }
518
520 bool isValue(const APInt &C) const { return C.isMaxSignedValue(); }
521};
522/// Match an integer or vector with values having all bits except for the high
523/// bit set (0x7f...).
524/// For vectors, this includes constants with undefined elements.
529 return V;
530}
531
533 bool isValue(const APInt &C) const { return C.isNegative(); }
534};
535/// Match an integer or vector of negative values.
536/// For vectors, this includes constants with undefined elements.
540inline api_pred_ty<is_negative> m_Negative(const APInt *&V) { return V; }
541
543 bool isValue(const APInt &C) const { return C.isNonNegative(); }
544};
545/// Match an integer or vector of non-negative values.
546/// For vectors, this includes constants with undefined elements.
550inline api_pred_ty<is_nonnegative> m_NonNegative(const APInt *&V) { return V; }
551
553 bool isValue(const APInt &C) const { return C.isStrictlyPositive(); }
554};
555/// Match an integer or vector of strictly positive values.
556/// For vectors, this includes constants with undefined elements.
561 return V;
562}
563
565 bool isValue(const APInt &C) const { return C.isNonPositive(); }
566};
567/// Match an integer or vector of non-positive values.
568/// For vectors, this includes constants with undefined elements.
572inline api_pred_ty<is_nonpositive> m_NonPositive(const APInt *&V) { return V; }
573
574struct is_one {
575 bool isValue(const APInt &C) const { return C.isOne(); }
576};
577/// Match an integer 1 or a vector with all elements equal to 1.
578/// For vectors, this includes constants with undefined elements.
580
582 bool isValue(const APInt &C) const { return C.isZero(); }
583};
584/// Match an integer 0 or a vector with all elements equal to 0.
585/// For vectors, this includes constants with undefined elements.
589
591 bool isValue(const APInt &C) const { return !C.isZero(); }
592};
593/// Match a non-zero integer or a vector with all non-zero elements.
594/// For vectors, this includes constants with undefined elements.
598
599struct is_zero {
600 template <typename ITy> bool match(ITy *V) const {
601 auto *C = dyn_cast<Constant>(V);
602 // FIXME: this should be able to do something for scalable vectors
603 return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C));
604 }
605};
606/// Match any null constant or a vector with all elements equal to 0.
607/// For vectors, this includes constants with undefined elements.
608inline is_zero m_Zero() { return is_zero(); }
609
610inline auto m_ZeroOrPoison() { return m_CombineOr(m_Zero(), m_Poison()); }
611
612struct is_power2 {
613 bool isValue(const APInt &C) const { return C.isPowerOf2(); }
614};
615/// Match an integer or vector power-of-2.
616/// For vectors, this includes constants with undefined elements.
618inline api_pred_ty<is_power2> m_Power2(const APInt *&V) { return V; }
619
621 bool isValue(const APInt &C) const { return C.isNegatedPowerOf2(); }
622};
623/// Match a integer or vector negated power-of-2.
624/// For vectors, this includes constants with undefined elements.
629 return V;
630}
631
633 bool isValue(const APInt &C) const { return !C || C.isNegatedPowerOf2(); }
634};
635/// Match a integer or vector negated power-of-2.
636/// For vectors, this includes constants with undefined elements.
642 return V;
643}
644
646 bool isValue(const APInt &C) const { return !C || C.isPowerOf2(); }
647};
648/// Match an integer or vector of 0 or power-of-2 values.
649/// For vectors, this includes constants with undefined elements.
654 return V;
655}
656
658 bool isValue(const APInt &C) const { return C.isSignMask(); }
659};
660/// Match an integer or vector with only the sign bit(s) set.
661/// For vectors, this includes constants with undefined elements.
665
667 bool isValue(const APInt &C) const { return C.isMask(); }
668};
669/// Match an integer or vector with only the low bit(s) set.
670/// For vectors, this includes constants with undefined elements.
674inline api_pred_ty<is_lowbit_mask> m_LowBitMask(const APInt *&V) { return V; }
675
677 bool isValue(const APInt &C) const { return !C || C.isMask(); }
678};
679/// Match an integer or vector with only the low bit(s) set.
680/// For vectors, this includes constants with undefined elements.
685 return V;
686}
687
690 const APInt *Thr;
691 bool isValue(const APInt &C) const {
692 return ICmpInst::compare(C, *Thr, Pred);
693 }
694};
695/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
696/// to Threshold. For vectors, this includes constants with undefined elements.
698m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold) {
700 P.Pred = Predicate;
701 P.Thr = &Threshold;
702 return P;
703}
704
705struct is_nan {
706 bool isValue(const APFloat &C) const { return C.isNaN(); }
707};
708/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
709/// For vectors, this includes constants with undefined elements.
711
712struct is_nonnan {
713 bool isValue(const APFloat &C) const { return !C.isNaN(); }
714};
715/// Match a non-NaN FP constant.
716/// For vectors, this includes constants with undefined elements.
720
721struct is_inf {
722 bool isValue(const APFloat &C) const { return C.isInfinity(); }
723};
724/// Match a positive or negative infinity FP constant.
725/// For vectors, this includes constants with undefined elements.
727
728template <bool IsNegative> struct is_signed_inf {
729 bool isValue(const APFloat &C) const {
730 return C.isInfinity() && IsNegative == C.isNegative();
731 }
732};
733
734/// Match a positive infinity FP constant.
735/// For vectors, this includes constants with undefined elements.
739
740/// Match a negative infinity FP constant.
741/// For vectors, this includes constants with undefined elements.
745
746struct is_noninf {
747 bool isValue(const APFloat &C) const { return !C.isInfinity(); }
748};
749/// Match a non-infinity FP constant, i.e. finite or NaN.
750/// For vectors, this includes constants with undefined elements.
754
755struct is_finite {
756 bool isValue(const APFloat &C) const { return C.isFinite(); }
757};
758/// Match a finite FP constant, i.e. not infinity or NaN.
759/// For vectors, this includes constants with undefined elements.
763inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
764
766 bool isValue(const APFloat &C) const { return C.isFiniteNonZero(); }
767};
768/// Match a finite non-zero FP constant.
769/// For vectors, this includes constants with undefined elements.
774 return V;
775}
776
778 bool isValue(const APFloat &C) const { return C.isZero(); }
779};
780/// Match a floating-point negative zero or positive zero.
781/// For vectors, this includes constants with undefined elements.
785
787 bool isValue(const APFloat &C) const { return C.isPosZero(); }
788};
789/// Match a floating-point positive zero.
790/// For vectors, this includes constants with undefined elements.
794
796 bool isValue(const APFloat &C) const { return C.isNegZero(); }
797};
798/// Match a floating-point negative zero.
799/// For vectors, this includes constants with undefined elements.
803
805 bool isValue(const APFloat &C) const { return C.isNonZero(); }
806};
807/// Match a floating-point non-zero.
808/// For vectors, this includes constants with undefined elements.
812
814 bool isValue(const APFloat &C) const {
815 return !C.isDenormal() && C.isNonZero();
816 }
817};
818
819/// Match a floating-point non-zero that is not a denormal.
820/// For vectors, this includes constants with undefined elements.
824
825///////////////////////////////////////////////////////////////////////////////
826
827/// Match a value, capturing it if we match.
828inline match_bind<Value> m_Value(Value *&V) { return V; }
829inline match_bind<const Value> m_Value(const Value *&V) { return V; }
830
831/// Match against the nested pattern, and capture the value if we match.
832template <typename Pattern> inline auto m_Value(Value *&V, const Pattern &P) {
833 return m_CombineAnd(P, match_bind<Value>(V));
834}
835
836/// Match against the nested pattern, and capture the value if we match.
837template <typename Pattern>
838inline auto m_Value(const Value *&V, const Pattern &P) {
840}
841
842/// Match an instruction, capturing it if we match.
845 return I;
846}
847
848/// Match against the nested pattern, and capture the instruction if we match.
849template <typename Pattern>
850inline auto m_Instruction(Instruction *&I, const Pattern &P) {
852}
853template <typename Pattern>
854inline auto m_Instruction(const Instruction *&I, const Pattern &P) {
856}
857
858/// Match a unary operator, capturing it if we match.
861 return I;
862}
863/// Match a binary operator, capturing it if we match.
866 return I;
867}
868/// Match any intrinsic call, capturing it if we match.
873/// Match a with overflow intrinsic, capturing it if we match.
879 return I;
880}
881
882/// Match a PHI node, capturing it if we match.
883inline match_bind<PHINode> m_Phi(PHINode *&PN) { return PN; }
884
885/// Match an UndefValue, capturing the value if we match.
887
888/// Match a Constant, capturing the value if we match.
890
891/// Match a ConstantInt, capturing the value if we match.
893
894/// Match a ConstantFP, capturing the value if we match.
896
897/// Match a ConstantExpr, capturing the value if we match.
899
900/// Match a basic block value, capturing it if we match.
903 return V;
904}
905
906// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
907// and use m_Unless(m_ConstantExpr).
909 template <typename ITy> static bool isImmConstant(ITy *V) {
910 if (auto *CV = dyn_cast<Constant>(V)) {
911 if (!match(CV, m_ConstantExpr()))
912 return true;
913
914 if (CV->getType()->isVectorTy()) {
915 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
916 if (!match(Splat, m_ConstantExpr())) {
917 return true;
918 }
919 }
920 }
921 }
922 return false;
923 }
924};
925
927 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
928};
929
930/// Match an arbitrary immediate Constant and ignore it.
932
935
937
938 template <typename ITy> bool match(ITy *V) const {
939 if (isImmConstant(V)) {
940 VR = cast<Constant>(V);
941 return true;
942 }
943 return false;
944 }
945};
946
947/// Match an immediate Constant, capturing the value if we match.
951
952/// Matcher for specified Value*.
954 const Value *Val;
955
956 specificval_ty(const Value *V) : Val(V) {}
957
958 template <typename ITy> bool match(ITy *V) const { return V == Val; }
959};
960
961/// Match if we have a specific specified value.
962inline specificval_ty m_Specific(const Value *V) { return V; }
963
964/// Like m_Specific(), but works if the specific value to match is determined
965/// as part of the same match() expression. For example:
966/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
967/// bind X before the pattern match starts.
968/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
969/// whichever value m_Value(X) populated.
970inline match_deferred<Value> m_Deferred(Value *const &V) { return V; }
972 return V;
973}
974
975/// Match a specified floating point value or vector of all elements of
976/// that value.
978 double Val;
979
980 specific_fpval(double V) : Val(V) {}
981
982 template <typename ITy> bool match(ITy *V) const {
983 if (const auto *CFP = dyn_cast<ConstantFP>(V))
984 return CFP->isExactlyValue(Val);
985 if (V->getType()->isVectorTy())
986 if (const auto *C = dyn_cast<Constant>(V))
987 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
988 return CFP->isExactlyValue(Val);
989 return false;
990 }
991};
992
993/// Match a specific floating point value or vector with all elements
994/// equal to the value.
995inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
996
997/// Match a float 1.0 or vector with all elements equal to 1.0.
998inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
999
1002
1004
1005 template <typename ITy> bool match(ITy *V) const {
1006 const APInt *ConstInt;
1007 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1008 return false;
1009 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1010 if (!ZExtVal)
1011 return false;
1012 VR = *ZExtVal;
1013 return true;
1014 }
1015};
1016
1017/// Match a specified integer value or vector of all elements of that
1018/// value.
1019template <bool AllowPoison> struct specific_intval {
1020 const APInt &Val;
1021
1022 specific_intval(const APInt &V) : Val(V) {}
1023
1024 template <typename ITy> bool match(ITy *V) const {
1025 const auto *CI = dyn_cast<ConstantInt>(V);
1026 if (!CI && V->getType()->isVectorTy())
1027 if (const auto *C = dyn_cast<Constant>(V))
1028 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1029
1030 return CI && APInt::isSameValue(CI->getValue(), Val);
1031 }
1032};
1033
1034template <bool AllowPoison> struct specific_intval64 {
1036
1038
1039 template <typename ITy> bool match(ITy *V) const {
1040 const auto *CI = dyn_cast<ConstantInt>(V);
1041 if (!CI && V->getType()->isVectorTy())
1042 if (const auto *C = dyn_cast<Constant>(V))
1043 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1044
1045 return CI && CI->getValue() == Val;
1046 }
1047};
1048
1049/// Match a specific integer value or vector with all elements equal to
1050/// the value.
1052 return specific_intval<false>(V);
1053}
1054
1058
1062
1066
1067/// Match a ConstantInt and bind to its value. This does not match
1068/// ConstantInts wider than 64-bits.
1070
1071/// Match a specified basic block value.
1074
1076
1077 template <typename ITy> bool match(ITy *V) const {
1078 const auto *BB = dyn_cast<BasicBlock>(V);
1079 return BB && BB == Val;
1080 }
1081};
1082
1083/// Match a specific basic block value.
1085 return specific_bbval(BB);
1086}
1087
1088/// A commutative-friendly version of m_Specific().
1090 return BB;
1091}
1093m_Deferred(const BasicBlock *const &BB) {
1094 return BB;
1095}
1096
1097template <typename Pattern> struct SpecificType_match {
1100
1102
1103 template <typename ITy> bool match(ITy *V) const {
1104 return V->getType() == RefTy && P.match(V);
1105 }
1106};
1107
1108// Explicit deduction guide.
1109template <typename Pattern>
1112
1113/// Match a value of a specific type.
1114template <typename Pattern>
1115inline auto m_SpecificType(Type *RefTy, const Pattern &P) {
1116 return SpecificType_match<Pattern>(RefTy, P);
1117}
1118inline auto m_SpecificType(Type *RefTy) {
1119 return m_SpecificType(RefTy, m_Value());
1120}
1121
1122/// Match a value of a specific type, capturing it if we match.
1123inline auto m_SpecificType(Type *RefTy, Value *&V) {
1124 return m_SpecificType(RefTy, m_Value(V));
1125}
1126inline auto m_SpecificType(Type *RefTy, const Value *&V) {
1127 return m_SpecificType(RefTy, m_Value(V));
1128}
1129
1130//===----------------------------------------------------------------------===//
1131// Matcher for any binary operator.
1132//
1133template <typename LHS_t, typename RHS_t, bool Commutable = false>
1137
1138 // The evaluation order is always stable, regardless of Commutability.
1139 // The LHS is always matched first.
1140 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1141
1142 template <typename OpTy> bool match(OpTy *V) const {
1143 if (auto *I = dyn_cast<BinaryOperator>(V))
1144 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1145 (Commutable && L.match(I->getOperand(1)) &&
1146 R.match(I->getOperand(0)));
1147 return false;
1148 }
1149};
1150
1151template <typename LHS, typename RHS>
1152inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1153 return AnyBinaryOp_match<LHS, RHS>(L, R);
1154}
1155
1156//===----------------------------------------------------------------------===//
1157// Matcher for any unary operator.
1158// TODO fuse unary, binary matcher into n-ary matcher
1159//
1160template <typename OP_t> struct AnyUnaryOp_match {
1161 OP_t X;
1162
1163 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1164
1165 template <typename OpTy> bool match(OpTy *V) const {
1166 if (auto *I = dyn_cast<UnaryOperator>(V))
1167 return X.match(I->getOperand(0));
1168 return false;
1169 }
1170};
1171
1172template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1173 return AnyUnaryOp_match<OP_t>(X);
1174}
1175
1176//===----------------------------------------------------------------------===//
1177// Matchers for specific binary operators.
1178//
1179
1180template <typename LHS_t, typename RHS_t, unsigned Opcode,
1181 bool Commutable = false>
1185
1186 // The evaluation order is always stable, regardless of Commutability.
1187 // The LHS is always matched first.
1188 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1189
1190 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1191 if (V->getValueID() == Value::InstructionVal + Opc) {
1192 auto *I = cast<BinaryOperator>(V);
1193 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1194 (Commutable && L.match(I->getOperand(1)) &&
1195 R.match(I->getOperand(0)));
1196 }
1197 return false;
1198 }
1199
1200 template <typename OpTy> bool match(OpTy *V) const {
1201 return match(Opcode, V);
1202 }
1203};
1204
1205template <typename LHS, typename RHS>
1207 const RHS &R) {
1209}
1210
1211template <typename LHS, typename RHS>
1213 const RHS &R) {
1215}
1216
1217template <typename LHS, typename RHS>
1219 const RHS &R) {
1221}
1222
1223template <typename LHS, typename RHS>
1225 const RHS &R) {
1227}
1228
1229template <typename Op_t> struct FNeg_match {
1230 Op_t X;
1231
1232 FNeg_match(const Op_t &Op) : X(Op) {}
1233 template <typename OpTy> bool match(OpTy *V) const {
1234 auto *FPMO = dyn_cast<FPMathOperator>(V);
1235 if (!FPMO)
1236 return false;
1237
1238 if (FPMO->getOpcode() == Instruction::FNeg)
1239 return X.match(FPMO->getOperand(0));
1240
1241 if (FPMO->getOpcode() == Instruction::FSub) {
1242 if (FPMO->hasNoSignedZeros()) {
1243 // With 'nsz', any zero goes.
1244 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1245 return false;
1246 } else {
1247 // Without 'nsz', we need fsub -0.0, X exactly.
1248 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1249 return false;
1250 }
1251
1252 return X.match(FPMO->getOperand(1));
1253 }
1254
1255 return false;
1256 }
1257};
1258
1259/// Match 'fneg X' as 'fsub -0.0, X'.
1260template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1261 return FNeg_match<OpTy>(X);
1262}
1263
1264/// Match 'fneg X' as 'fsub +-0.0, X'.
1265template <typename RHS>
1266inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1267m_FNegNSZ(const RHS &X) {
1268 return m_FSub(m_AnyZeroFP(), X);
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, typename RHS>
1321 const RHS &R) {
1323}
1324
1325template <typename LHS, typename RHS>
1327 const RHS &R) {
1329}
1330
1331template <typename LHS, typename RHS>
1333 const RHS &R) {
1335}
1336
1337template <typename LHS, typename RHS>
1339 const RHS &R) {
1341}
1342
1343template <typename LHS, typename RHS>
1345 const RHS &R) {
1347}
1348
1349template <typename LHS, typename RHS>
1351 const RHS &R) {
1353}
1354
1355template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1358
1359 ShiftLike_match(const LHS_t &LHS, uint64_t &RHS) : L(LHS), R(RHS) {}
1360
1361 template <typename OpTy> bool match(OpTy *V) const {
1362 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1363 if (Op->getOpcode() == Opcode)
1364 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1365 L.match(Op->getOperand(0));
1366 }
1367 // Interpreted as shiftop V, 0
1368 R = 0;
1369 return L.match(V);
1370 }
1371};
1372
1373/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1374template <typename LHS>
1379
1380/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1381template <typename LHS>
1386
1387/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1388template <typename LHS>
1393
1394template <typename LHS_t, typename RHS_t, unsigned Opcode,
1395 unsigned WrapFlags = 0, bool Commutable = false>
1399
1400 OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
1401 : L(LHS), R(RHS) {}
1402
1403 template <typename OpTy> bool match(OpTy *V) const {
1404 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1405 if (Op->getOpcode() != Opcode)
1406 return false;
1408 !Op->hasNoUnsignedWrap())
1409 return false;
1410 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1411 !Op->hasNoSignedWrap())
1412 return false;
1413 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1414 (Commutable && L.match(Op->getOperand(1)) &&
1415 R.match(Op->getOperand(0)));
1416 }
1417 return false;
1418 }
1419};
1420
1421template <typename LHS, typename RHS>
1422inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1424m_NSWAdd(const LHS &L, const RHS &R) {
1425 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1427 R);
1428}
1429template <typename LHS, typename RHS>
1430inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1432m_c_NSWAdd(const LHS &L, const RHS &R) {
1433 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1435 true>(L, R);
1436}
1437template <typename LHS, typename RHS>
1438inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1440m_NSWSub(const LHS &L, const RHS &R) {
1441 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1443 R);
1444}
1445template <typename LHS, typename RHS>
1446inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1448m_NSWMul(const LHS &L, const RHS &R) {
1449 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1451 R);
1452}
1453template <typename LHS, typename RHS>
1454inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1456m_NSWShl(const LHS &L, const RHS &R) {
1457 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1459 R);
1460}
1461
1462template <typename LHS, typename RHS>
1463inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1465m_NUWAdd(const LHS &L, const RHS &R) {
1466 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1468 L, R);
1469}
1470
1471template <typename LHS, typename RHS>
1473 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1474m_c_NUWAdd(const LHS &L, const RHS &R) {
1475 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1477 true>(L, R);
1478}
1479
1480template <typename LHS, typename RHS>
1481inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1483m_NUWSub(const LHS &L, const RHS &R) {
1484 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1486 L, R);
1487}
1488template <typename LHS, typename RHS>
1489inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1491m_NUWMul(const LHS &L, const RHS &R) {
1492 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1494 L, R);
1495}
1496template <typename LHS, typename RHS>
1497inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1499m_NUWShl(const LHS &L, const RHS &R) {
1500 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1502 L, R);
1503}
1504
1505template <typename LHS_t, typename RHS_t, bool Commutable = false>
1507 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1508 unsigned Opcode;
1509
1510 SpecificBinaryOp_match(unsigned Opcode, const LHS_t &LHS, const RHS_t &RHS)
1511 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1512
1513 template <typename OpTy> bool match(OpTy *V) const {
1515 }
1516};
1517
1518/// Matches a specific opcode.
1519template <typename LHS, typename RHS>
1520inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1521 const RHS &R) {
1522 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1523}
1524
1525template <typename LHS, typename RHS, bool Commutable = false>
1527 LHS L;
1528 RHS R;
1529
1530 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1531
1532 template <typename OpTy> bool match(OpTy *V) const {
1533 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1534 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1535 if (!PDI->isDisjoint())
1536 return false;
1537 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1538 (Commutable && L.match(PDI->getOperand(1)) &&
1539 R.match(PDI->getOperand(0)));
1540 }
1541 return false;
1542 }
1543};
1544
1545template <typename LHS, typename RHS>
1546inline DisjointOr_match<LHS, RHS> m_DisjointOr(const LHS &L, const RHS &R) {
1547 return DisjointOr_match<LHS, RHS>(L, R);
1548}
1549
1550template <typename LHS, typename RHS>
1552 const RHS &R) {
1554}
1555
1556/// Match either "add" or "or disjoint".
1557template <typename LHS, typename RHS>
1560m_AddLike(const LHS &L, const RHS &R) {
1561 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1562}
1563
1564/// Match either "add nsw" or "or disjoint"
1565template <typename LHS, typename RHS>
1566inline match_combine_or<
1567 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1570m_NSWAddLike(const LHS &L, const RHS &R) {
1571 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1572}
1573
1574/// Match either "add nuw" or "or disjoint"
1575template <typename LHS, typename RHS>
1576inline match_combine_or<
1577 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1580m_NUWAddLike(const LHS &L, const RHS &R) {
1581 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1582}
1583
1584template <typename LHS, typename RHS>
1586 LHS L;
1587 RHS R;
1588
1589 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1590
1591 template <typename OpTy> bool match(OpTy *V) const {
1592 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1593 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1594 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1595 ; // Pass
1596 else if (Op->getOpcode() != Instruction::Xor)
1597 return false;
1598 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1599 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1600 }
1601 return false;
1602 }
1603};
1604
1605/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1606/// Only commutative matcher as the `sub` will need to swap the L and R.
1607template <typename LHS, typename RHS>
1608inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1609 return XorLike_match<LHS, RHS>(L, R);
1610}
1611
1612//===----------------------------------------------------------------------===//
1613// Class that matches a group of binary opcodes.
1614//
1615template <typename LHS_t, typename RHS_t, typename Predicate,
1616 bool Commutable = false>
1617struct BinOpPred_match : Predicate {
1620
1621 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1622
1623 template <typename OpTy> bool match(OpTy *V) const {
1624 if (auto *I = dyn_cast<Instruction>(V))
1625 return this->isOpType(I->getOpcode()) &&
1626 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1627 (Commutable && L.match(I->getOperand(1)) &&
1628 R.match(I->getOperand(0))));
1629 return false;
1630 }
1631};
1632
1634 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1635};
1636
1638 bool isOpType(unsigned Opcode) const {
1639 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1640 }
1641};
1642
1644 bool isOpType(unsigned Opcode) const {
1645 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1646 }
1647};
1648
1650 bool isOpType(unsigned Opcode) const {
1651 return Instruction::isBitwiseLogicOp(Opcode);
1652 }
1653};
1654
1656 bool isOpType(unsigned Opcode) const {
1657 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1658 }
1659};
1660
1662 bool isOpType(unsigned Opcode) const {
1663 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1664 }
1665};
1666
1667/// Matches shift operations.
1668template <typename LHS, typename RHS>
1670 const RHS &R) {
1672}
1673
1674/// Matches logical shift operations.
1675template <typename LHS, typename RHS>
1677 const RHS &R) {
1679}
1680
1681/// Matches logical shift operations.
1682template <typename LHS, typename RHS>
1684m_LogicalShift(const LHS &L, const RHS &R) {
1686}
1687
1688/// Matches bitwise logic operations.
1689template <typename LHS, typename RHS>
1691m_BitwiseLogic(const LHS &L, const RHS &R) {
1693}
1694
1695/// Matches bitwise logic operations in either order.
1696template <typename LHS, typename RHS>
1698m_c_BitwiseLogic(const LHS &L, const RHS &R) {
1700}
1701
1702/// Matches integer division operations.
1703template <typename LHS, typename RHS>
1705 const RHS &R) {
1707}
1708
1709/// Matches integer remainder operations.
1710template <typename LHS, typename RHS>
1712 const RHS &R) {
1714}
1715
1716//===----------------------------------------------------------------------===//
1717// Class that matches exact binary ops.
1718//
1719template <typename SubPattern_t> struct Exact_match {
1720 SubPattern_t SubPattern;
1721
1722 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1723
1724 template <typename OpTy> bool match(OpTy *V) const {
1725 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1726 return PEO->isExact() && SubPattern.match(V);
1727 return false;
1728 }
1729};
1730
1731template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1732 return SubPattern;
1733}
1734
1735//===----------------------------------------------------------------------===//
1736// Matchers for CmpInst classes
1737//
1738
1739template <typename LHS_t, typename RHS_t, typename Class,
1740 bool Commutable = false>
1745
1746 // The evaluation order is always stable, regardless of Commutability.
1747 // The LHS is always matched first.
1748 CmpClass_match(CmpPredicate &Pred, const LHS_t &LHS, const RHS_t &RHS)
1749 : Predicate(&Pred), L(LHS), R(RHS) {}
1750 CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
1751 : Predicate(nullptr), L(LHS), R(RHS) {}
1752
1753 template <typename OpTy> bool match(OpTy *V) const {
1754 if (auto *I = dyn_cast<Class>(V)) {
1755 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1756 if (Predicate)
1758 return true;
1759 }
1760 if (Commutable && L.match(I->getOperand(1)) &&
1761 R.match(I->getOperand(0))) {
1762 if (Predicate)
1764 return true;
1765 }
1766 }
1767 return false;
1768 }
1769};
1770
1771template <typename LHS, typename RHS>
1773 const RHS &R) {
1774 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1775}
1776
1777template <typename LHS, typename RHS>
1779 const LHS &L, const RHS &R) {
1780 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1781}
1782
1783template <typename LHS, typename RHS>
1785 const LHS &L, const RHS &R) {
1786 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1787}
1788
1789template <typename LHS, typename RHS>
1790inline CmpClass_match<LHS, RHS, CmpInst> m_Cmp(const LHS &L, const RHS &R) {
1792}
1793
1794template <typename LHS, typename RHS>
1795inline CmpClass_match<LHS, RHS, ICmpInst> m_ICmp(const LHS &L, const RHS &R) {
1797}
1798
1799template <typename LHS, typename RHS>
1800inline CmpClass_match<LHS, RHS, FCmpInst> m_FCmp(const LHS &L, const RHS &R) {
1802}
1803
1804// Same as CmpClass, but instead of saving Pred as out output variable, match a
1805// specific input pred for equality.
1806template <typename LHS_t, typename RHS_t, typename Class,
1807 bool Commutable = false>
1812
1813 SpecificCmpClass_match(CmpPredicate Pred, const LHS_t &LHS, const RHS_t &RHS)
1814 : Predicate(Pred), L(LHS), R(RHS) {}
1815
1816 template <typename OpTy> bool match(OpTy *V) const {
1817 if (auto *I = dyn_cast<Class>(V)) {
1819 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1820 return true;
1821 if constexpr (Commutable) {
1824 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1825 return true;
1826 }
1827 }
1828
1829 return false;
1830 }
1831};
1832
1833template <typename LHS, typename RHS>
1835m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1836 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1837}
1838
1839template <typename LHS, typename RHS>
1841m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1842 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1843}
1844
1845template <typename LHS, typename RHS>
1847m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1849}
1850
1851template <typename LHS, typename RHS>
1853m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1854 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1855}
1856
1857//===----------------------------------------------------------------------===//
1858// Matchers for instructions with a given opcode and number of operands.
1859//
1860
1861/// Matches instructions with Opcode and three operands.
1862template <typename T0, unsigned Opcode> struct OneOps_match {
1864
1865 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1866
1867 template <typename OpTy> bool match(OpTy *V) const {
1868 if (V->getValueID() == Value::InstructionVal + Opcode) {
1869 auto *I = cast<Instruction>(V);
1870 return Op1.match(I->getOperand(0));
1871 }
1872 return false;
1873 }
1874};
1875
1876/// Matches instructions with Opcode and three operands.
1877template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1880
1881 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1882
1883 template <typename OpTy> bool match(OpTy *V) const {
1884 if (V->getValueID() == Value::InstructionVal + Opcode) {
1885 auto *I = cast<Instruction>(V);
1886 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1887 }
1888 return false;
1889 }
1890};
1891
1892/// Matches instructions with Opcode and three operands.
1893template <typename T0, typename T1, typename T2, unsigned Opcode,
1894 bool CommutableOp2Op3 = false>
1899
1900 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1901 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1902
1903 template <typename OpTy> bool match(OpTy *V) const {
1904 if (V->getValueID() == Value::InstructionVal + Opcode) {
1905 auto *I = cast<Instruction>(V);
1906 if (!Op1.match(I->getOperand(0)))
1907 return false;
1908 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1909 return true;
1910 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1911 Op3.match(I->getOperand(1));
1912 }
1913 return false;
1914 }
1915};
1916
1917/// Matches instructions with Opcode and any number of operands
1918template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1919 std::tuple<OperandTypes...> Operands;
1920
1921 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1922
1923 // Operand matching works by recursively calling match_operands, matching the
1924 // operands left to right. The first version is called for each operand but
1925 // the last, for which the second version is called. The second version of
1926 // match_operands is also used to match each individual operand.
1927 template <int Idx, int Last>
1928 std::enable_if_t<Idx != Last, bool>
1932
1933 template <int Idx, int Last>
1934 std::enable_if_t<Idx == Last, bool>
1936 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1937 }
1938
1939 template <typename OpTy> bool match(OpTy *V) const {
1940 if (V->getValueID() == Value::InstructionVal + Opcode) {
1941 auto *I = cast<Instruction>(V);
1942 return I->getNumOperands() == sizeof...(OperandTypes) &&
1943 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1944 }
1945 return false;
1946 }
1947};
1948
1949/// Matches SelectInst.
1950template <typename Cond, typename LHS, typename RHS>
1952m_Select(const Cond &C, const LHS &L, const RHS &R) {
1954}
1955
1956/// This matches a select of two constants, e.g.:
1957/// m_SelectCst<-1, 0>(m_Value(V))
1958template <int64_t L, int64_t R, typename Cond>
1960 Instruction::Select>
1963}
1964
1965/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1966template <typename LHS, typename RHS>
1967inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1968m_c_Select(const LHS &L, const RHS &R) {
1969 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1970 true>(m_Value(), L, R);
1971}
1972
1973/// Matches FreezeInst.
1974template <typename OpTy>
1978
1979/// Matches InsertElementInst.
1980template <typename Val_t, typename Elt_t, typename Idx_t>
1982m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1984 Val, Elt, Idx);
1985}
1986
1987/// Matches ExtractElementInst.
1988template <typename Val_t, typename Idx_t>
1990m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
1992}
1993
1994/// Matches shuffle.
1995template <typename T0, typename T1, typename T2> struct Shuffle_match {
1999
2000 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
2001 : Op1(Op1), Op2(Op2), Mask(Mask) {}
2002
2003 template <typename OpTy> bool match(OpTy *V) const {
2004 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
2005 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
2006 Mask.match(I->getShuffleMask());
2007 }
2008 return false;
2009 }
2010};
2011
2012struct m_Mask {
2015 bool match(ArrayRef<int> Mask) const {
2016 MaskRef = Mask;
2017 return true;
2018 }
2019};
2020
2022 bool match(ArrayRef<int> Mask) const {
2023 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
2024 }
2025};
2026
2030 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
2031};
2032
2034 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
2035};
2036
2040 bool match(ArrayRef<int> Mask) const {
2041 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2042 if (First == Mask.end())
2043 return false;
2044 SplatIndex = *First;
2045 return all_of(Mask,
2046 [First](int Elem) { return Elem == *First || Elem == -1; });
2047 }
2048};
2049
2050template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2051 PointerOpTy PointerOp;
2052 OffsetOpTy OffsetOp;
2053
2054 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2056
2057 template <typename OpTy> bool match(OpTy *V) const {
2058 auto *GEP = dyn_cast<GEPOperator>(V);
2059 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2060 PointerOp.match(GEP->getPointerOperand()) &&
2061 OffsetOp.match(GEP->idx_begin()->get());
2062 }
2063};
2064
2065/// Matches ShuffleVectorInst independently of mask value.
2066template <typename V1_t, typename V2_t>
2068m_Shuffle(const V1_t &v1, const V2_t &v2) {
2070}
2071
2072template <typename V1_t, typename V2_t, typename Mask_t>
2074m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2076}
2077
2078/// Matches LoadInst.
2079template <typename OpTy>
2083
2084/// Matches a simple (non-volatile, non-atomic) LoadInst.
2085template <typename OpTy> struct LoadSimple_match {
2087
2089
2090 template <typename ITy> bool match(ITy *V) const {
2091 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2092 }
2093};
2094
2095template <typename OpTy>
2099
2100/// Matches StoreInst.
2101template <typename ValueOpTy, typename PointerOpTy>
2103m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2105 PointerOp);
2106}
2107
2108/// Matches GetElementPtrInst.
2109template <typename... OperandTypes>
2110inline auto m_GEP(const OperandTypes &...Ops) {
2111 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2112}
2113
2114/// Matches GEP with i8 source element type
2115template <typename PointerOpTy, typename OffsetOpTy>
2117m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2119}
2120
2121//===----------------------------------------------------------------------===//
2122// Matchers for CastInst classes
2123//
2124
2125template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2126 Op_t Op;
2127
2128 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2129
2130 template <typename OpTy> bool match(OpTy *V) const {
2131 if (auto *O = dyn_cast<Operator>(V))
2132 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2133 return false;
2134 }
2135};
2136
2137template <typename Op_t, typename Class> struct CastInst_match {
2138 Op_t Op;
2139
2140 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2141
2142 template <typename OpTy> bool match(OpTy *V) const {
2143 if (auto *I = dyn_cast<Class>(V))
2144 return Op.match(I->getOperand(0));
2145 return false;
2146 }
2147};
2148
2149template <typename Op_t> struct PtrToIntSameSize_match {
2151 Op_t Op;
2152
2153 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2154 : DL(DL), Op(OpMatch) {}
2155
2156 template <typename OpTy> bool match(OpTy *V) const {
2157 if (auto *O = dyn_cast<Operator>(V))
2158 return O->getOpcode() == Instruction::PtrToInt &&
2159 DL.getTypeSizeInBits(O->getType()) ==
2160 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2161 Op.match(O->getOperand(0));
2162 return false;
2163 }
2164};
2165
2166template <typename Op_t> struct NNegZExt_match {
2167 Op_t Op;
2168
2169 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2170
2171 template <typename OpTy> bool match(OpTy *V) const {
2172 if (auto *I = dyn_cast<ZExtInst>(V))
2173 return I->hasNonNeg() && Op.match(I->getOperand(0));
2174 return false;
2175 }
2176};
2177
2178template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2179 Op_t Op;
2180
2181 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2182
2183 template <typename OpTy> bool match(OpTy *V) const {
2184 if (auto *I = dyn_cast<TruncInst>(V))
2185 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2186 Op.match(I->getOperand(0));
2187 return false;
2188 }
2189};
2190
2191/// Matches BitCast.
2192template <typename OpTy>
2197
2198template <typename Op_t> struct ElementWiseBitCast_match {
2199 Op_t Op;
2200
2201 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2202
2203 template <typename OpTy> bool match(OpTy *V) const {
2204 auto *I = dyn_cast<BitCastInst>(V);
2205 if (!I)
2206 return false;
2207 Type *SrcType = I->getSrcTy();
2208 Type *DstType = I->getType();
2209 // Make sure the bitcast doesn't change between scalar and vector and
2210 // doesn't change the number of vector elements.
2211 if (SrcType->isVectorTy() != DstType->isVectorTy())
2212 return false;
2213 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2214 SrcVecTy && SrcVecTy->getElementCount() !=
2215 cast<VectorType>(DstType)->getElementCount())
2216 return false;
2217 return Op.match(I->getOperand(0));
2218 }
2219};
2220
2221template <typename OpTy>
2225
2226/// Matches PtrToInt.
2227template <typename OpTy>
2232
2233template <typename OpTy>
2238
2239/// Matches PtrToAddr.
2240template <typename OpTy>
2245
2246/// Matches PtrToInt or PtrToAddr.
2247template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2249}
2250
2251/// Matches IntToPtr.
2252template <typename OpTy>
2257
2258/// Matches any cast or self. Used to ignore casts.
2259template <typename OpTy>
2264
2265/// Matches Trunc.
2266template <typename OpTy>
2270
2271/// Matches trunc nuw.
2272template <typename OpTy>
2277
2278/// Matches trunc nsw.
2279template <typename OpTy>
2284
2285template <typename OpTy>
2288 return m_CombineOr(m_Trunc(Op), Op);
2289}
2290
2291/// Matches SExt.
2292template <typename OpTy>
2296
2297/// Matches ZExt.
2298template <typename OpTy>
2302
2303template <typename OpTy>
2305 return NNegZExt_match<OpTy>(Op);
2306}
2307
2308template <typename OpTy>
2311 return m_CombineOr(m_ZExt(Op), Op);
2312}
2313
2314template <typename OpTy>
2317 return m_CombineOr(m_SExt(Op), Op);
2318}
2319
2320/// Match either "sext" or "zext nneg".
2321template <typename OpTy>
2324 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2325}
2326
2327template <typename OpTy>
2331 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2332}
2333
2334template <typename OpTy>
2337 OpTy>
2339 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2340}
2341
2342template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2343 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2344}
2345
2346template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2350
2352 : Pred(P), L(Left), R(Right) {}
2353
2354 template <typename OpTy> bool match(OpTy *V) const {
2355 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2356 return true;
2357 Value *A;
2358 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2359 if (V->getType()->isIntOrIntVectorTy(1) &&
2360 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2361 R.match(ConstantInt::getNullValue(A->getType()))) {
2363 return true;
2364 }
2365 return false;
2366 }
2367};
2368
2369template <typename LHS, typename RHS>
2371 const RHS &R) {
2372 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2373}
2374
2375template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2376 CondTy Cond;
2379
2380 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2381 : Cond(C), TrueC(TC), FalseC(FC) {}
2382
2383 template <typename OpTy> bool match(OpTy *V) const {
2384 // select(Cond, TrueC, FalseC) — captures both constants directly
2386 return true;
2387
2388 Type *Ty = V->getType();
2389 Value *CondV = nullptr;
2390
2391 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2392 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2393 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2394 TrueC.match(ConstantInt::get(Ty, 1)) &&
2395 FalseC.match(ConstantInt::get(Ty, 0)))
2396 return true;
2397
2398 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2399 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2400 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2401 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2402 FalseC.match(ConstantInt::get(Ty, 0)))
2403 return true;
2404
2405 return false;
2406 }
2407};
2408
2409/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2410/// select i1 Cond, TrueC, FalseC
2411/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2412/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2413///
2414/// The condition is matched against \p Cond, and the true/false constants
2415/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2416/// constants are bound to \p TrueC and \p FalseC via their matchers.
2417template <typename CondTy, typename LTy, typename RTy>
2419m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2420 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2421}
2422
2423template <typename OpTy>
2427
2428template <typename OpTy>
2432
2433template <typename OpTy>
2436m_IToFP(const OpTy &Op) {
2437 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2438}
2439
2440template <typename OpTy>
2444
2445template <typename OpTy>
2449
2450template <typename OpTy>
2453m_FPToI(const OpTy &Op) {
2454 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2455}
2456
2457template <typename OpTy>
2461
2462template <typename OpTy>
2466
2467//===----------------------------------------------------------------------===//
2468// Matchers for control flow.
2469//
2470
2471struct br_match {
2473
2475
2476 template <typename OpTy> bool match(OpTy *V) const {
2477 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2478 Succ = BI->getSuccessor();
2479 return true;
2480 }
2481 return false;
2482 }
2483};
2484
2485inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2486
2487template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2489 Cond_t Cond;
2490 TrueBlock_t T;
2491 FalseBlock_t F;
2492
2493 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2494 : Cond(C), T(t), F(f) {}
2495
2496 template <typename OpTy> bool match(OpTy *V) const {
2497 if (auto *BI = dyn_cast<CondBrInst>(V))
2498 if (Cond.match(BI->getCondition()))
2499 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2500 return false;
2501 }
2502};
2503
2504template <typename Cond_t>
2510
2511template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2513m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2515}
2516
2517//===----------------------------------------------------------------------===//
2518// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2519//
2520
2521template <typename LHS_t, typename RHS_t, typename Pred_t>
2523 using PredType = Pred_t;
2526
2527 // The evaluation order is always stable, regardless of Commutability.
2528 // The LHS is always matched first.
2529 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2530
2531 template <typename OpTy> bool match(OpTy *V) const {
2532 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2533 auto *SI = dyn_cast<SelectInst>(V);
2534 if (!SI)
2535 return false;
2536 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2537 if (!Cmp)
2538 return false;
2539 // At this point we have a select conditioned on a comparison. Check that
2540 // it is the values returned by the select that are being compared.
2541 auto *TrueVal = SI->getTrueValue();
2542 auto *FalseVal = SI->getFalseValue();
2543 auto *LHS = Cmp->getOperand(0);
2544 auto *RHS = Cmp->getOperand(1);
2545 if ((TrueVal != LHS || FalseVal != RHS) &&
2546 (TrueVal != RHS || FalseVal != LHS))
2547 return false;
2548 FCmpInst::Predicate Pred =
2549 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2550 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2551 if (!Pred_t::match(Pred))
2552 return false;
2553 // It does! Bind the operands.
2554 return L.match(LHS) && R.match(RHS);
2555 }
2556};
2557
2558/// Helper class for identifying ordered max predicates.
2560 static bool match(FCmpInst::Predicate Pred) {
2561 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2562 }
2563};
2564
2565/// Helper class for identifying ordered min predicates.
2567 static bool match(FCmpInst::Predicate Pred) {
2568 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2569 }
2570};
2571
2572/// Helper class for identifying unordered max predicates.
2574 static bool match(FCmpInst::Predicate Pred) {
2575 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2576 }
2577};
2578
2579/// Helper class for identifying unordered min predicates.
2581 static bool match(FCmpInst::Predicate Pred) {
2582 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2583 }
2584};
2585
2586/// Match an 'ordered' floating point maximum function.
2587/// Floating point has one special value 'NaN'. Therefore, there is no total
2588/// order. However, if we can ignore the 'NaN' value (for example, because of a
2589/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2590/// semantics. In the presence of 'NaN' we have to preserve the original
2591/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2592///
2593/// max(L, R) iff L and R are not NaN
2594/// m_OrdFMax(L, R) = R iff L or R are NaN
2595template <typename LHS, typename RHS>
2597 const RHS &R) {
2599}
2600
2601/// Match an 'ordered' floating point minimum function.
2602/// Floating point has one special value 'NaN'. Therefore, there is no total
2603/// order. However, if we can ignore the 'NaN' value (for example, because of a
2604/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2605/// semantics. In the presence of 'NaN' we have to preserve the original
2606/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2607///
2608/// min(L, R) iff L and R are not NaN
2609/// m_OrdFMin(L, R) = R iff L or R are NaN
2610template <typename LHS, typename RHS>
2612 const RHS &R) {
2614}
2615
2616/// Match an 'unordered' floating point maximum function.
2617/// Floating point has one special value 'NaN'. Therefore, there is no total
2618/// order. However, if we can ignore the 'NaN' value (for example, because of a
2619/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2620/// semantics. In the presence of 'NaN' we have to preserve the original
2621/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2622///
2623/// max(L, R) iff L and R are not NaN
2624/// m_UnordFMax(L, R) = L iff L or R are NaN
2625template <typename LHS, typename RHS>
2627 const RHS &R) {
2629}
2630
2631/// Match an 'unordered' floating point minimum function.
2632/// Floating point has one special value 'NaN'. Therefore, there is no total
2633/// order. However, if we can ignore the 'NaN' value (for example, because of a
2634/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2635/// semantics. In the presence of 'NaN' we have to preserve the original
2636/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2637///
2638/// min(L, R) iff L and R are not NaN
2639/// m_UnordFMin(L, R) = L iff L or R are NaN
2640template <typename LHS, typename RHS>
2642 const RHS &R) {
2644}
2645
2646/// Match an 'ordered' or 'unordered' floating point maximum function.
2647/// Floating point has one special value 'NaN'. Therefore, there is no total
2648/// order. However, if we can ignore the 'NaN' value (for example, because of a
2649/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2650/// semantics.
2651template <typename LHS, typename RHS>
2654m_OrdOrUnordFMax(const LHS &L, const RHS &R) {
2657}
2658
2659/// Match an 'ordered' or 'unordered' floating point minimum function.
2660/// Floating point has one special value 'NaN'. Therefore, there is no total
2661/// order. However, if we can ignore the 'NaN' value (for example, because of a
2662/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2663/// semantics.
2664template <typename LHS, typename RHS>
2667m_OrdOrUnordFMin(const LHS &L, const RHS &R) {
2670}
2671
2672/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2673/// NOTE: we first match the 'Not' (by matching '-1'),
2674/// and only then match the inner matcher!
2675template <typename ValTy>
2676inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2677m_Not(const ValTy &V) {
2678 return m_c_Xor(m_AllOnes(), V);
2679}
2680
2681template <typename ValTy>
2682inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2683 true>
2684m_NotForbidPoison(const ValTy &V) {
2685 return m_c_Xor(m_AllOnesForbidPoison(), V);
2686}
2687
2688//===----------------------------------------------------------------------===//
2689// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2690// Note that S might be matched to other instructions than AddInst.
2691//
2692
2693template <typename LHS_t, typename RHS_t, typename Sum_t>
2697 Sum_t S;
2698
2699 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2700 : L(L), R(R), S(S) {}
2701
2702 template <typename OpTy> bool match(OpTy *V) const {
2703 Value *ICmpLHS, *ICmpRHS;
2704 CmpPredicate Pred;
2705 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2706 return false;
2707
2708 Value *AddLHS, *AddRHS;
2709 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2710
2711 // (a + b) u< a, (a + b) u< b
2712 if (Pred == ICmpInst::ICMP_ULT)
2713 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2714 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2715
2716 // a >u (a + b), b >u (a + b)
2717 if (Pred == ICmpInst::ICMP_UGT)
2718 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2719 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2720
2721 Value *Op1;
2722 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2723 // (~a) <u b
2724 if (Pred == ICmpInst::ICMP_ULT) {
2725 if (XorExpr.match(ICmpLHS))
2726 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2727 }
2728 // b > u (~a)
2729 if (Pred == ICmpInst::ICMP_UGT) {
2730 if (XorExpr.match(ICmpRHS))
2731 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2732 }
2733
2734 // Match special-case for increment-by-1.
2735 if (Pred == ICmpInst::ICMP_EQ) {
2736 // (a + 1) == 0
2737 // (1 + a) == 0
2738 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2739 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2740 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2741 // 0 == (a + 1)
2742 // 0 == (1 + a)
2743 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2744 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2745 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2746 }
2747
2748 return false;
2749 }
2750};
2751
2752/// Match an icmp instruction checking for unsigned overflow on addition.
2753///
2754/// S is matched to the addition whose result is being checked for overflow, and
2755/// L and R are matched to the LHS and RHS of S.
2756template <typename LHS_t, typename RHS_t, typename Sum_t>
2758m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2760}
2761
2762template <typename Opnd_t> struct Argument_match {
2763 unsigned OpI;
2764 Opnd_t Val;
2765
2766 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2767
2768 template <typename OpTy> bool match(OpTy *V) const {
2769 // FIXME: Should likely be switched to use `CallBase`.
2770 if (const auto *CI = dyn_cast<CallInst>(V))
2771 return Val.match(CI->getArgOperand(OpI));
2772 return false;
2773 }
2774};
2775
2776/// Match an argument.
2777template <unsigned OpI, typename Opnd_t>
2778inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2779 return Argument_match<Opnd_t>(OpI, Op);
2780}
2781
2782/// Intrinsic matchers.
2784 unsigned ID;
2785
2787
2788 template <typename OpTy> bool match(OpTy *V) const {
2789 if (const auto *CI = dyn_cast<CallInst>(V))
2790 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2791 return F->getIntrinsicID() == ID;
2792 return false;
2793 }
2794};
2795
2796/// Match intrinsic calls with any of the given IDs.
2797template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2798 template <typename OpTy> bool match(OpTy *V) const {
2799 if (const auto *CI = dyn_cast<CallInst>(V))
2800 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2801 Intrinsic::ID ID = F->getIntrinsicID();
2802 return ((ID == IntrIDs) || ...);
2803 }
2804 return false;
2805 }
2806};
2807
2809 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2810 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2811 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2812 }
2813};
2814
2815/// Match intrinsic calls like this:
2816/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2817template <Intrinsic::ID IntrID, typename... Ts>
2818inline auto m_Intrinsic(const Ts &...Ops) {
2820 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2821}
2822
2823/// Match intrinsic calls with any of the given IDs like this:
2824/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2825/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2826/// because it performs the CallInst/Function cast only once.
2827template <Intrinsic::ID... IntrIDs>
2829 return IntrinsicIDs_match<IntrIDs...>();
2830}
2831
2832/// Matches MaskedLoad Intrinsic.
2833template <typename Opnd0, typename Opnd1, typename Opnd2>
2834inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2835 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2836}
2837
2838/// Matches MaskedStore Intrinsic.
2839template <typename Opnd0, typename Opnd1, typename Opnd2>
2840inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2841 const Opnd2 &Op2) {
2842 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2843}
2844
2845/// Matches MaskedGather Intrinsic.
2846template <typename Opnd0, typename Opnd1, typename Opnd2>
2847inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2848 const Opnd2 &Op2) {
2849 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2850}
2851
2852// Helper intrinsic matching specializations.
2853template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2855}
2856
2857template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2859}
2860template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2862}
2863
2864template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2865 return m_Intrinsic<Intrinsic::fabs>(Op0);
2866}
2867
2868template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2870}
2871
2872template <typename Opnd0, typename Opnd1>
2873inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2874 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2875}
2876
2877template <typename Opnd0, typename Opnd1>
2878inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2879 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2880}
2881
2882template <typename Opnd0, typename Opnd1>
2883inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2884 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2885}
2886
2887template <typename Opnd0, typename Opnd1>
2888inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2889 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2890}
2891
2892template <typename Opnd0, typename Opnd1>
2893inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2894 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2895}
2896
2897template <typename Opnd0, typename Opnd1>
2898inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2899 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2900}
2901
2902template <typename Opnd0, typename Opnd1>
2903inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2904 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2905 m_UMin(Op0, Op1));
2906}
2907
2908template <typename Opnd0, typename Opnd1>
2909inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2910 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2911}
2912
2913template <typename Opnd0, typename Opnd1>
2914inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2915 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2916}
2917
2918template <typename Opnd0, typename Opnd1>
2919inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2920 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2921}
2922
2923template <typename Opnd0, typename Opnd1>
2924inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2925 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2926}
2927
2928template <typename Opnd0, typename Opnd1>
2929inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2930 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2931}
2932
2933template <typename Opnd0, typename Opnd1>
2934inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2935 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2936}
2937
2938template <typename Opnd0, typename Opnd1>
2939inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2940 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2941}
2942
2943template <typename Opnd0, typename Opnd1>
2944inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2945 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2946}
2947
2948template <typename Opnd0, typename Opnd1, typename Opnd2>
2949inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2950 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2951}
2952
2953template <typename Opnd0, typename Opnd1, typename Opnd2>
2954inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2955 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2956}
2957
2958template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2959 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2960}
2961
2962template <typename Opnd0, typename Opnd1>
2963inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2964 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2965}
2966
2967template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
2969}
2970
2971template <typename Opnd0, typename Opnd1, typename Opnd2>
2972inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
2973 const Opnd2 &Op2) {
2974 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
2975}
2976
2977//===----------------------------------------------------------------------===//
2978// Matchers for two-operands operators with the operators in either order
2979//
2980
2981/// Matches a BinaryOperator with LHS and RHS in either order.
2982template <typename LHS, typename RHS>
2983inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) {
2985}
2986
2987/// Matches an ICmp with a predicate over LHS and RHS in either order.
2988/// Swaps the predicate if operands are commuted.
2989template <typename LHS, typename RHS>
2991m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
2993}
2994
2995template <typename LHS, typename RHS>
2997 const RHS &R) {
2999}
3000
3001/// Matches a specific opcode with LHS and RHS in either order.
3002template <typename LHS, typename RHS>
3004m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
3005 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
3006}
3007
3008/// Matches a Add with LHS and RHS in either order.
3009template <typename LHS, typename RHS>
3014
3015/// Matches a Mul with LHS and RHS in either order.
3016template <typename LHS, typename RHS>
3021
3022/// Matches an And with LHS and RHS in either order.
3023template <typename LHS, typename RHS>
3028
3029/// Matches an Or with LHS and RHS in either order.
3030template <typename LHS, typename RHS>
3032 const RHS &R) {
3034}
3035
3036/// Matches an Xor with LHS and RHS in either order.
3037template <typename LHS, typename RHS>
3042
3043/// Matches a 'Neg' as 'sub 0, V'.
3044template <typename ValTy>
3045inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3046m_Neg(const ValTy &V) {
3047 return m_Sub(m_ZeroInt(), V);
3048}
3049
3050/// Matches a 'Neg' as 'sub nsw 0, V'.
3051template <typename ValTy>
3053 Instruction::Sub,
3055m_NSWNeg(const ValTy &V) {
3056 return m_NSWSub(m_ZeroInt(), V);
3057}
3058
3059template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3061 LHS L;
3062 RHS R;
3063
3064 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3065
3066 template <typename OpTy> bool match(OpTy *V) const {
3067 const auto *II = dyn_cast<IntrinsicInst>(V);
3068 if (!II || II->getIntrinsicID() != IntrID)
3069 return false;
3070 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3071 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3072 }
3073};
3074
3075template <Intrinsic::ID IntrID, typename T0, typename T1>
3077m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3079}
3080
3081/// Matches an SMin with LHS and RHS in either order.
3082template <typename LHS, typename RHS>
3083inline auto m_c_SMin(const LHS &L, const RHS &R) {
3084 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3085}
3086/// Matches an SMax with LHS and RHS in either order.
3087template <typename LHS, typename RHS>
3088inline auto m_c_SMax(const LHS &L, const RHS &R) {
3089 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3090}
3091/// Matches a UMin with LHS and RHS in either order.
3092template <typename LHS, typename RHS>
3093inline auto m_c_UMin(const LHS &L, const RHS &R) {
3094 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3095}
3096/// Matches a UMax with LHS and RHS in either order.
3097template <typename LHS, typename RHS>
3098inline auto m_c_UMax(const LHS &L, const RHS &R) {
3099 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3100}
3101
3102template <typename LHS, typename RHS>
3103inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3104 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3105 m_c_UMin(L, R));
3106}
3107
3108/// Matches FAdd with LHS and RHS in either order.
3109template <typename LHS, typename RHS>
3111m_c_FAdd(const LHS &L, const RHS &R) {
3113}
3114
3115/// Matches FMul with LHS and RHS in either order.
3116template <typename LHS, typename RHS>
3118m_c_FMul(const LHS &L, const RHS &R) {
3120}
3121
3122template <typename Opnd_t> struct Signum_match {
3123 Opnd_t Val;
3124 Signum_match(const Opnd_t &V) : Val(V) {}
3125
3126 template <typename OpTy> bool match(OpTy *V) const {
3127 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3128 if (TypeSize == 0)
3129 return false;
3130
3131 unsigned ShiftWidth = TypeSize - 1;
3132 Value *Op;
3133
3134 // This is the representation of signum we match:
3135 //
3136 // signum(x) == (x >> 63) | (-x >>u 63)
3137 //
3138 // An i1 value is its own signum, so it's correct to match
3139 //
3140 // signum(x) == (x >> 0) | (-x >>u 0)
3141 //
3142 // for i1 values.
3143
3144 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3145 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3146 auto Signum = m_c_Or(LHS, RHS);
3147
3148 return Signum.match(V) && Val.match(Op);
3149 }
3150};
3151
3152/// Matches a signum pattern.
3153///
3154/// signum(x) =
3155/// x > 0 -> 1
3156/// x == 0 -> 0
3157/// x < 0 -> -1
3158template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3159 return Signum_match<Val_t>(V);
3160}
3161
3162template <int Ind, typename Opnd_t> struct ExtractValue_match {
3163 Opnd_t Val;
3164 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3165
3166 template <typename OpTy> bool match(OpTy *V) const {
3167 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3168 // If Ind is -1, don't inspect indices
3169 if (Ind != -1 &&
3170 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3171 return false;
3172 return Val.match(I->getAggregateOperand());
3173 }
3174 return false;
3175 }
3176};
3177
3178/// Match a single index ExtractValue instruction.
3179/// For example m_ExtractValue<1>(...)
3180template <int Ind, typename Val_t>
3184
3185/// Match an ExtractValue instruction with any index.
3186/// For example m_ExtractValue(...)
3187template <typename Val_t>
3188inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3189 return ExtractValue_match<-1, Val_t>(V);
3190}
3191
3192/// Matcher for a single index InsertValue instruction.
3193template <int Ind, typename T0, typename T1> struct InsertValue_match {
3196
3197 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3198
3199 template <typename OpTy> bool match(OpTy *V) const {
3200 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3201 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3202 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3203 }
3204 return false;
3205 }
3206};
3207
3208/// Matches a single index InsertValue instruction.
3209template <int Ind, typename Val_t, typename Elt_t>
3211 const Elt_t &Elt) {
3212 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3213}
3214
3215/// Matches a call to `llvm.vscale()`.
3216inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3217
3218template <typename Opnd0, typename Opnd1>
3219inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3221}
3222
3223template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3225}
3226
3227template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3229 LHS L;
3230 RHS R;
3231
3232 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3233
3234 template <typename T> bool match(T *V) const {
3235 auto *I = dyn_cast<Instruction>(V);
3236 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3237 return false;
3238
3239 if (I->getOpcode() == Opcode) {
3240 auto *Op0 = I->getOperand(0);
3241 auto *Op1 = I->getOperand(1);
3242 return (L.match(Op0) && R.match(Op1)) ||
3243 (Commutable && L.match(Op1) && R.match(Op0));
3244 }
3245
3246 if (auto *Select = dyn_cast<SelectInst>(I)) {
3247 auto *Cond = Select->getCondition();
3248 auto *TVal = Select->getTrueValue();
3249 auto *FVal = Select->getFalseValue();
3250
3251 // Don't match a scalar select of bool vectors.
3252 // Transforms expect a single type for operands if this matches.
3253 if (Cond->getType() != Select->getType())
3254 return false;
3255
3256 if (Opcode == Instruction::And) {
3257 auto *C = dyn_cast<Constant>(FVal);
3258 if (C && C->isNullValue())
3259 return (L.match(Cond) && R.match(TVal)) ||
3260 (Commutable && L.match(TVal) && R.match(Cond));
3261 } else {
3262 assert(Opcode == Instruction::Or);
3263 auto *C = dyn_cast<Constant>(TVal);
3264 if (C && C->isOneValue())
3265 return (L.match(Cond) && R.match(FVal)) ||
3266 (Commutable && L.match(FVal) && R.match(Cond));
3267 }
3268 }
3269
3270 return false;
3271 }
3272};
3273
3274/// Matches L && R either in the form of L & R or L ? R : false.
3275/// Note that the latter form is poison-blocking.
3276template <typename LHS, typename RHS>
3278 const RHS &R) {
3280}
3281
3282/// Matches L && R where L and R are arbitrary values.
3283inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3284
3285/// Matches L && R with LHS and RHS in either order.
3286template <typename LHS, typename RHS>
3288m_c_LogicalAnd(const LHS &L, const RHS &R) {
3290}
3291
3292/// Matches L || R either in the form of L | R or L ? true : R.
3293/// Note that the latter form is poison-blocking.
3294template <typename LHS, typename RHS>
3296 const RHS &R) {
3298}
3299
3300/// Matches L || R where L and R are arbitrary values.
3301inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3302
3303/// Matches L || R with LHS and RHS in either order.
3304template <typename LHS, typename RHS>
3306m_c_LogicalOr(const LHS &L, const RHS &R) {
3308}
3309
3310/// Matches either L && R or L || R,
3311/// either one being in the either binary or logical form.
3312/// Note that the latter form is poison-blocking.
3313template <typename LHS, typename RHS, bool Commutable = false>
3319
3320/// Matches either L && R or L || R where L and R are arbitrary values.
3321inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3322
3323/// Matches either L && R or L || R with LHS and RHS in either order.
3324template <typename LHS, typename RHS>
3325inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3326 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3327}
3328
3329} // end namespace PatternMatch
3330} // end namespace llvm
3331
3332#endif // LLVM_IR_PATTERNMATCH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition Compiler.h:215
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Hexagon Common GEP
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
Class for arbitrary precision integers.
Definition APInt.h:78
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
Definition APInt.h:1577
static bool isSameValue(const APInt &I1, const APInt &I2, bool SignedCompare=false)
Determine if two APInts have the same value, after zero-extending or sign-extending (if SignedCompare...
Definition APInt.h:555
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static LLVM_ABI CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
static LLVM_ABI CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
Base class for aggregate constants (with operands).
Definition Constants.h:565
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1316
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
bool isShift() const
A wrapper class for inspecting calls to intrinsic functions.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:263
'undef' values are things that do not have specified contents.
Definition Constants.h:1631
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
Base class of all SIMD vector types.
Represents an op.with.overflow intrinsic.
An efficient, type-erasing, non-owning reference to a callable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
match_combine_and< Ty... > m_CombineAnd(const Ty &...Ps)
Combine pattern matchers matching all of Ps patterns.
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
match_bind< PHINode > m_Phi(PHINode *&PN)
Match a PHI node, capturing it if we match.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
auto m_BSwap(const Opnd0 &Op0)
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
ShiftLike_match< LHS, Instruction::LShr > m_LShrOrSelf(const LHS &L, uint64_t &R)
Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
AllowFmf_match< T, FastMathFlags::NoSignedZeros > m_NoSignedZeros(const T &SubPattern)
auto m_Cmp()
Matches any compare instruction and ignore it.
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
auto m_BitReverse(const Opnd0 &Op0)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
auto m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
AllowFmf_match< T, FastMathFlags::NoInfs > m_NoInfs(const T &SubPattern)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
auto m_PtrToIntOrAddr(const OpTy &Op)
Matches PtrToInt or PtrToAddr.
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap, true > m_c_NSWAdd(const LHS &L, const RHS &R)
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, CastInst >, OpTy > m_CastOrSelf(const OpTy &Op)
Matches any cast or self. Used to ignore casts.
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
CommutativeBinaryIntrinsic_match< IntrID, T0, T1 > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
auto m_Poison()
Match an arbitrary poison constant.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
ap_match< APFloat > m_APFloatForbidPoison(const APFloat *&Res)
Match APFloat while forbidding poison in splat vector constants.
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
br_match m_UnconditionalBr(BasicBlock *&Succ)
CastOperator_match< OpTy, Instruction::PtrToAddr > m_PtrToAddr(const OpTy &Op)
Matches PtrToAddr.
auto m_Sqrt(const Opnd0 &Op0)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
auto m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
LoadSimple_match< OpTy > m_LoadSimple(const OpTy &Op)
bool match(Val *V, const Pattern &P)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
match_bind< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1)
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
cstval_pred_ty< Predicate, ConstantInt, AllowPoison > cst_pred_ty
specialization of cstval_pred_ty for ConstantInt
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
cstfp_pred_ty< is_signed_inf< true > > m_NegInf()
Match a negative infinity FP constant.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
auto m_c_XorLike(const LHS &L, const RHS &R)
Match either (xor L, R), (xor R, L) or (sub nuw R, L) iff R.isMask() Only commutative matcher as the ...
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
ap_match< APFloat > m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
ap_match< APFloat > m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
auto match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true > m_c_NUWAdd(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWNeg(const ValTy &V)
Matches a 'Neg' as 'sub nsw 0, V'.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
cstfp_pred_ty< is_finite > m_Finite()
Match a finite FP constant, i.e.
FMaxMin_match< LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R, either one being in the either binary or logical form.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
auto m_BinOp()
Match an arbitrary binary operation and ignore it.
auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< CastInst_match< OpTy, SExtInst >, OpTy > m_SExtOrSelf(const OpTy &Op)
FMaxMin_match< LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
InsertValue_match< Ind, Val_t, Elt_t > m_InsertValue(const Val_t &Val, const Elt_t &Elt)
Matches a single index InsertValue instruction.
auto m_BasicBlock()
Match an arbitrary basic block value and ignore it.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
match_combine_or< CastInst_match< OpTy, UIToFPInst >, CastInst_match< OpTy, SIToFPInst > > m_IToFP(const OpTy &Op)
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1)
ICmpLike_match< LHS, RHS > m_ICmpLike(CmpPredicate &Pred, const LHS &L, const RHS &R)
CastInst_match< OpTy, FPToUIInst > m_FPToUI(const OpTy &Op)
auto m_Value()
Match an arbitrary value and ignore it.
ShiftLike_match< LHS, Instruction::Shl > m_ShlOrSelf(const LHS &L, uint64_t &R)
Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
auto m_Ctpop(const Opnd0 &Op0)
auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1)
SpecificCmpClass_match< LHS, RHS, CmpInst > m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
auto m_SpecificType(Type *RefTy, const Pattern &P)
Match a value of a specific type.
auto m_UndefValue()
Match an arbitrary UndefValue constant.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
auto m_Constant()
Match an arbitrary Constant and ignore it.
ContainsMatchingVectorElement_match< SPTy > m_ContainsMatchingVectorElement(const SPTy &SubPattern)
Match a vector constant where at least one of its elements matches the subpattern.
NoWrapTrunc_match< OpTy, TruncInst::NoSignedWrap > m_NSWTrunc(const OpTy &Op)
Matches trunc nsw.
match_combine_or< match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
OneUse_match< T > m_OneUse(const T &SubPattern)
NNegZExt_match< OpTy > m_NNegZExt(const OpTy &Op)
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
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)
SpecificType_match(const Type *, const Pattern &) -> SpecificType_match< Pattern >
cstfp_pred_ty< is_signed_inf< false > > m_PosInf()
Match a positive infinity FP constant.
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
match_immconstant_ty m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
cst_pred_ty< is_negated_power2_or_zero > m_NegatedPower2OrZero()
Match a integer or vector negated power-of-2.
auto m_ZExtOrTruncOrSelf(const OpTy &Op)
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
ShiftLike_match< LHS, Instruction::AShr > m_AShrOrSelf(const LHS &L, uint64_t &R)
Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
cst_pred_ty< custom_checkfn< APInt > > m_CheckedInt(function_ref< bool(const APInt &)> CheckFn)
Match an integer or vector where CheckFn(ele) for each element is true.
SelectLike_match< CondTy, LTy, RTy > m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC)
Matches a value that behaves like a boolean-controlled select, i.e.
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
SpecificCmpClass_match< LHS, RHS, FCmpInst > m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)
Match either "add" or "or disjoint".
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
cstval_pred_ty< Predicate, ConstantFP, true > cstfp_pred_ty
specialization of cstval_pred_ty for ConstantFP
auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< CastInst_match< OpTy, SExtInst >, NNegZExt_match< OpTy > > m_SExtLike(const OpTy &Op)
Match either "sext" or "zext nneg".
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
auto m_Deinterleave2(const Opnd &Op)
auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedStore Intrinsic.
auto m_c_MaxOrMin(const LHS &L, const RHS &R)
cstfp_pred_ty< custom_checkfn< APFloat > > m_CheckedFp(function_ref< bool(const APFloat &)> CheckFn)
Match a float or vector where CheckFn(ele) for each element is true.
auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedLoad Intrinsic.
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
auto m_FAbs(const Opnd0 &Op0)
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap >, DisjointOr_match< LHS, RHS > > m_NSWAddLike(const LHS &L, const RHS &R)
Match either "add nsw" or "or disjoint".
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
match_combine_or< FMaxMin_match< LHS, RHS, ofmax_pred_ty >, FMaxMin_match< LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
Exact_match< T > m_Exact(const T &SubPattern)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
auto m_UnOp()
Match an arbitrary unary operation and ignore it.
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
UAddWithOverflow_match< LHS_t, RHS_t, Sum_t > m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Match an icmp instruction checking for unsigned overflow on addition.
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
auto m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
ThreeOps_match< Cond, constantint_match< L >, constantint_match< R >, Instruction::Select > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.: m_SelectCst<-1, 0>(m_Value(V))
auto m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
AllowFmf_match< T, FastMathFlags::AllowContract > m_AllowContract(const T &SubPattern)
CastInst_match< OpTy, FPTruncInst > m_FPTrunc(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
auto m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
auto m_VecReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap >, DisjointOr_match< LHS, RHS > > m_NUWAddLike(const LHS &L, const RHS &R)
Match either "add nuw" or "or disjoint".
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
auto m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
SpecificCmpClass_match< LHS, RHS, ICmpInst, true > m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
AllowFmf_match< T, FastMathFlags::AllowReciprocal > m_AllowReciprocal(const T &SubPattern)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
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)
SpecificType_match(Type *RefTy, const Pattern &P)
Splat_match(const SubPattern_t &SP)
Matches instructions with Opcode and three operands.
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
Matches instructions with Opcode and three operands.
TwoOps_match(const T0 &Op1, const T1 &Op2)
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
XorLike_match(const LHS &L, const RHS &R)
ap_match(const APTy *&Res, bool AllowPoison)
std::conditional_t< std::is_same_v< APTy, APInt >, ConstantInt, ConstantFP > ConstantTy
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
This helper class is used to match scalar and vector constants that satisfy a specified predicate,...
bool match(OpTy *V) const
br_match(BasicBlock *&Succ)
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
This helper class is used to match constant scalars, vector splats, and fixed width vectors that sati...
bool isValue(const APTy &C) const
function_ref< bool(const APTy &)> CheckFn
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isOpType(unsigned Opcode) const
bool isValue(const APFloat &C) const
bool isValue(const APFloat &C) const
bool isOpType(unsigned Opcode) const
bool isValue(const APFloat &C) const
bool isOpType(unsigned Opcode) const
bool isOpType(unsigned Opcode) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isOpType(unsigned Opcode) const
bool isOpType(unsigned Opcode) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool isValue(const APFloat &C) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
bool match(ITy *V) const
ArrayRef< int > & MaskRef
m_Mask(ArrayRef< int > &MaskRef)
bool match(ArrayRef< int > Mask) const
bool match(ArrayRef< int > Mask) const
m_SpecificMask(ArrayRef< int > Val)
bool match(ArrayRef< int > Mask) const
bool match(ArrayRef< int > Mask) const
bool match(ArrayRef< int > Mask) const
Helper class for identifying ordered max predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying ordered min predicates.
static bool match(FCmpInst::Predicate Pred)
Match a specified basic block value.
Match a specified floating point value or vector of all elements of that value.
Match a specified integer value or vector of all elements of that value.
Matcher for specified Value*.
Helper class for identifying unordered max predicates.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying unordered min predicates.
static bool match(FCmpInst::Predicate Pred)
static bool check(const Value *V)