LLVM  8.0.0svn
PatternMatch.h
Go to the documentation of this file.
1 //===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides a simple and efficient mechanism for performing general
11 // tree-based pattern matches on the LLVM IR. The power of these routines is
12 // that it allows you to write concise patterns that are expressive and easy to
13 // understand. The other major advantage of this is that it allows you to
14 // trivially capture/bind elements in the pattern to variables. For example,
15 // you can do something like this:
16 //
17 // Value *Exp = ...
18 // Value *X, *Y; ConstantInt *C1, *C2; // (X & C1) | (Y & C2)
19 // if (match(Exp, m_Or(m_And(m_Value(X), m_ConstantInt(C1)),
20 // m_And(m_Value(Y), m_ConstantInt(C2))))) {
21 // ... Pattern is matched and variables are bound ...
22 // }
23 //
24 // This is primarily useful to things like the instruction combiner, but can
25 // also be useful for static analysis tools or code generators.
26 //
27 //===----------------------------------------------------------------------===//
28 
29 #ifndef LLVM_IR_PATTERNMATCH_H
30 #define LLVM_IR_PATTERNMATCH_H
31 
32 #include "llvm/ADT/APFloat.h"
33 #include "llvm/ADT/APInt.h"
34 #include "llvm/IR/CallSite.h"
35 #include "llvm/IR/Constant.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/InstrTypes.h"
38 #include "llvm/IR/Instruction.h"
39 #include "llvm/IR/Instructions.h"
40 #include "llvm/IR/Intrinsics.h"
41 #include "llvm/IR/Operator.h"
42 #include "llvm/IR/Value.h"
43 #include "llvm/Support/Casting.h"
44 #include <cstdint>
45 
46 namespace llvm {
47 namespace PatternMatch {
48 
49 template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
50  return const_cast<Pattern &>(P).match(V);
51 }
52 
53 template <typename SubPattern_t> struct OneUse_match {
54  SubPattern_t SubPattern;
55 
56  OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
57 
58  template <typename OpTy> bool match(OpTy *V) {
59  return V->hasOneUse() && SubPattern.match(V);
60  }
61 };
62 
63 template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
64  return SubPattern;
65 }
66 
67 template <typename Class> struct class_match {
68  template <typename ITy> bool match(ITy *V) { return isa<Class>(V); }
69 };
70 
71 /// Match an arbitrary value and ignore it.
73 
74 /// Match an arbitrary binary operation and ignore it.
77 }
78 
79 /// Matches any compare instruction and ignore it.
81 
82 /// Match an arbitrary ConstantInt and ignore it.
84  return class_match<ConstantInt>();
85 }
86 
87 /// Match an arbitrary undef constant.
89 
90 /// Match an arbitrary Constant and ignore it.
92 
93 /// Matching combinators
94 template <typename LTy, typename RTy> struct match_combine_or {
95  LTy L;
96  RTy R;
97 
98  match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
99 
100  template <typename ITy> bool match(ITy *V) {
101  if (L.match(V))
102  return true;
103  if (R.match(V))
104  return true;
105  return false;
106  }
107 };
108 
109 template <typename LTy, typename RTy> struct match_combine_and {
110  LTy L;
111  RTy R;
112 
113  match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
114 
115  template <typename ITy> bool match(ITy *V) {
116  if (L.match(V))
117  if (R.match(V))
118  return true;
119  return false;
120  }
121 };
122 
123 /// Combine two pattern matchers matching L || R
124 template <typename LTy, typename RTy>
125 inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
126  return match_combine_or<LTy, RTy>(L, R);
127 }
128 
129 /// Combine two pattern matchers matching L && R
130 template <typename LTy, typename RTy>
131 inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
132  return match_combine_and<LTy, RTy>(L, R);
133 }
134 
135 struct apint_match {
136  const APInt *&Res;
137 
138  apint_match(const APInt *&R) : Res(R) {}
139 
140  template <typename ITy> bool match(ITy *V) {
141  if (auto *CI = dyn_cast<ConstantInt>(V)) {
142  Res = &CI->getValue();
143  return true;
144  }
145  if (V->getType()->isVectorTy())
146  if (const auto *C = dyn_cast<Constant>(V))
147  if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue())) {
148  Res = &CI->getValue();
149  return true;
150  }
151  return false;
152  }
153 };
154 // Either constexpr if or renaming ConstantFP::getValueAPF to
155 // ConstantFP::getValue is needed to do it via single template
156 // function for both apint/apfloat.
158  const APFloat *&Res;
159  apfloat_match(const APFloat *&R) : Res(R) {}
160  template <typename ITy> bool match(ITy *V) {
161  if (auto *CI = dyn_cast<ConstantFP>(V)) {
162  Res = &CI->getValueAPF();
163  return true;
164  }
165  if (V->getType()->isVectorTy())
166  if (const auto *C = dyn_cast<Constant>(V))
167  if (auto *CI = dyn_cast_or_null<ConstantFP>(C->getSplatValue())) {
168  Res = &CI->getValueAPF();
169  return true;
170  }
171  return false;
172  }
173 };
174 
175 /// Match a ConstantInt or splatted ConstantVector, binding the
176 /// specified pointer to the contained APInt.
177 inline apint_match m_APInt(const APInt *&Res) { return Res; }
178 
179 /// Match a ConstantFP or splatted ConstantVector, binding the
180 /// specified pointer to the contained APFloat.
181 inline apfloat_match m_APFloat(const APFloat *&Res) { return Res; }
182 
183 template <int64_t Val> struct constantint_match {
184  template <typename ITy> bool match(ITy *V) {
185  if (const auto *CI = dyn_cast<ConstantInt>(V)) {
186  const APInt &CIV = CI->getValue();
187  if (Val >= 0)
188  return CIV == static_cast<uint64_t>(Val);
189  // If Val is negative, and CI is shorter than it, truncate to the right
190  // number of bits. If it is larger, then we have to sign extend. Just
191  // compare their negated values.
192  return -CIV == -Val;
193  }
194  return false;
195  }
196 };
197 
198 /// Match a ConstantInt with a specific value.
199 template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
200  return constantint_match<Val>();
201 }
202 
203 /// This helper class is used to match scalar and vector integer constants that
204 /// satisfy a specified predicate.
205 /// For vector constants, undefined elements are ignored.
206 template <typename Predicate> struct cst_pred_ty : public Predicate {
207  template <typename ITy> bool match(ITy *V) {
208  if (const auto *CI = dyn_cast<ConstantInt>(V))
209  return this->isValue(CI->getValue());
210  if (V->getType()->isVectorTy()) {
211  if (const auto *C = dyn_cast<Constant>(V)) {
212  if (const auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
213  return this->isValue(CI->getValue());
214 
215  // Non-splat vector constant: check each element for a match.
216  unsigned NumElts = V->getType()->getVectorNumElements();
217  assert(NumElts != 0 && "Constant vector with no elements?");
218  bool HasNonUndefElements = false;
219  for (unsigned i = 0; i != NumElts; ++i) {
220  Constant *Elt = C->getAggregateElement(i);
221  if (!Elt)
222  return false;
223  if (isa<UndefValue>(Elt))
224  continue;
225  auto *CI = dyn_cast<ConstantInt>(Elt);
226  if (!CI || !this->isValue(CI->getValue()))
227  return false;
228  HasNonUndefElements = true;
229  }
230  return HasNonUndefElements;
231  }
232  }
233  return false;
234  }
235 };
236 
237 /// This helper class is used to match scalar and vector constants that
238 /// satisfy a specified predicate, and bind them to an APInt.
239 template <typename Predicate> struct api_pred_ty : public Predicate {
240  const APInt *&Res;
241 
242  api_pred_ty(const APInt *&R) : Res(R) {}
243 
244  template <typename ITy> bool match(ITy *V) {
245  if (const auto *CI = dyn_cast<ConstantInt>(V))
246  if (this->isValue(CI->getValue())) {
247  Res = &CI->getValue();
248  return true;
249  }
250  if (V->getType()->isVectorTy())
251  if (const auto *C = dyn_cast<Constant>(V))
252  if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
253  if (this->isValue(CI->getValue())) {
254  Res = &CI->getValue();
255  return true;
256  }
257 
258  return false;
259  }
260 };
261 
262 /// This helper class is used to match scalar and vector floating-point
263 /// constants that satisfy a specified predicate.
264 /// For vector constants, undefined elements are ignored.
265 template <typename Predicate> struct cstfp_pred_ty : public Predicate {
266  template <typename ITy> bool match(ITy *V) {
267  if (const auto *CF = dyn_cast<ConstantFP>(V))
268  return this->isValue(CF->getValueAPF());
269  if (V->getType()->isVectorTy()) {
270  if (const auto *C = dyn_cast<Constant>(V)) {
271  if (const auto *CF = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
272  return this->isValue(CF->getValueAPF());
273 
274  // Non-splat vector constant: check each element for a match.
275  unsigned NumElts = V->getType()->getVectorNumElements();
276  assert(NumElts != 0 && "Constant vector with no elements?");
277  bool HasNonUndefElements = false;
278  for (unsigned i = 0; i != NumElts; ++i) {
279  Constant *Elt = C->getAggregateElement(i);
280  if (!Elt)
281  return false;
282  if (isa<UndefValue>(Elt))
283  continue;
284  auto *CF = dyn_cast<ConstantFP>(Elt);
285  if (!CF || !this->isValue(CF->getValueAPF()))
286  return false;
287  HasNonUndefElements = true;
288  }
289  return HasNonUndefElements;
290  }
291  }
292  return false;
293  }
294 };
295 
296 ///////////////////////////////////////////////////////////////////////////////
297 //
298 // Encapsulate constant value queries for use in templated predicate matchers.
299 // This allows checking if constants match using compound predicates and works
300 // with vector constants, possibly with relaxed constraints. For example, ignore
301 // undef values.
302 //
303 ///////////////////////////////////////////////////////////////////////////////
304 
305 struct is_all_ones {
306  bool isValue(const APInt &C) { return C.isAllOnesValue(); }
307 };
308 /// Match an integer or vector with all bits set.
309 /// For vectors, this includes constants with undefined elements.
311  return cst_pred_ty<is_all_ones>();
312 }
313 
315  bool isValue(const APInt &C) { return C.isMaxSignedValue(); }
316 };
317 /// Match an integer or vector with values having all bits except for the high
318 /// bit set (0x7f...).
319 /// For vectors, this includes constants with undefined elements.
322 }
324  return V;
325 }
326 
327 struct is_negative {
328  bool isValue(const APInt &C) { return C.isNegative(); }
329 };
330 /// Match an integer or vector of negative values.
331 /// For vectors, this includes constants with undefined elements.
333  return cst_pred_ty<is_negative>();
334 }
336  return V;
337 }
338 
340  bool isValue(const APInt &C) { return C.isNonNegative(); }
341 };
342 /// Match an integer or vector of nonnegative values.
343 /// For vectors, this includes constants with undefined elements.
346 }
348  return V;
349 }
350 
351 struct is_one {
352  bool isValue(const APInt &C) { return C.isOneValue(); }
353 };
354 /// Match an integer 1 or a vector with all elements equal to 1.
355 /// For vectors, this includes constants with undefined elements.
357  return cst_pred_ty<is_one>();
358 }
359 
360 struct is_zero_int {
361  bool isValue(const APInt &C) { return C.isNullValue(); }
362 };
363 /// Match an integer 0 or a vector with all elements equal to 0.
364 /// For vectors, this includes constants with undefined elements.
366  return cst_pred_ty<is_zero_int>();
367 }
368 
369 struct is_zero {
370  template <typename ITy> bool match(ITy *V) {
371  auto *C = dyn_cast<Constant>(V);
372  return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C));
373  }
374 };
375 /// Match any null constant or a vector with all elements equal to 0.
376 /// For vectors, this includes constants with undefined elements.
377 inline is_zero m_Zero() {
378  return is_zero();
379 }
380 
381 struct is_power2 {
382  bool isValue(const APInt &C) { return C.isPowerOf2(); }
383 };
384 /// Match an integer or vector power-of-2.
385 /// For vectors, this includes constants with undefined elements.
387  return cst_pred_ty<is_power2>();
388 }
390  return V;
391 }
392 
394  bool isValue(const APInt &C) { return !C || C.isPowerOf2(); }
395 };
396 /// Match an integer or vector of 0 or power-of-2 values.
397 /// For vectors, this includes constants with undefined elements.
400 }
402  return V;
403 }
404 
405 struct is_sign_mask {
406  bool isValue(const APInt &C) { return C.isSignMask(); }
407 };
408 /// Match an integer or vector with only the sign bit(s) set.
409 /// For vectors, this includes constants with undefined elements.
411  return cst_pred_ty<is_sign_mask>();
412 }
413 
415  bool isValue(const APInt &C) { return C.isMask(); }
416 };
417 /// Match an integer or vector with only the low bit(s) set.
418 /// For vectors, this includes constants with undefined elements.
421 }
422 
423 struct is_nan {
424  bool isValue(const APFloat &C) { return C.isNaN(); }
425 };
426 /// Match an arbitrary NaN constant. This includes quiet and signalling nans.
427 /// For vectors, this includes constants with undefined elements.
429  return cstfp_pred_ty<is_nan>();
430 }
431 
433  bool isValue(const APFloat &C) { return C.isZero(); }
434 };
435 /// Match a floating-point negative zero or positive zero.
436 /// For vectors, this includes constants with undefined elements.
439 }
440 
442  bool isValue(const APFloat &C) { return C.isPosZero(); }
443 };
444 /// Match a floating-point positive zero.
445 /// For vectors, this includes constants with undefined elements.
448 }
449 
451  bool isValue(const APFloat &C) { return C.isNegZero(); }
452 };
453 /// Match a floating-point negative zero.
454 /// For vectors, this includes constants with undefined elements.
457 }
458 
459 ///////////////////////////////////////////////////////////////////////////////
460 
461 template <typename Class> struct bind_ty {
462  Class *&VR;
463 
464  bind_ty(Class *&V) : VR(V) {}
465 
466  template <typename ITy> bool match(ITy *V) {
467  if (auto *CV = dyn_cast<Class>(V)) {
468  VR = CV;
469  return true;
470  }
471  return false;
472  }
473 };
474 
475 /// Match a value, capturing it if we match.
476 inline bind_ty<Value> m_Value(Value *&V) { return V; }
477 inline bind_ty<const Value> m_Value(const Value *&V) { return V; }
478 
479 /// Match an instruction, capturing it if we match.
481 /// Match a binary operator, capturing it if we match.
483 
484 /// Match a ConstantInt, capturing the value if we match.
485 inline bind_ty<ConstantInt> m_ConstantInt(ConstantInt *&CI) { return CI; }
486 
487 /// Match a Constant, capturing the value if we match.
488 inline bind_ty<Constant> m_Constant(Constant *&C) { return C; }
489 
490 /// Match a ConstantFP, capturing the value if we match.
492 
493 /// Match a specified Value*.
495  const Value *Val;
496 
497  specificval_ty(const Value *V) : Val(V) {}
498 
499  template <typename ITy> bool match(ITy *V) { return V == Val; }
500 };
501 
502 /// Match if we have a specific specified value.
503 inline specificval_ty m_Specific(const Value *V) { return V; }
504 
505 /// Stores a reference to the Value *, not the Value * itself,
506 /// thus can be used in commutative matchers.
507 template <typename Class> struct deferredval_ty {
508  Class *const &Val;
509 
510  deferredval_ty(Class *const &V) : Val(V) {}
511 
512  template <typename ITy> bool match(ITy *const V) { return V == Val; }
513 };
514 
515 /// A commutative-friendly version of m_Specific().
516 inline deferredval_ty<Value> m_Deferred(Value *const &V) { return V; }
518  return V;
519 }
520 
521 /// Match a specified floating point value or vector of all elements of
522 /// that value.
524  double Val;
525 
526  specific_fpval(double V) : Val(V) {}
527 
528  template <typename ITy> bool match(ITy *V) {
529  if (const auto *CFP = dyn_cast<ConstantFP>(V))
530  return CFP->isExactlyValue(Val);
531  if (V->getType()->isVectorTy())
532  if (const auto *C = dyn_cast<Constant>(V))
533  if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
534  return CFP->isExactlyValue(Val);
535  return false;
536  }
537 };
538 
539 /// Match a specific floating point value or vector with all elements
540 /// equal to the value.
541 inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
542 
543 /// Match a float 1.0 or vector with all elements equal to 1.0.
544 inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
545 
547  uint64_t &VR;
548 
549  bind_const_intval_ty(uint64_t &V) : VR(V) {}
550 
551  template <typename ITy> bool match(ITy *V) {
552  if (const auto *CV = dyn_cast<ConstantInt>(V))
553  if (CV->getValue().ule(UINT64_MAX)) {
554  VR = CV->getZExtValue();
555  return true;
556  }
557  return false;
558  }
559 };
560 
561 /// Match a specified integer value or vector of all elements of that
562 // value.
564  uint64_t Val;
565 
566  specific_intval(uint64_t V) : Val(V) {}
567 
568  template <typename ITy> bool match(ITy *V) {
569  const auto *CI = dyn_cast<ConstantInt>(V);
570  if (!CI && V->getType()->isVectorTy())
571  if (const auto *C = dyn_cast<Constant>(V))
572  CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
573 
574  return CI && CI->getValue() == Val;
575  }
576 };
577 
578 /// Match a specific integer value or vector with all elements equal to
579 /// the value.
580 inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); }
581 
582 /// Match a ConstantInt and bind to its value. This does not match
583 /// ConstantInts wider than 64-bits.
584 inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; }
585 
586 //===----------------------------------------------------------------------===//
587 // Matcher for any binary operator.
588 //
589 template <typename LHS_t, typename RHS_t, bool Commutable = false>
591  LHS_t L;
592  RHS_t R;
593 
594  // The evaluation order is always stable, regardless of Commutability.
595  // The LHS is always matched first.
596  AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
597 
598  template <typename OpTy> bool match(OpTy *V) {
599  if (auto *I = dyn_cast<BinaryOperator>(V))
600  return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
601  (Commutable && L.match(I->getOperand(1)) &&
602  R.match(I->getOperand(0)));
603  return false;
604  }
605 };
606 
607 template <typename LHS, typename RHS>
608 inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
609  return AnyBinaryOp_match<LHS, RHS>(L, R);
610 }
611 
612 //===----------------------------------------------------------------------===//
613 // Matchers for specific binary operators.
614 //
615 
616 template <typename LHS_t, typename RHS_t, unsigned Opcode,
617  bool Commutable = false>
619  LHS_t L;
620  RHS_t R;
621 
622  // The evaluation order is always stable, regardless of Commutability.
623  // The LHS is always matched first.
624  BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
625 
626  template <typename OpTy> bool match(OpTy *V) {
627  if (V->getValueID() == Value::InstructionVal + Opcode) {
628  auto *I = cast<BinaryOperator>(V);
629  return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
630  (Commutable && L.match(I->getOperand(1)) &&
631  R.match(I->getOperand(0)));
632  }
633  if (auto *CE = dyn_cast<ConstantExpr>(V))
634  return CE->getOpcode() == Opcode &&
635  ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) ||
636  (Commutable && L.match(CE->getOperand(1)) &&
637  R.match(CE->getOperand(0))));
638  return false;
639  }
640 };
641 
642 template <typename LHS, typename RHS>
644  const RHS &R) {
646 }
647 
648 template <typename LHS, typename RHS>
650  const RHS &R) {
652 }
653 
654 template <typename LHS, typename RHS>
656  const RHS &R) {
658 }
659 
660 template <typename LHS, typename RHS>
662  const RHS &R) {
664 }
665 
666 template <typename Op_t> struct FNeg_match {
667  Op_t X;
668 
669  FNeg_match(const Op_t &Op) : X(Op) {}
670  template <typename OpTy> bool match(OpTy *V) {
671  auto *FPMO = dyn_cast<FPMathOperator>(V);
672  if (!FPMO || FPMO->getOpcode() != Instruction::FSub)
673  return false;
674  if (FPMO->hasNoSignedZeros()) {
675  // With 'nsz', any zero goes.
676  if (!cstfp_pred_ty<is_any_zero_fp>().match(FPMO->getOperand(0)))
677  return false;
678  } else {
679  // Without 'nsz', we need fsub -0.0, X exactly.
680  if (!cstfp_pred_ty<is_neg_zero_fp>().match(FPMO->getOperand(0)))
681  return false;
682  }
683  return X.match(FPMO->getOperand(1));
684  }
685 };
686 
687 /// Match 'fneg X' as 'fsub -0.0, X'.
688 template <typename OpTy>
689 inline FNeg_match<OpTy>
690 m_FNeg(const OpTy &X) {
691  return FNeg_match<OpTy>(X);
692 }
693 
694 /// Match 'fneg X' as 'fsub +-0.0, X'.
695 template <typename RHS>
696 inline BinaryOp_match<cstfp_pred_ty<is_any_zero_fp>, RHS, Instruction::FSub>
697 m_FNegNSZ(const RHS &X) {
698  return m_FSub(m_AnyZeroFP(), X);
699 }
700 
701 template <typename LHS, typename RHS>
703  const RHS &R) {
705 }
706 
707 template <typename LHS, typename RHS>
709  const RHS &R) {
711 }
712 
713 template <typename LHS, typename RHS>
715  const RHS &R) {
717 }
718 
719 template <typename LHS, typename RHS>
721  const RHS &R) {
723 }
724 
725 template <typename LHS, typename RHS>
727  const RHS &R) {
729 }
730 
731 template <typename LHS, typename RHS>
733  const RHS &R) {
735 }
736 
737 template <typename LHS, typename RHS>
739  const RHS &R) {
741 }
742 
743 template <typename LHS, typename RHS>
745  const RHS &R) {
747 }
748 
749 template <typename LHS, typename RHS>
751  const RHS &R) {
753 }
754 
755 template <typename LHS, typename RHS>
757  const RHS &R) {
759 }
760 
761 template <typename LHS, typename RHS>
763  const RHS &R) {
765 }
766 
767 template <typename LHS, typename RHS>
769  const RHS &R) {
771 }
772 
773 template <typename LHS, typename RHS>
775  const RHS &R) {
777 }
778 
779 template <typename LHS, typename RHS>
781  const RHS &R) {
783 }
784 
785 template <typename LHS_t, typename RHS_t, unsigned Opcode,
786  unsigned WrapFlags = 0>
788  LHS_t L;
789  RHS_t R;
790 
791  OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
792  : L(LHS), R(RHS) {}
793 
794  template <typename OpTy> bool match(OpTy *V) {
795  if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
796  if (Op->getOpcode() != Opcode)
797  return false;
799  !Op->hasNoUnsignedWrap())
800  return false;
801  if (WrapFlags & OverflowingBinaryOperator::NoSignedWrap &&
802  !Op->hasNoSignedWrap())
803  return false;
804  return L.match(Op->getOperand(0)) && R.match(Op->getOperand(1));
805  }
806  return false;
807  }
808 };
809 
810 template <typename LHS, typename RHS>
813 m_NSWAdd(const LHS &L, const RHS &R) {
816  L, R);
817 }
818 template <typename LHS, typename RHS>
819 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
821 m_NSWSub(const LHS &L, const RHS &R) {
822  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
824  L, R);
825 }
826 template <typename LHS, typename RHS>
827 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
829 m_NSWMul(const LHS &L, const RHS &R) {
830  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
832  L, R);
833 }
834 template <typename LHS, typename RHS>
835 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
837 m_NSWShl(const LHS &L, const RHS &R) {
838  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
840  L, R);
841 }
842 
843 template <typename LHS, typename RHS>
846 m_NUWAdd(const LHS &L, const RHS &R) {
849  L, R);
850 }
851 template <typename LHS, typename RHS>
852 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
854 m_NUWSub(const LHS &L, const RHS &R) {
855  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
857  L, R);
858 }
859 template <typename LHS, typename RHS>
860 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
862 m_NUWMul(const LHS &L, const RHS &R) {
863  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
865  L, R);
866 }
867 template <typename LHS, typename RHS>
868 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
870 m_NUWShl(const LHS &L, const RHS &R) {
871  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
873  L, R);
874 }
875 
876 //===----------------------------------------------------------------------===//
877 // Class that matches a group of binary opcodes.
878 //
879 template <typename LHS_t, typename RHS_t, typename Predicate>
881  LHS_t L;
882  RHS_t R;
883 
884  BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
885 
886  template <typename OpTy> bool match(OpTy *V) {
887  if (auto *I = dyn_cast<Instruction>(V))
888  return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) &&
889  R.match(I->getOperand(1));
890  if (auto *CE = dyn_cast<ConstantExpr>(V))
891  return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) &&
892  R.match(CE->getOperand(1));
893  return false;
894  }
895 };
896 
897 struct is_shift_op {
898  bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); }
899 };
900 
902  bool isOpType(unsigned Opcode) {
903  return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
904  }
905 };
906 
908  bool isOpType(unsigned Opcode) {
909  return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
910  }
911 };
912 
914  bool isOpType(unsigned Opcode) {
915  return Instruction::isBitwiseLogicOp(Opcode);
916  }
917 };
918 
919 struct is_idiv_op {
920  bool isOpType(unsigned Opcode) {
921  return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
922  }
923 };
924 
925 /// Matches shift operations.
926 template <typename LHS, typename RHS>
928  const RHS &R) {
930 }
931 
932 /// Matches logical shift operations.
933 template <typename LHS, typename RHS>
935  const RHS &R) {
937 }
938 
939 /// Matches logical shift operations.
940 template <typename LHS, typename RHS>
942 m_LogicalShift(const LHS &L, const RHS &R) {
944 }
945 
946 /// Matches bitwise logic operations.
947 template <typename LHS, typename RHS>
949 m_BitwiseLogic(const LHS &L, const RHS &R) {
951 }
952 
953 /// Matches integer division operations.
954 template <typename LHS, typename RHS>
956  const RHS &R) {
958 }
959 
960 //===----------------------------------------------------------------------===//
961 // Class that matches exact binary ops.
962 //
963 template <typename SubPattern_t> struct Exact_match {
964  SubPattern_t SubPattern;
965 
966  Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
967 
968  template <typename OpTy> bool match(OpTy *V) {
969  if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
970  return PEO->isExact() && SubPattern.match(V);
971  return false;
972  }
973 };
974 
975 template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
976  return SubPattern;
977 }
978 
979 //===----------------------------------------------------------------------===//
980 // Matchers for CmpInst classes
981 //
982 
983 template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
984  bool Commutable = false>
986  PredicateTy &Predicate;
987  LHS_t L;
988  RHS_t R;
989 
990  // The evaluation order is always stable, regardless of Commutability.
991  // The LHS is always matched first.
992  CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
993  : Predicate(Pred), L(LHS), R(RHS) {}
994 
995  template <typename OpTy> bool match(OpTy *V) {
996  if (auto *I = dyn_cast<Class>(V))
997  if ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
998  (Commutable && L.match(I->getOperand(1)) &&
999  R.match(I->getOperand(0)))) {
1000  Predicate = I->getPredicate();
1001  return true;
1002  }
1003  return false;
1004  }
1005 };
1006 
1007 template <typename LHS, typename RHS>
1009 m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1011 }
1012 
1013 template <typename LHS, typename RHS>
1015 m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1017 }
1018 
1019 template <typename LHS, typename RHS>
1021 m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1023 }
1024 
1025 //===----------------------------------------------------------------------===//
1026 // Matchers for instructions with a given opcode and number of operands.
1027 //
1028 
1029 /// Matches instructions with Opcode and three operands.
1030 template <typename T0, unsigned Opcode> struct OneOps_match {
1031  T0 Op1;
1032 
1033  OneOps_match(const T0 &Op1) : Op1(Op1) {}
1034 
1035  template <typename OpTy> bool match(OpTy *V) {
1036  if (V->getValueID() == Value::InstructionVal + Opcode) {
1037  auto *I = cast<Instruction>(V);
1038  return Op1.match(I->getOperand(0));
1039  }
1040  return false;
1041  }
1042 };
1043 
1044 /// Matches instructions with Opcode and three operands.
1045 template <typename T0, typename T1, unsigned Opcode> struct TwoOps_match {
1046  T0 Op1;
1048 
1049  TwoOps_match(const T0 &Op1, const T1 &Op2) : Op1(Op1), Op2(Op2) {}
1050 
1051  template <typename OpTy> bool match(OpTy *V) {
1052  if (V->getValueID() == Value::InstructionVal + Opcode) {
1053  auto *I = cast<Instruction>(V);
1054  return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1));
1055  }
1056  return false;
1057  }
1058 };
1059 
1060 /// Matches instructions with Opcode and three operands.
1061 template <typename T0, typename T1, typename T2, unsigned Opcode>
1063  T0 Op1;
1065  T2 Op3;
1066 
1067  ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
1068  : Op1(Op1), Op2(Op2), Op3(Op3) {}
1069 
1070  template <typename OpTy> bool match(OpTy *V) {
1071  if (V->getValueID() == Value::InstructionVal + Opcode) {
1072  auto *I = cast<Instruction>(V);
1073  return Op1.match(I->getOperand(0)) && Op2.match(I->getOperand(1)) &&
1074  Op3.match(I->getOperand(2));
1075  }
1076  return false;
1077  }
1078 };
1079 
1080 /// Matches SelectInst.
1081 template <typename Cond, typename LHS, typename RHS>
1083 m_Select(const Cond &C, const LHS &L, const RHS &R) {
1085 }
1086 
1087 /// This matches a select of two constants, e.g.:
1088 /// m_SelectCst<-1, 0>(m_Value(V))
1089 template <int64_t L, int64_t R, typename Cond>
1092 m_SelectCst(const Cond &C) {
1093  return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1094 }
1095 
1096 /// Matches InsertElementInst.
1097 template <typename Val_t, typename Elt_t, typename Idx_t>
1099 m_InsertElement(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx) {
1101  Val, Elt, Idx);
1102 }
1103 
1104 /// Matches ExtractElementInst.
1105 template <typename Val_t, typename Idx_t>
1107 m_ExtractElement(const Val_t &Val, const Idx_t &Idx) {
1109 }
1110 
1111 /// Matches ShuffleVectorInst.
1112 template <typename V1_t, typename V2_t, typename Mask_t>
1114 m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m) {
1116  m);
1117 }
1118 
1119 /// Matches LoadInst.
1120 template <typename OpTy>
1123 }
1124 
1125 /// Matches StoreInst.
1126 template <typename ValueOpTy, typename PointerOpTy>
1128 m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
1130  PointerOp);
1131 }
1132 
1133 //===----------------------------------------------------------------------===//
1134 // Matchers for CastInst classes
1135 //
1136 
1137 template <typename Op_t, unsigned Opcode> struct CastClass_match {
1138  Op_t Op;
1139 
1140  CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
1141 
1142  template <typename OpTy> bool match(OpTy *V) {
1143  if (auto *O = dyn_cast<Operator>(V))
1144  return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
1145  return false;
1146  }
1147 };
1148 
1149 /// Matches BitCast.
1150 template <typename OpTy>
1153 }
1154 
1155 /// Matches PtrToInt.
1156 template <typename OpTy>
1159 }
1160 
1161 /// Matches Trunc.
1162 template <typename OpTy>
1165 }
1166 
1167 /// Matches SExt.
1168 template <typename OpTy>
1171 }
1172 
1173 /// Matches ZExt.
1174 template <typename OpTy>
1177 }
1178 
1179 template <typename OpTy>
1182 m_ZExtOrSExt(const OpTy &Op) {
1183  return m_CombineOr(m_ZExt(Op), m_SExt(Op));
1184 }
1185 
1186 /// Matches UIToFP.
1187 template <typename OpTy>
1190 }
1191 
1192 /// Matches SIToFP.
1193 template <typename OpTy>
1196 }
1197 
1198 /// Matches FPTrunc
1199 template <typename OpTy>
1202 }
1203 
1204 /// Matches FPExt
1205 template <typename OpTy>
1208 }
1209 
1210 //===----------------------------------------------------------------------===//
1211 // Matchers for control flow.
1212 //
1213 
1214 struct br_match {
1216 
1217  br_match(BasicBlock *&Succ) : Succ(Succ) {}
1218 
1219  template <typename OpTy> bool match(OpTy *V) {
1220  if (auto *BI = dyn_cast<BranchInst>(V))
1221  if (BI->isUnconditional()) {
1222  Succ = BI->getSuccessor(0);
1223  return true;
1224  }
1225  return false;
1226  }
1227 };
1228 
1229 inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
1230 
1231 template <typename Cond_t> struct brc_match {
1232  Cond_t Cond;
1234 
1235  brc_match(const Cond_t &C, BasicBlock *&t, BasicBlock *&f)
1236  : Cond(C), T(t), F(f) {}
1237 
1238  template <typename OpTy> bool match(OpTy *V) {
1239  if (auto *BI = dyn_cast<BranchInst>(V))
1240  if (BI->isConditional() && Cond.match(BI->getCondition())) {
1241  T = BI->getSuccessor(0);
1242  F = BI->getSuccessor(1);
1243  return true;
1244  }
1245  return false;
1246  }
1247 };
1248 
1249 template <typename Cond_t>
1250 inline brc_match<Cond_t> m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) {
1251  return brc_match<Cond_t>(C, T, F);
1252 }
1253 
1254 //===----------------------------------------------------------------------===//
1255 // Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
1256 //
1257 
1258 template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t,
1259  bool Commutable = false>
1261  LHS_t L;
1262  RHS_t R;
1263 
1264  // The evaluation order is always stable, regardless of Commutability.
1265  // The LHS is always matched first.
1266  MaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1267 
1268  template <typename OpTy> bool match(OpTy *V) {
1269  // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
1270  auto *SI = dyn_cast<SelectInst>(V);
1271  if (!SI)
1272  return false;
1273  auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
1274  if (!Cmp)
1275  return false;
1276  // At this point we have a select conditioned on a comparison. Check that
1277  // it is the values returned by the select that are being compared.
1278  Value *TrueVal = SI->getTrueValue();
1279  Value *FalseVal = SI->getFalseValue();
1280  Value *LHS = Cmp->getOperand(0);
1281  Value *RHS = Cmp->getOperand(1);
1282  if ((TrueVal != LHS || FalseVal != RHS) &&
1283  (TrueVal != RHS || FalseVal != LHS))
1284  return false;
1285  typename CmpInst_t::Predicate Pred =
1286  LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1287  // Does "(x pred y) ? x : y" represent the desired max/min operation?
1288  if (!Pred_t::match(Pred))
1289  return false;
1290  // It does! Bind the operands.
1291  return (L.match(LHS) && R.match(RHS)) ||
1292  (Commutable && L.match(RHS) && R.match(LHS));
1293  }
1294 };
1295 
1296 /// Helper class for identifying signed max predicates.
1298  static bool match(ICmpInst::Predicate Pred) {
1299  return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE;
1300  }
1301 };
1302 
1303 /// Helper class for identifying signed min predicates.
1305  static bool match(ICmpInst::Predicate Pred) {
1306  return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE;
1307  }
1308 };
1309 
1310 /// Helper class for identifying unsigned max predicates.
1312  static bool match(ICmpInst::Predicate Pred) {
1313  return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE;
1314  }
1315 };
1316 
1317 /// Helper class for identifying unsigned min predicates.
1319  static bool match(ICmpInst::Predicate Pred) {
1320  return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE;
1321  }
1322 };
1323 
1324 /// Helper class for identifying ordered max predicates.
1326  static bool match(FCmpInst::Predicate Pred) {
1327  return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
1328  }
1329 };
1330 
1331 /// Helper class for identifying ordered min predicates.
1333  static bool match(FCmpInst::Predicate Pred) {
1334  return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
1335  }
1336 };
1337 
1338 /// Helper class for identifying unordered max predicates.
1340  static bool match(FCmpInst::Predicate Pred) {
1341  return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
1342  }
1343 };
1344 
1345 /// Helper class for identifying unordered min predicates.
1347  static bool match(FCmpInst::Predicate Pred) {
1348  return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
1349  }
1350 };
1351 
1352 template <typename LHS, typename RHS>
1354  const RHS &R) {
1356 }
1357 
1358 template <typename LHS, typename RHS>
1360  const RHS &R) {
1362 }
1363 
1364 template <typename LHS, typename RHS>
1366  const RHS &R) {
1368 }
1369 
1370 template <typename LHS, typename RHS>
1372  const RHS &R) {
1374 }
1375 
1376 /// Match an 'ordered' floating point maximum function.
1377 /// Floating point has one special value 'NaN'. Therefore, there is no total
1378 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1379 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
1380 /// semantics. In the presence of 'NaN' we have to preserve the original
1381 /// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
1382 ///
1383 /// max(L, R) iff L and R are not NaN
1384 /// m_OrdFMax(L, R) = R iff L or R are NaN
1385 template <typename LHS, typename RHS>
1387  const RHS &R) {
1389 }
1390 
1391 /// Match an 'ordered' floating point minimum function.
1392 /// Floating point has one special value 'NaN'. Therefore, there is no total
1393 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1394 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
1395 /// semantics. In the presence of 'NaN' we have to preserve the original
1396 /// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
1397 ///
1398 /// min(L, R) iff L and R are not NaN
1399 /// m_OrdFMin(L, R) = R iff L or R are NaN
1400 template <typename LHS, typename RHS>
1402  const RHS &R) {
1404 }
1405 
1406 /// Match an 'unordered' floating point maximum function.
1407 /// Floating point has one special value 'NaN'. Therefore, there is no total
1408 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1409 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
1410 /// semantics. In the presence of 'NaN' we have to preserve the original
1411 /// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
1412 ///
1413 /// max(L, R) iff L and R are not NaN
1414 /// m_UnordFMax(L, R) = L iff L or R are NaN
1415 template <typename LHS, typename RHS>
1417 m_UnordFMax(const LHS &L, const RHS &R) {
1419 }
1420 
1421 /// Match an 'unordered' floating point minimum function.
1422 /// Floating point has one special value 'NaN'. Therefore, there is no total
1423 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1424 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
1425 /// semantics. In the presence of 'NaN' we have to preserve the original
1426 /// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
1427 ///
1428 /// min(L, R) iff L and R are not NaN
1429 /// m_UnordFMin(L, R) = L iff L or R are NaN
1430 template <typename LHS, typename RHS>
1432 m_UnordFMin(const LHS &L, const RHS &R) {
1434 }
1435 
1436 //===----------------------------------------------------------------------===//
1437 // Matchers for overflow check patterns: e.g. (a + b) u< a
1438 //
1439 
1440 template <typename LHS_t, typename RHS_t, typename Sum_t>
1442  LHS_t L;
1443  RHS_t R;
1444  Sum_t S;
1445 
1446  UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
1447  : L(L), R(R), S(S) {}
1448 
1449  template <typename OpTy> bool match(OpTy *V) {
1450  Value *ICmpLHS, *ICmpRHS;
1451  ICmpInst::Predicate Pred;
1452  if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
1453  return false;
1454 
1455  Value *AddLHS, *AddRHS;
1456  auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
1457 
1458  // (a + b) u< a, (a + b) u< b
1459  if (Pred == ICmpInst::ICMP_ULT)
1460  if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1461  return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1462 
1463  // a >u (a + b), b >u (a + b)
1464  if (Pred == ICmpInst::ICMP_UGT)
1465  if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1466  return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1467 
1468  return false;
1469  }
1470 };
1471 
1472 /// Match an icmp instruction checking for unsigned overflow on addition.
1473 ///
1474 /// S is matched to the addition whose result is being checked for overflow, and
1475 /// L and R are matched to the LHS and RHS of S.
1476 template <typename LHS_t, typename RHS_t, typename Sum_t>
1478 m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
1480 }
1481 
1482 template <typename Opnd_t> struct Argument_match {
1483  unsigned OpI;
1484  Opnd_t Val;
1485 
1486  Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
1487 
1488  template <typename OpTy> bool match(OpTy *V) {
1489  CallSite CS(V);
1490  return CS.isCall() && Val.match(CS.getArgument(OpI));
1491  }
1492 };
1493 
1494 /// Match an argument.
1495 template <unsigned OpI, typename Opnd_t>
1496 inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
1497  return Argument_match<Opnd_t>(OpI, Op);
1498 }
1499 
1500 /// Intrinsic matchers.
1502  unsigned ID;
1503 
1504  IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
1505 
1506  template <typename OpTy> bool match(OpTy *V) {
1507  if (const auto *CI = dyn_cast<CallInst>(V))
1508  if (const auto *F = CI->getCalledFunction())
1509  return F->getIntrinsicID() == ID;
1510  return false;
1511  }
1512 };
1513 
1514 /// Intrinsic matches are combinations of ID matchers, and argument
1515 /// matchers. Higher arity matcher are defined recursively in terms of and-ing
1516 /// them with lower arity matchers. Here's some convenient typedefs for up to
1517 /// several arguments, and more can be added as needed
1518 template <typename T0 = void, typename T1 = void, typename T2 = void,
1519  typename T3 = void, typename T4 = void, typename T5 = void,
1520  typename T6 = void, typename T7 = void, typename T8 = void,
1521  typename T9 = void, typename T10 = void>
1523 template <typename T0> struct m_Intrinsic_Ty<T0> {
1525 };
1526 template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
1527  using Ty =
1529 };
1530 template <typename T0, typename T1, typename T2>
1531 struct m_Intrinsic_Ty<T0, T1, T2> {
1532  using Ty =
1535 };
1536 template <typename T0, typename T1, typename T2, typename T3>
1537 struct m_Intrinsic_Ty<T0, T1, T2, T3> {
1538  using Ty =
1541 };
1542 
1543 /// Match intrinsic calls like this:
1544 /// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
1545 template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
1546  return IntrinsicID_match(IntrID);
1547 }
1548 
1549 template <Intrinsic::ID IntrID, typename T0>
1550 inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
1551  return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
1552 }
1553 
1554 template <Intrinsic::ID IntrID, typename T0, typename T1>
1555 inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
1556  const T1 &Op1) {
1557  return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
1558 }
1559 
1560 template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
1561 inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
1562 m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
1563  return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
1564 }
1565 
1566 template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
1567  typename T3>
1568 inline typename m_Intrinsic_Ty<T0, T1, T2, T3>::Ty
1569 m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
1570  return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
1571 }
1572 
1573 // Helper intrinsic matching specializations.
1574 template <typename Opnd0>
1575 inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BitReverse(const Opnd0 &Op0) {
1576  return m_Intrinsic<Intrinsic::bitreverse>(Op0);
1577 }
1578 
1579 template <typename Opnd0>
1580 inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BSwap(const Opnd0 &Op0) {
1581  return m_Intrinsic<Intrinsic::bswap>(Op0);
1582 }
1583 
1584 template <typename Opnd0>
1585 inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FAbs(const Opnd0 &Op0) {
1586  return m_Intrinsic<Intrinsic::fabs>(Op0);
1587 }
1588 
1589 template <typename Opnd0>
1590 inline typename m_Intrinsic_Ty<Opnd0>::Ty m_FCanonicalize(const Opnd0 &Op0) {
1591  return m_Intrinsic<Intrinsic::canonicalize>(Op0);
1592 }
1593 
1594 template <typename Opnd0, typename Opnd1>
1595 inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMin(const Opnd0 &Op0,
1596  const Opnd1 &Op1) {
1597  return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
1598 }
1599 
1600 template <typename Opnd0, typename Opnd1>
1601 inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMax(const Opnd0 &Op0,
1602  const Opnd1 &Op1) {
1603  return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
1604 }
1605 
1606 //===----------------------------------------------------------------------===//
1607 // Matchers for two-operands operators with the operators in either order
1608 //
1609 
1610 /// Matches a BinaryOperator with LHS and RHS in either order.
1611 template <typename LHS, typename RHS>
1612 inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) {
1613  return AnyBinaryOp_match<LHS, RHS, true>(L, R);
1614 }
1615 
1616 /// Matches an ICmp with a predicate over LHS and RHS in either order.
1617 /// Does not swap the predicate.
1618 template <typename LHS, typename RHS>
1620 m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1622  R);
1623 }
1624 
1625 /// Matches a Add with LHS and RHS in either order.
1626 template <typename LHS, typename RHS>
1628  const RHS &R) {
1630 }
1631 
1632 /// Matches a Mul with LHS and RHS in either order.
1633 template <typename LHS, typename RHS>
1635  const RHS &R) {
1637 }
1638 
1639 /// Matches an And with LHS and RHS in either order.
1640 template <typename LHS, typename RHS>
1642  const RHS &R) {
1644 }
1645 
1646 /// Matches an Or with LHS and RHS in either order.
1647 template <typename LHS, typename RHS>
1649  const RHS &R) {
1651 }
1652 
1653 /// Matches an Xor with LHS and RHS in either order.
1654 template <typename LHS, typename RHS>
1656  const RHS &R) {
1658 }
1659 
1660 /// Matches a 'Neg' as 'sub 0, V'.
1661 template <typename ValTy>
1662 inline BinaryOp_match<cst_pred_ty<is_zero_int>, ValTy, Instruction::Sub>
1663 m_Neg(const ValTy &V) {
1664  return m_Sub(m_ZeroInt(), V);
1665 }
1666 
1667 /// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
1668 template <typename ValTy>
1669 inline BinaryOp_match<ValTy, cst_pred_ty<is_all_ones>, Instruction::Xor, true>
1670 m_Not(const ValTy &V) {
1671  return m_c_Xor(V, m_AllOnes());
1672 }
1673 
1674 /// Matches an SMin with LHS and RHS in either order.
1675 template <typename LHS, typename RHS>
1677 m_c_SMin(const LHS &L, const RHS &R) {
1679 }
1680 /// Matches an SMax with LHS and RHS in either order.
1681 template <typename LHS, typename RHS>
1683 m_c_SMax(const LHS &L, const RHS &R) {
1685 }
1686 /// Matches a UMin with LHS and RHS in either order.
1687 template <typename LHS, typename RHS>
1689 m_c_UMin(const LHS &L, const RHS &R) {
1691 }
1692 /// Matches a UMax with LHS and RHS in either order.
1693 template <typename LHS, typename RHS>
1695 m_c_UMax(const LHS &L, const RHS &R) {
1697 }
1698 
1699 /// Matches FAdd with LHS and RHS in either order.
1700 template <typename LHS, typename RHS>
1702 m_c_FAdd(const LHS &L, const RHS &R) {
1704 }
1705 
1706 /// Matches FMul with LHS and RHS in either order.
1707 template <typename LHS, typename RHS>
1709 m_c_FMul(const LHS &L, const RHS &R) {
1711 }
1712 
1713 template <typename Opnd_t> struct Signum_match {
1714  Opnd_t Val;
1715  Signum_match(const Opnd_t &V) : Val(V) {}
1716 
1717  template <typename OpTy> bool match(OpTy *V) {
1718  unsigned TypeSize = V->getType()->getScalarSizeInBits();
1719  if (TypeSize == 0)
1720  return false;
1721 
1722  unsigned ShiftWidth = TypeSize - 1;
1723  Value *OpL = nullptr, *OpR = nullptr;
1724 
1725  // This is the representation of signum we match:
1726  //
1727  // signum(x) == (x >> 63) | (-x >>u 63)
1728  //
1729  // An i1 value is its own signum, so it's correct to match
1730  //
1731  // signum(x) == (x >> 0) | (-x >>u 0)
1732  //
1733  // for i1 values.
1734 
1735  auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
1736  auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
1737  auto Signum = m_Or(LHS, RHS);
1738 
1739  return Signum.match(V) && OpL == OpR && Val.match(OpL);
1740  }
1741 };
1742 
1743 /// Matches a signum pattern.
1744 ///
1745 /// signum(x) =
1746 /// x > 0 -> 1
1747 /// x == 0 -> 0
1748 /// x < 0 -> -1
1749 template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
1750  return Signum_match<Val_t>(V);
1751 }
1752 
1753 } // end namespace PatternMatch
1754 } // end namespace llvm
1755 
1756 #endif // LLVM_IR_PATTERNMATCH_H
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Definition: PatternMatch.h:750
uint64_t CallInst * C
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
Definition: PatternMatch.h:934
bool isValue(const APFloat &C)
Definition: PatternMatch.h:442
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:821
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of nonnegative values.
Definition: PatternMatch.h:344
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
static bool match(FCmpInst::Predicate Pred)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:72
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
Definition: PatternMatch.h:88
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool isSignMask() const
Check if the APInt&#39;s value is returned by getSignMask.
Definition: APInt.h:473
bool isZero() const
Definition: APFloat.h:1143
Match a specified integer value or vector of all elements of that.
Definition: PatternMatch.h:563
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
Definition: PatternMatch.h:80
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:655
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
Definition: PatternMatch.h:377
br_match(BasicBlock *&Succ)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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)
Definition: PatternMatch.h:649
Matches instructions with Opcode and three operands.
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
Match a specified floating point value or vector of all elements of that value.
Definition: PatternMatch.h:523
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
bool isValue(const APInt &C)
Definition: PatternMatch.h:406
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
Definition: PatternMatch.h:726
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
Definition: PatternMatch.h:738
bool isValue(const APInt &C)
Definition: PatternMatch.h:361
Exact_match(const SubPattern_t &SP)
Definition: PatternMatch.h:966
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match &#39;fneg X&#39; as &#39;fsub +-0.0, X&#39;.
Definition: PatternMatch.h:697
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.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:702
br_match m_UnconditionalBr(BasicBlock *&Succ)
This helper class is used to match scalar and vector floating-point constants that satisfy a specifie...
Definition: PatternMatch.h:265
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
Definition: PatternMatch.h:410
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElement(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition: PatternMatch.h:91
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
unsigned less or equal
Definition: InstrTypes.h:668
unsigned less than
Definition: InstrTypes.h:667
bool isValue(const APInt &C)
Definition: PatternMatch.h:328
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
Definition: PatternMatch.h:780
static bool match(ICmpInst::Predicate Pred)
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:648
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
match_combine_or(const LTy &Left, const RTy &Right)
Definition: PatternMatch.h:98
F(f)
ThreeOps_match< V1_t, V2_t, Mask_t, Instruction::ShuffleVector > m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m)
Matches ShuffleVectorInst.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:661
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an &#39;unordered&#39; floating point maximum function.
Argument_match(unsigned OpIdx, const Opnd_t &V)
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
Definition: PatternMatch.h:365
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
Definition: PatternMatch.h:942
Matches instructions with Opcode and three operands.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
Definition: PatternMatch.h:541
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
CmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Helper class for identifying signed min predicates.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
Definition: PatternMatch.h:762
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElement(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
This class represents the LLVM &#39;select&#39; instruction.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition: APInt.h:369
Exact_match< T > m_Exact(const T &SubPattern)
Definition: PatternMatch.h:975
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
Definition: PatternMatch.h:419
bool isValue(const APFloat &C)
Definition: PatternMatch.h:433
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
bool isValue(const APFloat &C)
Definition: PatternMatch.h:424
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f...
Definition: PatternMatch.h:320
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.
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:649
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an &#39;unordered&#39; floating point minimum function.
This file implements a class to represent arbitrary precision integral constant values and operations...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
Definition: PatternMatch.h:643
bind_ty< ConstantFP > m_ConstantFP(ConstantFP *&C)
Match a ConstantFP, capturing the value if we match.
Definition: PatternMatch.h:491
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
Definition: Instruction.h:178
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
Definition: PatternMatch.h:846
#define UINT64_MAX
Definition: DataTypes.h:83
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
Definition: PatternMatch.h:428
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
Definition: PatternMatch.h:181
CastClass_match< OpTy, Instruction::FPExt > m_FPExt(const OpTy &Op)
Matches FPExt.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
Definition: PatternMatch.h:125
CastClass_match(const Op_t &OpMatch)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
#define T
CastClass_match< OpTy, Instruction::FPTrunc > m_FPTrunc(const OpTy &Op)
Matches FPTrunc.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an &#39;ordered&#39; floating point minimum function.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Definition: PatternMatch.h:83
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:138
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
Definition: PatternMatch.h:446
IntrinsicID_match(Intrinsic::ID IntrID)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
Definition: PatternMatch.h:386
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:862
bool isCall() const
Return true if a CallInst is enclosed.
Definition: CallSite.h:87
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying ordered min predicates.
match_combine_and(const LTy &Left, const RTy &Right)
Definition: PatternMatch.h:113
OneUse_match< T > m_OneUse(const T &SubPattern)
Definition: PatternMatch.h:63
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:364
#define P(N)
bool isNegZero() const
Definition: APFloat.h:1159
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Definition: PatternMatch.h:774
Helper class for identifying signed max predicates.
bool isAllOnesValue() const
Determine if all bits are set.
Definition: APInt.h:396
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
Definition: PatternMatch.h:177
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
Definition: PatternMatch.h:720
This helper class is used to match scalar and vector integer constants that satisfy a specified predi...
Definition: PatternMatch.h:206
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.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
Definition: PatternMatch.h:870
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
Definition: PatternMatch.h:744
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
Definition: PatternMatch.h:398
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
Definition: PatternMatch.h:756
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
bool isNaN() const
Definition: APFloat.h:1145
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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.
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:264
bool isMask(unsigned numBits) const
Definition: APInt.h:495
bool isOneValue() const
Determine if this is a value of 1.
Definition: APInt.h:411
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
Definition: PatternMatch.h:310
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Definition: PatternMatch.h:503
brc_match< Cond_t > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
Definition: PatternMatch.h:768
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:642
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
Helper class for identifying unsigned min predicates.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
Definition: PatternMatch.h:949
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true > m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:596
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Definition: PatternMatch.h:75
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
Definition: PatternMatch.h:955
Helper class for identifying unordered min predicates.
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:657
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:624
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
Definition: PatternMatch.h:516
signed greater than
Definition: InstrTypes.h:669
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true > m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
OneUse_match(const SubPattern_t &SP)
Definition: PatternMatch.h:56
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:646
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
Definition: PatternMatch.h:332
Intrinsic matches are combinations of ID matchers, and argument matchers.
static bool match(ICmpInst::Predicate Pred)
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.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
Definition: APInt.h:427
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
static bool match(ICmpInst::Predicate Pred)
bool isValue(const APInt &C)
Definition: PatternMatch.h:382
ValTy * getArgument(unsigned ArgNo) const
Definition: CallSite.h:186
Match a specified Value*.
Definition: PatternMatch.h:494
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:656
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition: Operator.h:240
brc_match(const Cond_t &C, BasicBlock *&t, BasicBlock *&f)
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
Definition: PatternMatch.h:732
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:27
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
Definition: PatternMatch.h:714
signed less than
Definition: InstrTypes.h:671
bool isOpType(unsigned Opcode)
Definition: PatternMatch.h:920
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.
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers...
Definition: PatternMatch.h:507
CastClass_match< OpTy, Instruction::UIToFP > m_UIToFP(const OpTy &Op)
Matches UIToFP.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:708
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
Definition: PatternMatch.h:813
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a &#39;Neg&#39; as &#39;sub 0, V&#39;.
signed less or equal
Definition: InstrTypes.h:672
Class for arbitrary precision integers.
Definition: APInt.h:70
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
Definition: PatternMatch.h:455
bool isPowerOf2() const
Check if this APInt&#39;s value is a power of two greater than zero.
Definition: APInt.h:464
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
Definition: PatternMatch.h:927
Helper class for identifying unsigned max predicates.
Helper class for identifying ordered max predicates.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:854
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
Definition: PatternMatch.h:544
m_Intrinsic_Ty< Opnd0 >::Ty m_FCanonicalize(const Opnd0 &Op0)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match &#39;fneg X&#39; as &#39;fsub -0.0, X&#39;.
Definition: PatternMatch.h:690
bool isPosZero() const
Definition: APFloat.h:1158
unsigned greater or equal
Definition: InstrTypes.h:666
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:992
#define I(x, y, z)
Definition: MD5.cpp:58
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
Definition: PatternMatch.h:837
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
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.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
CastClass_match< OpTy, Instruction::SIToFP > m_SIToFP(const OpTy &Op)
Matches SIToFP.
1 0 1 0 True if unordered or greater than
Definition: InstrTypes.h:654
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:791
Matches instructions with Opcode and three operands.
bool isOpType(unsigned Opcode)
Definition: PatternMatch.h:898
static bool match(FCmpInst::Predicate Pred)
apfloat_match(const APFloat *&R)
Definition: PatternMatch.h:159
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an &#39;ordered&#39; floating point maximum function.
Helper class for identifying unordered max predicates.
LLVM Value Representation.
Definition: Value.h:73
bool isValue(const APInt &C)
Definition: PatternMatch.h:306
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:655
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:829
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
Definition: PatternMatch.h:356
static bool match(ICmpInst::Predicate Pred)
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:884
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
Definition: PatternMatch.h:131
static bool match(FCmpInst::Predicate Pred)
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
unsigned greater than
Definition: InstrTypes.h:665
specific_intval m_SpecificInt(uint64_t V)
Match a specific integer value or vector with all elements equal to the value.
Definition: PatternMatch.h:580
bool isValue(const APInt &C)
Definition: PatternMatch.h:352
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
Definition: PatternMatch.h:437
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:647
bool isValue(const APFloat &C)
Definition: PatternMatch.h:451
This helper class is used to match scalar and vector constants that satisfy a specified predicate...
Definition: PatternMatch.h:239
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
Definition: PatternMatch.h:480
#define T1
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a &#39;Not&#39; as &#39;xor V, -1&#39; or &#39;xor -1, V&#39;.
bool isNullValue() const
Determine if all bits are clear.
Definition: APInt.h:406
signed greater or equal
Definition: InstrTypes.h:670
TwoOps_match(const T0 &Op1, const T1 &Op2)
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.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)