LLVM  7.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 match_zero {
136  template <typename ITy> bool match(ITy *V) {
137  if (const auto *C = dyn_cast<Constant>(V))
138  return C->isNullValue();
139  return false;
140  }
141 };
142 
143 /// Match an arbitrary zero/null constant. This includes
144 /// zero_initializer for vectors and ConstantPointerNull for pointers.
145 inline match_zero m_Zero() { return match_zero(); }
146 
148  template <typename ITy> bool match(ITy *V) {
149  if (const auto *C = dyn_cast<Constant>(V))
150  return C->isNegativeZeroValue();
151  return false;
152  }
153 };
154 
155 /// Match an arbitrary zero/null constant. This includes
156 /// zero_initializer for vectors and ConstantPointerNull for pointers. For
157 /// floating point constants, this will match negative zero but not positive
158 /// zero
160 
162  template <typename ITy> bool match(ITy *V) {
163  if (const auto *C = dyn_cast<Constant>(V))
164  return C->isZeroValue();
165  return false;
166  }
167 };
168 
169 /// Match an arbitrary zero/null constant. This includes
170 /// zero_initializer for vectors and ConstantPointerNull for pointers. For
171 /// floating point constants, this will match negative zero and positive zero
173 
174 struct match_nan {
175  template <typename ITy> bool match(ITy *V) {
176  if (const auto *C = dyn_cast<ConstantFP>(V))
177  return C->isNaN();
178  return false;
179  }
180 };
181 
182 /// Match an arbitrary NaN constant. This includes quiet and signalling nans.
183 inline match_nan m_NaN() { return match_nan(); }
184 
185 struct apint_match {
186  const APInt *&Res;
187 
188  apint_match(const APInt *&R) : Res(R) {}
189 
190  template <typename ITy> bool match(ITy *V) {
191  if (auto *CI = dyn_cast<ConstantInt>(V)) {
192  Res = &CI->getValue();
193  return true;
194  }
195  if (V->getType()->isVectorTy())
196  if (const auto *C = dyn_cast<Constant>(V))
197  if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue())) {
198  Res = &CI->getValue();
199  return true;
200  }
201  return false;
202  }
203 };
204 // Either constexpr if or renaming ConstantFP::getValueAPF to
205 // ConstantFP::getValue is needed to do it via single template
206 // function for both apint/apfloat.
208  const APFloat *&Res;
209  apfloat_match(const APFloat *&R) : Res(R) {}
210  template <typename ITy> bool match(ITy *V) {
211  if (auto *CI = dyn_cast<ConstantFP>(V)) {
212  Res = &CI->getValueAPF();
213  return true;
214  }
215  if (V->getType()->isVectorTy())
216  if (const auto *C = dyn_cast<Constant>(V))
217  if (auto *CI = dyn_cast_or_null<ConstantFP>(C->getSplatValue())) {
218  Res = &CI->getValueAPF();
219  return true;
220  }
221  return false;
222  }
223 };
224 
225 /// Match a ConstantInt or splatted ConstantVector, binding the
226 /// specified pointer to the contained APInt.
227 inline apint_match m_APInt(const APInt *&Res) { return Res; }
228 
229 /// Match a ConstantFP or splatted ConstantVector, binding the
230 /// specified pointer to the contained APFloat.
231 inline apfloat_match m_APFloat(const APFloat *&Res) { return Res; }
232 
233 template <int64_t Val> struct constantint_match {
234  template <typename ITy> bool match(ITy *V) {
235  if (const auto *CI = dyn_cast<ConstantInt>(V)) {
236  const APInt &CIV = CI->getValue();
237  if (Val >= 0)
238  return CIV == static_cast<uint64_t>(Val);
239  // If Val is negative, and CI is shorter than it, truncate to the right
240  // number of bits. If it is larger, then we have to sign extend. Just
241  // compare their negated values.
242  return -CIV == -Val;
243  }
244  return false;
245  }
246 };
247 
248 /// Match a ConstantInt with a specific value.
249 template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
250  return constantint_match<Val>();
251 }
252 
253 /// This helper class is used to match scalar and vector constants that satisfy
254 /// a specified predicate. For vector constants, undefined elements are ignored.
255 template <typename Predicate> struct cst_pred_ty : public Predicate {
256  template <typename ITy> bool match(ITy *V) {
257  if (const auto *CI = dyn_cast<ConstantInt>(V))
258  return this->isValue(CI->getValue());
259  if (V->getType()->isVectorTy()) {
260  if (const auto *C = dyn_cast<Constant>(V)) {
261  if (const auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
262  return this->isValue(CI->getValue());
263 
264  // Non-splat vector constant: check each element for a match.
265  unsigned NumElts = V->getType()->getVectorNumElements();
266  assert(NumElts != 0 && "Constant vector with no elements?");
267  for (unsigned i = 0; i != NumElts; ++i) {
268  Constant *Elt = C->getAggregateElement(i);
269  if (!Elt)
270  return false;
271  if (isa<UndefValue>(Elt))
272  continue;
273  auto *CI = dyn_cast<ConstantInt>(Elt);
274  if (!CI || !this->isValue(CI->getValue()))
275  return false;
276  }
277  return true;
278  }
279  }
280  return false;
281  }
282 };
283 
284 /// This helper class is used to match scalar and vector constants that
285 /// satisfy a specified predicate, and bind them to an APInt.
286 template <typename Predicate> struct api_pred_ty : public Predicate {
287  const APInt *&Res;
288 
289  api_pred_ty(const APInt *&R) : Res(R) {}
290 
291  template <typename ITy> bool match(ITy *V) {
292  if (const auto *CI = dyn_cast<ConstantInt>(V))
293  if (this->isValue(CI->getValue())) {
294  Res = &CI->getValue();
295  return true;
296  }
297  if (V->getType()->isVectorTy())
298  if (const auto *C = dyn_cast<Constant>(V))
299  if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
300  if (this->isValue(CI->getValue())) {
301  Res = &CI->getValue();
302  return true;
303  }
304 
305  return false;
306  }
307 };
308 
309 ///////////////////////////////////////////////////////////////////////////////
310 //
311 // Encapsulate constant value queries for use in templated predicate matchers.
312 // This allows checking if constants match using compound predicates and works
313 // with vector constants, possibly with relaxed constraints. For example, ignore
314 // undef values.
315 //
316 ///////////////////////////////////////////////////////////////////////////////
317 
318 struct is_all_ones {
319  bool isValue(const APInt &C) { return C.isAllOnesValue(); }
320 };
321 /// Match an integer or vector with all bits set.
323  return cst_pred_ty<is_all_ones>();
324 }
325 
327  bool isValue(const APInt &C) { return C.isMaxSignedValue(); }
328 };
329 /// Match an integer or vector with values having all bits except for the high
330 /// bit set (0x7f...).
333 }
335  return V;
336 }
337 
338 struct is_negative {
339  bool isValue(const APInt &C) { return C.isNegative(); }
340 };
341 /// Match an integer or vector of negative values.
343  return cst_pred_ty<is_negative>();
344 }
346  return V;
347 }
348 
350  bool isValue(const APInt &C) { return C.isNonNegative(); }
351 };
352 /// Match an integer or vector of nonnegative values.
355 }
357  return V;
358 }
359 
360 struct is_one {
361  bool isValue(const APInt &C) { return C.isOneValue(); }
362 };
363 /// Match an integer 1 or a vector with all elements equal to 1.
365  return cst_pred_ty<is_one>();
366 }
367 
368 struct is_power2 {
369  bool isValue(const APInt &C) { return C.isPowerOf2(); }
370 };
371 /// Match an integer or vector power-of-2.
373  return cst_pred_ty<is_power2>();
374 }
376  return V;
377 }
378 
380  bool isValue(const APInt &C) { return !C || C.isPowerOf2(); }
381 };
382 /// Match an integer or vector of 0 or power-of-2 values.
385 }
387  return V;
388 }
389 
390 struct is_sign_mask {
391  bool isValue(const APInt &C) { return C.isSignMask(); }
392 };
393 /// Match an integer or vector with only the sign bit(s) set.
395  return cst_pred_ty<is_sign_mask>();
396 }
397 
398 ///////////////////////////////////////////////////////////////////////////////
399 
400 template <typename Class> struct bind_ty {
401  Class *&VR;
402 
403  bind_ty(Class *&V) : VR(V) {}
404 
405  template <typename ITy> bool match(ITy *V) {
406  if (auto *CV = dyn_cast<Class>(V)) {
407  VR = CV;
408  return true;
409  }
410  return false;
411  }
412 };
413 
414 /// Match a value, capturing it if we match.
415 inline bind_ty<Value> m_Value(Value *&V) { return V; }
416 inline bind_ty<const Value> m_Value(const Value *&V) { return V; }
417 
418 /// Match an instruction, capturing it if we match.
420 /// Match a binary operator, capturing it if we match.
422 
423 /// Match a ConstantInt, capturing the value if we match.
424 inline bind_ty<ConstantInt> m_ConstantInt(ConstantInt *&CI) { return CI; }
425 
426 /// Match a Constant, capturing the value if we match.
427 inline bind_ty<Constant> m_Constant(Constant *&C) { return C; }
428 
429 /// Match a ConstantFP, capturing the value if we match.
431 
432 /// Match a specified Value*.
434  const Value *Val;
435 
436  specificval_ty(const Value *V) : Val(V) {}
437 
438  template <typename ITy> bool match(ITy *V) { return V == Val; }
439 };
440 
441 /// Match if we have a specific specified value.
442 inline specificval_ty m_Specific(const Value *V) { return V; }
443 
444 /// Match a specified floating point value or vector of all elements of
445 /// that value.
447  double Val;
448 
449  specific_fpval(double V) : Val(V) {}
450 
451  template <typename ITy> bool match(ITy *V) {
452  if (const auto *CFP = dyn_cast<ConstantFP>(V))
453  return CFP->isExactlyValue(Val);
454  if (V->getType()->isVectorTy())
455  if (const auto *C = dyn_cast<Constant>(V))
456  if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
457  return CFP->isExactlyValue(Val);
458  return false;
459  }
460 };
461 
462 /// Match a specific floating point value or vector with all elements
463 /// equal to the value.
464 inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
465 
466 /// Match a float 1.0 or vector with all elements equal to 1.0.
467 inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
468 
470  uint64_t &VR;
471 
472  bind_const_intval_ty(uint64_t &V) : VR(V) {}
473 
474  template <typename ITy> bool match(ITy *V) {
475  if (const auto *CV = dyn_cast<ConstantInt>(V))
476  if (CV->getValue().ule(UINT64_MAX)) {
477  VR = CV->getZExtValue();
478  return true;
479  }
480  return false;
481  }
482 };
483 
484 /// Match a specified integer value or vector of all elements of that
485 // value.
487  uint64_t Val;
488 
489  specific_intval(uint64_t V) : Val(V) {}
490 
491  template <typename ITy> bool match(ITy *V) {
492  const auto *CI = dyn_cast<ConstantInt>(V);
493  if (!CI && V->getType()->isVectorTy())
494  if (const auto *C = dyn_cast<Constant>(V))
495  CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
496 
497  return CI && CI->getValue() == Val;
498  }
499 };
500 
501 /// Match a specific integer value or vector with all elements equal to
502 /// the value.
503 inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); }
504 
505 /// Match a ConstantInt and bind to its value. This does not match
506 /// ConstantInts wider than 64-bits.
507 inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; }
508 
509 //===----------------------------------------------------------------------===//
510 // Matcher for any binary operator.
511 //
512 template <typename LHS_t, typename RHS_t, bool Commutable = false>
514  LHS_t L;
515  RHS_t R;
516 
517  AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
518 
519  template <typename OpTy> bool match(OpTy *V) {
520  if (auto *I = dyn_cast<BinaryOperator>(V))
521  return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
522  (Commutable && R.match(I->getOperand(0)) &&
523  L.match(I->getOperand(1)));
524  return false;
525  }
526 };
527 
528 template <typename LHS, typename RHS>
529 inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
530  return AnyBinaryOp_match<LHS, RHS>(L, R);
531 }
532 
533 //===----------------------------------------------------------------------===//
534 // Matchers for specific binary operators.
535 //
536 
537 template <typename LHS_t, typename RHS_t, unsigned Opcode,
538  bool Commutable = false>
540  LHS_t L;
541  RHS_t R;
542 
543  BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
544 
545  template <typename OpTy> bool match(OpTy *V) {
546  if (V->getValueID() == Value::InstructionVal + Opcode) {
547  auto *I = cast<BinaryOperator>(V);
548  return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
549  (Commutable && R.match(I->getOperand(0)) &&
550  L.match(I->getOperand(1)));
551  }
552  if (auto *CE = dyn_cast<ConstantExpr>(V))
553  return CE->getOpcode() == Opcode &&
554  ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) ||
555  (Commutable && R.match(CE->getOperand(0)) &&
556  L.match(CE->getOperand(1))));
557  return false;
558  }
559 };
560 
561 template <typename LHS, typename RHS>
563  const RHS &R) {
565 }
566 
567 template <typename LHS, typename RHS>
569  const RHS &R) {
571 }
572 
573 template <typename LHS, typename RHS>
575  const RHS &R) {
577 }
578 
579 template <typename LHS, typename RHS>
581  const RHS &R) {
583 }
584 
585 template <typename LHS, typename RHS>
587  const RHS &R) {
589 }
590 
591 template <typename LHS, typename RHS>
593  const RHS &R) {
595 }
596 
597 template <typename LHS, typename RHS>
599  const RHS &R) {
601 }
602 
603 template <typename LHS, typename RHS>
605  const RHS &R) {
607 }
608 
609 template <typename LHS, typename RHS>
611  const RHS &R) {
613 }
614 
615 template <typename LHS, typename RHS>
617  const RHS &R) {
619 }
620 
621 template <typename LHS, typename RHS>
623  const RHS &R) {
625 }
626 
627 template <typename LHS, typename RHS>
629  const RHS &R) {
631 }
632 
633 template <typename LHS, typename RHS>
635  const RHS &R) {
637 }
638 
639 template <typename LHS, typename RHS>
641  const RHS &R) {
643 }
644 
645 template <typename LHS, typename RHS>
647  const RHS &R) {
649 }
650 
651 template <typename LHS, typename RHS>
653  const RHS &R) {
655 }
656 
657 template <typename LHS, typename RHS>
659  const RHS &R) {
661 }
662 
663 template <typename LHS, typename RHS>
665  const RHS &R) {
667 }
668 
669 template <typename LHS_t, typename RHS_t, unsigned Opcode,
670  unsigned WrapFlags = 0>
672  LHS_t L;
673  RHS_t R;
674 
675  OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
676  : L(LHS), R(RHS) {}
677 
678  template <typename OpTy> bool match(OpTy *V) {
679  if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
680  if (Op->getOpcode() != Opcode)
681  return false;
683  !Op->hasNoUnsignedWrap())
684  return false;
685  if (WrapFlags & OverflowingBinaryOperator::NoSignedWrap &&
686  !Op->hasNoSignedWrap())
687  return false;
688  return L.match(Op->getOperand(0)) && R.match(Op->getOperand(1));
689  }
690  return false;
691  }
692 };
693 
694 template <typename LHS, typename RHS>
697 m_NSWAdd(const LHS &L, const RHS &R) {
700  L, R);
701 }
702 template <typename LHS, typename RHS>
703 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
705 m_NSWSub(const LHS &L, const RHS &R) {
706  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
708  L, R);
709 }
710 template <typename LHS, typename RHS>
711 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
713 m_NSWMul(const LHS &L, const RHS &R) {
714  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
716  L, R);
717 }
718 template <typename LHS, typename RHS>
719 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
721 m_NSWShl(const LHS &L, const RHS &R) {
722  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
724  L, R);
725 }
726 
727 template <typename LHS, typename RHS>
730 m_NUWAdd(const LHS &L, const RHS &R) {
733  L, R);
734 }
735 template <typename LHS, typename RHS>
736 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
738 m_NUWSub(const LHS &L, const RHS &R) {
739  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
741  L, R);
742 }
743 template <typename LHS, typename RHS>
744 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
746 m_NUWMul(const LHS &L, const RHS &R) {
747  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
749  L, R);
750 }
751 template <typename LHS, typename RHS>
752 inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
754 m_NUWShl(const LHS &L, const RHS &R) {
755  return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
757  L, R);
758 }
759 
760 //===----------------------------------------------------------------------===//
761 // Class that matches a group of binary opcodes.
762 //
763 template <typename LHS_t, typename RHS_t, typename Predicate>
765  LHS_t L;
766  RHS_t R;
767 
768  BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
769 
770  template <typename OpTy> bool match(OpTy *V) {
771  if (auto *I = dyn_cast<Instruction>(V))
772  return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) &&
773  R.match(I->getOperand(1));
774  if (auto *CE = dyn_cast<ConstantExpr>(V))
775  return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) &&
776  R.match(CE->getOperand(1));
777  return false;
778  }
779 };
780 
781 struct is_shift_op {
782  bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); }
783 };
784 
786  bool isOpType(unsigned Opcode) {
787  return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
788  }
789 };
790 
792  bool isOpType(unsigned Opcode) {
793  return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
794  }
795 };
796 
798  bool isOpType(unsigned Opcode) {
799  return Instruction::isBitwiseLogicOp(Opcode);
800  }
801 };
802 
803 struct is_idiv_op {
804  bool isOpType(unsigned Opcode) {
805  return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
806  }
807 };
808 
809 /// Matches shift operations.
810 template <typename LHS, typename RHS>
812  const RHS &R) {
814 }
815 
816 /// Matches logical shift operations.
817 template <typename LHS, typename RHS>
819  const RHS &R) {
821 }
822 
823 /// Matches logical shift operations.
824 template <typename LHS, typename RHS>
826 m_LogicalShift(const LHS &L, const RHS &R) {
828 }
829 
830 /// Matches bitwise logic operations.
831 template <typename LHS, typename RHS>
833 m_BitwiseLogic(const LHS &L, const RHS &R) {
835 }
836 
837 /// Matches integer division operations.
838 template <typename LHS, typename RHS>
840  const RHS &R) {
842 }
843 
844 //===----------------------------------------------------------------------===//
845 // Class that matches exact binary ops.
846 //
847 template <typename SubPattern_t> struct Exact_match {
848  SubPattern_t SubPattern;
849 
850  Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
851 
852  template <typename OpTy> bool match(OpTy *V) {
853  if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
854  return PEO->isExact() && SubPattern.match(V);
855  return false;
856  }
857 };
858 
859 template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
860  return SubPattern;
861 }
862 
863 //===----------------------------------------------------------------------===//
864 // Matchers for CmpInst classes
865 //
866 
867 template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
868  bool Commutable = false>
870  PredicateTy &Predicate;
871  LHS_t L;
872  RHS_t R;
873 
874  CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
875  : Predicate(Pred), L(LHS), R(RHS) {}
876 
877  template <typename OpTy> bool match(OpTy *V) {
878  if (auto *I = dyn_cast<Class>(V))
879  if ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
880  (Commutable && R.match(I->getOperand(0)) &&
881  L.match(I->getOperand(1)))) {
882  Predicate = I->getPredicate();
883  return true;
884  }
885  return false;
886  }
887 };
888 
889 template <typename LHS, typename RHS>
891 m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
893 }
894 
895 template <typename LHS, typename RHS>
897 m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
899 }
900 
901 template <typename LHS, typename RHS>
903 m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
905 }
906 
907 //===----------------------------------------------------------------------===//
908 // Matchers for SelectInst classes
909 //
910 
911 template <typename Cond_t, typename LHS_t, typename RHS_t>
913  Cond_t C;
914  LHS_t L;
915  RHS_t R;
916 
917  SelectClass_match(const Cond_t &Cond, const LHS_t &LHS, const RHS_t &RHS)
918  : C(Cond), L(LHS), R(RHS) {}
919 
920  template <typename OpTy> bool match(OpTy *V) {
921  if (auto *I = dyn_cast<SelectInst>(V))
922  return C.match(I->getOperand(0)) && L.match(I->getOperand(1)) &&
923  R.match(I->getOperand(2));
924  return false;
925  }
926 };
927 
928 template <typename Cond, typename LHS, typename RHS>
929 inline SelectClass_match<Cond, LHS, RHS> m_Select(const Cond &C, const LHS &L,
930  const RHS &R) {
931  return SelectClass_match<Cond, LHS, RHS>(C, L, R);
932 }
933 
934 /// This matches a select of two constants, e.g.:
935 /// m_SelectCst<-1, 0>(m_Value(V))
936 template <int64_t L, int64_t R, typename Cond>
938 m_SelectCst(const Cond &C) {
939  return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
940 }
941 
942 //===----------------------------------------------------------------------===//
943 // Matchers for CastInst classes
944 //
945 
946 template <typename Op_t, unsigned Opcode> struct CastClass_match {
947  Op_t Op;
948 
949  CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
950 
951  template <typename OpTy> bool match(OpTy *V) {
952  if (auto *O = dyn_cast<Operator>(V))
953  return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
954  return false;
955  }
956 };
957 
958 /// Matches BitCast.
959 template <typename OpTy>
962 }
963 
964 /// Matches PtrToInt.
965 template <typename OpTy>
968 }
969 
970 /// Matches Trunc.
971 template <typename OpTy>
974 }
975 
976 /// Matches SExt.
977 template <typename OpTy>
980 }
981 
982 /// Matches ZExt.
983 template <typename OpTy>
986 }
987 
988 template <typename OpTy>
991 m_ZExtOrSExt(const OpTy &Op) {
992  return m_CombineOr(m_ZExt(Op), m_SExt(Op));
993 }
994 
995 /// Matches UIToFP.
996 template <typename OpTy>
999 }
1000 
1001 /// Matches SIToFP.
1002 template <typename OpTy>
1005 }
1006 
1007 /// Matches FPTrunc
1008 template <typename OpTy>
1011 }
1012 
1013 /// Matches FPExt
1014 template <typename OpTy>
1017 }
1018 
1019 //===----------------------------------------------------------------------===//
1020 // Matcher for LoadInst classes
1021 //
1022 
1023 template <typename Op_t> struct LoadClass_match {
1024  Op_t Op;
1025 
1026  LoadClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
1027 
1028  template <typename OpTy> bool match(OpTy *V) {
1029  if (auto *LI = dyn_cast<LoadInst>(V))
1030  return Op.match(LI->getPointerOperand());
1031  return false;
1032  }
1033 };
1034 
1035 /// Matches LoadInst.
1036 template <typename OpTy> inline LoadClass_match<OpTy> m_Load(const OpTy &Op) {
1037  return LoadClass_match<OpTy>(Op);
1038 }
1039 //===----------------------------------------------------------------------===//
1040 // Matchers for unary operators
1041 //
1042 
1043 template <typename LHS_t> struct not_match {
1044  LHS_t L;
1045 
1046  not_match(const LHS_t &LHS) : L(LHS) {}
1047 
1048  template <typename OpTy> bool match(OpTy *V) {
1049  if (auto *O = dyn_cast<Operator>(V))
1050  if (O->getOpcode() == Instruction::Xor) {
1051  if (isAllOnes(O->getOperand(1)))
1052  return L.match(O->getOperand(0));
1053  if (isAllOnes(O->getOperand(0)))
1054  return L.match(O->getOperand(1));
1055  }
1056  return false;
1057  }
1058 
1059 private:
1060  bool isAllOnes(Value *V) {
1061  return isa<Constant>(V) && cast<Constant>(V)->isAllOnesValue();
1062  }
1063 };
1064 
1065 template <typename LHS> inline not_match<LHS> m_Not(const LHS &L) { return L; }
1066 
1067 template <typename LHS_t> struct neg_match {
1068  LHS_t L;
1069 
1070  neg_match(const LHS_t &LHS) : L(LHS) {}
1071 
1072  template <typename OpTy> bool match(OpTy *V) {
1073  if (auto *O = dyn_cast<Operator>(V))
1074  if (O->getOpcode() == Instruction::Sub)
1075  return matchIfNeg(O->getOperand(0), O->getOperand(1));
1076  return false;
1077  }
1078 
1079 private:
1080  bool matchIfNeg(Value *LHS, Value *RHS) {
1081  return ((isa<ConstantInt>(LHS) && cast<ConstantInt>(LHS)->isZero()) ||
1082  isa<ConstantAggregateZero>(LHS)) &&
1083  L.match(RHS);
1084  }
1085 };
1086 
1087 /// Match an integer negate.
1088 template <typename LHS> inline neg_match<LHS> m_Neg(const LHS &L) { return L; }
1089 
1090 template <typename LHS_t> struct fneg_match {
1091  LHS_t L;
1092 
1093  fneg_match(const LHS_t &LHS) : L(LHS) {}
1094 
1095  template <typename OpTy> bool match(OpTy *V) {
1096  if (auto *O = dyn_cast<Operator>(V))
1097  if (O->getOpcode() == Instruction::FSub)
1098  return matchIfFNeg(O->getOperand(0), O->getOperand(1));
1099  return false;
1100  }
1101 
1102 private:
1103  bool matchIfFNeg(Value *LHS, Value *RHS) {
1104  if (const auto *C = dyn_cast<Constant>(LHS))
1105  return C->isNegativeZeroValue() && L.match(RHS);
1106  return false;
1107  }
1108 };
1109 
1110 /// Match a floating point negate.
1111 template <typename LHS> inline fneg_match<LHS> m_FNeg(const LHS &L) {
1112  return L;
1113 }
1114 
1115 //===----------------------------------------------------------------------===//
1116 // Matchers for control flow.
1117 //
1118 
1119 struct br_match {
1121 
1122  br_match(BasicBlock *&Succ) : Succ(Succ) {}
1123 
1124  template <typename OpTy> bool match(OpTy *V) {
1125  if (auto *BI = dyn_cast<BranchInst>(V))
1126  if (BI->isUnconditional()) {
1127  Succ = BI->getSuccessor(0);
1128  return true;
1129  }
1130  return false;
1131  }
1132 };
1133 
1134 inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
1135 
1136 template <typename Cond_t> struct brc_match {
1137  Cond_t Cond;
1139 
1140  brc_match(const Cond_t &C, BasicBlock *&t, BasicBlock *&f)
1141  : Cond(C), T(t), F(f) {}
1142 
1143  template <typename OpTy> bool match(OpTy *V) {
1144  if (auto *BI = dyn_cast<BranchInst>(V))
1145  if (BI->isConditional() && Cond.match(BI->getCondition())) {
1146  T = BI->getSuccessor(0);
1147  F = BI->getSuccessor(1);
1148  return true;
1149  }
1150  return false;
1151  }
1152 };
1153 
1154 template <typename Cond_t>
1155 inline brc_match<Cond_t> m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) {
1156  return brc_match<Cond_t>(C, T, F);
1157 }
1158 
1159 //===----------------------------------------------------------------------===//
1160 // Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
1161 //
1162 
1163 template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t,
1164  bool Commutable = false>
1166  LHS_t L;
1167  RHS_t R;
1168 
1169  MaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1170 
1171  template <typename OpTy> bool match(OpTy *V) {
1172  // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
1173  auto *SI = dyn_cast<SelectInst>(V);
1174  if (!SI)
1175  return false;
1176  auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
1177  if (!Cmp)
1178  return false;
1179  // At this point we have a select conditioned on a comparison. Check that
1180  // it is the values returned by the select that are being compared.
1181  Value *TrueVal = SI->getTrueValue();
1182  Value *FalseVal = SI->getFalseValue();
1183  Value *LHS = Cmp->getOperand(0);
1184  Value *RHS = Cmp->getOperand(1);
1185  if ((TrueVal != LHS || FalseVal != RHS) &&
1186  (TrueVal != RHS || FalseVal != LHS))
1187  return false;
1188  typename CmpInst_t::Predicate Pred =
1189  LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1190  // Does "(x pred y) ? x : y" represent the desired max/min operation?
1191  if (!Pred_t::match(Pred))
1192  return false;
1193  // It does! Bind the operands.
1194  return (L.match(LHS) && R.match(RHS)) ||
1195  (Commutable && R.match(LHS) && L.match(RHS));
1196  }
1197 };
1198 
1199 /// Helper class for identifying signed max predicates.
1201  static bool match(ICmpInst::Predicate Pred) {
1202  return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE;
1203  }
1204 };
1205 
1206 /// Helper class for identifying signed min predicates.
1208  static bool match(ICmpInst::Predicate Pred) {
1209  return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE;
1210  }
1211 };
1212 
1213 /// Helper class for identifying unsigned max predicates.
1215  static bool match(ICmpInst::Predicate Pred) {
1216  return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE;
1217  }
1218 };
1219 
1220 /// Helper class for identifying unsigned min predicates.
1222  static bool match(ICmpInst::Predicate Pred) {
1223  return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE;
1224  }
1225 };
1226 
1227 /// Helper class for identifying ordered max predicates.
1229  static bool match(FCmpInst::Predicate Pred) {
1230  return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
1231  }
1232 };
1233 
1234 /// Helper class for identifying ordered min predicates.
1236  static bool match(FCmpInst::Predicate Pred) {
1237  return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
1238  }
1239 };
1240 
1241 /// Helper class for identifying unordered max predicates.
1243  static bool match(FCmpInst::Predicate Pred) {
1244  return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
1245  }
1246 };
1247 
1248 /// Helper class for identifying unordered min predicates.
1250  static bool match(FCmpInst::Predicate Pred) {
1251  return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
1252  }
1253 };
1254 
1255 template <typename LHS, typename RHS>
1257  const RHS &R) {
1259 }
1260 
1261 template <typename LHS, typename RHS>
1263  const RHS &R) {
1265 }
1266 
1267 template <typename LHS, typename RHS>
1269  const RHS &R) {
1271 }
1272 
1273 template <typename LHS, typename RHS>
1275  const RHS &R) {
1277 }
1278 
1279 /// Match an 'ordered' floating point maximum function.
1280 /// Floating point has one special value 'NaN'. Therefore, there is no total
1281 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1282 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
1283 /// semantics. In the presence of 'NaN' we have to preserve the original
1284 /// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
1285 ///
1286 /// max(L, R) iff L and R are not NaN
1287 /// m_OrdFMax(L, R) = R iff L or R are NaN
1288 template <typename LHS, typename RHS>
1290  const RHS &R) {
1292 }
1293 
1294 /// Match an 'ordered' floating point minimum function.
1295 /// Floating point has one special value 'NaN'. Therefore, there is no total
1296 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1297 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
1298 /// semantics. In the presence of 'NaN' we have to preserve the original
1299 /// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
1300 ///
1301 /// min(L, R) iff L and R are not NaN
1302 /// m_OrdFMin(L, R) = R iff L or R are NaN
1303 template <typename LHS, typename RHS>
1305  const RHS &R) {
1307 }
1308 
1309 /// Match an 'unordered' floating point maximum function.
1310 /// Floating point has one special value 'NaN'. Therefore, there is no total
1311 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1312 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
1313 /// semantics. In the presence of 'NaN' we have to preserve the original
1314 /// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
1315 ///
1316 /// max(L, R) iff L and R are not NaN
1317 /// m_UnordFMax(L, R) = L iff L or R are NaN
1318 template <typename LHS, typename RHS>
1320 m_UnordFMax(const LHS &L, const RHS &R) {
1322 }
1323 
1324 /// Match an 'unordered' floating point minimum function.
1325 /// Floating point has one special value 'NaN'. Therefore, there is no total
1326 /// order. However, if we can ignore the 'NaN' value (for example, because of a
1327 /// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
1328 /// semantics. In the presence of 'NaN' we have to preserve the original
1329 /// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
1330 ///
1331 /// min(L, R) iff L and R are not NaN
1332 /// m_UnordFMin(L, R) = L iff L or R are NaN
1333 template <typename LHS, typename RHS>
1335 m_UnordFMin(const LHS &L, const RHS &R) {
1337 }
1338 
1339 //===----------------------------------------------------------------------===//
1340 // Matchers for overflow check patterns: e.g. (a + b) u< a
1341 //
1342 
1343 template <typename LHS_t, typename RHS_t, typename Sum_t>
1345  LHS_t L;
1346  RHS_t R;
1347  Sum_t S;
1348 
1349  UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
1350  : L(L), R(R), S(S) {}
1351 
1352  template <typename OpTy> bool match(OpTy *V) {
1353  Value *ICmpLHS, *ICmpRHS;
1354  ICmpInst::Predicate Pred;
1355  if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
1356  return false;
1357 
1358  Value *AddLHS, *AddRHS;
1359  auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
1360 
1361  // (a + b) u< a, (a + b) u< b
1362  if (Pred == ICmpInst::ICMP_ULT)
1363  if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1364  return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1365 
1366  // a >u (a + b), b >u (a + b)
1367  if (Pred == ICmpInst::ICMP_UGT)
1368  if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1369  return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1370 
1371  return false;
1372  }
1373 };
1374 
1375 /// Match an icmp instruction checking for unsigned overflow on addition.
1376 ///
1377 /// S is matched to the addition whose result is being checked for overflow, and
1378 /// L and R are matched to the LHS and RHS of S.
1379 template <typename LHS_t, typename RHS_t, typename Sum_t>
1381 m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
1383 }
1384 
1385 template <typename Opnd_t> struct Argument_match {
1386  unsigned OpI;
1387  Opnd_t Val;
1388 
1389  Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
1390 
1391  template <typename OpTy> bool match(OpTy *V) {
1392  CallSite CS(V);
1393  return CS.isCall() && Val.match(CS.getArgument(OpI));
1394  }
1395 };
1396 
1397 /// Match an argument.
1398 template <unsigned OpI, typename Opnd_t>
1399 inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
1400  return Argument_match<Opnd_t>(OpI, Op);
1401 }
1402 
1403 /// Intrinsic matchers.
1405  unsigned ID;
1406 
1407  IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
1408 
1409  template <typename OpTy> bool match(OpTy *V) {
1410  if (const auto *CI = dyn_cast<CallInst>(V))
1411  if (const auto *F = CI->getCalledFunction())
1412  return F->getIntrinsicID() == ID;
1413  return false;
1414  }
1415 };
1416 
1417 /// Intrinsic matches are combinations of ID matchers, and argument
1418 /// matchers. Higher arity matcher are defined recursively in terms of and-ing
1419 /// them with lower arity matchers. Here's some convenient typedefs for up to
1420 /// several arguments, and more can be added as needed
1421 template <typename T0 = void, typename T1 = void, typename T2 = void,
1422  typename T3 = void, typename T4 = void, typename T5 = void,
1423  typename T6 = void, typename T7 = void, typename T8 = void,
1424  typename T9 = void, typename T10 = void>
1426 template <typename T0> struct m_Intrinsic_Ty<T0> {
1428 };
1429 template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
1430  using Ty =
1432 };
1433 template <typename T0, typename T1, typename T2>
1434 struct m_Intrinsic_Ty<T0, T1, T2> {
1435  using Ty =
1438 };
1439 template <typename T0, typename T1, typename T2, typename T3>
1440 struct m_Intrinsic_Ty<T0, T1, T2, T3> {
1441  using Ty =
1444 };
1445 
1446 /// Match intrinsic calls like this:
1447 /// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
1448 template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
1449  return IntrinsicID_match(IntrID);
1450 }
1451 
1452 template <Intrinsic::ID IntrID, typename T0>
1453 inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
1454  return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
1455 }
1456 
1457 template <Intrinsic::ID IntrID, typename T0, typename T1>
1458 inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
1459  const T1 &Op1) {
1460  return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
1461 }
1462 
1463 template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
1464 inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
1465 m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
1466  return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
1467 }
1468 
1469 template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
1470  typename T3>
1471 inline typename m_Intrinsic_Ty<T0, T1, T2, T3>::Ty
1472 m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
1473  return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
1474 }
1475 
1476 // Helper intrinsic matching specializations.
1477 template <typename Opnd0>
1478 inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BitReverse(const Opnd0 &Op0) {
1479  return m_Intrinsic<Intrinsic::bitreverse>(Op0);
1480 }
1481 
1482 template <typename Opnd0>
1483 inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BSwap(const Opnd0 &Op0) {
1484  return m_Intrinsic<Intrinsic::bswap>(Op0);
1485 }
1486 
1487 template <typename Opnd0, typename Opnd1>
1488 inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMin(const Opnd0 &Op0,
1489  const Opnd1 &Op1) {
1490  return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
1491 }
1492 
1493 template <typename Opnd0, typename Opnd1>
1494 inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMax(const Opnd0 &Op0,
1495  const Opnd1 &Op1) {
1496  return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
1497 }
1498 
1499 template <typename Opnd_t> struct Signum_match {
1500  Opnd_t Val;
1501  Signum_match(const Opnd_t &V) : Val(V) {}
1502 
1503  template <typename OpTy> bool match(OpTy *V) {
1504  unsigned TypeSize = V->getType()->getScalarSizeInBits();
1505  if (TypeSize == 0)
1506  return false;
1507 
1508  unsigned ShiftWidth = TypeSize - 1;
1509  Value *OpL = nullptr, *OpR = nullptr;
1510 
1511  // This is the representation of signum we match:
1512  //
1513  // signum(x) == (x >> 63) | (-x >>u 63)
1514  //
1515  // An i1 value is its own signum, so it's correct to match
1516  //
1517  // signum(x) == (x >> 0) | (-x >>u 0)
1518  //
1519  // for i1 values.
1520 
1521  auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
1522  auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
1523  auto Signum = m_Or(LHS, RHS);
1524 
1525  return Signum.match(V) && OpL == OpR && Val.match(OpL);
1526  }
1527 };
1528 
1529 /// Matches a signum pattern.
1530 ///
1531 /// signum(x) =
1532 /// x > 0 -> 1
1533 /// x == 0 -> 0
1534 /// x < 0 -> -1
1535 template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
1536  return Signum_match<Val_t>(V);
1537 }
1538 
1539 //===----------------------------------------------------------------------===//
1540 // Matchers for two-operands operators with the operators in either order
1541 //
1542 
1543 /// Matches a BinaryOperator with LHS and RHS in either order.
1544 template <typename LHS, typename RHS>
1545 inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) {
1546  return AnyBinaryOp_match<LHS, RHS, true>(L, R);
1547 }
1548 
1549 /// Matches an ICmp with a predicate over LHS and RHS in either order.
1550 /// Does not swap the predicate.
1551 template <typename LHS, typename RHS>
1553 m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1555  R);
1556 }
1557 
1558 /// Matches a Add with LHS and RHS in either order.
1559 template <typename LHS, typename RHS>
1561  const RHS &R) {
1563 }
1564 
1565 /// Matches a Mul with LHS and RHS in either order.
1566 template <typename LHS, typename RHS>
1568  const RHS &R) {
1570 }
1571 
1572 /// Matches an And with LHS and RHS in either order.
1573 template <typename LHS, typename RHS>
1575  const RHS &R) {
1577 }
1578 
1579 /// Matches an Or with LHS and RHS in either order.
1580 template <typename LHS, typename RHS>
1582  const RHS &R) {
1584 }
1585 
1586 /// Matches an Xor with LHS and RHS in either order.
1587 template <typename LHS, typename RHS>
1589  const RHS &R) {
1591 }
1592 
1593 /// Matches an SMin with LHS and RHS in either order.
1594 template <typename LHS, typename RHS>
1596 m_c_SMin(const LHS &L, const RHS &R) {
1598 }
1599 /// Matches an SMax with LHS and RHS in either order.
1600 template <typename LHS, typename RHS>
1602 m_c_SMax(const LHS &L, const RHS &R) {
1604 }
1605 /// Matches a UMin with LHS and RHS in either order.
1606 template <typename LHS, typename RHS>
1608 m_c_UMin(const LHS &L, const RHS &R) {
1610 }
1611 /// Matches a UMax with LHS and RHS in either order.
1612 template <typename LHS, typename RHS>
1614 m_c_UMax(const LHS &L, const RHS &R) {
1616 }
1617 
1618 /// Matches FAdd with LHS and RHS in either order.
1619 template <typename LHS, typename RHS>
1621 m_c_FAdd(const LHS &L, const RHS &R) {
1623 }
1624 
1625 /// Matches FMul with LHS and RHS in either order.
1626 template <typename LHS, typename RHS>
1628 m_c_FMul(const LHS &L, const RHS &R) {
1630 }
1631 
1632 } // end namespace PatternMatch
1633 } // end namespace llvm
1634 
1635 #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:634
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:818
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:705
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of nonnegative values.
Definition: PatternMatch.h:353
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
bool isSignMask() const
Check if the APInt&#39;s value is returned by getSignMask.
Definition: APInt.h:466
Match a specified integer value or vector of all elements of that.
Definition: PatternMatch.h:486
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
Definition: PatternMatch.h:80
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:574
br_match(BasicBlock *&Succ)
Compute iterated dominance frontiers using a linear time algorithm.
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:568
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:446
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
bool isValue(const APInt &C)
Definition: PatternMatch.h:391
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
Definition: PatternMatch.h:610
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
Definition: PatternMatch.h:622
match_zero m_Zero()
Match an arbitrary zero/null constant.
Definition: PatternMatch.h:145
Exact_match(const SubPattern_t &SP)
Definition: PatternMatch.h:850
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:586
br_match m_UnconditionalBr(BasicBlock *&Succ)
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
Definition: PatternMatch.h:394
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:911
unsigned less than
Definition: InstrTypes.h:910
bool isValue(const APInt &C)
Definition: PatternMatch.h:339
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
Definition: PatternMatch.h:664
static bool match(ICmpInst::Predicate Pred)
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:891
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)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
Definition: PatternMatch.h:580
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.
fneg_match< LHS > m_FNeg(const LHS &L)
Match a floating point negate.
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.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
Definition: PatternMatch.h:826
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
Definition: PatternMatch.h:464
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)
Definition: PatternMatch.h:903
Helper class for identifying signed min predicates.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
Definition: PatternMatch.h:646
This class represents the LLVM &#39;select&#39; instruction.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition: APInt.h:362
Exact_match< T > m_Exact(const T &SubPattern)
Definition: PatternMatch.h:859
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
Definition: PatternMatch.h:972
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:331
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:892
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...
not_match< LHS > m_Not(const LHS &L)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
Definition: PatternMatch.h:562
bind_ty< ConstantFP > m_ConstantFP(ConstantFP *&C)
Match a ConstantFP, capturing the value if we match.
Definition: PatternMatch.h:430
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
Definition: Instruction.h:166
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
Definition: PatternMatch.h:730
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
Definition: PatternMatch.h:231
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
LoadClass_match(const Op_t &OpMatch)
CastClass_match(const Op_t &OpMatch)
Definition: PatternMatch.h:949
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
Definition: PatternMatch.h:984
#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)
IntrinsicID_match(Intrinsic::ID IntrID)
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
Definition: PatternMatch.h:929
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
Definition: PatternMatch.h:372
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:746
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:357
#define P(N)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Definition: PatternMatch.h:658
Helper class for identifying signed max predicates.
bool isAllOnesValue() const
Determine if all bits are set.
Definition: APInt.h:389
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:227
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
Definition: PatternMatch.h:604
This helper class is used to match scalar and vector constants that satisfy a specified predicate...
Definition: PatternMatch.h:255
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:754
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
Definition: PatternMatch.h:628
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
Definition: PatternMatch.h:383
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
Definition: PatternMatch.h:640
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
Definition: PatternMatch.h:960
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 isOneValue() const
Determine if this is a value of 1.
Definition: APInt.h:404
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
Definition: PatternMatch.h:322
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Definition: PatternMatch.h:442
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:652
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:885
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
Definition: PatternMatch.h:991
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:833
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:517
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Definition: PatternMatch.h:75
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:839
Helper class for identifying unordered min predicates.
1 1 0 1 True if unordered, less than, or equal
Definition: InstrTypes.h:900
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:543
signed greater than
Definition: InstrTypes.h:912
LoadClass_match< OpTy > m_Load(const OpTy &Op)
Matches LoadInst.
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
neg_match< LHS > m_Neg(const LHS &L)
Match an integer negate.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Definition: PatternMatch.h:978
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:889
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
Definition: PatternMatch.h:342
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:420
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:369
ValTy * getArgument(unsigned ArgNo) const
Definition: CallSite.h:186
Match a specified Value*.
Definition: PatternMatch.h:433
match_any_zero m_AnyZero()
Match an arbitrary zero/null constant.
Definition: PatternMatch.h:172
1 1 0 0 True if unordered or less than
Definition: InstrTypes.h:899
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:616
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:598
signed less than
Definition: InstrTypes.h:914
bool isOpType(unsigned Opcode)
Definition: PatternMatch.h:804
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.
CastClass_match< OpTy, Instruction::UIToFP > m_UIToFP(const OpTy &Op)
Matches UIToFP.
Definition: PatternMatch.h:997
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:592
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
Definition: PatternMatch.h:697
signed less or equal
Definition: InstrTypes.h:915
Class for arbitrary precision integers.
Definition: APInt.h:69
bool isPowerOf2() const
Check if this APInt&#39;s value is a power of two greater than zero.
Definition: APInt.h:457
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
Definition: PatternMatch.h:966
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
Definition: PatternMatch.h:811
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:738
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
Definition: PatternMatch.h:467
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition: Lint.cpp:546
unsigned greater or equal
Definition: InstrTypes.h:909
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:874
#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:721
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
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:897
SelectClass_match< Cond, constantint_match< L >, constantint_match< R > > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.
Definition: PatternMatch.h:938
match_neg_zero m_NegZero()
Match an arbitrary zero/null constant.
Definition: PatternMatch.h:159
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:675
bool isOpType(unsigned Opcode)
Definition: PatternMatch.h:782
static bool match(FCmpInst::Predicate Pred)
apfloat_match(const APFloat *&R)
Definition: PatternMatch.h:209
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:319
1 0 1 1 True if unordered, greater than, or equal
Definition: InstrTypes.h:898
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
Definition: PatternMatch.h:713
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
Definition: PatternMatch.h:364
static bool match(ICmpInst::Predicate Pred)
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:768
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:908
match_nan m_NaN()
Match an arbitrary NaN constant. This includes quiet and signalling nans.
Definition: PatternMatch.h:183
specific_intval m_SpecificInt(uint64_t V)
Match a specific integer value or vector with all elements equal to the value.
Definition: PatternMatch.h:503
bool isValue(const APInt &C)
Definition: PatternMatch.h:361
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
SelectClass_match(const Cond_t &Cond, const LHS_t &LHS, const RHS_t &RHS)
Definition: PatternMatch.h:917
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:890
This helper class is used to match scalar and vector constants that satisfy a specified predicate...
Definition: PatternMatch.h:286
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
Definition: PatternMatch.h:419
#define T1
signed greater or equal
Definition: InstrTypes.h:913
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)
Definition: PatternMatch.h:897