LLVM  4.0.0
ConstantRange.cpp
Go to the documentation of this file.
1 //===-- ConstantRange.cpp - ConstantRange implementation ------------------===//
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 // Represent a range of possible values that may occur when the program is run
11 // for an integral value. This keeps track of a lower and upper bound for the
12 // constant, which MAY wrap around the end of the numeric range. To do this, it
13 // keeps track of a [lower, upper) bound, which specifies an interval just like
14 // STL iterators. When used with boolean values, the following are important
15 // ranges (other integral ranges use min/max values for special range values):
16 //
17 // [F, F) = {} = Empty set
18 // [T, F) = {T}
19 // [F, T) = {F}
20 // [T, T) = {F, T} = Full set
21 //
22 //===----------------------------------------------------------------------===//
23 
24 #include "llvm/IR/Instruction.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/IR/Operator.h"
27 #include "llvm/IR/ConstantRange.h"
28 #include "llvm/Support/Debug.h"
30 using namespace llvm;
31 
32 /// Initialize a full (the default) or empty set for the specified type.
33 ///
35  if (Full)
36  Lower = Upper = APInt::getMaxValue(BitWidth);
37  else
38  Lower = Upper = APInt::getMinValue(BitWidth);
39 }
40 
41 /// Initialize a range to hold the single specified value.
42 ///
44  : Lower(std::move(V)), Upper(Lower + 1) {}
45 
47  : Lower(std::move(L)), Upper(std::move(U)) {
48  assert(Lower.getBitWidth() == Upper.getBitWidth() &&
49  "ConstantRange with unequal bit widths");
50  assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) &&
51  "Lower == Upper, but they aren't min or max value!");
52 }
53 
55  const ConstantRange &CR) {
56  if (CR.isEmptySet())
57  return CR;
58 
59  uint32_t W = CR.getBitWidth();
60  switch (Pred) {
61  default:
62  llvm_unreachable("Invalid ICmp predicate to makeAllowedICmpRegion()");
63  case CmpInst::ICMP_EQ:
64  return CR;
65  case CmpInst::ICMP_NE:
66  if (CR.isSingleElement())
67  return ConstantRange(CR.getUpper(), CR.getLower());
68  return ConstantRange(W);
69  case CmpInst::ICMP_ULT: {
70  APInt UMax(CR.getUnsignedMax());
71  if (UMax.isMinValue())
72  return ConstantRange(W, /* empty */ false);
73  return ConstantRange(APInt::getMinValue(W), UMax);
74  }
75  case CmpInst::ICMP_SLT: {
76  APInt SMax(CR.getSignedMax());
77  if (SMax.isMinSignedValue())
78  return ConstantRange(W, /* empty */ false);
79  return ConstantRange(APInt::getSignedMinValue(W), SMax);
80  }
81  case CmpInst::ICMP_ULE: {
82  APInt UMax(CR.getUnsignedMax());
83  if (UMax.isMaxValue())
84  return ConstantRange(W);
85  return ConstantRange(APInt::getMinValue(W), UMax + 1);
86  }
87  case CmpInst::ICMP_SLE: {
88  APInt SMax(CR.getSignedMax());
89  if (SMax.isMaxSignedValue())
90  return ConstantRange(W);
91  return ConstantRange(APInt::getSignedMinValue(W), SMax + 1);
92  }
93  case CmpInst::ICMP_UGT: {
94  APInt UMin(CR.getUnsignedMin());
95  if (UMin.isMaxValue())
96  return ConstantRange(W, /* empty */ false);
97  return ConstantRange(UMin + 1, APInt::getNullValue(W));
98  }
99  case CmpInst::ICMP_SGT: {
100  APInt SMin(CR.getSignedMin());
101  if (SMin.isMaxSignedValue())
102  return ConstantRange(W, /* empty */ false);
103  return ConstantRange(SMin + 1, APInt::getSignedMinValue(W));
104  }
105  case CmpInst::ICMP_UGE: {
106  APInt UMin(CR.getUnsignedMin());
107  if (UMin.isMinValue())
108  return ConstantRange(W);
109  return ConstantRange(UMin, APInt::getNullValue(W));
110  }
111  case CmpInst::ICMP_SGE: {
112  APInt SMin(CR.getSignedMin());
113  if (SMin.isMinSignedValue())
114  return ConstantRange(W);
115  return ConstantRange(SMin, APInt::getSignedMinValue(W));
116  }
117  }
118 }
119 
121  const ConstantRange &CR) {
122  // Follows from De-Morgan's laws:
123  //
124  // ~(~A union ~B) == A intersect B.
125  //
127  .inverse();
128 }
129 
131  const APInt &C) {
132  // Computes the exact range that is equal to both the constant ranges returned
133  // by makeAllowedICmpRegion and makeSatisfyingICmpRegion. This is always true
134  // when RHS is a singleton such as an APInt and so the assert is valid.
135  // However for non-singleton RHS, for example ult [2,5) makeAllowedICmpRegion
136  // returns [0,4) but makeSatisfyICmpRegion returns [0,2).
137  //
139  return makeAllowedICmpRegion(Pred, C);
140 }
141 
143  APInt &RHS) const {
144  bool Success = false;
145 
146  if (isFullSet() || isEmptySet()) {
148  RHS = APInt(getBitWidth(), 0);
149  Success = true;
150  } else if (auto *OnlyElt = getSingleElement()) {
151  Pred = CmpInst::ICMP_EQ;
152  RHS = *OnlyElt;
153  Success = true;
154  } else if (auto *OnlyMissingElt = getSingleMissingElement()) {
155  Pred = CmpInst::ICMP_NE;
156  RHS = *OnlyMissingElt;
157  Success = true;
158  } else if (getLower().isMinSignedValue() || getLower().isMinValue()) {
159  Pred =
161  RHS = getUpper();
162  Success = true;
163  } else if (getUpper().isMinSignedValue() || getUpper().isMinValue()) {
164  Pred =
166  RHS = getLower();
167  Success = true;
168  }
169 
170  assert((!Success || ConstantRange::makeExactICmpRegion(Pred, RHS) == *this) &&
171  "Bad result!");
172 
173  return Success;
174 }
175 
178  const ConstantRange &Other,
179  unsigned NoWrapKind) {
180  typedef OverflowingBinaryOperator OBO;
181 
182  // Computes the intersection of CR0 and CR1. It is different from
183  // intersectWith in that the ConstantRange returned will only contain elements
184  // in both CR0 and CR1 (i.e. SubsetIntersect(X, Y) is a *subset*, proper or
185  // not, of both X and Y).
186  auto SubsetIntersect =
187  [](const ConstantRange &CR0, const ConstantRange &CR1) {
188  return CR0.inverse().unionWith(CR1.inverse()).inverse();
189  };
190 
191  assert(BinOp >= Instruction::BinaryOpsBegin &&
192  BinOp < Instruction::BinaryOpsEnd && "Binary operators only!");
193 
194  assert((NoWrapKind == OBO::NoSignedWrap ||
195  NoWrapKind == OBO::NoUnsignedWrap ||
196  NoWrapKind == (OBO::NoUnsignedWrap | OBO::NoSignedWrap)) &&
197  "NoWrapKind invalid!");
198 
199  unsigned BitWidth = Other.getBitWidth();
200  if (BinOp != Instruction::Add)
201  // Conservative answer: empty set
202  return ConstantRange(BitWidth, false);
203 
204  if (auto *C = Other.getSingleElement())
205  if (C->isMinValue())
206  // Full set: nothing signed / unsigned wraps when added to 0.
207  return ConstantRange(BitWidth);
208 
209  ConstantRange Result(BitWidth);
210 
211  if (NoWrapKind & OBO::NoUnsignedWrap)
212  Result =
213  SubsetIntersect(Result, ConstantRange(APInt::getNullValue(BitWidth),
214  -Other.getUnsignedMax()));
215 
216  if (NoWrapKind & OBO::NoSignedWrap) {
217  APInt SignedMin = Other.getSignedMin();
218  APInt SignedMax = Other.getSignedMax();
219 
220  if (SignedMax.isStrictlyPositive())
221  Result = SubsetIntersect(
222  Result,
224  APInt::getSignedMinValue(BitWidth) - SignedMax));
225 
226  if (SignedMin.isNegative())
227  Result = SubsetIntersect(
228  Result, ConstantRange(APInt::getSignedMinValue(BitWidth) - SignedMin,
229  APInt::getSignedMinValue(BitWidth)));
230  }
231 
232  return Result;
233 }
234 
235 /// isFullSet - Return true if this set contains all of the elements possible
236 /// for this data-type
238  return Lower == Upper && Lower.isMaxValue();
239 }
240 
241 /// isEmptySet - Return true if this set contains no members.
242 ///
244  return Lower == Upper && Lower.isMinValue();
245 }
246 
247 /// isWrappedSet - Return true if this set wraps around the top of the range,
248 /// for example: [100, 8)
249 ///
251  return Lower.ugt(Upper);
252 }
253 
254 /// isSignWrappedSet - Return true if this set wraps around the INT_MIN of
255 /// its bitwidth, for example: i8 [120, 140).
256 ///
260 }
261 
262 /// getSetSize - Return the number of elements in this set.
263 ///
265  if (isFullSet()) {
266  APInt Size(getBitWidth()+1, 0);
267  Size.setBit(getBitWidth());
268  return Size;
269  }
270 
271  // This is also correct for wrapped sets.
272  return (Upper - Lower).zext(getBitWidth()+1);
273 }
274 
275 /// getUnsignedMax - Return the largest unsigned value contained in the
276 /// ConstantRange.
277 ///
279  if (isFullSet() || isWrappedSet())
281  return getUpper() - 1;
282 }
283 
284 /// getUnsignedMin - Return the smallest unsigned value contained in the
285 /// ConstantRange.
286 ///
288  if (isFullSet() || (isWrappedSet() && getUpper() != 0))
290  return getLower();
291 }
292 
293 /// getSignedMax - Return the largest signed value contained in the
294 /// ConstantRange.
295 ///
298  if (!isWrappedSet()) {
299  if (getLower().sle(getUpper() - 1))
300  return getUpper() - 1;
301  return SignedMax;
302  }
303  if (getLower().isNegative() == getUpper().isNegative())
304  return SignedMax;
305  return getUpper() - 1;
306 }
307 
308 /// getSignedMin - Return the smallest signed value contained in the
309 /// ConstantRange.
310 ///
313  if (!isWrappedSet()) {
314  if (getLower().sle(getUpper() - 1))
315  return getLower();
316  return SignedMin;
317  }
318  if ((getUpper() - 1).slt(getLower())) {
319  if (getUpper() != SignedMin)
320  return SignedMin;
321  }
322  return getLower();
323 }
324 
325 /// contains - Return true if the specified value is in the set.
326 ///
327 bool ConstantRange::contains(const APInt &V) const {
328  if (Lower == Upper)
329  return isFullSet();
330 
331  if (!isWrappedSet())
332  return Lower.ule(V) && V.ult(Upper);
333  return Lower.ule(V) || V.ult(Upper);
334 }
335 
336 /// contains - Return true if the argument is a subset of this range.
337 /// Two equal sets contain each other. The empty set contained by all other
338 /// sets.
339 ///
340 bool ConstantRange::contains(const ConstantRange &Other) const {
341  if (isFullSet() || Other.isEmptySet()) return true;
342  if (isEmptySet() || Other.isFullSet()) return false;
343 
344  if (!isWrappedSet()) {
345  if (Other.isWrappedSet())
346  return false;
347 
348  return Lower.ule(Other.getLower()) && Other.getUpper().ule(Upper);
349  }
350 
351  if (!Other.isWrappedSet())
352  return Other.getUpper().ule(Upper) ||
353  Lower.ule(Other.getLower());
354 
355  return Other.getUpper().ule(Upper) && Lower.ule(Other.getLower());
356 }
357 
358 /// subtract - Subtract the specified constant from the endpoints of this
359 /// constant range.
361  assert(Val.getBitWidth() == getBitWidth() && "Wrong bit width");
362  // If the set is empty or full, don't modify the endpoints.
363  if (Lower == Upper)
364  return *this;
365  return ConstantRange(Lower - Val, Upper - Val);
366 }
367 
368 /// \brief Subtract the specified range from this range (aka relative complement
369 /// of the sets).
371  return intersectWith(CR.inverse());
372 }
373 
374 /// intersectWith - Return the range that results from the intersection of this
375 /// range with another range. The resultant range is guaranteed to include all
376 /// elements contained in both input ranges, and to have the smallest possible
377 /// set size that does so. Because there may be two intersections with the
378 /// same set size, A.intersectWith(B) might not be equal to B.intersectWith(A).
380  assert(getBitWidth() == CR.getBitWidth() &&
381  "ConstantRange types don't agree!");
382 
383  // Handle common cases.
384  if ( isEmptySet() || CR.isFullSet()) return *this;
385  if (CR.isEmptySet() || isFullSet()) return CR;
386 
387  if (!isWrappedSet() && CR.isWrappedSet())
388  return CR.intersectWith(*this);
389 
390  if (!isWrappedSet() && !CR.isWrappedSet()) {
391  if (Lower.ult(CR.Lower)) {
392  if (Upper.ule(CR.Lower))
393  return ConstantRange(getBitWidth(), false);
394 
395  if (Upper.ult(CR.Upper))
396  return ConstantRange(CR.Lower, Upper);
397 
398  return CR;
399  }
400  if (Upper.ult(CR.Upper))
401  return *this;
402 
403  if (Lower.ult(CR.Upper))
404  return ConstantRange(Lower, CR.Upper);
405 
406  return ConstantRange(getBitWidth(), false);
407  }
408 
409  if (isWrappedSet() && !CR.isWrappedSet()) {
410  if (CR.Lower.ult(Upper)) {
411  if (CR.Upper.ult(Upper))
412  return CR;
413 
414  if (CR.Upper.ule(Lower))
415  return ConstantRange(CR.Lower, Upper);
416 
417  if (getSetSize().ult(CR.getSetSize()))
418  return *this;
419  return CR;
420  }
421  if (CR.Lower.ult(Lower)) {
422  if (CR.Upper.ule(Lower))
423  return ConstantRange(getBitWidth(), false);
424 
425  return ConstantRange(Lower, CR.Upper);
426  }
427  return CR;
428  }
429 
430  if (CR.Upper.ult(Upper)) {
431  if (CR.Lower.ult(Upper)) {
432  if (getSetSize().ult(CR.getSetSize()))
433  return *this;
434  return CR;
435  }
436 
437  if (CR.Lower.ult(Lower))
438  return ConstantRange(Lower, CR.Upper);
439 
440  return CR;
441  }
442  if (CR.Upper.ule(Lower)) {
443  if (CR.Lower.ult(Lower))
444  return *this;
445 
446  return ConstantRange(CR.Lower, Upper);
447  }
448  if (getSetSize().ult(CR.getSetSize()))
449  return *this;
450  return CR;
451 }
452 
453 
454 /// unionWith - Return the range that results from the union of this range with
455 /// another range. The resultant range is guaranteed to include the elements of
456 /// both sets, but may contain more. For example, [3, 9) union [12,15) is
457 /// [3, 15), which includes 9, 10, and 11, which were not included in either
458 /// set before.
459 ///
461  assert(getBitWidth() == CR.getBitWidth() &&
462  "ConstantRange types don't agree!");
463 
464  if ( isFullSet() || CR.isEmptySet()) return *this;
465  if (CR.isFullSet() || isEmptySet()) return CR;
466 
467  if (!isWrappedSet() && CR.isWrappedSet()) return CR.unionWith(*this);
468 
469  if (!isWrappedSet() && !CR.isWrappedSet()) {
470  if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower)) {
471  // If the two ranges are disjoint, find the smaller gap and bridge it.
472  APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
473  if (d1.ult(d2))
474  return ConstantRange(Lower, CR.Upper);
475  return ConstantRange(CR.Lower, Upper);
476  }
477 
478  APInt L = Lower, U = Upper;
479  if (CR.Lower.ult(L))
480  L = CR.Lower;
481  if ((CR.Upper - 1).ugt(U - 1))
482  U = CR.Upper;
483 
484  if (L == 0 && U == 0)
485  return ConstantRange(getBitWidth());
486 
487  return ConstantRange(L, U);
488  }
489 
490  if (!CR.isWrappedSet()) {
491  // ------U L----- and ------U L----- : this
492  // L--U L--U : CR
493  if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower))
494  return *this;
495 
496  // ------U L----- : this
497  // L---------U : CR
498  if (CR.Lower.ule(Upper) && Lower.ule(CR.Upper))
499  return ConstantRange(getBitWidth());
500 
501  // ----U L---- : this
502  // L---U : CR
503  // <d1> <d2>
504  if (Upper.ule(CR.Lower) && CR.Upper.ule(Lower)) {
505  APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
506  if (d1.ult(d2))
507  return ConstantRange(Lower, CR.Upper);
508  return ConstantRange(CR.Lower, Upper);
509  }
510 
511  // ----U L----- : this
512  // L----U : CR
513  if (Upper.ult(CR.Lower) && Lower.ult(CR.Upper))
514  return ConstantRange(CR.Lower, Upper);
515 
516  // ------U L---- : this
517  // L-----U : CR
518  assert(CR.Lower.ult(Upper) && CR.Upper.ult(Lower) &&
519  "ConstantRange::unionWith missed a case with one range wrapped");
520  return ConstantRange(Lower, CR.Upper);
521  }
522 
523  // ------U L---- and ------U L---- : this
524  // -U L----------- and ------------U L : CR
525  if (CR.Lower.ule(Upper) || Lower.ule(CR.Upper))
526  return ConstantRange(getBitWidth());
527 
528  APInt L = Lower, U = Upper;
529  if (CR.Upper.ugt(U))
530  U = CR.Upper;
531  if (CR.Lower.ult(L))
532  L = CR.Lower;
533 
534  return ConstantRange(L, U);
535 }
536 
538  uint32_t ResultBitWidth) const {
539  switch (CastOp) {
540  default:
541  llvm_unreachable("unsupported cast type");
542  case Instruction::Trunc:
543  return truncate(ResultBitWidth);
544  case Instruction::SExt:
545  return signExtend(ResultBitWidth);
546  case Instruction::ZExt:
547  return zeroExtend(ResultBitWidth);
548  case Instruction::BitCast:
549  return *this;
550  case Instruction::FPToUI:
551  case Instruction::FPToSI:
552  if (getBitWidth() == ResultBitWidth)
553  return *this;
554  else
555  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
556  case Instruction::UIToFP: {
557  // TODO: use input range if available
558  auto BW = getBitWidth();
559  APInt Min = APInt::getMinValue(BW).zextOrSelf(ResultBitWidth);
560  APInt Max = APInt::getMaxValue(BW).zextOrSelf(ResultBitWidth);
561  return ConstantRange(Min, Max);
562  }
563  case Instruction::SIToFP: {
564  // TODO: use input range if available
565  auto BW = getBitWidth();
566  APInt SMin = APInt::getSignedMinValue(BW).sextOrSelf(ResultBitWidth);
567  APInt SMax = APInt::getSignedMaxValue(BW).sextOrSelf(ResultBitWidth);
568  return ConstantRange(SMin, SMax);
569  }
570  case Instruction::FPTrunc:
571  case Instruction::FPExt:
572  case Instruction::IntToPtr:
573  case Instruction::PtrToInt:
574  case Instruction::AddrSpaceCast:
575  // Conservatively return full set.
576  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
577  };
578 }
579 
580 /// zeroExtend - Return a new range in the specified integer type, which must
581 /// be strictly larger than the current type. The returned range will
582 /// correspond to the possible range of values as if the source range had been
583 /// zero extended.
585  if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
586 
587  unsigned SrcTySize = getBitWidth();
588  assert(SrcTySize < DstTySize && "Not a value extension");
589  if (isFullSet() || isWrappedSet()) {
590  // Change into [0, 1 << src bit width)
591  APInt LowerExt(DstTySize, 0);
592  if (!Upper) // special case: [X, 0) -- not really wrapping around
593  LowerExt = Lower.zext(DstTySize);
594  return ConstantRange(LowerExt, APInt::getOneBitSet(DstTySize, SrcTySize));
595  }
596 
597  return ConstantRange(Lower.zext(DstTySize), Upper.zext(DstTySize));
598 }
599 
600 /// signExtend - Return a new range in the specified integer type, which must
601 /// be strictly larger than the current type. The returned range will
602 /// correspond to the possible range of values as if the source range had been
603 /// sign extended.
605  if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
606 
607  unsigned SrcTySize = getBitWidth();
608  assert(SrcTySize < DstTySize && "Not a value extension");
609 
610  // special case: [X, INT_MIN) -- not really wrapping around
611  if (Upper.isMinSignedValue())
612  return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize));
613 
614  if (isFullSet() || isSignWrappedSet()) {
615  return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
616  APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 1);
617  }
618 
619  return ConstantRange(Lower.sext(DstTySize), Upper.sext(DstTySize));
620 }
621 
622 /// truncate - Return a new range in the specified integer type, which must be
623 /// strictly smaller than the current type. The returned range will
624 /// correspond to the possible range of values as if the source range had been
625 /// truncated to the specified type.
627  assert(getBitWidth() > DstTySize && "Not a value truncation");
628  if (isEmptySet())
629  return ConstantRange(DstTySize, /*isFullSet=*/false);
630  if (isFullSet())
631  return ConstantRange(DstTySize, /*isFullSet=*/true);
632 
633  APInt MaxValue = APInt::getMaxValue(DstTySize).zext(getBitWidth());
634  APInt MaxBitValue(getBitWidth(), 0);
635  MaxBitValue.setBit(DstTySize);
636 
637  APInt LowerDiv(Lower), UpperDiv(Upper);
638  ConstantRange Union(DstTySize, /*isFullSet=*/false);
639 
640  // Analyze wrapped sets in their two parts: [0, Upper) \/ [Lower, MaxValue]
641  // We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and
642  // then we do the union with [MaxValue, Upper)
643  if (isWrappedSet()) {
644  // If Upper is greater than Max Value, it covers the whole truncated range.
645  if (Upper.uge(MaxValue))
646  return ConstantRange(DstTySize, /*isFullSet=*/true);
647 
648  Union = ConstantRange(APInt::getMaxValue(DstTySize),Upper.trunc(DstTySize));
649  UpperDiv = APInt::getMaxValue(getBitWidth());
650 
651  // Union covers the MaxValue case, so return if the remaining range is just
652  // MaxValue.
653  if (LowerDiv == UpperDiv)
654  return Union;
655  }
656 
657  // Chop off the most significant bits that are past the destination bitwidth.
658  if (LowerDiv.uge(MaxValue)) {
659  APInt Div(getBitWidth(), 0);
660  APInt::udivrem(LowerDiv, MaxBitValue, Div, LowerDiv);
661  UpperDiv = UpperDiv - MaxBitValue * Div;
662  }
663 
664  if (UpperDiv.ule(MaxValue))
665  return ConstantRange(LowerDiv.trunc(DstTySize),
666  UpperDiv.trunc(DstTySize)).unionWith(Union);
667 
668  // The truncated value wraps around. Check if we can do better than fullset.
669  APInt UpperModulo = UpperDiv - MaxBitValue;
670  if (UpperModulo.ult(LowerDiv))
671  return ConstantRange(LowerDiv.trunc(DstTySize),
672  UpperModulo.trunc(DstTySize)).unionWith(Union);
673 
674  return ConstantRange(DstTySize, /*isFullSet=*/true);
675 }
676 
677 /// zextOrTrunc - make this range have the bit width given by \p DstTySize. The
678 /// value is zero extended, truncated, or left alone to make it that width.
680  unsigned SrcTySize = getBitWidth();
681  if (SrcTySize > DstTySize)
682  return truncate(DstTySize);
683  if (SrcTySize < DstTySize)
684  return zeroExtend(DstTySize);
685  return *this;
686 }
687 
688 /// sextOrTrunc - make this range have the bit width given by \p DstTySize. The
689 /// value is sign extended, truncated, or left alone to make it that width.
691  unsigned SrcTySize = getBitWidth();
692  if (SrcTySize > DstTySize)
693  return truncate(DstTySize);
694  if (SrcTySize < DstTySize)
695  return signExtend(DstTySize);
696  return *this;
697 }
698 
700  const ConstantRange &Other) const {
701  assert(BinOp >= Instruction::BinaryOpsBegin &&
702  BinOp < Instruction::BinaryOpsEnd && "Binary operators only!");
703 
704  switch (BinOp) {
705  case Instruction::Add:
706  return add(Other);
707  case Instruction::Sub:
708  return sub(Other);
709  case Instruction::Mul:
710  return multiply(Other);
711  case Instruction::UDiv:
712  return udiv(Other);
713  case Instruction::Shl:
714  return shl(Other);
715  case Instruction::LShr:
716  return lshr(Other);
717  case Instruction::And:
718  return binaryAnd(Other);
719  case Instruction::Or:
720  return binaryOr(Other);
721  // Note: floating point operations applied to abstract ranges are just
722  // ideal integer operations with a lossy representation
723  case Instruction::FAdd:
724  return add(Other);
725  case Instruction::FSub:
726  return sub(Other);
727  case Instruction::FMul:
728  return multiply(Other);
729  default:
730  // Conservatively return full set.
731  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
732  }
733 }
734 
736 ConstantRange::add(const ConstantRange &Other) const {
737  if (isEmptySet() || Other.isEmptySet())
738  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
739  if (isFullSet() || Other.isFullSet())
740  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
741 
742  APInt Spread_X = getSetSize(), Spread_Y = Other.getSetSize();
743  APInt NewLower = getLower() + Other.getLower();
744  APInt NewUpper = getUpper() + Other.getUpper() - 1;
745  if (NewLower == NewUpper)
746  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
747 
748  ConstantRange X = ConstantRange(NewLower, NewUpper);
749  if (X.getSetSize().ult(Spread_X) || X.getSetSize().ult(Spread_Y))
750  // We've wrapped, therefore, full set.
751  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
752 
753  return X;
754 }
755 
757  // Calculate the subset of this range such that "X + Other" is
758  // guaranteed not to wrap (overflow) for all X in this subset.
759  // makeGuaranteedNoWrapRegion will produce an exact NSW range since we are
760  // passing a single element range.
762  ConstantRange(Other),
764  auto NSWConstrainedRange = intersectWith(NSWRange);
765 
766  return NSWConstrainedRange.add(ConstantRange(Other));
767 }
768 
770 ConstantRange::sub(const ConstantRange &Other) const {
771  if (isEmptySet() || Other.isEmptySet())
772  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
773  if (isFullSet() || Other.isFullSet())
774  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
775 
776  APInt Spread_X = getSetSize(), Spread_Y = Other.getSetSize();
777  APInt NewLower = getLower() - Other.getUpper() + 1;
778  APInt NewUpper = getUpper() - Other.getLower();
779  if (NewLower == NewUpper)
780  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
781 
782  ConstantRange X = ConstantRange(NewLower, NewUpper);
783  if (X.getSetSize().ult(Spread_X) || X.getSetSize().ult(Spread_Y))
784  // We've wrapped, therefore, full set.
785  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
786 
787  return X;
788 }
789 
792  // TODO: If either operand is a single element and the multiply is known to
793  // be non-wrapping, round the result min and max value to the appropriate
794  // multiple of that element. If wrapping is possible, at least adjust the
795  // range according to the greatest power-of-two factor of the single element.
796 
797  if (isEmptySet() || Other.isEmptySet())
798  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
799 
800  // Multiplication is signedness-independent. However different ranges can be
801  // obtained depending on how the input ranges are treated. These different
802  // ranges are all conservatively correct, but one might be better than the
803  // other. We calculate two ranges; one treating the inputs as unsigned
804  // and the other signed, then return the smallest of these ranges.
805 
806  // Unsigned range first.
807  APInt this_min = getUnsignedMin().zext(getBitWidth() * 2);
808  APInt this_max = getUnsignedMax().zext(getBitWidth() * 2);
809  APInt Other_min = Other.getUnsignedMin().zext(getBitWidth() * 2);
810  APInt Other_max = Other.getUnsignedMax().zext(getBitWidth() * 2);
811 
812  ConstantRange Result_zext = ConstantRange(this_min * Other_min,
813  this_max * Other_max + 1);
814  ConstantRange UR = Result_zext.truncate(getBitWidth());
815 
816  // If the unsigned range doesn't wrap, and isn't negative then it's a range
817  // from one positive number to another which is as good as we can generate.
818  // In this case, skip the extra work of generating signed ranges which aren't
819  // going to be better than this range.
820  if (!UR.isWrappedSet() && UR.getLower().isNonNegative())
821  return UR;
822 
823  // Now the signed range. Because we could be dealing with negative numbers
824  // here, the lower bound is the smallest of the cartesian product of the
825  // lower and upper ranges; for example:
826  // [-1,4) * [-2,3) = min(-1*-2, -1*2, 3*-2, 3*2) = -6.
827  // Similarly for the upper bound, swapping min for max.
828 
829  this_min = getSignedMin().sext(getBitWidth() * 2);
830  this_max = getSignedMax().sext(getBitWidth() * 2);
831  Other_min = Other.getSignedMin().sext(getBitWidth() * 2);
832  Other_max = Other.getSignedMax().sext(getBitWidth() * 2);
833 
834  auto L = {this_min * Other_min, this_min * Other_max,
835  this_max * Other_min, this_max * Other_max};
836  auto Compare = [](const APInt &A, const APInt &B) { return A.slt(B); };
837  ConstantRange Result_sext(std::min(L, Compare), std::max(L, Compare) + 1);
838  ConstantRange SR = Result_sext.truncate(getBitWidth());
839 
840  return UR.getSetSize().ult(SR.getSetSize()) ? UR : SR;
841 }
842 
844 ConstantRange::smax(const ConstantRange &Other) const {
845  // X smax Y is: range(smax(X_smin, Y_smin),
846  // smax(X_smax, Y_smax))
847  if (isEmptySet() || Other.isEmptySet())
848  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
849  APInt NewL = APIntOps::smax(getSignedMin(), Other.getSignedMin());
850  APInt NewU = APIntOps::smax(getSignedMax(), Other.getSignedMax()) + 1;
851  if (NewU == NewL)
852  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
853  return ConstantRange(NewL, NewU);
854 }
855 
857 ConstantRange::umax(const ConstantRange &Other) const {
858  // X umax Y is: range(umax(X_umin, Y_umin),
859  // umax(X_umax, Y_umax))
860  if (isEmptySet() || Other.isEmptySet())
861  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
863  APInt NewU = APIntOps::umax(getUnsignedMax(), Other.getUnsignedMax()) + 1;
864  if (NewU == NewL)
865  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
866  return ConstantRange(NewL, NewU);
867 }
868 
870 ConstantRange::smin(const ConstantRange &Other) const {
871  // X smin Y is: range(smin(X_smin, Y_smin),
872  // smin(X_smax, Y_smax))
873  if (isEmptySet() || Other.isEmptySet())
874  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
875  APInt NewL = APIntOps::smin(getSignedMin(), Other.getSignedMin());
876  APInt NewU = APIntOps::smin(getSignedMax(), Other.getSignedMax()) + 1;
877  if (NewU == NewL)
878  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
879  return ConstantRange(NewL, NewU);
880 }
881 
883 ConstantRange::umin(const ConstantRange &Other) const {
884  // X umin Y is: range(umin(X_umin, Y_umin),
885  // umin(X_umax, Y_umax))
886  if (isEmptySet() || Other.isEmptySet())
887  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
889  APInt NewU = APIntOps::umin(getUnsignedMax(), Other.getUnsignedMax()) + 1;
890  if (NewU == NewL)
891  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
892  return ConstantRange(NewL, NewU);
893 }
894 
897  if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax() == 0)
898  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
899  if (RHS.isFullSet())
900  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
901 
902  APInt Lower = getUnsignedMin().udiv(RHS.getUnsignedMax());
903 
904  APInt RHS_umin = RHS.getUnsignedMin();
905  if (RHS_umin == 0) {
906  // We want the lowest value in RHS excluding zero. Usually that would be 1
907  // except for a range in the form of [X, 1) in which case it would be X.
908  if (RHS.getUpper() == 1)
909  RHS_umin = RHS.getLower();
910  else
911  RHS_umin = APInt(getBitWidth(), 1);
912  }
913 
914  APInt Upper = getUnsignedMax().udiv(RHS_umin) + 1;
915 
916  // If the LHS is Full and the RHS is a wrapped interval containing 1 then
917  // this could occur.
918  if (Lower == Upper)
919  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
920 
921  return ConstantRange(Lower, Upper);
922 }
923 
926  if (isEmptySet() || Other.isEmptySet())
927  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
928 
929  // TODO: replace this with something less conservative
930 
932  if (umin.isAllOnesValue())
933  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
934  return ConstantRange(APInt::getNullValue(getBitWidth()), umin + 1);
935 }
936 
939  if (isEmptySet() || Other.isEmptySet())
940  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
941 
942  // TODO: replace this with something less conservative
943 
945  if (umax.isMinValue())
946  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
948 }
949 
951 ConstantRange::shl(const ConstantRange &Other) const {
952  if (isEmptySet() || Other.isEmptySet())
953  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
954 
956  APInt max = getUnsignedMax().shl(Other.getUnsignedMax());
957 
958  // there's no overflow!
960  if (Zeros.ugt(Other.getUnsignedMax()))
961  return ConstantRange(min, max + 1);
962 
963  // FIXME: implement the other tricky cases
964  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
965 }
966 
968 ConstantRange::lshr(const ConstantRange &Other) const {
969  if (isEmptySet() || Other.isEmptySet())
970  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
971 
972  APInt max = getUnsignedMax().lshr(Other.getUnsignedMin());
974  if (min == max + 1)
975  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
976 
977  return ConstantRange(min, max + 1);
978 }
979 
981  if (isFullSet())
982  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
983  if (isEmptySet())
984  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
985  return ConstantRange(Upper, Lower);
986 }
987 
988 /// print - Print out the bounds to a stream...
989 ///
991  if (isFullSet())
992  OS << "full-set";
993  else if (isEmptySet())
994  OS << "empty-set";
995  else
996  OS << "[" << Lower << "," << Upper << ")";
997 }
998 
999 /// dump - Allow printing from a debugger easily...
1000 ///
1002  print(dbgs());
1003 }
1004 
1006  const unsigned NumRanges = Ranges.getNumOperands() / 2;
1007  assert(NumRanges >= 1 && "Must have at least one range!");
1008  assert(Ranges.getNumOperands() % 2 == 0 && "Must be a sequence of pairs");
1009 
1010  auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.getOperand(0));
1011  auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.getOperand(1));
1012 
1013  ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
1014 
1015  for (unsigned i = 1; i < NumRanges; ++i) {
1016  auto *Low = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
1017  auto *High = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
1018 
1019  // Note: unionWith will potentially create a range that contains values not
1020  // contained in any of the original N ranges.
1021  CR = CR.unionWith(ConstantRange(Low->getValue(), High->getValue()));
1022  }
1023 
1024  return CR;
1025 }
MachineLoop * L
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
size_t i
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:450
void setBit(unsigned bitPosition)
Set a given bit to 1.
Definition: APInt.cpp:553
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1040
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition: APInt.h:329
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Definition: APInt.h:536
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition: InstrTypes.h:984
unsigned less or equal
Definition: InstrTypes.h:906
unsigned less than
Definition: InstrTypes.h:905
bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const
Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
Metadata node.
Definition: Metadata.h:830
bool isSingleElement() const
Return true if this set contains exactly one member.
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
Definition: MathExtras.h:180
uint64_t High
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:431
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:324
ConstantRange truncate(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly smaller than the current typ...
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Definition: APInt.cpp:1122
ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition: APInt.h:850
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
Definition: APInt.h:1788
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition: APInt.h:1783
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:1015
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition: APInt.cpp:501
static ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the largest range such that all values in the returned range satisfy the given predicate with...
void dump() const
Allow printing from a debugger easily.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
Definition: APInt.h:518
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
APInt trunc(unsigned width) const
Truncate to new width.
Definition: APInt.cpp:916
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
ConstantRange lshr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a logical right shift of a value i...
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
const APInt * getSingleMissingElement() const
If this set contains all but a single element, return it, otherwise return null.
APInt sextOrSelf(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:1021
bool isWrappedSet() const
Return true if this set wraps around the top of the range.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
Definition: APInt.h:1947
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition: APInt.h:484
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:939
ConstantRange udiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned division of a value in...
ConstantRange(uint32_t BitWidth, bool isFullSet=true)
Initialize a full (the default) or empty set for the specified bit width.
ConstantRange castOp(Instruction::CastOps CastOp, uint32_t BitWidth) const
Return a new range representing the possible values resulting from an application of the specified ca...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:880
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
Definition: Operator.h:75
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1255
ConstantRange binaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other) const
Return a new range representing the possible values resulting from an application of the specified bi...
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition: APInt.h:1119
ConstantRange addWithNoSignedWrap(const APInt &Other) const
Return a new range representing the possible values resulting from a known NSW addition of a value in...
bool isMaxValue() const
Determine if this is the largest unsigned value.
Definition: APInt.h:352
ConstantRange sub(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a subtraction of a value in this r...
void print(raw_ostream &OS) const
Print out the bounds to a stream.
ConstantRange zeroExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
bool isEmptySet() const
Return true if this set contains no members.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
signed greater than
Definition: InstrTypes.h:907
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition: APInt.h:1793
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
Definition: APInt.h:1083
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1034
static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
bool slt(const APInt &RHS) const
Signed less than comparison.
Definition: APInt.cpp:533
bool isSignWrappedSet() const
Return true if this set wraps around the INT_MIN of its bitwidth.
APInt getSetSize() const
Return the number of elements in this set.
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
This class represents a range of values.
Definition: ConstantRange.h:45
signed less than
Definition: InstrTypes.h:909
const APInt & getLower() const
Return the lower value for this range.
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
Definition: APInt.h:337
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:438
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
ConstantRange binaryOr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a binary-or of a value in this ran...
signed less or equal
Definition: InstrTypes.h:910
Class for arbitrary precision integers.
Definition: APInt.h:77
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
Definition: APInt.h:1798
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:426
bool isMinValue() const
Determine if this is the smallest unsigned value.
Definition: APInt.h:366
ConstantRange shl(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a left shift of a value in this ra...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Definition: APInt.h:1942
#define Success
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
bool isAllOnesValue() const
Determine if all bits are set.
Definition: APInt.h:342
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Definition: APInt.h:372
APInt udiv(const APInt &RHS) const
Unsigned division operation.
Definition: APInt.cpp:1817
unsigned greater or equal
Definition: InstrTypes.h:904
ConstantRange binaryAnd(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a binary-and of a value in this ra...
const APInt & getUpper() const
Return the upper value for this range.
static ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)
Return the largest range containing all X such that "X BinOpC Y" is guaranteed not to wrap (overflow)...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:441
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
Definition: APInt.cpp:1913
ConstantRange smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
ConstantRange zextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
unsigned greater than
Definition: InstrTypes.h:903
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:980
static APInt getNullValue(unsigned numBits)
Get the '0' value.
Definition: APInt.h:465
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Definition: APInt.h:1051
signed greater or equal
Definition: InstrTypes.h:908
APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.