LLVM 24.0.0git
PatternMatch.h
Go to the documentation of this file.
1//===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides a simple and efficient mechanism for performing general
10// tree-based pattern matches on the LLVM IR. The power of these routines is
11// that it allows you to write concise patterns that are expressive and easy to
12// understand. The other major advantage of this is that it allows you to
13// trivially capture/bind elements in the pattern to variables. For example,
14// you can do something like this:
15//
16// Value *Exp = ...
17// Value *X, *Y; ConstantInt *C1, *C2; // (X & C1) | (Y & C2)
18// if (match(Exp, m_Or(m_And(m_Value(X), m_ConstantInt(C1)),
19// m_And(m_Value(Y), m_ConstantInt(C2))))) {
20// ... Pattern is matched and variables are bound ...
21// }
22//
23// This is primarily useful to things like the instruction combiner, but can
24// also be useful for static analysis tools or code generators.
25//
26//===----------------------------------------------------------------------===//
27
28#ifndef LLVM_IR_PATTERNMATCH_H
29#define LLVM_IR_PATTERNMATCH_H
30
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/APInt.h"
33#include "llvm/IR/Constant.h"
34#include "llvm/IR/Constants.h"
35#include "llvm/IR/DataLayout.h"
36#include "llvm/IR/FMF.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
41#include "llvm/IR/Intrinsics.h"
42#include "llvm/IR/Operator.h"
43#include "llvm/IR/Value.h"
46#include <cstdint>
47#include <utility>
48
49namespace llvm {
50namespace PatternMatch {
51
52using namespace llvm::PatternMatchHelpers;
53
54template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
55 return P.match(V);
56}
57
58/// A match functor that can be used as a UnaryPredicate in functional
59/// algorithms like all_of.
60template <typename Val = const Value, typename Pattern>
61auto match_fn(const Pattern &P) {
63}
64
65template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
66 return P.match(Mask);
67}
68
69template <typename SubPattern_t> struct OneUse_match {
70 SubPattern_t SubPattern;
71
72 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
73
74 template <typename OpTy> bool match(OpTy *V) const {
75 return V->hasOneUse() && SubPattern.match(V);
76 }
77};
78
79template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
80 return SubPattern;
81}
82
83template <typename SubPattern_t, int Flag> struct AllowFmf_match {
84 SubPattern_t SubPattern;
86
87 AllowFmf_match(const SubPattern_t &SP) : SubPattern(SP), FMF(Flag) {}
88
89 template <typename OpTy> bool match(OpTy *V) const {
90 auto *I = dyn_cast<FPMathOperator>(V);
91 return I && ((I->getFastMathFlags() & FMF) == FMF) && SubPattern.match(I);
92 }
93};
94
95template <typename T>
97m_AllowReassoc(const T &SubPattern) {
98 return SubPattern;
99}
100
101template <typename T>
103m_AllowReciprocal(const T &SubPattern) {
104 return SubPattern;
105}
106
107template <typename T>
109m_AllowContract(const T &SubPattern) {
110 return SubPattern;
111}
112
113template <typename T>
115m_ApproxFunc(const T &SubPattern) {
116 return SubPattern;
117}
118
119template <typename T>
121 return SubPattern;
122}
123
124template <typename T>
126 return SubPattern;
127}
128
129template <typename T>
131m_NoSignedZeros(const T &SubPattern) {
132 return SubPattern;
133}
134
135/// Match an arbitrary value and ignore it.
136inline auto m_Value() { return m_Isa<Value>(); }
137
138/// Match an arbitrary unary operation and ignore it.
139inline auto m_UnOp() { return m_Isa<UnaryOperator>(); }
140
141/// Match an arbitrary binary operation and ignore it.
142inline auto m_BinOp() { return m_Isa<BinaryOperator>(); }
143
144/// Matches any compare instruction and ignore it.
145inline auto m_Cmp() { return m_Isa<CmpInst>(); }
146
147/// Matches any intrinsic call and ignore it.
148inline auto m_AnyIntrinsic() { return m_Isa<IntrinsicInst>(); }
149
151private:
152 LLVM_ABI static bool checkAggregate(const ConstantAggregate *CA);
153
154public:
155 static bool check(const Value *V) {
156 if (isa<UndefValue>(V))
157 return true;
158 if (const auto *CA = dyn_cast<ConstantAggregate>(V))
159 return checkAggregate(CA);
160 return false;
161 }
162 template <typename ITy> bool match(ITy *V) const { return check(V); }
163};
164
165/// Match an arbitrary undef constant. This matches poison as well.
166/// If this is an aggregate and contains a non-aggregate element that is
167/// neither undef nor poison, the aggregate is not matched.
168inline auto m_Undef() { return undef_match(); }
169
170/// Match an arbitrary UndefValue constant.
171inline auto m_UndefValue() { return m_Isa<UndefValue>(); }
172
173/// Match an arbitrary poison constant.
174inline auto m_Poison() { return m_Isa<PoisonValue>(); }
175
176/// Match an arbitrary Constant and ignore it.
177inline auto m_Constant() { return m_Isa<Constant>(); }
178
179/// Match an arbitrary ConstantInt and ignore it.
180inline auto m_ConstantInt() { return m_Isa<ConstantInt>(); }
181
182/// Match an arbitrary ConstantFP and ignore it.
183inline auto m_ConstantFP() { return m_Isa<ConstantFP>(); }
184
185template <typename SPTy> struct ContainsMatchingVectorElement_match {
188
189 template <typename ITy> bool match(ITy *V) const {
190 auto *C = dyn_cast<Constant>(V);
191 return C && C->containsMatchingVectorElement(
192 [&](Constant *E) { return SubPattern.match(E); });
193 }
194};
195
196/// Match a vector constant where at least one of its elements matches the
197/// subpattern. Scalable vector constants are not matched. Any bindings in the
198/// subpattern will be bound to the first match.
199template <typename SPTy>
201m_ContainsMatchingVectorElement(const SPTy &SubPattern) {
202 return SubPattern;
203}
204
205/// Match a constant expression or a constant that contains a constant
206/// expression.
211
212template <typename SubPattern_t> struct Splat_match {
213 SubPattern_t SubPattern;
214 Splat_match(const SubPattern_t &SP) : SubPattern(SP) {}
215
216 template <typename OpTy> bool match(OpTy *V) const {
217 if (auto *C = dyn_cast<Constant>(V)) {
218 auto *Splat = C->getSplatValue();
219 return Splat ? SubPattern.match(Splat) : false;
220 }
221 // 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
235template <typename APTy> struct ap_match {
236 static_assert(std::is_same_v<APTy, APInt> || std::is_same_v<APTy, APFloat>);
238 std::conditional_t<std::is_same_v<APTy, APInt>, ConstantInt, ConstantFP>;
239
240 const APTy *&Res;
242
243 ap_match(const APTy *&Res, bool AllowPoison)
245
246 template <typename ITy> bool match(ITy *V) const {
247 if (auto *CI = dyn_cast<ConstantTy>(V)) {
248 Res = &CI->getValue();
249 return true;
250 }
251 if (V->getType()->isVectorTy())
252 if (const auto *C = dyn_cast<Constant>(V))
253 if (auto *CI =
254 dyn_cast_or_null<ConstantTy>(C->getSplatValue(AllowPoison))) {
255 Res = &CI->getValue();
256 return true;
257 }
258 return false;
259 }
260};
261
262/// Match a ConstantInt or splatted ConstantVector, binding the
263/// specified pointer to the contained APInt.
264inline ap_match<APInt> m_APInt(const APInt *&Res) {
265 // Forbid poison by default to maintain previous behavior.
266 return ap_match<APInt>(Res, /* AllowPoison */ false);
267}
268
269/// Match APInt while allowing poison in splat vector constants.
271 return ap_match<APInt>(Res, /* AllowPoison */ true);
272}
273
274/// Match APInt while forbidding poison in splat vector constants.
276 return ap_match<APInt>(Res, /* AllowPoison */ false);
277}
278
279/// Match a ConstantFP or splatted ConstantVector, binding the
280/// specified pointer to the contained APFloat.
282 // Forbid undefs by default to maintain previous behavior.
283 return ap_match<APFloat>(Res, /* AllowPoison */ false);
284}
285
286/// Match APFloat while allowing poison in splat vector constants.
288 return ap_match<APFloat>(Res, /* AllowPoison */ true);
289}
290
291/// Match APFloat while forbidding poison in splat vector constants.
293 return ap_match<APFloat>(Res, /* AllowPoison */ false);
294}
295
296template <int64_t Val> struct constantint_match {
297 template <typename ITy> bool match(ITy *V) const {
298 if (const auto *CI = dyn_cast<ConstantInt>(V)) {
299 const APInt &CIV = CI->getValue();
300 if (Val >= 0)
301 return CIV == static_cast<uint64_t>(Val);
302 // If Val is negative, and CI is shorter than it, truncate to the right
303 // number of bits. If it is larger, then we have to sign extend. Just
304 // compare their negated values.
305 return -CIV == -Val;
306 }
307 return false;
308 }
309};
310
311/// Match a ConstantInt with a specific value.
312template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
313 return constantint_match<Val>();
314}
315
316/// This helper class is used to match constant scalars, vector splats,
317/// and fixed width vectors that satisfy a specified predicate.
318/// For fixed width vector constants, poison elements are ignored if AllowPoison
319/// is true.
320template <typename Predicate, typename ConstantVal, bool AllowPoison>
321struct cstval_pred_ty : public Predicate {
322private:
323 bool matchVector(const Value *V) const {
324 if (const auto *C = dyn_cast<Constant>(V)) {
325 if (const auto *CV = dyn_cast_or_null<ConstantVal>(C->getSplatValue()))
326 return this->isValue(CV->getValue());
327
328 // Number of elements of a scalable vector unknown at compile time
329 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
330 if (!FVTy)
331 return false;
332
333 // Non-splat vector constant: check each element for a match.
334 unsigned NumElts = FVTy->getNumElements();
335 assert(NumElts != 0 && "Constant vector with no elements?");
336 bool HasNonPoisonElements = false;
337 for (unsigned i = 0; i != NumElts; ++i) {
338 Constant *Elt = C->getAggregateElement(i);
339 if (!Elt)
340 return false;
341 if (AllowPoison && isa<PoisonValue>(Elt))
342 continue;
343 auto *CV = dyn_cast<ConstantVal>(Elt);
344 if (!CV || !this->isValue(CV->getValue()))
345 return false;
346 HasNonPoisonElements = true;
347 }
348 return HasNonPoisonElements;
349 }
350 return false;
351 }
352
353public:
354 const Constant **Res = nullptr;
355 template <typename ITy> bool match_impl(ITy *V) const {
356 if (const auto *CV = dyn_cast<ConstantVal>(V))
357 return this->isValue(CV->getValue());
358 if (isa<VectorType>(V->getType()))
359 return matchVector(V);
360 return false;
361 }
362
363 template <typename ITy> bool match(ITy *V) const {
364 if (this->match_impl(V)) {
365 if (Res)
366 *Res = cast<Constant>(V);
367 return true;
368 }
369 return false;
370 }
371};
372
373/// specialization of cstval_pred_ty for ConstantInt
374template <typename Predicate, bool AllowPoison = true>
376
377/// specialization of cstval_pred_ty for ConstantFP
378template <typename Predicate>
380 /*AllowPoison=*/true>;
381
382/// This helper class is used to match scalar and vector constants that
383/// satisfy a specified predicate, and bind them to an APInt.
384template <typename Predicate> struct api_pred_ty : public Predicate {
385 const APInt *&Res;
386
387 api_pred_ty(const APInt *&R) : Res(R) {}
388
389 template <typename ITy> bool match(ITy *V) const {
390 if (const auto *CI = dyn_cast<ConstantInt>(V))
391 if (this->isValue(CI->getValue())) {
392 Res = &CI->getValue();
393 return true;
394 }
395 if (V->getType()->isVectorTy())
396 if (const auto *C = dyn_cast<Constant>(V))
397 if (auto *CI = dyn_cast_or_null<ConstantInt>(
398 C->getSplatValue(/*AllowPoison=*/true)))
399 if (this->isValue(CI->getValue())) {
400 Res = &CI->getValue();
401 return true;
402 }
403
404 return false;
405 }
406};
407
408/// This helper class is used to match scalar and vector constants that
409/// satisfy a specified predicate, and bind them to an APFloat.
410/// Poison is allowed in splat vector constants.
411template <typename Predicate> struct apf_pred_ty : public Predicate {
412 const APFloat *&Res;
413
414 apf_pred_ty(const APFloat *&R) : Res(R) {}
415
416 template <typename ITy> bool match(ITy *V) const {
417 if (const auto *CI = dyn_cast<ConstantFP>(V))
418 if (this->isValue(CI->getValue())) {
419 Res = &CI->getValue();
420 return true;
421 }
422 if (V->getType()->isVectorTy())
423 if (const auto *C = dyn_cast<Constant>(V))
424 if (auto *CI = dyn_cast_or_null<ConstantFP>(
425 C->getSplatValue(/* AllowPoison */ true)))
426 if (this->isValue(CI->getValue())) {
427 Res = &CI->getValue();
428 return true;
429 }
430
431 return false;
432 }
433};
434
435///////////////////////////////////////////////////////////////////////////////
436//
437// Encapsulate constant value queries for use in templated predicate matchers.
438// This allows checking if constants match using compound predicates and works
439// with vector constants, possibly with relaxed constraints. For example, ignore
440// undef values.
441//
442///////////////////////////////////////////////////////////////////////////////
443
444template <typename APTy> struct custom_checkfn {
445 function_ref<bool(const APTy &)> CheckFn;
446 bool isValue(const APTy &C) const { return CheckFn(C); }
447};
448
449/// Match an integer or vector where CheckFn(ele) for each element is true.
450/// For vectors, poison elements are assumed to match.
452m_CheckedInt(function_ref<bool(const APInt &)> CheckFn) {
453 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}};
454}
455
457m_CheckedInt(const Constant *&V, function_ref<bool(const APInt &)> CheckFn) {
458 return cst_pred_ty<custom_checkfn<APInt>>{{CheckFn}, &V};
459}
460
461/// Match a float or vector where CheckFn(ele) for each element is true.
462/// For vectors, poison elements are assumed to match.
464m_CheckedFp(function_ref<bool(const APFloat &)> CheckFn) {
465 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}};
466}
467
469m_CheckedFp(const Constant *&V, function_ref<bool(const APFloat &)> CheckFn) {
470 return cstfp_pred_ty<custom_checkfn<APFloat>>{{CheckFn}, &V};
471}
472
474 bool isValue(const APInt &C) const { return true; }
475};
476/// Match an integer or vector with any integral constant.
477/// For vectors, this includes constants with undefined elements.
481
483 bool isValue(const APInt &C) const { return C.isShiftedMask(); }
484};
485
489
491 bool isValue(const APInt &C) const { return C.isAllOnes(); }
492};
493/// Match an integer or vector with all bits set.
494/// For vectors, this includes constants with undefined elements.
498
502
503inline auto m_AllOnesOrPoison() { return m_CombineOr(m_AllOnes(), m_Poison()); }
504
506 bool isValue(const APInt &C) const { return C.isMaxSignedValue(); }
507};
508/// Match an integer or vector with values having all bits except for the high
509/// bit set (0x7f...).
510/// For vectors, this includes constants with undefined elements.
515 return V;
516}
517
519 bool isValue(const APInt &C) const { return C.isNegative(); }
520};
521/// Match an integer or vector of negative values.
522/// For vectors, this includes constants with undefined elements.
526inline api_pred_ty<is_negative> m_Negative(const APInt *&V) { return V; }
527
529 bool isValue(const APInt &C) const { return C.isNonNegative(); }
530};
531/// Match an integer or vector of non-negative values.
532/// For vectors, this includes constants with undefined elements.
536inline api_pred_ty<is_nonnegative> m_NonNegative(const APInt *&V) { return V; }
537
539 bool isValue(const APInt &C) const { return C.isStrictlyPositive(); }
540};
541/// Match an integer or vector of strictly positive values.
542/// For vectors, this includes constants with undefined elements.
547 return V;
548}
549
551 bool isValue(const APInt &C) const { return C.isNonPositive(); }
552};
553/// Match an integer or vector of non-positive values.
554/// For vectors, this includes constants with undefined elements.
558inline api_pred_ty<is_nonpositive> m_NonPositive(const APInt *&V) { return V; }
559
560struct is_one {
561 bool isValue(const APInt &C) const { return C.isOne(); }
562};
563/// Match an integer 1 or a vector with all elements equal to 1.
564/// For vectors, this includes constants with undefined elements.
566
568 bool isValue(const APInt &C) const { return C.isZero(); }
569};
570/// Match an integer 0 or a vector with all elements equal to 0.
571/// For vectors, this includes constants with undefined elements.
575
577 bool isValue(const APInt &C) const { return !C.isZero(); }
578};
579/// Match a non-zero integer or a vector with all non-zero elements.
580/// For vectors, this includes constants with undefined elements.
584
585struct is_zero {
586 template <typename ITy> bool match(ITy *V) const {
587 auto *C = dyn_cast<Constant>(V);
588 // FIXME: this should be able to do something for scalable vectors
589 return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C));
590 }
591};
592/// Match any null constant or a vector with all elements equal to 0.
593/// For vectors, this includes constants with undefined elements.
594inline is_zero m_Zero() { return is_zero(); }
595
596inline auto m_ZeroOrPoison() { return m_CombineOr(m_Zero(), m_Poison()); }
597
598struct is_power2 {
599 bool isValue(const APInt &C) const { return C.isPowerOf2(); }
600};
601/// Match an integer or vector power-of-2.
602/// For vectors, this includes constants with undefined elements.
604inline api_pred_ty<is_power2> m_Power2(const APInt *&V) { return V; }
605
607 bool isValue(const APInt &C) const { return C.isNegatedPowerOf2(); }
608};
609/// Match a integer or vector negated power-of-2.
610/// For vectors, this includes constants with undefined elements.
615 return V;
616}
617
619 bool isValue(const APInt &C) const { return !C || C.isNegatedPowerOf2(); }
620};
621/// Match a integer or vector negated power-of-2.
622/// For vectors, this includes constants with undefined elements.
628 return V;
629}
630
632 bool isValue(const APInt &C) const { return !C || C.isPowerOf2(); }
633};
634/// Match an integer or vector of 0 or power-of-2 values.
635/// For vectors, this includes constants with undefined elements.
640 return V;
641}
642
644 bool isValue(const APInt &C) const { return C.isSignMask(); }
645};
646/// Match an integer or vector with only the sign bit(s) set.
647/// For vectors, this includes constants with undefined elements.
651
653 bool isValue(const APInt &C) const { return C.isMask(); }
654};
655/// Match an integer or vector with only the low bit(s) set.
656/// For vectors, this includes constants with undefined elements.
660inline api_pred_ty<is_lowbit_mask> m_LowBitMask(const APInt *&V) { return V; }
661
663 bool isValue(const APInt &C) const { return !C || C.isMask(); }
664};
665/// Match an integer or vector with only the low bit(s) set.
666/// For vectors, this includes constants with undefined elements.
671 return V;
672}
673
676 const APInt *Thr;
677 bool isValue(const APInt &C) const {
678 return ICmpInst::compare(C, *Thr, Pred);
679 }
680};
681/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
682/// to Threshold. For vectors, this includes constants with undefined elements.
686 P.Pred = Predicate;
687 P.Thr = &Threshold;
688 return P;
689}
690
691/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
692/// to Threshold. For vectors, this includes constants with undefined elements.
695 const APInt &Threshold) {
697 P.Pred = Predicate;
698 P.Thr = &Threshold;
699 return P;
700}
701
702struct is_nan {
703 bool isValue(const APFloat &C) const { return C.isNaN(); }
704};
705/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
706/// For vectors, this includes constants with undefined elements.
708
709struct is_nonnan {
710 bool isValue(const APFloat &C) const { return !C.isNaN(); }
711};
712/// Match a non-NaN FP constant.
713/// For vectors, this includes constants with undefined elements.
717
718struct is_inf {
719 bool isValue(const APFloat &C) const { return C.isInfinity(); }
720};
721/// Match a positive or negative infinity FP constant.
722/// For vectors, this includes constants with undefined elements.
724
725template <bool IsNegative> struct is_signed_inf {
726 bool isValue(const APFloat &C) const {
727 return C.isInfinity() && IsNegative == C.isNegative();
728 }
729};
730
731/// Match a positive infinity FP constant.
732/// For vectors, this includes constants with undefined elements.
736
737/// Match a negative infinity FP constant.
738/// For vectors, this includes constants with undefined elements.
742
743struct is_noninf {
744 bool isValue(const APFloat &C) const { return !C.isInfinity(); }
745};
746/// Match a non-infinity FP constant, i.e. finite or NaN.
747/// For vectors, this includes constants with undefined elements.
751
752struct is_finite {
753 bool isValue(const APFloat &C) const { return C.isFinite(); }
754};
755/// Match a finite FP constant, i.e. not infinity or NaN.
756/// For vectors, this includes constants with undefined elements.
760inline apf_pred_ty<is_finite> m_Finite(const APFloat *&V) { return V; }
761
763 bool isValue(const APFloat &C) const { return C.isFiniteNonZero(); }
764};
765/// Match a finite non-zero FP constant.
766/// For vectors, this includes constants with undefined elements.
771 return V;
772}
773
775 bool isValue(const APFloat &C) const { return C.isZero(); }
776};
777/// Match a floating-point negative zero or positive zero.
778/// For vectors, this includes constants with undefined elements.
782
784 bool isValue(const APFloat &C) const { return C.isPosZero(); }
785};
786/// Match a floating-point positive zero.
787/// For vectors, this includes constants with undefined elements.
791
793 bool isValue(const APFloat &C) const { return C.isNegZero(); }
794};
795/// Match a floating-point negative zero.
796/// For vectors, this includes constants with undefined elements.
800
802 bool isValue(const APFloat &C) const { return C.isNonZero(); }
803};
804/// Match a floating-point non-zero.
805/// For vectors, this includes constants with undefined elements.
809
811 bool isValue(const APFloat &C) const {
812 return !C.isDenormal() && C.isNonZero();
813 }
814};
815
816/// Match a floating-point non-zero that is not a denormal.
817/// For vectors, this includes constants with undefined elements.
821
822///////////////////////////////////////////////////////////////////////////////
823
824/// Match a value, capturing it if we match.
825inline match_bind<Value> m_Value(Value *&V) { return V; }
826inline match_bind<const Value> m_Value(const Value *&V) { return V; }
827
828/// Match against the nested pattern, and capture the value if we match.
829template <typename Pattern> inline auto m_Value(Value *&V, const Pattern &P) {
830 return m_CombineAnd(P, match_bind<Value>(V));
831}
832
833/// Match against the nested pattern, and capture the value if we match.
834template <typename Pattern>
835inline auto m_Value(const Value *&V, const Pattern &P) {
837}
838
839/// Match an instruction, capturing it if we match.
842 return I;
843}
844
845/// Match against the nested pattern, and capture the instruction if we match.
846template <typename Pattern>
847inline auto m_Instruction(Instruction *&I, const Pattern &P) {
849}
850template <typename Pattern>
851inline auto m_Instruction(const Instruction *&I, const Pattern &P) {
853}
854
855/// Match a unary operator, capturing it if we match.
858 return I;
859}
860/// Match a binary operator, capturing it if we match.
863 return I;
864}
865/// Match any intrinsic call, capturing it if we match.
870/// Match a with overflow intrinsic, capturing it if we match.
876 return I;
877}
878
879/// Match a PHI node, capturing it if we match.
880inline match_bind<PHINode> m_Phi(PHINode *&PN) { return PN; }
881
882/// Match an UndefValue, capturing the value if we match.
884
885/// Match a Constant, capturing the value if we match.
887
888/// Match a ConstantInt, capturing the value if we match.
890
891/// Match a ConstantFP, capturing the value if we match.
893
894/// Match a ConstantExpr, capturing the value if we match.
896
897/// Match a basic block value, capturing it if we match.
900 return V;
901}
902
903// TODO: Remove once UseConstant{Int,FP}ForScalableSplat is enabled by default,
904// and use m_Unless(m_ConstantExpr).
906 template <typename ITy> static bool isImmConstant(ITy *V) {
907 if (auto *CV = dyn_cast<Constant>(V)) {
908 if (!match(CV, m_ConstantExpr()))
909 return true;
910
911 if (CV->getType()->isVectorTy()) {
912 if (auto *Splat = CV->getSplatValue(/*AllowPoison=*/true)) {
913 if (!match(Splat, m_ConstantExpr())) {
914 return true;
915 }
916 }
917 }
918 }
919 return false;
920 }
921};
922
924 template <typename ITy> bool match(ITy *V) const { return isImmConstant(V); }
925};
926
927/// Match an arbitrary immediate Constant and ignore it.
929
932
934
935 template <typename ITy> bool match(ITy *V) const {
936 if (isImmConstant(V)) {
937 VR = cast<Constant>(V);
938 return true;
939 }
940 return false;
941 }
942};
943
944/// Match an immediate Constant, capturing the value if we match.
948
949/// Matcher for specified Value*.
951 const Value *Val;
952
953 specificval_ty(const Value *V) : Val(V) {}
954
955 template <typename ITy> bool match(ITy *V) const { return V == Val; }
956};
957
958/// Match if we have a specific specified value.
959inline specificval_ty m_Specific(const Value *V) { return V; }
960
961/// Like m_Specific(), but works if the specific value to match is determined
962/// as part of the same match() expression. For example:
963/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
964/// bind X before the pattern match starts.
965/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
966/// whichever value m_Value(X) populated.
967inline match_deferred<Value> m_Deferred(Value *const &V) { return V; }
969 return V;
970}
971
972/// Match a specified floating point value or vector of all elements of
973/// that value.
975 double Val;
976
977 specific_fpval(double V) : Val(V) {}
978
979 template <typename ITy> bool match(ITy *V) const {
980 if (const auto *CFP = dyn_cast<ConstantFP>(V))
981 return CFP->isExactlyValue(Val);
982 if (V->getType()->isVectorTy())
983 if (const auto *C = dyn_cast<Constant>(V))
984 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
985 return CFP->isExactlyValue(Val);
986 return false;
987 }
988};
989
990/// Match a specific floating point value or vector with all elements
991/// equal to the value.
992inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
993
994/// Match a float 1.0 or vector with all elements equal to 1.0.
995inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
996
999
1001
1002 template <typename ITy> bool match(ITy *V) const {
1003 const APInt *ConstInt;
1004 if (!ap_match<APInt>(ConstInt, /*AllowPoison=*/false).match(V))
1005 return false;
1006 std::optional<uint64_t> ZExtVal = ConstInt->tryZExtValue();
1007 if (!ZExtVal)
1008 return false;
1009 VR = *ZExtVal;
1010 return true;
1011 }
1012};
1013
1014/// Match a specified integer value or vector of all elements of that
1015/// value.
1016template <bool AllowPoison> struct specific_intval {
1017 const APInt &Val;
1018
1019 specific_intval(const APInt &V) : Val(V) {}
1020
1021 template <typename ITy> bool match(ITy *V) const {
1022 const auto *CI = dyn_cast<ConstantInt>(V);
1023 if (!CI && V->getType()->isVectorTy())
1024 if (const auto *C = dyn_cast<Constant>(V))
1025 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1026
1027 return CI && APInt::isSameValue(CI->getValue(), Val);
1028 }
1029};
1030
1031template <bool AllowPoison> struct specific_intval64 {
1033
1035
1036 template <typename ITy> bool match(ITy *V) const {
1037 const auto *CI = dyn_cast<ConstantInt>(V);
1038 if (!CI && V->getType()->isVectorTy())
1039 if (const auto *C = dyn_cast<Constant>(V))
1040 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowPoison));
1041
1042 return CI && CI->getValue() == Val;
1043 }
1044};
1045
1046/// Match a specific integer value or vector with all elements equal to
1047/// the value.
1049 return specific_intval<false>(V);
1050}
1051
1055
1059
1063
1064/// Match a ConstantInt and bind to its value. This does not match
1065/// ConstantInts wider than 64-bits.
1067
1068/// Match a specified basic block value.
1071
1073
1074 template <typename ITy> bool match(ITy *V) const {
1075 const auto *BB = dyn_cast<BasicBlock>(V);
1076 return BB && BB == Val;
1077 }
1078};
1079
1080/// Match a specific basic block value.
1082 return specific_bbval(BB);
1083}
1084
1085/// A commutative-friendly version of m_Specific().
1087 return BB;
1088}
1090m_Deferred(const BasicBlock *const &BB) {
1091 return BB;
1092}
1093
1094template <typename Pattern> struct SpecificType_match {
1097
1099
1100 template <typename ITy> bool match(ITy *V) const {
1101 return V->getType() == RefTy && P.match(V);
1102 }
1103};
1104
1105// Explicit deduction guide.
1106template <typename Pattern>
1109
1110/// Match a value of a specific type.
1111template <typename Pattern>
1112inline auto m_SpecificType(Type *RefTy, const Pattern &P) {
1113 return SpecificType_match<Pattern>(RefTy, P);
1114}
1115inline auto m_SpecificType(Type *RefTy) {
1116 return m_SpecificType(RefTy, m_Value());
1117}
1118
1119/// Match a value of a specific type, capturing it if we match.
1120inline auto m_SpecificType(Type *RefTy, Value *&V) {
1121 return m_SpecificType(RefTy, m_Value(V));
1122}
1123inline auto m_SpecificType(Type *RefTy, const Value *&V) {
1124 return m_SpecificType(RefTy, m_Value(V));
1125}
1126
1127//===----------------------------------------------------------------------===//
1128// Matcher for any binary operator.
1129//
1130template <typename LHS_t, typename RHS_t, bool Commutable = false>
1134
1135 // The evaluation order is always stable, regardless of Commutability.
1136 // The LHS is always matched first.
1137 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1138
1139 template <typename OpTy> bool match(OpTy *V) const {
1140 if (auto *I = dyn_cast<BinaryOperator>(V))
1141 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1142 (Commutable && L.match(I->getOperand(1)) &&
1143 R.match(I->getOperand(0)));
1144 return false;
1145 }
1146};
1147
1148template <typename LHS, typename RHS>
1149inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
1150 return AnyBinaryOp_match<LHS, RHS>(L, R);
1151}
1152
1153//===----------------------------------------------------------------------===//
1154// Matcher for any unary operator.
1155// TODO fuse unary, binary matcher into n-ary matcher
1156//
1157template <typename OP_t> struct AnyUnaryOp_match {
1158 OP_t X;
1159
1160 AnyUnaryOp_match(const OP_t &X) : X(X) {}
1161
1162 template <typename OpTy> bool match(OpTy *V) const {
1163 if (auto *I = dyn_cast<UnaryOperator>(V))
1164 return X.match(I->getOperand(0));
1165 return false;
1166 }
1167};
1168
1169template <typename OP_t> inline AnyUnaryOp_match<OP_t> m_UnOp(const OP_t &X) {
1170 return AnyUnaryOp_match<OP_t>(X);
1171}
1172
1173//===----------------------------------------------------------------------===//
1174// Matchers for specific binary operators.
1175//
1176
1177template <typename LHS_t, typename RHS_t, unsigned Opcode,
1178 bool Commutable = false>
1182
1183 // The evaluation order is always stable, regardless of Commutability.
1184 // The LHS is always matched first.
1185 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1186
1187 template <typename OpTy> inline bool match(unsigned Opc, OpTy *V) const {
1188 if (V->getValueID() == Value::InstructionVal + Opc) {
1189 auto *I = cast<BinaryOperator>(V);
1190 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1191 (Commutable && L.match(I->getOperand(1)) &&
1192 R.match(I->getOperand(0)));
1193 }
1194 return false;
1195 }
1196
1197 template <typename OpTy> bool match(OpTy *V) const {
1198 return match(Opcode, V);
1199 }
1200};
1201
1202template <typename LHS, typename RHS>
1207
1208template <typename LHS, typename RHS>
1213
1214template <typename LHS, typename RHS>
1219
1220template <typename LHS, typename RHS>
1225
1226template <typename Op_t> struct FNeg_match {
1227 Op_t X;
1228
1229 FNeg_match(const Op_t &Op) : X(Op) {}
1230 template <typename OpTy> bool match(OpTy *V) const {
1231 auto *FPMO = dyn_cast<FPMathOperator>(V);
1232 if (!FPMO)
1233 return false;
1234
1235 if (FPMO->getOpcode() == Instruction::FNeg)
1236 return X.match(FPMO->getOperand(0));
1237
1238 if (FPMO->getOpcode() == Instruction::FSub) {
1239 if (FPMO->hasNoSignedZeros()) {
1240 // With 'nsz', any zero goes.
1241 if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
1242 return false;
1243 } else {
1244 // Without 'nsz', we need fsub -0.0, X exactly.
1245 if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
1246 return false;
1247 }
1248
1249 return X.match(FPMO->getOperand(1));
1250 }
1251
1252 return false;
1253 }
1254};
1255
1256/// Match 'fneg X' as 'fsub -0.0, X'.
1257template <typename OpTy> inline FNeg_match<OpTy> m_FNeg(const OpTy &X) {
1258 return FNeg_match<OpTy>(X);
1259}
1260
1261/// Match 'fneg X' as 'fsub +-0.0, X'.
1262template <typename RHS>
1263inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
1264m_FNegNSZ(const RHS &X) {
1265 return m_FSub(m_AnyZeroFP(), X);
1266}
1267
1268template <typename LHS, typename RHS>
1273
1274template <typename LHS, typename RHS>
1279
1280template <typename LHS, typename RHS>
1285
1286template <typename LHS, typename RHS>
1291
1292template <typename LHS, typename RHS>
1297
1298template <typename LHS, typename RHS>
1303
1304template <typename LHS, typename RHS>
1309
1310template <typename LHS, typename RHS>
1315
1316template <typename LHS, typename RHS>
1321
1322template <typename LHS, typename RHS>
1327
1328template <typename LHS, typename RHS>
1333
1334template <typename LHS, typename RHS>
1339
1340template <typename LHS, typename RHS>
1345
1346template <typename LHS, typename RHS>
1351
1352template <typename LHS_t, unsigned Opcode> struct ShiftLike_match {
1355
1357
1358 template <typename OpTy> bool match(OpTy *V) const {
1359 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1360 if (Op->getOpcode() == Opcode)
1361 return m_ConstantInt(R).match(Op->getOperand(1)) &&
1362 L.match(Op->getOperand(0));
1363 }
1364 // Interpreted as shiftop V, 0
1365 R = 0;
1366 return L.match(V);
1367 }
1368};
1369
1370/// Matches shl L, ConstShAmt or L itself (R will be set to zero in this case).
1371template <typename LHS>
1376
1377/// Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
1378template <typename LHS>
1383
1384/// Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
1385template <typename LHS>
1390
1391template <typename LHS_t, typename RHS_t, unsigned Opcode,
1392 unsigned WrapFlags = 0, bool Commutable = false>
1396
1398 : L(LHS), R(RHS) {}
1399
1400 template <typename OpTy> bool match(OpTy *V) const {
1401 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
1402 if (Op->getOpcode() != Opcode)
1403 return false;
1405 !Op->hasNoUnsignedWrap())
1406 return false;
1407 if ((WrapFlags & OverflowingBinaryOperator::NoSignedWrap) &&
1408 !Op->hasNoSignedWrap())
1409 return false;
1410 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1411 (Commutable && L.match(Op->getOperand(1)) &&
1412 R.match(Op->getOperand(0)));
1413 }
1414 return false;
1415 }
1416};
1417
1418template <typename LHS, typename RHS>
1419inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1421m_NSWAdd(const LHS &L, const RHS &R) {
1422 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1424 R);
1425}
1426template <typename LHS, typename RHS>
1427inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1429m_c_NSWAdd(const LHS &L, const RHS &R) {
1430 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1432 true>(L, R);
1433}
1434template <typename LHS, typename RHS>
1435inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1437m_NSWSub(const LHS &L, const RHS &R) {
1438 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1440 R);
1441}
1442template <typename LHS, typename RHS>
1443inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1445m_NSWMul(const LHS &L, const RHS &R) {
1446 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1448 R);
1449}
1450template <typename LHS, typename RHS>
1451inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1453m_NSWShl(const LHS &L, const RHS &R) {
1454 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1456 R);
1457}
1458
1459template <typename LHS, typename RHS>
1460inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1462m_NUWAdd(const LHS &L, const RHS &R) {
1463 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1465 L, R);
1466}
1467
1468template <typename LHS, typename RHS>
1470 LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap, true>
1471m_c_NUWAdd(const LHS &L, const RHS &R) {
1472 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1474 true>(L, R);
1475}
1476
1477template <typename LHS, typename RHS>
1478inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1480m_NUWSub(const LHS &L, const RHS &R) {
1481 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
1483 L, R);
1484}
1485template <typename LHS, typename RHS>
1486inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1488m_NUWMul(const LHS &L, const RHS &R) {
1489 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
1491 L, R);
1492}
1493template <typename LHS, typename RHS>
1494inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1496m_NUWShl(const LHS &L, const RHS &R) {
1497 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
1499 L, R);
1500}
1501
1502template <typename LHS_t, typename RHS_t, bool Commutable = false>
1504 : public BinaryOp_match<LHS_t, RHS_t, 0, Commutable> {
1505 unsigned Opcode;
1506
1508 : BinaryOp_match<LHS_t, RHS_t, 0, Commutable>(LHS, RHS), Opcode(Opcode) {}
1509
1510 template <typename OpTy> bool match(OpTy *V) const {
1512 }
1513};
1514
1515/// Matches a specific opcode.
1516template <typename LHS, typename RHS>
1517inline SpecificBinaryOp_match<LHS, RHS> m_BinOp(unsigned Opcode, const LHS &L,
1518 const RHS &R) {
1519 return SpecificBinaryOp_match<LHS, RHS>(Opcode, L, R);
1520}
1521
1522template <typename LHS, typename RHS, bool Commutable = false>
1526
1527 DisjointOr_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1528
1529 template <typename OpTy> bool match(OpTy *V) const {
1530 if (auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1531 assert(PDI->getOpcode() == Instruction::Or && "Only or can be disjoint");
1532 if (!PDI->isDisjoint())
1533 return false;
1534 return (L.match(PDI->getOperand(0)) && R.match(PDI->getOperand(1))) ||
1535 (Commutable && L.match(PDI->getOperand(1)) &&
1536 R.match(PDI->getOperand(0)));
1537 }
1538 return false;
1539 }
1540};
1541
1542template <typename LHS, typename RHS>
1544 return DisjointOr_match<LHS, RHS>(L, R);
1545}
1546
1547template <typename LHS, typename RHS>
1549 const RHS &R) {
1551}
1552
1553/// Match either "add" or "or disjoint".
1554template <typename LHS, typename RHS>
1557m_AddLike(const LHS &L, const RHS &R) {
1558 return m_CombineOr(m_Add(L, R), m_DisjointOr(L, R));
1559}
1560
1561/// Match either "add nsw" or "or disjoint"
1562template <typename LHS, typename RHS>
1563inline match_combine_or<
1564 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1567m_NSWAddLike(const LHS &L, const RHS &R) {
1568 return m_CombineOr(m_NSWAdd(L, R), m_DisjointOr(L, R));
1569}
1570
1571/// Match either "add nuw" or "or disjoint"
1572template <typename LHS, typename RHS>
1573inline match_combine_or<
1574 OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
1577m_NUWAddLike(const LHS &L, const RHS &R) {
1578 return m_CombineOr(m_NUWAdd(L, R), m_DisjointOr(L, R));
1579}
1580
1581template <typename LHS, typename RHS>
1585
1586 XorLike_match(const LHS &L, const RHS &R) : L(L), R(R) {}
1587
1588 template <typename OpTy> bool match(OpTy *V) const {
1589 if (auto *Op = dyn_cast<BinaryOperator>(V)) {
1590 if (Op->getOpcode() == Instruction::Sub && Op->hasNoUnsignedWrap() &&
1591 PatternMatch::match(Op->getOperand(0), m_LowBitMask()))
1592 ; // Pass
1593 else if (Op->getOpcode() != Instruction::Xor)
1594 return false;
1595 return (L.match(Op->getOperand(0)) && R.match(Op->getOperand(1))) ||
1596 (L.match(Op->getOperand(1)) && R.match(Op->getOperand(0)));
1597 }
1598 return false;
1599 }
1600};
1601
1602/// Match either `(xor L, R)`, `(xor R, L)` or `(sub nuw R, L)` iff `R.isMask()`
1603/// Only commutative matcher as the `sub` will need to swap the L and R.
1604template <typename LHS, typename RHS>
1605inline auto m_c_XorLike(const LHS &L, const RHS &R) {
1606 return XorLike_match<LHS, RHS>(L, R);
1607}
1608
1609//===----------------------------------------------------------------------===//
1610// Class that matches a group of binary opcodes.
1611//
1612template <typename LHS_t, typename RHS_t, typename Predicate,
1613 bool Commutable = false>
1614struct BinOpPred_match : Predicate {
1617
1618 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1619
1620 template <typename OpTy> bool match(OpTy *V) const {
1621 if (auto *I = dyn_cast<Instruction>(V))
1622 return this->isOpType(I->getOpcode()) &&
1623 ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
1624 (Commutable && L.match(I->getOperand(1)) &&
1625 R.match(I->getOperand(0))));
1626 return false;
1627 }
1628};
1629
1631 bool isOpType(unsigned Opcode) const { return Instruction::isShift(Opcode); }
1632};
1633
1635 bool isOpType(unsigned Opcode) const {
1636 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1637 }
1638};
1639
1641 bool isOpType(unsigned Opcode) const {
1642 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1643 }
1644};
1645
1647 bool isOpType(unsigned Opcode) const {
1648 return Instruction::isBitwiseLogicOp(Opcode);
1649 }
1650};
1651
1653 bool isOpType(unsigned Opcode) const {
1654 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1655 }
1656};
1657
1659 bool isOpType(unsigned Opcode) const {
1660 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1661 }
1662};
1663
1664/// Matches shift operations.
1665template <typename LHS, typename RHS>
1667 const RHS &R) {
1669}
1670
1671/// Matches logical shift operations.
1672template <typename LHS, typename RHS>
1677
1678/// Matches logical shift operations.
1679template <typename LHS, typename RHS>
1681m_LogicalShift(const LHS &L, const RHS &R) {
1683}
1684
1685/// Matches bitwise logic operations.
1686template <typename LHS, typename RHS>
1688m_BitwiseLogic(const LHS &L, const RHS &R) {
1690}
1691
1692/// Matches bitwise logic operations in either order.
1693template <typename LHS, typename RHS>
1698
1699/// Matches integer division operations.
1700template <typename LHS, typename RHS>
1702 const RHS &R) {
1704}
1705
1706/// Matches integer remainder operations.
1707template <typename LHS, typename RHS>
1709 const RHS &R) {
1711}
1712
1713//===----------------------------------------------------------------------===//
1714// Class that matches exact binary ops.
1715//
1716template <typename SubPattern_t> struct Exact_match {
1717 SubPattern_t SubPattern;
1718
1719 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
1720
1721 template <typename OpTy> bool match(OpTy *V) const {
1722 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1723 return PEO->isExact() && SubPattern.match(V);
1724 return false;
1725 }
1726};
1727
1728template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
1729 return SubPattern;
1730}
1731
1732//===----------------------------------------------------------------------===//
1733// Matchers for CmpInst classes
1734//
1735
1736template <typename LHS_t, typename RHS_t, typename Class,
1737 bool Commutable = false>
1742
1743 // The evaluation order is always stable, regardless of Commutability.
1744 // The LHS is always matched first.
1746 : Predicate(&Pred), L(LHS), R(RHS) {}
1748 : Predicate(nullptr), L(LHS), R(RHS) {}
1749
1750 template <typename OpTy> bool match(OpTy *V) const {
1751 if (auto *I = dyn_cast<Class>(V)) {
1752 if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1753 if (Predicate)
1755 return true;
1756 }
1757 if (Commutable && L.match(I->getOperand(1)) &&
1758 R.match(I->getOperand(0))) {
1759 if (Predicate)
1761 return true;
1762 }
1763 }
1764 return false;
1765 }
1766};
1767
1768template <typename LHS, typename RHS>
1770 const RHS &R) {
1771 return CmpClass_match<LHS, RHS, CmpInst>(Pred, L, R);
1772}
1773
1774template <typename LHS, typename RHS>
1776 const LHS &L, const RHS &R) {
1777 return CmpClass_match<LHS, RHS, ICmpInst>(Pred, L, R);
1778}
1779
1780template <typename LHS, typename RHS>
1782 const LHS &L, const RHS &R) {
1783 return CmpClass_match<LHS, RHS, FCmpInst>(Pred, L, R);
1784}
1785
1786template <typename LHS, typename RHS>
1789}
1790
1791template <typename LHS, typename RHS>
1794}
1795
1796template <typename LHS, typename RHS>
1799}
1800
1801// Same as CmpClass, but instead of saving Pred as out output variable, match a
1802// specific input pred for equality.
1803template <typename LHS_t, typename RHS_t, typename Class,
1804 bool Commutable = false>
1809
1811 : Predicate(Pred), L(LHS), R(RHS) {}
1812
1813 template <typename OpTy> bool match(OpTy *V) const {
1814 if (auto *I = dyn_cast<Class>(V)) {
1816 L.match(I->getOperand(0)) && R.match(I->getOperand(1)))
1817 return true;
1818 if constexpr (Commutable) {
1821 L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1822 return true;
1823 }
1824 }
1825
1826 return false;
1827 }
1828};
1829
1830template <typename LHS, typename RHS>
1832m_SpecificCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1833 return SpecificCmpClass_match<LHS, RHS, CmpInst>(MatchPred, L, R);
1834}
1835
1836template <typename LHS, typename RHS>
1838m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1839 return SpecificCmpClass_match<LHS, RHS, ICmpInst>(MatchPred, L, R);
1840}
1841
1842template <typename LHS, typename RHS>
1844m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1846}
1847
1848template <typename LHS, typename RHS>
1850m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R) {
1851 return SpecificCmpClass_match<LHS, RHS, FCmpInst>(MatchPred, L, R);
1852}
1853
1854//===----------------------------------------------------------------------===//
1855// Matchers for instructions with a given opcode and number of operands.
1856//
1857
1858/// Matches instructions with Opcode and three operands.
1859template <typename T0, unsigned Opcode> struct OneOps_match {
1861
1862 OneOps_match(const T0 &Op1) : Op1(Op1) {}
1863
1864 template <typename OpTy> bool match(OpTy *V) const {
1865 if (V->getValueID() == Value::InstructionVal + Opcode) {
1866 auto *I = cast<Instruction>(V);
1867 return Op1.match(I->getOperand(0));
1868 }
1869 return false;
1870 }
1871};
1872
1873/// Matches instructions with Opcode and three operands.
1874template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1877
1878 TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1879
1880 template <typename OpTy> bool match(OpTy *V) const {
1881 if (V->getValueID() == Value::InstructionVal + Opcode) {
1882 auto *I = cast<Instruction>(V);
1883 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1884 }
1885 return false;
1886 }
1887};
1888
1889/// Matches instructions with Opcode and three operands.
1890template <typename T0, typename T1, typename T2, unsigned Opcode,
1891 bool CommutableOp2Op3 = false>
1896
1897 ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1898 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1899
1900 template <typename OpTy> bool match(OpTy *V) const {
1901 if (V->getValueID() == Value::InstructionVal + Opcode) {
1902 auto *I = cast<Instruction>(V);
1903 if (!Op1.match(I->getOperand(0)))
1904 return false;
1905 if (Op2.match(I->getOperand(1)) && Op3.match(I->getOperand(2)))
1906 return true;
1907 return CommutableOp2Op3 && Op2.match(I->getOperand(2)) &&
1908 Op3.match(I->getOperand(1));
1909 }
1910 return false;
1911 }
1912};
1913
1914/// Matches instructions with Opcode and any number of operands
1915template <unsigned Opcode, typename... OperandTypes> struct AnyOps_match {
1916 std::tuple<OperandTypes...> Operands;
1917
1918 AnyOps_match(const OperandTypes &...Ops) : Operands(Ops...) {}
1919
1920 // Operand matching works by recursively calling match_operands, matching the
1921 // operands left to right. The first version is called for each operand but
1922 // the last, for which the second version is called. The second version of
1923 // match_operands is also used to match each individual operand.
1924 template <int Idx, int Last>
1925 std::enable_if_t<Idx != Last, bool>
1929
1930 template <int Idx, int Last>
1931 std::enable_if_t<Idx == Last, bool>
1933 return std::get<Idx>(Operands).match(I->getOperand(Idx));
1934 }
1935
1936 template <typename OpTy> bool match(OpTy *V) const {
1937 if (V->getValueID() == Value::InstructionVal + Opcode) {
1938 auto *I = cast<Instruction>(V);
1939 return I->getNumOperands() == sizeof...(OperandTypes) &&
1940 match_operands<0, sizeof...(OperandTypes) - 1>(I);
1941 }
1942 return false;
1943 }
1944};
1945
1946/// Matches SelectInst.
1947template <typename Cond, typename LHS, typename RHS>
1949m_Select(const Cond &C, const LHS &L, const RHS &R) {
1951}
1952
1953/// This matches a select of two constants, e.g.:
1954/// m_SelectCst<-1, 0>(m_Value(V))
1955template <int64_t L, int64_t R, typename Cond>
1957 Instruction::Select>
1960}
1961
1962/// Match Select(C, LHS, RHS) or Select(C, RHS, LHS)
1963template <typename LHS, typename RHS>
1964inline ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select, true>
1965m_c_Select(const LHS &L, const RHS &R) {
1966 return ThreeOps_match<decltype(m_Value()), LHS, RHS, Instruction::Select,
1967 true>(m_Value(), L, R);
1968}
1969
1970/// Matches FreezeInst.
1971template <typename OpTy>
1975
1976/// Matches InsertElementInst.
1977template <typename Val_t, typename Elt_t, typename Idx_t>
1979m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1981 Val, Elt, Idx);
1982}
1983
1984/// Matches ExtractElementInst.
1985template <typename Val_t, typename Idx_t>
1987m_ExtractElt(const Val_t &Val, const Idx_t &Idx) {
1989}
1990
1991/// Matches shuffle.
1992template <typename T0, typename T1, typename T2> struct Shuffle_match {
1996
1997 Shuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
1998 : Op1(Op1), Op2(Op2), Mask(Mask) {}
1999
2000 template <typename OpTy> bool match(OpTy *V) const {
2001 if (auto *I = dyn_cast<ShuffleVectorInst>(V)) {
2002 return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
2003 Mask.match(I->getShuffleMask());
2004 }
2005 return false;
2006 }
2007};
2008
2009struct m_Mask {
2012 bool match(ArrayRef<int> Mask) const {
2013 MaskRef = Mask;
2014 return true;
2015 }
2016};
2017
2019 bool match(ArrayRef<int> Mask) const {
2020 return all_of(Mask, [](int Elem) { return Elem == 0 || Elem == -1; });
2021 }
2022};
2023
2027 bool match(ArrayRef<int> Mask) const { return Val == Mask; }
2028};
2029
2031 bool match(ArrayRef<int> Mask) const { return all_equal(Mask); }
2032};
2033
2037 bool match(ArrayRef<int> Mask) const {
2038 const auto *First = find_if(Mask, [](int Elem) { return Elem != -1; });
2039 if (First == Mask.end())
2040 return false;
2041 SplatIndex = *First;
2042 return all_of(Mask,
2043 [First](int Elem) { return Elem == *First || Elem == -1; });
2044 }
2045};
2046
2047template <typename PointerOpTy, typename OffsetOpTy> struct PtrAdd_match {
2048 PointerOpTy PointerOp;
2049 OffsetOpTy OffsetOp;
2050
2051 PtrAdd_match(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
2053
2054 template <typename OpTy> bool match(OpTy *V) const {
2055 auto *GEP = dyn_cast<GEPOperator>(V);
2056 return GEP && GEP->getSourceElementType()->isIntegerTy(8) &&
2057 PointerOp.match(GEP->getPointerOperand()) &&
2058 OffsetOp.match(GEP->idx_begin()->get());
2059 }
2060};
2061
2062/// Matches ShuffleVectorInst independently of mask value.
2063template <typename V1_t, typename V2_t>
2065m_Shuffle(const V1_t &v1, const V2_t &v2) {
2067}
2068
2069template <typename V1_t, typename V2_t, typename Mask_t>
2071m_Shuffle(const V1_t &v1, const V2_t &v2, const Mask_t &mask) {
2073}
2074
2075/// Matches LoadInst.
2076template <typename OpTy>
2080
2081/// Matches a simple (non-volatile, non-atomic) LoadInst.
2082template <typename OpTy> struct LoadSimple_match {
2084
2086
2087 template <typename ITy> bool match(ITy *V) const {
2088 return Base.match(V) && cast<LoadInst>(V)->isSimple();
2089 }
2090};
2091
2092template <typename OpTy>
2096
2097/// Matches StoreInst.
2098template <typename ValueOpTy, typename PointerOpTy>
2100m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
2102 PointerOp);
2103}
2104
2105/// Matches GetElementPtrInst.
2106template <typename... OperandTypes>
2107inline auto m_GEP(const OperandTypes &...Ops) {
2108 return AnyOps_match<Instruction::GetElementPtr, OperandTypes...>(Ops...);
2109}
2110
2111/// Matches GEP with i8 source element type
2112template <typename PointerOpTy, typename OffsetOpTy>
2114m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp) {
2116}
2117
2118//===----------------------------------------------------------------------===//
2119// Matchers for CastInst classes
2120//
2121
2122template <typename Op_t, unsigned Opcode> struct CastOperator_match {
2123 Op_t Op;
2124
2125 CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
2126
2127 template <typename OpTy> bool match(OpTy *V) const {
2128 if (auto *O = dyn_cast<Operator>(V))
2129 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
2130 return false;
2131 }
2132};
2133
2134template <typename Op_t, typename Class> struct CastInst_match {
2135 Op_t Op;
2136
2137 CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
2138
2139 template <typename OpTy> bool match(OpTy *V) const {
2140 if (auto *I = dyn_cast<Class>(V))
2141 return Op.match(I->getOperand(0));
2142 return false;
2143 }
2144};
2145
2146template <typename Op_t> struct PtrToIntSameSize_match {
2148 Op_t Op;
2149
2150 PtrToIntSameSize_match(const DataLayout &DL, const Op_t &OpMatch)
2151 : DL(DL), Op(OpMatch) {}
2152
2153 template <typename OpTy> bool match(OpTy *V) const {
2154 if (auto *O = dyn_cast<Operator>(V))
2155 return O->getOpcode() == Instruction::PtrToInt &&
2156 DL.getTypeSizeInBits(O->getType()) ==
2157 DL.getTypeSizeInBits(O->getOperand(0)->getType()) &&
2158 Op.match(O->getOperand(0));
2159 return false;
2160 }
2161};
2162
2163template <typename Op_t> struct NNegZExt_match {
2164 Op_t Op;
2165
2166 NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
2167
2168 template <typename OpTy> bool match(OpTy *V) const {
2169 if (auto *I = dyn_cast<ZExtInst>(V))
2170 return I->hasNonNeg() && Op.match(I->getOperand(0));
2171 return false;
2172 }
2173};
2174
2175template <typename Op_t, unsigned WrapFlags = 0> struct NoWrapTrunc_match {
2176 Op_t Op;
2177
2178 NoWrapTrunc_match(const Op_t &OpMatch) : Op(OpMatch) {}
2179
2180 template <typename OpTy> bool match(OpTy *V) const {
2181 if (auto *I = dyn_cast<TruncInst>(V))
2182 return (I->getNoWrapKind() & WrapFlags) == WrapFlags &&
2183 Op.match(I->getOperand(0));
2184 return false;
2185 }
2186};
2187
2188/// Matches BitCast.
2189template <typename OpTy>
2194
2195template <typename Op_t> struct ElementWiseBitCast_match {
2196 Op_t Op;
2197
2198 ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
2199
2200 template <typename OpTy> bool match(OpTy *V) const {
2201 auto *I = dyn_cast<BitCastInst>(V);
2202 if (!I)
2203 return false;
2204 Type *SrcType = I->getSrcTy();
2205 Type *DstType = I->getType();
2206 // Make sure the bitcast doesn't change between scalar and vector and
2207 // doesn't change the number of vector elements.
2208 if (SrcType->isVectorTy() != DstType->isVectorTy())
2209 return false;
2210 if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcType);
2211 SrcVecTy && SrcVecTy->getElementCount() !=
2212 cast<VectorType>(DstType)->getElementCount())
2213 return false;
2214 return Op.match(I->getOperand(0));
2215 }
2216};
2217
2218template <typename OpTy>
2222
2223/// Matches PtrToInt.
2224template <typename OpTy>
2229
2230template <typename OpTy>
2235
2236/// Matches PtrToAddr.
2237template <typename OpTy>
2242
2243/// Matches PtrToInt or PtrToAddr.
2244template <typename OpTy> inline auto m_PtrToIntOrAddr(const OpTy &Op) {
2246}
2247
2248/// Matches IntToPtr.
2249template <typename OpTy>
2254
2255/// Matches any cast or self. Used to ignore casts.
2256template <typename OpTy>
2261
2262/// Matches Trunc.
2263template <typename OpTy>
2267
2268/// Matches trunc nuw.
2269template <typename OpTy>
2274
2275/// Matches trunc nsw.
2276template <typename OpTy>
2281
2282template <typename OpTy>
2285 return m_CombineOr(m_Trunc(Op), Op);
2286}
2287
2288/// Matches SExt.
2289template <typename OpTy>
2293
2294/// Matches ZExt.
2295template <typename OpTy>
2299
2300template <typename OpTy>
2302 return NNegZExt_match<OpTy>(Op);
2303}
2304
2305template <typename OpTy>
2308 return m_CombineOr(m_ZExt(Op), Op);
2309}
2310
2311template <typename OpTy>
2314 return m_CombineOr(m_SExt(Op), Op);
2315}
2316
2317/// Match either "sext" or "zext nneg".
2318template <typename OpTy>
2321 return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
2322}
2323
2324template <typename OpTy>
2328 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
2329}
2330
2331template <typename OpTy>
2334 OpTy>
2336 return m_CombineOr(m_ZExtOrSExt(Op), Op);
2337}
2338
2339template <typename OpTy> inline auto m_ZExtOrTruncOrSelf(const OpTy &Op) {
2340 return m_CombineOr(m_ZExt(Op), m_Trunc(Op), Op);
2341}
2342
2343template <typename LHS_t, typename RHS_t> struct ICmpLike_match {
2347
2349 : Pred(P), L(Left), R(Right) {}
2350
2351 template <typename OpTy> bool match(OpTy *V) const {
2352 if (PatternMatch::match(V, m_ICmp(Pred, L, R)))
2353 return true;
2354 Value *A;
2355 // trunc nuw x to i1 is equivalent to icmp ne x, 0
2356 if (V->getType()->isIntOrIntVectorTy(1) &&
2357 PatternMatch::match(V, m_NUWTrunc(m_Value(A))) && L.match(A) &&
2358 R.match(ConstantInt::getNullValue(A->getType()))) {
2360 return true;
2361 }
2362 return false;
2363 }
2364};
2365
2366template <typename LHS, typename RHS>
2368 const RHS &R) {
2369 return ICmpLike_match<LHS, RHS>(Pred, L, R);
2370}
2371
2372template <typename CondTy, typename LTy, typename RTy> struct SelectLike_match {
2373 CondTy Cond;
2376
2377 SelectLike_match(const CondTy &C, const LTy &TC, const RTy &FC)
2378 : Cond(C), TrueC(TC), FalseC(FC) {}
2379
2380 template <typename OpTy> bool match(OpTy *V) const {
2381 // select(Cond, TrueC, FalseC) — captures both constants directly
2383 return true;
2384
2385 Type *Ty = V->getType();
2386 Value *CondV = nullptr;
2387
2388 // zext(i1 Cond) is equivalent to select(Cond, 1, 0)
2389 if (PatternMatch::match(V, m_ZExt(m_Value(CondV))) &&
2390 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2391 TrueC.match(ConstantInt::get(Ty, 1)) &&
2392 FalseC.match(ConstantInt::get(Ty, 0)))
2393 return true;
2394
2395 // sext(i1 Cond) is equivalent to select(Cond, -1, 0)
2396 if (PatternMatch::match(V, m_SExt(m_Value(CondV))) &&
2397 CondV->getType()->isIntOrIntVectorTy(1) && Cond.match(CondV) &&
2398 TrueC.match(Constant::getAllOnesValue(Ty)) &&
2399 FalseC.match(ConstantInt::get(Ty, 0)))
2400 return true;
2401
2402 return false;
2403 }
2404};
2405
2406/// Matches a value that behaves like a boolean-controlled select, i.e. one of:
2407/// select i1 Cond, TrueC, FalseC
2408/// zext i1 Cond (equivalent to select i1 Cond, 1, 0)
2409/// sext i1 Cond (equivalent to select i1 Cond, -1, 0)
2410///
2411/// The condition is matched against \p Cond, and the true/false constants
2412/// against \p TrueC and \p FalseC respectively. For zext/sext, the synthetic
2413/// constants are bound to \p TrueC and \p FalseC via their matchers.
2414template <typename CondTy, typename LTy, typename RTy>
2416m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC) {
2417 return SelectLike_match<CondTy, LTy, RTy>(C, TrueC, FalseC);
2418}
2419
2420template <typename OpTy>
2424
2425template <typename OpTy>
2429
2430template <typename OpTy>
2433m_IToFP(const OpTy &Op) {
2434 return m_CombineOr(m_UIToFP(Op), m_SIToFP(Op));
2435}
2436
2437template <typename OpTy>
2441
2442template <typename OpTy>
2446
2447template <typename OpTy>
2450m_FPToI(const OpTy &Op) {
2451 return m_CombineOr(m_FPToUI(Op), m_FPToSI(Op));
2452}
2453
2454template <typename OpTy>
2458
2459template <typename OpTy>
2463
2464//===----------------------------------------------------------------------===//
2465// Matchers for control flow.
2466//
2467
2468struct br_match {
2470
2472
2473 template <typename OpTy> bool match(OpTy *V) const {
2474 if (auto *BI = dyn_cast<UncondBrInst>(V)) {
2475 Succ = BI->getSuccessor();
2476 return true;
2477 }
2478 return false;
2479 }
2480};
2481
2482inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
2483
2484template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2486 Cond_t Cond;
2487 TrueBlock_t T;
2488 FalseBlock_t F;
2489
2490 brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
2491 : Cond(C), T(t), F(f) {}
2492
2493 template <typename OpTy> bool match(OpTy *V) const {
2494 if (auto *BI = dyn_cast<CondBrInst>(V))
2495 if (Cond.match(BI->getCondition()))
2496 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
2497 return false;
2498 }
2499};
2500
2501template <typename Cond_t>
2507
2508template <typename Cond_t, typename TrueBlock_t, typename FalseBlock_t>
2510m_Br(const Cond_t &C, const TrueBlock_t &T, const FalseBlock_t &F) {
2512}
2513
2514//===----------------------------------------------------------------------===//
2515// Matchers for fmax/fmin idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
2516//
2517
2518template <typename LHS_t, typename RHS_t, typename Pred_t>
2520 using PredType = Pred_t;
2523
2524 // The evaluation order is always stable, regardless of Commutability.
2525 // The LHS is always matched first.
2526 FMaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
2527
2528 template <typename OpTy> bool match(OpTy *V) const {
2529 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
2530 auto *SI = dyn_cast<SelectInst>(V);
2531 if (!SI)
2532 return false;
2533 auto *Cmp = dyn_cast<FCmpInst>(SI->getCondition());
2534 if (!Cmp)
2535 return false;
2536 // At this point we have a select conditioned on a comparison. Check that
2537 // it is the values returned by the select that are being compared.
2538 auto *TrueVal = SI->getTrueValue();
2539 auto *FalseVal = SI->getFalseValue();
2540 auto *LHS = Cmp->getOperand(0);
2541 auto *RHS = Cmp->getOperand(1);
2542 if ((TrueVal != LHS || FalseVal != RHS) &&
2543 (TrueVal != RHS || FalseVal != LHS))
2544 return false;
2545 FCmpInst::Predicate Pred =
2546 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
2547 // Does "(x pred y) ? x : y" represent the desired max/min operation?
2548 if (!Pred_t::match(Pred))
2549 return false;
2550 // It does! Bind the operands.
2551 return L.match(LHS) && R.match(RHS);
2552 }
2553};
2554
2555/// Helper class for identifying ordered max predicates.
2557 static bool match(FCmpInst::Predicate Pred) {
2558 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
2559 }
2560};
2561
2562/// Helper class for identifying ordered min predicates.
2564 static bool match(FCmpInst::Predicate Pred) {
2565 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
2566 }
2567};
2568
2569/// Helper class for identifying unordered max predicates.
2571 static bool match(FCmpInst::Predicate Pred) {
2572 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
2573 }
2574};
2575
2576/// Helper class for identifying unordered min predicates.
2578 static bool match(FCmpInst::Predicate Pred) {
2579 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
2580 }
2581};
2582
2583/// Match an 'ordered' floating point maximum function.
2584/// Floating point has one special value 'NaN'. Therefore, there is no total
2585/// order. However, if we can ignore the 'NaN' value (for example, because of a
2586/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2587/// semantics. In the presence of 'NaN' we have to preserve the original
2588/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
2589///
2590/// max(L, R) iff L and R are not NaN
2591/// m_OrdFMax(L, R) = R iff L or R are NaN
2592template <typename LHS, typename RHS>
2594 const RHS &R) {
2596}
2597
2598/// Match an 'ordered' floating point minimum function.
2599/// Floating point has one special value 'NaN'. Therefore, there is no total
2600/// order. However, if we can ignore the 'NaN' value (for example, because of a
2601/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2602/// semantics. In the presence of 'NaN' we have to preserve the original
2603/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
2604///
2605/// min(L, R) iff L and R are not NaN
2606/// m_OrdFMin(L, R) = R iff L or R are NaN
2607template <typename LHS, typename RHS>
2609 const RHS &R) {
2611}
2612
2613/// Match an 'unordered' floating point maximum function.
2614/// Floating point has one special value 'NaN'. Therefore, there is no total
2615/// order. However, if we can ignore the 'NaN' value (for example, because of a
2616/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2617/// semantics. In the presence of 'NaN' we have to preserve the original
2618/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
2619///
2620/// max(L, R) iff L and R are not NaN
2621/// m_UnordFMax(L, R) = L iff L or R are NaN
2622template <typename LHS, typename RHS>
2627
2628/// Match an 'unordered' floating point minimum function.
2629/// Floating point has one special value 'NaN'. Therefore, there is no total
2630/// order. However, if we can ignore the 'NaN' value (for example, because of a
2631/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2632/// semantics. In the presence of 'NaN' we have to preserve the original
2633/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
2634///
2635/// min(L, R) iff L and R are not NaN
2636/// m_UnordFMin(L, R) = L iff L or R are NaN
2637template <typename LHS, typename RHS>
2642
2643/// Match an 'ordered' or 'unordered' floating point maximum function.
2644/// Floating point has one special value 'NaN'. Therefore, there is no total
2645/// order. However, if we can ignore the 'NaN' value (for example, because of a
2646/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
2647/// semantics.
2648template <typename LHS, typename RHS>
2655
2656/// Match an 'ordered' or 'unordered' floating point minimum function.
2657/// Floating point has one special value 'NaN'. Therefore, there is no total
2658/// order. However, if we can ignore the 'NaN' value (for example, because of a
2659/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
2660/// semantics.
2661template <typename LHS, typename RHS>
2668
2669/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
2670/// NOTE: we first match the 'Not' (by matching '-1'),
2671/// and only then match the inner matcher!
2672template <typename ValTy>
2673inline BinaryOp_match<cst_pred_ty<is_all_ones>, ValTy, Instruction::Xor, true>
2674m_Not(const ValTy &V) {
2675 return m_c_Xor(m_AllOnes(), V);
2676}
2677
2678template <typename ValTy>
2679inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor,
2680 true>
2681m_NotForbidPoison(const ValTy &V) {
2682 return m_c_Xor(m_AllOnesForbidPoison(), V);
2683}
2684
2685//===----------------------------------------------------------------------===//
2686// Matchers for overflow check patterns: e.g. (a + b) u< a, (a ^ -1) <u b
2687// Note that S might be matched to other instructions than AddInst.
2688//
2689
2690template <typename LHS_t, typename RHS_t, typename Sum_t>
2694 Sum_t S;
2695
2696 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
2697 : L(L), R(R), S(S) {}
2698
2699 template <typename OpTy> bool match(OpTy *V) const {
2700 Value *ICmpLHS, *ICmpRHS;
2701 CmpPredicate Pred;
2702 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
2703 return false;
2704
2705 Value *AddLHS, *AddRHS;
2706 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
2707
2708 // (a + b) u< a, (a + b) u< b
2709 if (Pred == ICmpInst::ICMP_ULT)
2710 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
2711 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2712
2713 // a >u (a + b), b >u (a + b)
2714 if (Pred == ICmpInst::ICMP_UGT)
2715 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
2716 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2717
2718 Value *Op1;
2719 auto XorExpr = m_OneUse(m_Not(m_Value(Op1)));
2720 // (~a) <u b
2721 if (Pred == ICmpInst::ICMP_ULT) {
2722 if (XorExpr.match(ICmpLHS))
2723 return L.match(Op1) && R.match(ICmpRHS) && S.match(ICmpLHS);
2724 }
2725 // b > u (~a)
2726 if (Pred == ICmpInst::ICMP_UGT) {
2727 if (XorExpr.match(ICmpRHS))
2728 return L.match(Op1) && R.match(ICmpLHS) && S.match(ICmpRHS);
2729 }
2730
2731 // Match special-case for increment-by-1.
2732 if (Pred == ICmpInst::ICMP_EQ) {
2733 // (a + 1) == 0
2734 // (1 + a) == 0
2735 if (AddExpr.match(ICmpLHS) && m_ZeroInt().match(ICmpRHS) &&
2736 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2737 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
2738 // 0 == (a + 1)
2739 // 0 == (1 + a)
2740 if (m_ZeroInt().match(ICmpLHS) && AddExpr.match(ICmpRHS) &&
2741 (m_One().match(AddLHS) || m_One().match(AddRHS)))
2742 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
2743 }
2744
2745 return false;
2746 }
2747};
2748
2749/// Match an icmp instruction checking for unsigned overflow on addition.
2750///
2751/// S is matched to the addition whose result is being checked for overflow, and
2752/// L and R are matched to the LHS and RHS of S.
2753template <typename LHS_t, typename RHS_t, typename Sum_t>
2755m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
2757}
2758
2759template <typename Opnd_t> struct Argument_match {
2760 unsigned OpI;
2761 Opnd_t Val;
2762
2763 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
2764
2765 template <typename OpTy> bool match(OpTy *V) const {
2766 // FIXME: Should likely be switched to use `CallBase`.
2767 if (const auto *CI = dyn_cast<CallInst>(V))
2768 return Val.match(CI->getArgOperand(OpI));
2769 return false;
2770 }
2771};
2772
2773/// Match an argument.
2774template <unsigned OpI, typename Opnd_t>
2775inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
2776 return Argument_match<Opnd_t>(OpI, Op);
2777}
2778
2779/// Intrinsic matchers.
2781 unsigned ID;
2782
2784
2785 template <typename OpTy> bool match(OpTy *V) const {
2786 if (const auto *CI = dyn_cast<CallInst>(V))
2787 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
2788 return F->getIntrinsicID() == ID;
2789 return false;
2790 }
2791};
2792
2793/// Match intrinsic calls with any of the given IDs.
2794template <Intrinsic::ID... IntrIDs> struct IntrinsicIDs_match {
2795 template <typename OpTy> bool match(OpTy *V) const {
2796 if (const auto *CI = dyn_cast<CallInst>(V))
2797 if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand())) {
2798 Intrinsic::ID ID = F->getIntrinsicID();
2799 return ((ID == IntrIDs) || ...);
2800 }
2801 return false;
2802 }
2803};
2804
2806 template <Intrinsic::ID IntrID, typename... Ts, size_t... Is>
2807 static auto impl(std::index_sequence<Is...>, const Ts &...Ops) {
2808 return m_CombineAnd(IntrinsicID_match(IntrID), m_Argument<Is>(Ops)...);
2809 }
2810};
2811
2812/// Match intrinsic calls like this:
2813/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
2814template <Intrinsic::ID IntrID, typename... Ts>
2815inline auto m_Intrinsic(const Ts &...Ops) {
2817 std::make_index_sequence<sizeof...(Ts)>{}, Ops...);
2818}
2819
2820/// Match intrinsic calls with any of the given IDs like this:
2821/// m_AnyIntrinsic<Intrinsic::fptosi_sat, Intrinsic::fptoui_sat>()
2822/// This is more efficient than using nested m_CombineOr with m_Intrinsic
2823/// because it performs the CallInst/Function cast only once.
2824template <Intrinsic::ID... IntrIDs>
2826 return IntrinsicIDs_match<IntrIDs...>();
2827}
2828
2829/// Matches MaskedLoad Intrinsic.
2830template <typename Opnd0, typename Opnd1, typename Opnd2>
2831inline auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2832 return m_Intrinsic<Intrinsic::masked_load>(Op0, Op1, Op2);
2833}
2834
2835/// Matches MaskedStore Intrinsic.
2836template <typename Opnd0, typename Opnd1, typename Opnd2>
2837inline auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1,
2838 const Opnd2 &Op2) {
2839 return m_Intrinsic<Intrinsic::masked_store>(Op0, Op1, Op2);
2840}
2841
2842/// Matches MaskedGather Intrinsic.
2843template <typename Opnd0, typename Opnd1, typename Opnd2>
2844inline auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1,
2845 const Opnd2 &Op2) {
2846 return m_Intrinsic<Intrinsic::masked_gather>(Op0, Op1, Op2);
2847}
2848
2849// Helper intrinsic matching specializations.
2850template <typename Opnd0> inline auto m_BitReverse(const Opnd0 &Op0) {
2852}
2853
2854template <typename Opnd0> inline auto m_BSwap(const Opnd0 &Op0) {
2856}
2857template <typename Opnd0> inline auto m_Ctpop(const Opnd0 &Op0) {
2859}
2860
2861template <typename Opnd0> inline auto m_FAbs(const Opnd0 &Op0) {
2862 return m_Intrinsic<Intrinsic::fabs>(Op0);
2863}
2864
2865template <typename Opnd0> inline auto m_FCanonicalize(const Opnd0 &Op0) {
2867}
2868
2869template <typename Opnd0, typename Opnd1>
2870inline auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1) {
2871 return m_Intrinsic<Intrinsic::ctlz>(Op0, Op1);
2872}
2873
2874template <typename Opnd0, typename Opnd1>
2875inline auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1) {
2876 return m_Intrinsic<Intrinsic::cttz>(Op0, Op1);
2877}
2878
2879template <typename Opnd0, typename Opnd1>
2880inline auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2881 return m_Intrinsic<Intrinsic::smax>(Op0, Op1);
2882}
2883
2884template <typename Opnd0, typename Opnd1>
2885inline auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2886 return m_Intrinsic<Intrinsic::smin>(Op0, Op1);
2887}
2888
2889template <typename Opnd0, typename Opnd1>
2890inline auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1) {
2891 return m_Intrinsic<Intrinsic::umax>(Op0, Op1);
2892}
2893
2894template <typename Opnd0, typename Opnd1>
2895inline auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2896 return m_Intrinsic<Intrinsic::umin>(Op0, Op1);
2897}
2898
2899template <typename Opnd0, typename Opnd1>
2900inline auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1) {
2901 return m_CombineOr(m_SMax(Op0, Op1), m_SMin(Op0, Op1), m_UMax(Op0, Op1),
2902 m_UMin(Op0, Op1));
2903}
2904
2905template <typename Opnd0, typename Opnd1>
2906inline auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2907 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
2908}
2909
2910template <typename Opnd0, typename Opnd1>
2911inline auto m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1) {
2912 return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
2913}
2914
2915template <typename Opnd0, typename Opnd1>
2916inline auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2917 return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
2918}
2919
2920template <typename Opnd0, typename Opnd1>
2921inline auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2922 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
2923}
2924
2925template <typename Opnd0, typename Opnd1>
2926inline auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1) {
2927 return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
2928}
2929
2930template <typename Opnd0, typename Opnd1>
2931inline auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2932 return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
2933}
2934
2935template <typename Opnd0, typename Opnd1>
2936inline auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2937 return m_CombineOr(m_FMaxNum(Op0, Op1), m_FMaximumNum(Op0, Op1));
2938}
2939
2940template <typename Opnd0, typename Opnd1>
2941inline auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
2942 return m_CombineOr(m_FMinNum(Op0, Op1), m_FMinimumNum(Op0, Op1));
2943}
2944
2945template <typename Opnd0, typename Opnd1, typename Opnd2>
2946inline auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2947 return m_Intrinsic<Intrinsic::fshl>(Op0, Op1, Op2);
2948}
2949
2950template <typename Opnd0, typename Opnd1, typename Opnd2>
2951inline auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
2952 return m_Intrinsic<Intrinsic::fshr>(Op0, Op1, Op2);
2953}
2954
2955template <typename Opnd0> inline auto m_Sqrt(const Opnd0 &Op0) {
2956 return m_Intrinsic<Intrinsic::sqrt>(Op0);
2957}
2958
2959template <typename Opnd0, typename Opnd1>
2960inline auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1) {
2961 return m_Intrinsic<Intrinsic::copysign>(Op0, Op1);
2962}
2963
2964template <typename Opnd0> inline auto m_VecReverse(const Opnd0 &Op0) {
2966}
2967
2968template <typename Opnd0, typename Opnd1, typename Opnd2>
2969inline auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1,
2970 const Opnd2 &Op2) {
2971 return m_Intrinsic<Intrinsic::vector_insert>(Op0, Op1, Op2);
2972}
2973
2974//===----------------------------------------------------------------------===//
2975// Matchers for two-operands operators with the operators in either order
2976//
2977
2978/// Matches a BinaryOperator with LHS and RHS in either order.
2979template <typename LHS, typename RHS>
2982}
2983
2984/// Matches an ICmp with a predicate over LHS and RHS in either order.
2985/// Swaps the predicate if operands are commuted.
2986template <typename LHS, typename RHS>
2988m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R) {
2990}
2991
2992template <typename LHS, typename RHS>
2997
2998/// Matches a specific opcode with LHS and RHS in either order.
2999template <typename LHS, typename RHS>
3001m_c_BinOp(unsigned Opcode, const LHS &L, const RHS &R) {
3002 return SpecificBinaryOp_match<LHS, RHS, true>(Opcode, L, R);
3003}
3004
3005/// Matches a Add with LHS and RHS in either order.
3006template <typename LHS, typename RHS>
3011
3012/// Matches a Mul with LHS and RHS in either order.
3013template <typename LHS, typename RHS>
3018
3019/// Matches an And with LHS and RHS in either order.
3020template <typename LHS, typename RHS>
3025
3026/// Matches an Or with LHS and RHS in either order.
3027template <typename LHS, typename RHS>
3032
3033/// Matches an Xor with LHS and RHS in either order.
3034template <typename LHS, typename RHS>
3039
3040/// Matches a 'Neg' as 'sub 0, V'.
3041template <typename ValTy>
3042inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
3043m_Neg(const ValTy &V) {
3044 return m_Sub(m_ZeroInt(), V);
3045}
3046
3047/// Matches a 'Neg' as 'sub nsw 0, V'.
3048template <typename ValTy>
3050 Instruction::Sub,
3052m_NSWNeg(const ValTy &V) {
3053 return m_NSWSub(m_ZeroInt(), V);
3054}
3055
3056template <Intrinsic::ID IntrID, typename LHS, typename RHS>
3060
3061 CommutativeBinaryIntrinsic_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3062
3063 template <typename OpTy> bool match(OpTy *V) const {
3064 const auto *II = dyn_cast<IntrinsicInst>(V);
3065 if (!II || II->getIntrinsicID() != IntrID)
3066 return false;
3067 return (L.match(II->getArgOperand(0)) && R.match(II->getArgOperand(1))) ||
3068 (L.match(II->getArgOperand(1)) && R.match(II->getArgOperand(0)));
3069 }
3070};
3071
3072template <Intrinsic::ID IntrID, typename T0, typename T1>
3074m_c_Intrinsic(const T0 &Op0, const T1 &Op1) {
3076}
3077
3078/// Matches an SMin with LHS and RHS in either order.
3079template <typename LHS, typename RHS>
3080inline auto m_c_SMin(const LHS &L, const RHS &R) {
3081 return m_c_Intrinsic<Intrinsic::smin>(L, R);
3082}
3083/// Matches an SMax with LHS and RHS in either order.
3084template <typename LHS, typename RHS>
3085inline auto m_c_SMax(const LHS &L, const RHS &R) {
3086 return m_c_Intrinsic<Intrinsic::smax>(L, R);
3087}
3088/// Matches a UMin with LHS and RHS in either order.
3089template <typename LHS, typename RHS>
3090inline auto m_c_UMin(const LHS &L, const RHS &R) {
3091 return m_c_Intrinsic<Intrinsic::umin>(L, R);
3092}
3093/// Matches a UMax with LHS and RHS in either order.
3094template <typename LHS, typename RHS>
3095inline auto m_c_UMax(const LHS &L, const RHS &R) {
3096 return m_c_Intrinsic<Intrinsic::umax>(L, R);
3097}
3098
3099template <typename LHS, typename RHS>
3100inline auto m_c_MaxOrMin(const LHS &L, const RHS &R) {
3101 return m_CombineOr(m_c_SMax(L, R), m_c_SMin(L, R), m_c_UMax(L, R),
3102 m_c_UMin(L, R));
3103}
3104
3105/// Matches FAdd with LHS and RHS in either order.
3106template <typename LHS, typename RHS>
3108m_c_FAdd(const LHS &L, const RHS &R) {
3110}
3111
3112/// Matches FMul with LHS and RHS in either order.
3113template <typename LHS, typename RHS>
3115m_c_FMul(const LHS &L, const RHS &R) {
3117}
3118
3119template <typename Opnd_t> struct Signum_match {
3120 Opnd_t Val;
3121 Signum_match(const Opnd_t &V) : Val(V) {}
3122
3123 template <typename OpTy> bool match(OpTy *V) const {
3124 unsigned TypeSize = V->getType()->getScalarSizeInBits();
3125 if (TypeSize == 0)
3126 return false;
3127
3128 unsigned ShiftWidth = TypeSize - 1;
3129 Value *Op;
3130
3131 // This is the representation of signum we match:
3132 //
3133 // signum(x) == (x >> 63) | (-x >>u 63)
3134 //
3135 // An i1 value is its own signum, so it's correct to match
3136 //
3137 // signum(x) == (x >> 0) | (-x >>u 0)
3138 //
3139 // for i1 values.
3140
3141 auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
3142 auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
3143 auto Signum = m_c_Or(LHS, RHS);
3144
3145 return Signum.match(V) && Val.match(Op);
3146 }
3147};
3148
3149/// Matches a signum pattern.
3150///
3151/// signum(x) =
3152/// x > 0 -> 1
3153/// x == 0 -> 0
3154/// x < 0 -> -1
3155template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
3156 return Signum_match<Val_t>(V);
3157}
3158
3159template <int Ind, typename Opnd_t> struct ExtractValue_match {
3160 Opnd_t Val;
3161 ExtractValue_match(const Opnd_t &V) : Val(V) {}
3162
3163 template <typename OpTy> bool match(OpTy *V) const {
3164 if (auto *I = dyn_cast<ExtractValueInst>(V)) {
3165 // If Ind is -1, don't inspect indices
3166 if (Ind != -1 &&
3167 !(I->getNumIndices() == 1 && I->getIndices()[0] == (unsigned)Ind))
3168 return false;
3169 return Val.match(I->getAggregateOperand());
3170 }
3171 return false;
3172 }
3173};
3174
3175/// Match a single index ExtractValue instruction.
3176/// For example m_ExtractValue<1>(...)
3177template <int Ind, typename Val_t>
3181
3182/// Match an ExtractValue instruction with any index.
3183/// For example m_ExtractValue(...)
3184template <typename Val_t>
3185inline ExtractValue_match<-1, Val_t> m_ExtractValue(const Val_t &V) {
3186 return ExtractValue_match<-1, Val_t>(V);
3187}
3188
3189/// Matcher for a single index InsertValue instruction.
3190template <int Ind, typename T0, typename T1> struct InsertValue_match {
3193
3194 InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
3195
3196 template <typename OpTy> bool match(OpTy *V) const {
3197 if (auto *I = dyn_cast<InsertValueInst>(V)) {
3198 return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
3199 I->getNumIndices() == 1 && Ind == I->getIndices()[0];
3200 }
3201 return false;
3202 }
3203};
3204
3205/// Matches a single index InsertValue instruction.
3206template <int Ind, typename Val_t, typename Elt_t>
3208 const Elt_t &Elt) {
3209 return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
3210}
3211
3212/// Matches a call to `llvm.vscale()`.
3213inline auto m_VScale() { return m_Intrinsic<Intrinsic::vscale>(); }
3214
3215template <typename Opnd0, typename Opnd1>
3216inline auto m_Interleave2(const Opnd0 &Op0, const Opnd1 &Op1) {
3218}
3219
3220template <typename Opnd> inline auto m_Deinterleave2(const Opnd &Op) {
3222}
3223
3224template <typename LHS, typename RHS, unsigned Opcode, bool Commutable = false>
3228
3229 LogicalOp_match(const LHS &L, const RHS &R) : L(L), R(R) {}
3230
3231 template <typename T> bool match(T *V) const {
3232 auto *I = dyn_cast<Instruction>(V);
3233 if (!I || !I->getType()->isIntOrIntVectorTy(1))
3234 return false;
3235
3236 if (I->getOpcode() == Opcode) {
3237 auto *Op0 = I->getOperand(0);
3238 auto *Op1 = I->getOperand(1);
3239 return (L.match(Op0) && R.match(Op1)) ||
3240 (Commutable && L.match(Op1) && R.match(Op0));
3241 }
3242
3243 if (auto *Select = dyn_cast<SelectInst>(I)) {
3244 auto *Cond = Select->getCondition();
3245 auto *TVal = Select->getTrueValue();
3246 auto *FVal = Select->getFalseValue();
3247
3248 // Don't match a scalar select of bool vectors.
3249 // Transforms expect a single type for operands if this matches.
3250 if (Cond->getType() != Select->getType())
3251 return false;
3252
3253 if (Opcode == Instruction::And) {
3254 auto *C = dyn_cast<Constant>(FVal);
3255 if (C && C->isNullValue())
3256 return (L.match(Cond) && R.match(TVal)) ||
3257 (Commutable && L.match(TVal) && R.match(Cond));
3258 } else {
3259 assert(Opcode == Instruction::Or);
3260 auto *C = dyn_cast<Constant>(TVal);
3261 if (C && C->isOneValue())
3262 return (L.match(Cond) && R.match(FVal)) ||
3263 (Commutable && L.match(FVal) && R.match(Cond));
3264 }
3265 }
3266
3267 return false;
3268 }
3269};
3270
3271/// Matches L && R either in the form of L & R or L ? R : false.
3272/// Note that the latter form is poison-blocking.
3273template <typename LHS, typename RHS>
3278
3279/// Matches L && R where L and R are arbitrary values.
3280inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
3281
3282/// Matches L && R with LHS and RHS in either order.
3283template <typename LHS, typename RHS>
3285m_c_LogicalAnd(const LHS &L, const RHS &R) {
3287}
3288
3289/// Matches L || R either in the form of L | R or L ? true : R.
3290/// Note that the latter form is poison-blocking.
3291template <typename LHS, typename RHS>
3296
3297/// Matches L || R where L and R are arbitrary values.
3298inline auto m_LogicalOr() { return m_LogicalOr(m_Value(), m_Value()); }
3299
3300/// Matches L || R with LHS and RHS in either order.
3301template <typename LHS, typename RHS>
3303m_c_LogicalOr(const LHS &L, const RHS &R) {
3305}
3306
3307/// Matches either L && R or L || R,
3308/// either one being in the either binary or logical form.
3309/// Note that the latter form is poison-blocking.
3310template <typename LHS, typename RHS, bool Commutable = false>
3316
3317/// Matches either L && R or L || R where L and R are arbitrary values.
3318inline auto m_LogicalOp() { return m_LogicalOp(m_Value(), m_Value()); }
3319
3320/// Matches either L && R or L || R with LHS and RHS in either order.
3321template <typename LHS, typename RHS>
3322inline auto m_c_LogicalOp(const LHS &L, const RHS &R) {
3323 return m_LogicalOp<LHS, RHS, /*Commutable=*/true>(L, R);
3324}
3325
3326} // end namespace PatternMatch
3327} // end namespace llvm
3328
3329#endif // LLVM_IR_PATTERNMATCH_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Hexagon Common GEP
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
#define T1
uint64_t IntrinsicInst * II
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
Definition APInt.h:1573
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:551
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static LLVM_ABI CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
static LLVM_ABI CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
Base class for aggregate constants (with operands).
Definition Constants.h:565
A constant value that is initialized with an expression using other constant values.
Definition Constants.h:1316
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
bool isShift() const
A wrapper class for inspecting calls to intrinsic functions.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
'undef' values are things that do not have specified contents.
Definition Constants.h:1631
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
Base class of all SIMD vector types.
Represents an op.with.overflow intrinsic.
An efficient, type-erasing, non-owning reference to a callable.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
match_combine_and< Ty... > m_CombineAnd(const Ty &...Ps)
Combine pattern matchers matching all of Ps patterns.
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
match_bind< PHINode > m_Phi(PHINode *&PN)
Match a PHI node, capturing it if we match.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
auto m_BSwap(const Opnd0 &Op0)
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
ShiftLike_match< LHS, Instruction::LShr > m_LShrOrSelf(const LHS &L, uint64_t &R)
Matches lshr L, ConstShAmt or L itself (R will be set to zero in this case).
AllowFmf_match< T, FastMathFlags::NoSignedZeros > m_NoSignedZeros(const T &SubPattern)
auto m_Cmp()
Matches any compare instruction and ignore it.
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
auto m_BitReverse(const Opnd0 &Op0)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
auto m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
AllowFmf_match< T, FastMathFlags::NoInfs > m_NoInfs(const T &SubPattern)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
auto m_PtrToIntOrAddr(const OpTy &Op)
Matches PtrToInt or PtrToAddr.
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap, true > m_c_NSWAdd(const LHS &L, const RHS &R)
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, CastInst >, OpTy > m_CastOrSelf(const OpTy &Op)
Matches any cast or self. Used to ignore casts.
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
auto m_LogicalOp()
Matches either L && R or L || R where L and R are arbitrary values.
CommutativeBinaryIntrinsic_match< IntrID, T0, T1 > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
auto m_Poison()
Match an arbitrary poison constant.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
ap_match< APFloat > m_APFloatForbidPoison(const APFloat *&Res)
Match APFloat while forbidding poison in splat vector constants.
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
br_match m_UnconditionalBr(BasicBlock *&Succ)
CastOperator_match< OpTy, Instruction::PtrToAddr > m_PtrToAddr(const OpTy &Op)
Matches PtrToAddr.
auto m_Sqrt(const Opnd0 &Op0)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
auto m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
LoadSimple_match< OpTy > m_LoadSimple(const OpTy &Op)
bool match(Val *V, const Pattern &P)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
match_bind< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
cst_pred_ty< is_shifted_mask > m_ShiftedMask()
auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1)
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
cstval_pred_ty< Predicate, ConstantInt, AllowPoison > cst_pred_ty
specialization of cstval_pred_ty for ConstantInt
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
DisjointOr_match< LHS, RHS > m_DisjointOr(const LHS &L, const RHS &R)
cstfp_pred_ty< is_signed_inf< true > > m_NegInf()
Match a negative infinity FP constant.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
auto m_c_XorLike(const LHS &L, const RHS &R)
Match either (xor L, R), (xor R, L) or (sub nuw R, L) iff R.isMask() Only commutative matcher as the ...
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
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)
cst_pred_ty< icmp_pred_with_threshold, false > m_SpecificInt_ICMP_ForbidPoison(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
SpecificType_match(const Type *, const Pattern &) -> SpecificType_match< Pattern >
cstfp_pred_ty< is_signed_inf< false > > m_PosInf()
Match a positive infinity FP constant.
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
match_immconstant_ty m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
cst_pred_ty< is_negated_power2_or_zero > m_NegatedPower2OrZero()
Match a integer or vector negated power-of-2.
auto m_ZExtOrTruncOrSelf(const OpTy &Op)
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
ShiftLike_match< LHS, Instruction::AShr > m_AShrOrSelf(const LHS &L, uint64_t &R)
Matches ashr L, ConstShAmt or L itself (R will be set to zero in this case).
cst_pred_ty< custom_checkfn< APInt > > m_CheckedInt(function_ref< bool(const APInt &)> CheckFn)
Match an integer or vector where CheckFn(ele) for each element is true.
SelectLike_match< CondTy, LTy, RTy > m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC)
Matches a value that behaves like a boolean-controlled select, i.e.
cst_pred_ty< is_lowbit_mask_or_zero > m_LowBitMaskOrZero()
Match an integer or vector with only the low bit(s) set.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
DisjointOr_match< LHS, RHS, true > m_c_DisjointOr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
SpecificCmpClass_match< LHS, RHS, FCmpInst > m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)
Match either "add" or "or disjoint".
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
cstval_pred_ty< Predicate, ConstantFP, true > cstfp_pred_ty
specialization of cstval_pred_ty for ConstantFP
auto m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< CastInst_match< OpTy, SExtInst >, NNegZExt_match< OpTy > > m_SExtLike(const OpTy &Op)
Match either "sext" or "zext nneg".
cstfp_pred_ty< is_finitenonzero > m_FiniteNonZero()
Match a finite non-zero FP constant.
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
auto m_Deinterleave2(const Opnd &Op)
auto m_MaskedStore(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedStore Intrinsic.
auto m_c_MaxOrMin(const LHS &L, const RHS &R)
cstfp_pred_ty< custom_checkfn< APFloat > > m_CheckedFp(function_ref< bool(const APFloat &)> CheckFn)
Match a float or vector where CheckFn(ele) for each element is true.
auto m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_VectorInsert(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
auto m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedLoad Intrinsic.
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
auto m_FAbs(const Opnd0 &Op0)
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap >, DisjointOr_match< LHS, RHS > > m_NSWAddLike(const LHS &L, const RHS &R)
Match either "add nsw" or "or disjoint".
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
match_combine_or< FMaxMin_match< LHS, RHS, ofmax_pred_ty >, FMaxMin_match< LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
CastInst_match< OpTy, SIToFPInst > m_SIToFP(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
match_combine_or< CastInst_match< OpTy, ZExtInst >, CastInst_match< OpTy, SExtInst > > m_ZExtOrSExt(const OpTy &Op)
Exact_match< T > m_Exact(const T &SubPattern)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
auto m_UnOp()
Match an arbitrary unary operation and ignore it.
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
cstfp_pred_ty< is_non_zero_fp > m_NonZeroFP()
Match a floating-point non-zero.
UAddWithOverflow_match< LHS_t, RHS_t, Sum_t > m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Match an icmp instruction checking for unsigned overflow on addition.
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
auto m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
ThreeOps_match< Cond, constantint_match< L >, constantint_match< R >, Instruction::Select > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.: m_SelectCst<-1, 0>(m_Value(V))
auto m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
AllowFmf_match< T, FastMathFlags::AllowContract > m_AllowContract(const T &SubPattern)
CastInst_match< OpTy, FPTruncInst > m_FPTrunc(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
auto m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
auto m_ConstantFP()
Match an arbitrary ConstantFP and ignore it.
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
auto m_VecReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
match_combine_or< OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap >, DisjointOr_match< LHS, RHS > > m_NUWAddLike(const LHS &L, const RHS &R)
Match either "add nuw" or "or disjoint".
CastOperator_match< OpTy, Instruction::IntToPtr > m_IntToPtr(const OpTy &Op)
Matches IntToPtr.
auto m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
SpecificCmpClass_match< LHS, RHS, ICmpInst, true > m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
AllowFmf_match< T, FastMathFlags::AllowReciprocal > m_AllowReciprocal(const T &SubPattern)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
cstfp_pred_ty< is_noninf > m_NonInf()
Match a non-infinity FP constant, i.e.
auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h: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)