LLVM  7.0.0svn
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/ADT/APInt.h"
25 #include "llvm/Config/llvm-config.h"
26 #include "llvm/IR/ConstantRange.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/InstrTypes.h"
29 #include "llvm/IR/Instruction.h"
30 #include "llvm/IR/Metadata.h"
31 #include "llvm/IR/Operator.h"
32 #include "llvm/Support/Compiler.h"
33 #include "llvm/Support/Debug.h"
36 #include <algorithm>
37 #include <cassert>
38 #include <cstdint>
39 
40 using namespace llvm;
41 
43  : Lower(Full ? APInt::getMaxValue(BitWidth) : APInt::getMinValue(BitWidth)),
44  Upper(Lower) {}
45 
47  : Lower(std::move(V)), Upper(Lower + 1) {}
48 
50  : Lower(std::move(L)), Upper(std::move(U)) {
51  assert(Lower.getBitWidth() == Upper.getBitWidth() &&
52  "ConstantRange with unequal bit widths");
53  assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) &&
54  "Lower == Upper, but they aren't min or max value!");
55 }
56 
58  const ConstantRange &CR) {
59  if (CR.isEmptySet())
60  return CR;
61 
62  uint32_t W = CR.getBitWidth();
63  switch (Pred) {
64  default:
65  llvm_unreachable("Invalid ICmp predicate to makeAllowedICmpRegion()");
66  case CmpInst::ICMP_EQ:
67  return CR;
68  case CmpInst::ICMP_NE:
69  if (CR.isSingleElement())
70  return ConstantRange(CR.getUpper(), CR.getLower());
71  return ConstantRange(W);
72  case CmpInst::ICMP_ULT: {
73  APInt UMax(CR.getUnsignedMax());
74  if (UMax.isMinValue())
75  return ConstantRange(W, /* empty */ false);
76  return ConstantRange(APInt::getMinValue(W), std::move(UMax));
77  }
78  case CmpInst::ICMP_SLT: {
79  APInt SMax(CR.getSignedMax());
80  if (SMax.isMinSignedValue())
81  return ConstantRange(W, /* empty */ false);
82  return ConstantRange(APInt::getSignedMinValue(W), std::move(SMax));
83  }
84  case CmpInst::ICMP_ULE: {
85  APInt UMax(CR.getUnsignedMax());
86  if (UMax.isMaxValue())
87  return ConstantRange(W);
88  return ConstantRange(APInt::getMinValue(W), std::move(UMax) + 1);
89  }
90  case CmpInst::ICMP_SLE: {
91  APInt SMax(CR.getSignedMax());
92  if (SMax.isMaxSignedValue())
93  return ConstantRange(W);
94  return ConstantRange(APInt::getSignedMinValue(W), std::move(SMax) + 1);
95  }
96  case CmpInst::ICMP_UGT: {
97  APInt UMin(CR.getUnsignedMin());
98  if (UMin.isMaxValue())
99  return ConstantRange(W, /* empty */ false);
100  return ConstantRange(std::move(UMin) + 1, APInt::getNullValue(W));
101  }
102  case CmpInst::ICMP_SGT: {
103  APInt SMin(CR.getSignedMin());
104  if (SMin.isMaxSignedValue())
105  return ConstantRange(W, /* empty */ false);
106  return ConstantRange(std::move(SMin) + 1, APInt::getSignedMinValue(W));
107  }
108  case CmpInst::ICMP_UGE: {
109  APInt UMin(CR.getUnsignedMin());
110  if (UMin.isMinValue())
111  return ConstantRange(W);
112  return ConstantRange(std::move(UMin), APInt::getNullValue(W));
113  }
114  case CmpInst::ICMP_SGE: {
115  APInt SMin(CR.getSignedMin());
116  if (SMin.isMinSignedValue())
117  return ConstantRange(W);
118  return ConstantRange(std::move(SMin), APInt::getSignedMinValue(W));
119  }
120  }
121 }
122 
124  const ConstantRange &CR) {
125  // Follows from De-Morgan's laws:
126  //
127  // ~(~A union ~B) == A intersect B.
128  //
130  .inverse();
131 }
132 
134  const APInt &C) {
135  // Computes the exact range that is equal to both the constant ranges returned
136  // by makeAllowedICmpRegion and makeSatisfyingICmpRegion. This is always true
137  // when RHS is a singleton such as an APInt and so the assert is valid.
138  // However for non-singleton RHS, for example ult [2,5) makeAllowedICmpRegion
139  // returns [0,4) but makeSatisfyICmpRegion returns [0,2).
140  //
142  return makeAllowedICmpRegion(Pred, C);
143 }
144 
146  APInt &RHS) const {
147  bool Success = false;
148 
149  if (isFullSet() || isEmptySet()) {
151  RHS = APInt(getBitWidth(), 0);
152  Success = true;
153  } else if (auto *OnlyElt = getSingleElement()) {
154  Pred = CmpInst::ICMP_EQ;
155  RHS = *OnlyElt;
156  Success = true;
157  } else if (auto *OnlyMissingElt = getSingleMissingElement()) {
158  Pred = CmpInst::ICMP_NE;
159  RHS = *OnlyMissingElt;
160  Success = true;
161  } else if (getLower().isMinSignedValue() || getLower().isMinValue()) {
162  Pred =
164  RHS = getUpper();
165  Success = true;
166  } else if (getUpper().isMinSignedValue() || getUpper().isMinValue()) {
167  Pred =
169  RHS = getLower();
170  Success = true;
171  }
172 
173  assert((!Success || ConstantRange::makeExactICmpRegion(Pred, RHS) == *this) &&
174  "Bad result!");
175 
176  return Success;
177 }
178 
181  const ConstantRange &Other,
182  unsigned NoWrapKind) {
183  using OBO = OverflowingBinaryOperator;
184 
185  // Computes the intersection of CR0 and CR1. It is different from
186  // intersectWith in that the ConstantRange returned will only contain elements
187  // in both CR0 and CR1 (i.e. SubsetIntersect(X, Y) is a *subset*, proper or
188  // not, of both X and Y).
189  auto SubsetIntersect =
190  [](const ConstantRange &CR0, const ConstantRange &CR1) {
191  return CR0.inverse().unionWith(CR1.inverse()).inverse();
192  };
193 
194  assert(Instruction::isBinaryOp(BinOp) && "Binary operators only!");
195 
196  assert((NoWrapKind == OBO::NoSignedWrap ||
197  NoWrapKind == OBO::NoUnsignedWrap ||
198  NoWrapKind == (OBO::NoUnsignedWrap | OBO::NoSignedWrap)) &&
199  "NoWrapKind invalid!");
200 
201  unsigned BitWidth = Other.getBitWidth();
202  ConstantRange Result(BitWidth);
203 
204  switch (BinOp) {
205  default:
206  // Conservative answer: empty set
207  return ConstantRange(BitWidth, false);
208 
209  case Instruction::Add:
210  if (auto *C = Other.getSingleElement())
211  if (C->isNullValue())
212  // Full set: nothing signed / unsigned wraps when added to 0.
213  return ConstantRange(BitWidth);
214  if (NoWrapKind & OBO::NoUnsignedWrap)
215  Result =
216  SubsetIntersect(Result, ConstantRange(APInt::getNullValue(BitWidth),
217  -Other.getUnsignedMax()));
218  if (NoWrapKind & OBO::NoSignedWrap) {
219  const APInt &SignedMin = Other.getSignedMin();
220  const APInt &SignedMax = Other.getSignedMax();
221  if (SignedMax.isStrictlyPositive())
222  Result = SubsetIntersect(
223  Result,
225  APInt::getSignedMinValue(BitWidth) - SignedMax));
226  if (SignedMin.isNegative())
227  Result = SubsetIntersect(
228  Result,
229  ConstantRange(APInt::getSignedMinValue(BitWidth) - SignedMin,
230  APInt::getSignedMinValue(BitWidth)));
231  }
232  return Result;
233 
234  case Instruction::Sub:
235  if (auto *C = Other.getSingleElement())
236  if (C->isNullValue())
237  // Full set: nothing signed / unsigned wraps when subtracting 0.
238  return ConstantRange(BitWidth);
239  if (NoWrapKind & OBO::NoUnsignedWrap)
240  Result =
241  SubsetIntersect(Result, ConstantRange(Other.getUnsignedMax(),
242  APInt::getMinValue(BitWidth)));
243  if (NoWrapKind & OBO::NoSignedWrap) {
244  const APInt &SignedMin = Other.getSignedMin();
245  const APInt &SignedMax = Other.getSignedMax();
246  if (SignedMax.isStrictlyPositive())
247  Result = SubsetIntersect(
248  Result,
249  ConstantRange(APInt::getSignedMinValue(BitWidth) + SignedMax,
250  APInt::getSignedMinValue(BitWidth)));
251  if (SignedMin.isNegative())
252  Result = SubsetIntersect(
253  Result,
255  APInt::getSignedMinValue(BitWidth) + SignedMin));
256  }
257  return Result;
258  }
259 }
260 
262  return Lower == Upper && Lower.isMaxValue();
263 }
264 
266  return Lower == Upper && Lower.isMinValue();
267 }
268 
270  return Lower.ugt(Upper);
271 }
272 
276 }
277 
279  if (isFullSet())
281 
282  // This is also correct for wrapped sets.
283  return (Upper - Lower).zext(getBitWidth()+1);
284 }
285 
286 bool
288  assert(getBitWidth() == Other.getBitWidth());
289  if (isFullSet())
290  return false;
291  if (Other.isFullSet())
292  return true;
293  return (Upper - Lower).ult(Other.Upper - Other.Lower);
294 }
295 
296 bool
297 ConstantRange::isSizeLargerThan(uint64_t MaxSize) const {
298  assert(MaxSize && "MaxSize can't be 0.");
299  // If this a full set, we need special handling to avoid needing an extra bit
300  // to represent the size.
301  if (isFullSet())
302  return APInt::getMaxValue(getBitWidth()).ugt(MaxSize - 1);
303 
304  return (Upper - Lower).ugt(MaxSize);
305 }
306 
308  if (isFullSet() || isWrappedSet())
310  return getUpper() - 1;
311 }
312 
314  if (isFullSet() || (isWrappedSet() && !getUpper().isNullValue()))
316  return getLower();
317 }
318 
320  if (isFullSet() || Lower.sgt(Upper))
322  return getUpper() - 1;
323 }
324 
326  if (isFullSet() || (Lower.sgt(Upper) && !getUpper().isMinSignedValue()))
328  return getLower();
329 }
330 
331 bool ConstantRange::contains(const APInt &V) const {
332  if (Lower == Upper)
333  return isFullSet();
334 
335  if (!isWrappedSet())
336  return Lower.ule(V) && V.ult(Upper);
337  return Lower.ule(V) || V.ult(Upper);
338 }
339 
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 
359  assert(Val.getBitWidth() == getBitWidth() && "Wrong bit width");
360  // If the set is empty or full, don't modify the endpoints.
361  if (Lower == Upper)
362  return *this;
363  return ConstantRange(Lower - Val, Upper - Val);
364 }
365 
367  return intersectWith(CR.inverse());
368 }
369 
371  assert(getBitWidth() == CR.getBitWidth() &&
372  "ConstantRange types don't agree!");
373 
374  // Handle common cases.
375  if ( isEmptySet() || CR.isFullSet()) return *this;
376  if (CR.isEmptySet() || isFullSet()) return CR;
377 
378  if (!isWrappedSet() && CR.isWrappedSet())
379  return CR.intersectWith(*this);
380 
381  if (!isWrappedSet() && !CR.isWrappedSet()) {
382  if (Lower.ult(CR.Lower)) {
383  if (Upper.ule(CR.Lower))
384  return ConstantRange(getBitWidth(), false);
385 
386  if (Upper.ult(CR.Upper))
387  return ConstantRange(CR.Lower, Upper);
388 
389  return CR;
390  }
391  if (Upper.ult(CR.Upper))
392  return *this;
393 
394  if (Lower.ult(CR.Upper))
395  return ConstantRange(Lower, CR.Upper);
396 
397  return ConstantRange(getBitWidth(), false);
398  }
399 
400  if (isWrappedSet() && !CR.isWrappedSet()) {
401  if (CR.Lower.ult(Upper)) {
402  if (CR.Upper.ult(Upper))
403  return CR;
404 
405  if (CR.Upper.ule(Lower))
406  return ConstantRange(CR.Lower, Upper);
407 
409  return *this;
410  return CR;
411  }
412  if (CR.Lower.ult(Lower)) {
413  if (CR.Upper.ule(Lower))
414  return ConstantRange(getBitWidth(), false);
415 
416  return ConstantRange(Lower, CR.Upper);
417  }
418  return CR;
419  }
420 
421  if (CR.Upper.ult(Upper)) {
422  if (CR.Lower.ult(Upper)) {
424  return *this;
425  return CR;
426  }
427 
428  if (CR.Lower.ult(Lower))
429  return ConstantRange(Lower, CR.Upper);
430 
431  return CR;
432  }
433  if (CR.Upper.ule(Lower)) {
434  if (CR.Lower.ult(Lower))
435  return *this;
436 
437  return ConstantRange(CR.Lower, Upper);
438  }
440  return *this;
441  return CR;
442 }
443 
445  assert(getBitWidth() == CR.getBitWidth() &&
446  "ConstantRange types don't agree!");
447 
448  if ( isFullSet() || CR.isEmptySet()) return *this;
449  if (CR.isFullSet() || isEmptySet()) return CR;
450 
451  if (!isWrappedSet() && CR.isWrappedSet()) return CR.unionWith(*this);
452 
453  if (!isWrappedSet() && !CR.isWrappedSet()) {
454  if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower)) {
455  // If the two ranges are disjoint, find the smaller gap and bridge it.
456  APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
457  if (d1.ult(d2))
458  return ConstantRange(Lower, CR.Upper);
459  return ConstantRange(CR.Lower, Upper);
460  }
461 
462  APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower;
463  APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper;
464 
465  if (L.isNullValue() && U.isNullValue())
466  return ConstantRange(getBitWidth());
467 
468  return ConstantRange(std::move(L), std::move(U));
469  }
470 
471  if (!CR.isWrappedSet()) {
472  // ------U L----- and ------U L----- : this
473  // L--U L--U : CR
474  if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower))
475  return *this;
476 
477  // ------U L----- : this
478  // L---------U : CR
479  if (CR.Lower.ule(Upper) && Lower.ule(CR.Upper))
480  return ConstantRange(getBitWidth());
481 
482  // ----U L---- : this
483  // L---U : CR
484  // <d1> <d2>
485  if (Upper.ule(CR.Lower) && CR.Upper.ule(Lower)) {
486  APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
487  if (d1.ult(d2))
488  return ConstantRange(Lower, CR.Upper);
489  return ConstantRange(CR.Lower, Upper);
490  }
491 
492  // ----U L----- : this
493  // L----U : CR
494  if (Upper.ult(CR.Lower) && Lower.ult(CR.Upper))
495  return ConstantRange(CR.Lower, Upper);
496 
497  // ------U L---- : this
498  // L-----U : CR
499  assert(CR.Lower.ult(Upper) && CR.Upper.ult(Lower) &&
500  "ConstantRange::unionWith missed a case with one range wrapped");
501  return ConstantRange(Lower, CR.Upper);
502  }
503 
504  // ------U L---- and ------U L---- : this
505  // -U L----------- and ------------U L : CR
506  if (CR.Lower.ule(Upper) || Lower.ule(CR.Upper))
507  return ConstantRange(getBitWidth());
508 
509  APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower;
510  APInt U = CR.Upper.ugt(Upper) ? CR.Upper : Upper;
511 
512  return ConstantRange(std::move(L), std::move(U));
513 }
514 
516  uint32_t ResultBitWidth) const {
517  switch (CastOp) {
518  default:
519  llvm_unreachable("unsupported cast type");
520  case Instruction::Trunc:
521  return truncate(ResultBitWidth);
522  case Instruction::SExt:
523  return signExtend(ResultBitWidth);
524  case Instruction::ZExt:
525  return zeroExtend(ResultBitWidth);
526  case Instruction::BitCast:
527  return *this;
528  case Instruction::FPToUI:
529  case Instruction::FPToSI:
530  if (getBitWidth() == ResultBitWidth)
531  return *this;
532  else
533  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
534  case Instruction::UIToFP: {
535  // TODO: use input range if available
536  auto BW = getBitWidth();
537  APInt Min = APInt::getMinValue(BW).zextOrSelf(ResultBitWidth);
538  APInt Max = APInt::getMaxValue(BW).zextOrSelf(ResultBitWidth);
539  return ConstantRange(std::move(Min), std::move(Max));
540  }
541  case Instruction::SIToFP: {
542  // TODO: use input range if available
543  auto BW = getBitWidth();
544  APInt SMin = APInt::getSignedMinValue(BW).sextOrSelf(ResultBitWidth);
545  APInt SMax = APInt::getSignedMaxValue(BW).sextOrSelf(ResultBitWidth);
546  return ConstantRange(std::move(SMin), std::move(SMax));
547  }
548  case Instruction::FPTrunc:
549  case Instruction::FPExt:
550  case Instruction::IntToPtr:
551  case Instruction::PtrToInt:
552  case Instruction::AddrSpaceCast:
553  // Conservatively return full set.
554  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
555  };
556 }
557 
559  if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
560 
561  unsigned SrcTySize = getBitWidth();
562  assert(SrcTySize < DstTySize && "Not a value extension");
563  if (isFullSet() || isWrappedSet()) {
564  // Change into [0, 1 << src bit width)
565  APInt LowerExt(DstTySize, 0);
566  if (!Upper) // special case: [X, 0) -- not really wrapping around
567  LowerExt = Lower.zext(DstTySize);
568  return ConstantRange(std::move(LowerExt),
569  APInt::getOneBitSet(DstTySize, SrcTySize));
570  }
571 
572  return ConstantRange(Lower.zext(DstTySize), Upper.zext(DstTySize));
573 }
574 
576  if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
577 
578  unsigned SrcTySize = getBitWidth();
579  assert(SrcTySize < DstTySize && "Not a value extension");
580 
581  // special case: [X, INT_MIN) -- not really wrapping around
582  if (Upper.isMinSignedValue())
583  return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize));
584 
585  if (isFullSet() || isSignWrappedSet()) {
586  return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
587  APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 1);
588  }
589 
590  return ConstantRange(Lower.sext(DstTySize), Upper.sext(DstTySize));
591 }
592 
594  assert(getBitWidth() > DstTySize && "Not a value truncation");
595  if (isEmptySet())
596  return ConstantRange(DstTySize, /*isFullSet=*/false);
597  if (isFullSet())
598  return ConstantRange(DstTySize, /*isFullSet=*/true);
599 
600  APInt LowerDiv(Lower), UpperDiv(Upper);
601  ConstantRange Union(DstTySize, /*isFullSet=*/false);
602 
603  // Analyze wrapped sets in their two parts: [0, Upper) \/ [Lower, MaxValue]
604  // We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and
605  // then we do the union with [MaxValue, Upper)
606  if (isWrappedSet()) {
607  // If Upper is greater than or equal to MaxValue(DstTy), it covers the whole
608  // truncated range.
609  if (Upper.getActiveBits() > DstTySize ||
610  Upper.countTrailingOnes() == DstTySize)
611  return ConstantRange(DstTySize, /*isFullSet=*/true);
612 
613  Union = ConstantRange(APInt::getMaxValue(DstTySize),Upper.trunc(DstTySize));
614  UpperDiv.setAllBits();
615 
616  // Union covers the MaxValue case, so return if the remaining range is just
617  // MaxValue(DstTy).
618  if (LowerDiv == UpperDiv)
619  return Union;
620  }
621 
622  // Chop off the most significant bits that are past the destination bitwidth.
623  if (LowerDiv.getActiveBits() > DstTySize) {
624  // Mask to just the signficant bits and subtract from LowerDiv/UpperDiv.
625  APInt Adjust = LowerDiv & APInt::getBitsSetFrom(getBitWidth(), DstTySize);
626  LowerDiv -= Adjust;
627  UpperDiv -= Adjust;
628  }
629 
630  unsigned UpperDivWidth = UpperDiv.getActiveBits();
631  if (UpperDivWidth <= DstTySize)
632  return ConstantRange(LowerDiv.trunc(DstTySize),
633  UpperDiv.trunc(DstTySize)).unionWith(Union);
634 
635  // The truncated value wraps around. Check if we can do better than fullset.
636  if (UpperDivWidth == DstTySize + 1) {
637  // Clear the MSB so that UpperDiv wraps around.
638  UpperDiv.clearBit(DstTySize);
639  if (UpperDiv.ult(LowerDiv))
640  return ConstantRange(LowerDiv.trunc(DstTySize),
641  UpperDiv.trunc(DstTySize)).unionWith(Union);
642  }
643 
644  return ConstantRange(DstTySize, /*isFullSet=*/true);
645 }
646 
648  unsigned SrcTySize = getBitWidth();
649  if (SrcTySize > DstTySize)
650  return truncate(DstTySize);
651  if (SrcTySize < DstTySize)
652  return zeroExtend(DstTySize);
653  return *this;
654 }
655 
657  unsigned SrcTySize = getBitWidth();
658  if (SrcTySize > DstTySize)
659  return truncate(DstTySize);
660  if (SrcTySize < DstTySize)
661  return signExtend(DstTySize);
662  return *this;
663 }
664 
666  const ConstantRange &Other) const {
667  assert(Instruction::isBinaryOp(BinOp) && "Binary operators only!");
668 
669  switch (BinOp) {
670  case Instruction::Add:
671  return add(Other);
672  case Instruction::Sub:
673  return sub(Other);
674  case Instruction::Mul:
675  return multiply(Other);
676  case Instruction::UDiv:
677  return udiv(Other);
678  case Instruction::Shl:
679  return shl(Other);
680  case Instruction::LShr:
681  return lshr(Other);
682  case Instruction::AShr:
683  return ashr(Other);
684  case Instruction::And:
685  return binaryAnd(Other);
686  case Instruction::Or:
687  return binaryOr(Other);
688  // Note: floating point operations applied to abstract ranges are just
689  // ideal integer operations with a lossy representation
690  case Instruction::FAdd:
691  return add(Other);
692  case Instruction::FSub:
693  return sub(Other);
694  case Instruction::FMul:
695  return multiply(Other);
696  default:
697  // Conservatively return full set.
698  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
699  }
700 }
701 
704  if (isEmptySet() || Other.isEmptySet())
705  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
706  if (isFullSet() || Other.isFullSet())
707  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
708 
709  APInt NewLower = getLower() + Other.getLower();
710  APInt NewUpper = getUpper() + Other.getUpper() - 1;
711  if (NewLower == NewUpper)
712  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
713 
714  ConstantRange X = ConstantRange(std::move(NewLower), std::move(NewUpper));
715  if (X.isSizeStrictlySmallerThan(*this) ||
716  X.isSizeStrictlySmallerThan(Other))
717  // We've wrapped, therefore, full set.
718  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
719  return X;
720 }
721 
723  // Calculate the subset of this range such that "X + Other" is
724  // guaranteed not to wrap (overflow) for all X in this subset.
725  // makeGuaranteedNoWrapRegion will produce an exact NSW range since we are
726  // passing a single element range.
728  ConstantRange(Other),
730  auto NSWConstrainedRange = intersectWith(NSWRange);
731 
732  return NSWConstrainedRange.add(ConstantRange(Other));
733 }
734 
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 NewLower = getLower() - Other.getUpper() + 1;
743  APInt NewUpper = getUpper() - Other.getLower();
744  if (NewLower == NewUpper)
745  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
746 
747  ConstantRange X = ConstantRange(std::move(NewLower), std::move(NewUpper));
748  if (X.isSizeStrictlySmallerThan(*this) ||
749  X.isSizeStrictlySmallerThan(Other))
750  // We've wrapped, therefore, full set.
751  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
752  return X;
753 }
754 
757  // TODO: If either operand is a single element and the multiply is known to
758  // be non-wrapping, round the result min and max value to the appropriate
759  // multiple of that element. If wrapping is possible, at least adjust the
760  // range according to the greatest power-of-two factor of the single element.
761 
762  if (isEmptySet() || Other.isEmptySet())
763  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
764 
765  // Multiplication is signedness-independent. However different ranges can be
766  // obtained depending on how the input ranges are treated. These different
767  // ranges are all conservatively correct, but one might be better than the
768  // other. We calculate two ranges; one treating the inputs as unsigned
769  // and the other signed, then return the smallest of these ranges.
770 
771  // Unsigned range first.
772  APInt this_min = getUnsignedMin().zext(getBitWidth() * 2);
773  APInt this_max = getUnsignedMax().zext(getBitWidth() * 2);
774  APInt Other_min = Other.getUnsignedMin().zext(getBitWidth() * 2);
775  APInt Other_max = Other.getUnsignedMax().zext(getBitWidth() * 2);
776 
777  ConstantRange Result_zext = ConstantRange(this_min * Other_min,
778  this_max * Other_max + 1);
779  ConstantRange UR = Result_zext.truncate(getBitWidth());
780 
781  // If the unsigned range doesn't wrap, and isn't negative then it's a range
782  // from one positive number to another which is as good as we can generate.
783  // In this case, skip the extra work of generating signed ranges which aren't
784  // going to be better than this range.
785  if (!UR.isWrappedSet() &&
786  (UR.getUpper().isNonNegative() || UR.getUpper().isMinSignedValue()))
787  return UR;
788 
789  // Now the signed range. Because we could be dealing with negative numbers
790  // here, the lower bound is the smallest of the cartesian product of the
791  // lower and upper ranges; for example:
792  // [-1,4) * [-2,3) = min(-1*-2, -1*2, 3*-2, 3*2) = -6.
793  // Similarly for the upper bound, swapping min for max.
794 
795  this_min = getSignedMin().sext(getBitWidth() * 2);
796  this_max = getSignedMax().sext(getBitWidth() * 2);
797  Other_min = Other.getSignedMin().sext(getBitWidth() * 2);
798  Other_max = Other.getSignedMax().sext(getBitWidth() * 2);
799 
800  auto L = {this_min * Other_min, this_min * Other_max,
801  this_max * Other_min, this_max * Other_max};
802  auto Compare = [](const APInt &A, const APInt &B) { return A.slt(B); };
803  ConstantRange Result_sext(std::min(L, Compare), std::max(L, Compare) + 1);
804  ConstantRange SR = Result_sext.truncate(getBitWidth());
805 
806  return UR.isSizeStrictlySmallerThan(SR) ? UR : SR;
807 }
808 
811  // X smax Y is: range(smax(X_smin, Y_smin),
812  // smax(X_smax, Y_smax))
813  if (isEmptySet() || Other.isEmptySet())
814  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
815  APInt NewL = APIntOps::smax(getSignedMin(), Other.getSignedMin());
816  APInt NewU = APIntOps::smax(getSignedMax(), Other.getSignedMax()) + 1;
817  if (NewU == NewL)
818  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
819  return ConstantRange(std::move(NewL), std::move(NewU));
820 }
821 
824  // X umax Y is: range(umax(X_umin, Y_umin),
825  // umax(X_umax, Y_umax))
826  if (isEmptySet() || Other.isEmptySet())
827  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
829  APInt NewU = APIntOps::umax(getUnsignedMax(), Other.getUnsignedMax()) + 1;
830  if (NewU == NewL)
831  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
832  return ConstantRange(std::move(NewL), std::move(NewU));
833 }
834 
837  // X smin Y is: range(smin(X_smin, Y_smin),
838  // smin(X_smax, Y_smax))
839  if (isEmptySet() || Other.isEmptySet())
840  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
841  APInt NewL = APIntOps::smin(getSignedMin(), Other.getSignedMin());
842  APInt NewU = APIntOps::smin(getSignedMax(), Other.getSignedMax()) + 1;
843  if (NewU == NewL)
844  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
845  return ConstantRange(std::move(NewL), std::move(NewU));
846 }
847 
850  // X umin Y is: range(umin(X_umin, Y_umin),
851  // umin(X_umax, Y_umax))
852  if (isEmptySet() || Other.isEmptySet())
853  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
855  APInt NewU = APIntOps::umin(getUnsignedMax(), Other.getUnsignedMax()) + 1;
856  if (NewU == NewL)
857  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
858  return ConstantRange(std::move(NewL), std::move(NewU));
859 }
860 
863  if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isNullValue())
864  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
865  if (RHS.isFullSet())
866  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
867 
869 
870  APInt RHS_umin = RHS.getUnsignedMin();
871  if (RHS_umin.isNullValue()) {
872  // We want the lowest value in RHS excluding zero. Usually that would be 1
873  // except for a range in the form of [X, 1) in which case it would be X.
874  if (RHS.getUpper() == 1)
875  RHS_umin = RHS.getLower();
876  else
877  RHS_umin = 1;
878  }
879 
880  APInt Upper = getUnsignedMax().udiv(RHS_umin) + 1;
881 
882  // If the LHS is Full and the RHS is a wrapped interval containing 1 then
883  // this could occur.
884  if (Lower == Upper)
885  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
886 
887  return ConstantRange(std::move(Lower), std::move(Upper));
888 }
889 
892  if (isEmptySet() || Other.isEmptySet())
893  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
894 
895  // TODO: replace this with something less conservative
896 
898  if (umin.isAllOnesValue())
899  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
900  return ConstantRange(APInt::getNullValue(getBitWidth()), std::move(umin) + 1);
901 }
902 
905  if (isEmptySet() || Other.isEmptySet())
906  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
907 
908  // TODO: replace this with something less conservative
909 
911  if (umax.isNullValue())
912  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
913  return ConstantRange(std::move(umax), APInt::getNullValue(getBitWidth()));
914 }
915 
918  if (isEmptySet() || Other.isEmptySet())
919  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
920 
922  APInt Other_umax = Other.getUnsignedMax();
923 
924  // there's overflow!
925  if (Other_umax.uge(max.countLeadingZeros()))
926  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
927 
928  // FIXME: implement the other tricky cases
929 
930  APInt min = getUnsignedMin();
931  min <<= Other.getUnsignedMin();
932  max <<= Other_umax;
933 
934  return ConstantRange(std::move(min), std::move(max) + 1);
935 }
936 
939  if (isEmptySet() || Other.isEmptySet())
940  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
941 
942  APInt max = getUnsignedMax().lshr(Other.getUnsignedMin()) + 1;
943  APInt min = getUnsignedMin().lshr(Other.getUnsignedMax());
944  if (min == max)
945  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
946 
947  return ConstantRange(std::move(min), std::move(max));
948 }
949 
952  if (isEmptySet() || Other.isEmptySet())
953  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
954 
955  // May straddle zero, so handle both positive and negative cases.
956  // 'PosMax' is the upper bound of the result of the ashr
957  // operation, when Upper of the LHS of ashr is a non-negative.
958  // number. Since ashr of a non-negative number will result in a
959  // smaller number, the Upper value of LHS is shifted right with
960  // the minimum value of 'Other' instead of the maximum value.
961  APInt PosMax = getSignedMax().ashr(Other.getUnsignedMin()) + 1;
962 
963  // 'PosMin' is the lower bound of the result of the ashr
964  // operation, when Lower of the LHS is a non-negative number.
965  // Since ashr of a non-negative number will result in a smaller
966  // number, the Lower value of LHS is shifted right with the
967  // maximum value of 'Other'.
968  APInt PosMin = getSignedMin().ashr(Other.getUnsignedMax());
969 
970  // 'NegMax' is the upper bound of the result of the ashr
971  // operation, when Upper of the LHS of ashr is a negative number.
972  // Since 'ashr' of a negative number will result in a bigger
973  // number, the Upper value of LHS is shifted right with the
974  // maximum value of 'Other'.
975  APInt NegMax = getSignedMax().ashr(Other.getUnsignedMax()) + 1;
976 
977  // 'NegMin' is the lower bound of the result of the ashr
978  // operation, when Lower of the LHS of ashr is a negative number.
979  // Since 'ashr' of a negative number will result in a bigger
980  // number, the Lower value of LHS is shifted right with the
981  // minimum value of 'Other'.
982  APInt NegMin = getSignedMin().ashr(Other.getUnsignedMin());
983 
984  APInt max, min;
985  if (getSignedMin().isNonNegative()) {
986  // Upper and Lower of LHS are non-negative.
987  min = PosMin;
988  max = PosMax;
989  } else if (getSignedMax().isNegative()) {
990  // Upper and Lower of LHS are negative.
991  min = NegMin;
992  max = NegMax;
993  } else {
994  // Upper is non-negative and Lower is negative.
995  min = NegMin;
996  max = PosMax;
997  }
998  if (min == max)
999  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
1000 
1001  return ConstantRange(std::move(min), std::move(max));
1002 }
1003 
1005  if (isFullSet())
1006  return ConstantRange(getBitWidth(), /*isFullSet=*/false);
1007  if (isEmptySet())
1008  return ConstantRange(getBitWidth(), /*isFullSet=*/true);
1009  return ConstantRange(Upper, Lower);
1010 }
1011 
1013  if (isFullSet())
1014  OS << "full-set";
1015  else if (isEmptySet())
1016  OS << "empty-set";
1017  else
1018  OS << "[" << Lower << "," << Upper << ")";
1019 }
1020 
1021 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1023  print(dbgs());
1024 }
1025 #endif
1026 
1028  const unsigned NumRanges = Ranges.getNumOperands() / 2;
1029  assert(NumRanges >= 1 && "Must have at least one range!");
1030  assert(Ranges.getNumOperands() % 2 == 0 && "Must be a sequence of pairs");
1031 
1032  auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.getOperand(0));
1033  auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.getOperand(1));
1034 
1035  ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
1036 
1037  for (unsigned i = 1; i < NumRanges; ++i) {
1038  auto *Low = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
1039  auto *High = mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
1040 
1041  // Note: unionWith will potentially create a range that contains values not
1042  // contained in any of the original N ranges.
1043  CR = CR.unionWith(ConstantRange(Low->getValue(), High->getValue()));
1044  }
1045 
1046  return CR;
1047 }
uint64_t CallInst * C
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:840
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
const APInt & getUpper() const
Return the upper value for this range.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
ConstantRange addWithNoSignedWrap(const APInt &Other) const
Return a new range representing the possible values resulting from a known NSW addition of a value in...
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:864
bool slt(const APInt &RHS) const
Signed less than comparison.
Definition: APInt.h:1188
APInt udiv(const APInt &RHS) const
Unsigned division operation.
Definition: APInt.cpp:1530
This file contains the declarations for metadata subclasses.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Definition: APInt.h:641
bool isSizeLargerThan(uint64_t MaxSize) const
ConstantRange lshr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a logical right shift of a value i...
unsigned less or equal
Definition: InstrTypes.h:911
unsigned less than
Definition: InstrTypes.h:910
ConstantRange truncate(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly smaller than the current typ...
ConstantRange sub(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a subtraction of a value in this r...
APInt trunc(unsigned width) const
Truncate to new width.
Definition: APInt.cpp:817
void setAllBits()
Set every bit to 1.
Definition: APInt.h:1374
ConstantRange ashr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a arithmetic right shift of a valu...
Metadata node.
Definition: Metadata.h:862
ConstantRange udiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned division of a value in...
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
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...
void print(raw_ostream &OS) const
Print out the bounds to a stream.
uint64_t High
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:528
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1493
bool isWrappedSet() const
Return true if this set wraps around the top of the range.
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Definition: BitVector.h:921
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
Definition: InstrTypes.h:983
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Definition: APInt.h:362
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:898
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
ConstantRange zextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:770
This file implements a class to represent arbitrary precision integral constant values and operations...
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
Definition: APInt.h:2094
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition: APInt.h:1517
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition: APInt.h:2089
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the maximum value of an extendable operand.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
Definition: APInt.h:1446
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Get a value with upper bits starting at loBit set.
Definition: APInt.h:617
APInt getSetSize() const
Return the number of elements in this set.
void dump() const
Allow printing from a debugger easily.
APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
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...
The operation itself must be expressed in terms of simpler actions on this target.
Definition: LegalizerInfo.h:72
bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const
Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
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...
bool isSizeStrictlySmallerThan(const ConstantRange &CR) const
Compare set size of this range with the range CR.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
Definition: APInt.h:629
bool isNegative() const
Determine sign of this APInt.
Definition: APInt.h:357
bool isAllOnesValue() const
Determine if all bits are set.
Definition: APInt.h:389
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the minimum value of an extendable operand.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
Definition: APInt.h:384
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition: APInt.h:1169
bool isSignWrappedSet() const
Return true if this set wraps around the INT_MIN of its bitwidth.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition: APInt.h:581
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Definition: APInt.h:436
ConstantRange(uint32_t BitWidth, bool isFullSet=true)
Initialize a full (the default) or empty set for the specified bit width.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:885
bool isBinaryOp() const
Definition: Instruction.h:130
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl...
Definition: Operator.h:67
ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Definition: APInt.h:964
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
signed greater than
Definition: InstrTypes.h:912
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition: APInt.h:2099
bool isEmptySet() const
Return true if this set contains no members.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Definition: APInt.h:940
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...
This class represents a range of values.
Definition: ConstantRange.h:47
signed less than
Definition: InstrTypes.h:914
ConstantRange smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:535
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition: APInt.h:1277
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...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
unsigned countTrailingOnes() const
Count the number of trailing one bits.
Definition: APInt.h:1630
signed less or equal
Definition: InstrTypes.h:915
Class for arbitrary precision integers.
Definition: APInt.h:69
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Definition: APInt.h:1207
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
Definition: APInt.h:2104
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:523
const APInt * getSingleMissingElement() const
If this set contains all but a single element, return it, otherwise return null.
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
#define Success
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 ugt(const APInt &RHS) const
Unsigned greather than comparison.
Definition: APInt.h:1239
unsigned greater or equal
Definition: InstrTypes.h:909
const APInt & getLower() const
Return the lower value for this range.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool isSingleElement() const
Return true if this set contains exactly one member.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
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:538
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
unsigned greater than
Definition: InstrTypes.h:908
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
Definition: APInt.h:1580
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...
static APInt getNullValue(unsigned numBits)
Get the &#39;0&#39; value.
Definition: APInt.h:562
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
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...
APInt sextOrSelf(unsigned width) const
Sign extend or truncate to width.
Definition: APInt.cpp:904
bool isNullValue() const
Determine if all bits are clear.
Definition: APInt.h:399
signed greater or equal
Definition: InstrTypes.h:913
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...