LLVM  14.0.0git
ConstantRange.h
Go to the documentation of this file.
1 //===- ConstantRange.h - Represent a range ----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Represent a range of possible values that may occur when the program is run
10 // for an integral value. This keeps track of a lower and upper bound for the
11 // constant, which MAY wrap around the end of the numeric range. To do this, it
12 // keeps track of a [lower, upper) bound, which specifies an interval just like
13 // STL iterators. When used with boolean values, the following are important
14 // ranges: :
15 //
16 // [F, F) = {} = Empty set
17 // [T, F) = {T}
18 // [F, T) = {F}
19 // [T, T) = {F, T} = Full set
20 //
21 // The other integral ranges use min/max values for special range values. For
22 // example, for 8-bit types, it uses:
23 // [0, 0) = {} = Empty set
24 // [255, 255) = {0..255} = Full Set
25 //
26 // Note that ConstantRange can be used to represent either signed or
27 // unsigned ranges.
28 //
29 //===----------------------------------------------------------------------===//
30 
31 #ifndef LLVM_IR_CONSTANTRANGE_H
32 #define LLVM_IR_CONSTANTRANGE_H
33 
34 #include "llvm/ADT/APInt.h"
35 #include "llvm/IR/InstrTypes.h"
36 #include "llvm/IR/Instruction.h"
37 #include "llvm/Support/Compiler.h"
38 #include <cstdint>
39 
40 namespace llvm {
41 
42 class MDNode;
43 class raw_ostream;
44 struct KnownBits;
45 
46 /// This class represents a range of values.
48  APInt Lower, Upper;
49 
50  /// Create empty constant range with same bitwidth.
51  ConstantRange getEmpty() const {
52  return ConstantRange(getBitWidth(), false);
53  }
54 
55  /// Create full constant range with same bitwidth.
56  ConstantRange getFull() const {
57  return ConstantRange(getBitWidth(), true);
58  }
59 
60 public:
61  /// Initialize a full or empty set for the specified bit width.
62  explicit ConstantRange(uint32_t BitWidth, bool isFullSet);
63 
64  /// Initialize a range to hold the single specified value.
66 
67  /// Initialize a range of values explicitly. This will assert out if
68  /// Lower==Upper and Lower != Min or Max value for its type. It will also
69  /// assert out if the two APInt's are not the same bit width.
71 
72  /// Create empty constant range with the given bit width.
74  return ConstantRange(BitWidth, false);
75  }
76 
77  /// Create full constant range with the given bit width.
79  return ConstantRange(BitWidth, true);
80  }
81 
82  /// Create non-empty constant range with the given bounds. If Lower and
83  /// Upper are the same, a full range is returned.
84  static ConstantRange getNonEmpty(APInt Lower, APInt Upper) {
85  if (Lower == Upper)
86  return getFull(Lower.getBitWidth());
87  return ConstantRange(std::move(Lower), std::move(Upper));
88  }
89 
90  /// Initialize a range based on a known bits constraint. The IsSigned flag
91  /// indicates whether the constant range should not wrap in the signed or
92  /// unsigned domain.
93  static ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned);
94 
95  /// Produce the smallest range such that all values that may satisfy the given
96  /// predicate with any value contained within Other is contained in the
97  /// returned range. Formally, this returns a superset of
98  /// 'union over all y in Other . { x : icmp op x y is true }'. If the exact
99  /// answer is not representable as a ConstantRange, the return value will be a
100  /// proper superset of the above.
101  ///
102  /// Example: Pred = ult and Other = i8 [2, 5) returns Result = [0, 4)
103  static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred,
104  const ConstantRange &Other);
105 
106  /// Produce the largest range such that all values in the returned range
107  /// satisfy the given predicate with all values contained within Other.
108  /// Formally, this returns a subset of
109  /// 'intersection over all y in Other . { x : icmp op x y is true }'. If the
110  /// exact answer is not representable as a ConstantRange, the return value
111  /// will be a proper subset of the above.
112  ///
113  /// Example: Pred = ult and Other = i8 [2, 5) returns [0, 2)
114  static ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred,
115  const ConstantRange &Other);
116 
117  /// Produce the exact range such that all values in the returned range satisfy
118  /// the given predicate with any value contained within Other. Formally, this
119  /// returns the exact answer when the superset of 'union over all y in Other
120  /// is exactly same as the subset of intersection over all y in Other.
121  /// { x : icmp op x y is true}'.
122  ///
123  /// Example: Pred = ult and Other = i8 3 returns [0, 3)
124  static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred,
125  const APInt &Other);
126 
127  /// Does the predicate \p Pred hold between ranges this and \p Other?
128  /// NOTE: false does not mean that inverse predicate holds!
129  bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const;
130 
131  /// Produce the largest range containing all X such that "X BinOp Y" is
132  /// guaranteed not to wrap (overflow) for *all* Y in Other. However, there may
133  /// be *some* Y in Other for which additional X not contained in the result
134  /// also do not overflow.
135  ///
136  /// NoWrapKind must be one of OBO::NoUnsignedWrap or OBO::NoSignedWrap.
137  ///
138  /// Examples:
139  /// typedef OverflowingBinaryOperator OBO;
140  /// #define MGNR makeGuaranteedNoWrapRegion
141  /// MGNR(Add, [i8 1, 2), OBO::NoSignedWrap) == [-128, 127)
142  /// MGNR(Add, [i8 1, 2), OBO::NoUnsignedWrap) == [0, -1)
143  /// MGNR(Add, [i8 0, 1), OBO::NoUnsignedWrap) == Full Set
144  /// MGNR(Add, [i8 -1, 6), OBO::NoSignedWrap) == [INT_MIN+1, INT_MAX-4)
145  /// MGNR(Sub, [i8 1, 2), OBO::NoSignedWrap) == [-127, 128)
146  /// MGNR(Sub, [i8 1, 2), OBO::NoUnsignedWrap) == [1, 0)
147  static ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp,
148  const ConstantRange &Other,
149  unsigned NoWrapKind);
150 
151  /// Produce the range that contains X if and only if "X BinOp Other" does
152  /// not wrap.
153  static ConstantRange makeExactNoWrapRegion(Instruction::BinaryOps BinOp,
154  const APInt &Other,
155  unsigned NoWrapKind);
156 
157  /// Returns true if ConstantRange calculations are supported for intrinsic
158  /// with \p IntrinsicID.
159  static bool isIntrinsicSupported(Intrinsic::ID IntrinsicID);
160 
161  /// Compute range of intrinsic result for the given operand ranges.
162  static ConstantRange intrinsic(Intrinsic::ID IntrinsicID,
164 
165  /// Set up \p Pred and \p RHS such that
166  /// ConstantRange::makeExactICmpRegion(Pred, RHS) == *this. Return true if
167  /// successful.
168  bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const;
169 
170  /// Return the lower value for this range.
171  const APInt &getLower() const { return Lower; }
172 
173  /// Return the upper value for this range.
174  const APInt &getUpper() const { return Upper; }
175 
176  /// Get the bit width of this ConstantRange.
177  uint32_t getBitWidth() const { return Lower.getBitWidth(); }
178 
179  /// Return true if this set contains all of the elements possible
180  /// for this data-type.
181  bool isFullSet() const;
182 
183  /// Return true if this set contains no members.
184  bool isEmptySet() const;
185 
186  /// Return true if this set wraps around the unsigned domain. Special cases:
187  /// * Empty set: Not wrapped.
188  /// * Full set: Not wrapped.
189  /// * [X, 0) == [X, Max]: Not wrapped.
190  bool isWrappedSet() const;
191 
192  /// Return true if the exclusive upper bound wraps around the unsigned
193  /// domain. Special cases:
194  /// * Empty set: Not wrapped.
195  /// * Full set: Not wrapped.
196  /// * [X, 0): Wrapped.
197  bool isUpperWrapped() const;
198 
199  /// Return true if this set wraps around the signed domain. Special cases:
200  /// * Empty set: Not wrapped.
201  /// * Full set: Not wrapped.
202  /// * [X, SignedMin) == [X, SignedMax]: Not wrapped.
203  bool isSignWrappedSet() const;
204 
205  /// Return true if the (exclusive) upper bound wraps around the signed
206  /// domain. Special cases:
207  /// * Empty set: Not wrapped.
208  /// * Full set: Not wrapped.
209  /// * [X, SignedMin): Wrapped.
210  bool isUpperSignWrapped() const;
211 
212  /// Return true if the specified value is in the set.
213  bool contains(const APInt &Val) const;
214 
215  /// Return true if the other range is a subset of this one.
216  bool contains(const ConstantRange &CR) const;
217 
218  /// If this set contains a single element, return it, otherwise return null.
219  const APInt *getSingleElement() const {
220  if (Upper == Lower + 1)
221  return &Lower;
222  return nullptr;
223  }
224 
225  /// If this set contains all but a single element, return it, otherwise return
226  /// null.
228  if (Lower == Upper + 1)
229  return &Upper;
230  return nullptr;
231  }
232 
233  /// Return true if this set contains exactly one member.
234  bool isSingleElement() const { return getSingleElement() != nullptr; }
235 
236  /// Compare set size of this range with the range CR.
237  bool isSizeStrictlySmallerThan(const ConstantRange &CR) const;
238 
239  /// Compare set size of this range with Value.
240  bool isSizeLargerThan(uint64_t MaxSize) const;
241 
242  /// Return true if all values in this range are negative.
243  bool isAllNegative() const;
244 
245  /// Return true if all values in this range are non-negative.
246  bool isAllNonNegative() const;
247 
248  /// Return the largest unsigned value contained in the ConstantRange.
249  APInt getUnsignedMax() const;
250 
251  /// Return the smallest unsigned value contained in the ConstantRange.
252  APInt getUnsignedMin() const;
253 
254  /// Return the largest signed value contained in the ConstantRange.
255  APInt getSignedMax() const;
256 
257  /// Return the smallest signed value contained in the ConstantRange.
258  APInt getSignedMin() const;
259 
260  /// Return true if this range is equal to another range.
261  bool operator==(const ConstantRange &CR) const {
262  return Lower == CR.Lower && Upper == CR.Upper;
263  }
264  bool operator!=(const ConstantRange &CR) const {
265  return !operator==(CR);
266  }
267 
268  /// Compute the maximal number of active bits needed to represent every value
269  /// in this range.
270  unsigned getActiveBits() const;
271 
272  /// Compute the maximal number of bits needed to represent every value
273  /// in this signed range.
274  unsigned getMinSignedBits() const;
275 
276  /// Subtract the specified constant from the endpoints of this constant range.
277  ConstantRange subtract(const APInt &CI) const;
278 
279  /// Subtract the specified range from this range (aka relative complement of
280  /// the sets).
281  ConstantRange difference(const ConstantRange &CR) const;
282 
283  /// If represented precisely, the result of some range operations may consist
284  /// of multiple disjoint ranges. As only a single range may be returned, any
285  /// range covering these disjoint ranges constitutes a valid result, but some
286  /// may be more useful than others depending on context. The preferred range
287  /// type specifies whether a range that is non-wrapping in the unsigned or
288  /// signed domain, or has the smallest size, is preferred. If a signedness is
289  /// preferred but all ranges are non-wrapping or all wrapping, then the
290  /// smallest set size is preferred. If there are multiple smallest sets, any
291  /// one of them may be returned.
292  enum PreferredRangeType { Smallest, Unsigned, Signed };
293 
294  /// Return the range that results from the intersection of this range with
295  /// another range. If the intersection is disjoint, such that two results
296  /// are possible, the preferred range is determined by the PreferredRangeType.
297  ConstantRange intersectWith(const ConstantRange &CR,
298  PreferredRangeType Type = Smallest) const;
299 
300  /// Return the range that results from the union of this range
301  /// with another range. The resultant range is guaranteed to include the
302  /// elements of both sets, but may contain more. For example, [3, 9) union
303  /// [12,15) is [3, 15), which includes 9, 10, and 11, which were not included
304  /// in either set before.
305  ConstantRange unionWith(const ConstantRange &CR,
306  PreferredRangeType Type = Smallest) const;
307 
308  /// Return a new range representing the possible values resulting
309  /// from an application of the specified cast operator to this range. \p
310  /// BitWidth is the target bitwidth of the cast. For casts which don't
311  /// change bitwidth, it must be the same as the source bitwidth. For casts
312  /// which do change bitwidth, the bitwidth must be consistent with the
313  /// requested cast and source bitwidth.
314  ConstantRange castOp(Instruction::CastOps CastOp,
315  uint32_t BitWidth) const;
316 
317  /// Return a new range in the specified integer type, which must
318  /// be strictly larger than the current type. The returned range will
319  /// correspond to the possible range of values if the source range had been
320  /// zero extended to BitWidth.
321  ConstantRange zeroExtend(uint32_t BitWidth) const;
322 
323  /// Return a new range in the specified integer type, which must
324  /// be strictly larger than the current type. The returned range will
325  /// correspond to the possible range of values if the source range had been
326  /// sign extended to BitWidth.
327  ConstantRange signExtend(uint32_t BitWidth) const;
328 
329  /// Return a new range in the specified integer type, which must be
330  /// strictly smaller than the current type. The returned range will
331  /// correspond to the possible range of values if the source range had been
332  /// truncated to the specified type.
333  ConstantRange truncate(uint32_t BitWidth) const;
334 
335  /// Make this range have the bit width given by \p BitWidth. The
336  /// value is zero extended, truncated, or left alone to make it that width.
337  ConstantRange zextOrTrunc(uint32_t BitWidth) const;
338 
339  /// Make this range have the bit width given by \p BitWidth. The
340  /// value is sign extended, truncated, or left alone to make it that width.
341  ConstantRange sextOrTrunc(uint32_t BitWidth) const;
342 
343  /// Return a new range representing the possible values resulting
344  /// from an application of the specified binary operator to an left hand side
345  /// of this range and a right hand side of \p Other.
346  ConstantRange binaryOp(Instruction::BinaryOps BinOp,
347  const ConstantRange &Other) const;
348 
349  /// Return a new range representing the possible values resulting
350  /// from an application of the specified overflowing binary operator to a
351  /// left hand side of this range and a right hand side of \p Other given
352  /// the provided knowledge about lack of wrapping \p NoWrapKind.
353  ConstantRange overflowingBinaryOp(Instruction::BinaryOps BinOp,
354  const ConstantRange &Other,
355  unsigned NoWrapKind) const;
356 
357  /// Return a new range representing the possible values resulting
358  /// from an addition of a value in this range and a value in \p Other.
359  ConstantRange add(const ConstantRange &Other) const;
360 
361  /// Return a new range representing the possible values resulting
362  /// from an addition with wrap type \p NoWrapKind of a value in this
363  /// range and a value in \p Other.
364  /// If the result range is disjoint, the preferred range is determined by the
365  /// \p PreferredRangeType.
366  ConstantRange addWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind,
367  PreferredRangeType RangeType = Smallest) const;
368 
369  /// Return a new range representing the possible values resulting
370  /// from a subtraction of a value in this range and a value in \p Other.
371  ConstantRange sub(const ConstantRange &Other) const;
372 
373  /// Return a new range representing the possible values resulting
374  /// from an subtraction with wrap type \p NoWrapKind of a value in this
375  /// range and a value in \p Other.
376  /// If the result range is disjoint, the preferred range is determined by the
377  /// \p PreferredRangeType.
378  ConstantRange subWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind,
379  PreferredRangeType RangeType = Smallest) const;
380 
381  /// Return a new range representing the possible values resulting
382  /// from a multiplication of a value in this range and a value in \p Other,
383  /// treating both this and \p Other as unsigned ranges.
384  ConstantRange multiply(const ConstantRange &Other) const;
385 
386  /// Return range of possible values for a signed multiplication of this and
387  /// \p Other. However, if overflow is possible always return a full range
388  /// rather than trying to determine a more precise result.
389  ConstantRange smul_fast(const ConstantRange &Other) const;
390 
391  /// Return a new range representing the possible values resulting
392  /// from a signed maximum of a value in this range and a value in \p Other.
393  ConstantRange smax(const ConstantRange &Other) const;
394 
395  /// Return a new range representing the possible values resulting
396  /// from an unsigned maximum of a value in this range and a value in \p Other.
397  ConstantRange umax(const ConstantRange &Other) const;
398 
399  /// Return a new range representing the possible values resulting
400  /// from a signed minimum of a value in this range and a value in \p Other.
401  ConstantRange smin(const ConstantRange &Other) const;
402 
403  /// Return a new range representing the possible values resulting
404  /// from an unsigned minimum of a value in this range and a value in \p Other.
405  ConstantRange umin(const ConstantRange &Other) const;
406 
407  /// Return a new range representing the possible values resulting
408  /// from an unsigned division of a value in this range and a value in
409  /// \p Other.
410  ConstantRange udiv(const ConstantRange &Other) const;
411 
412  /// Return a new range representing the possible values resulting
413  /// from a signed division of a value in this range and a value in
414  /// \p Other. Division by zero and division of SignedMin by -1 are considered
415  /// undefined behavior, in line with IR, and do not contribute towards the
416  /// result.
417  ConstantRange sdiv(const ConstantRange &Other) const;
418 
419  /// Return a new range representing the possible values resulting
420  /// from an unsigned remainder operation of a value in this range and a
421  /// value in \p Other.
422  ConstantRange urem(const ConstantRange &Other) const;
423 
424  /// Return a new range representing the possible values resulting
425  /// from a signed remainder operation of a value in this range and a
426  /// value in \p Other.
427  ConstantRange srem(const ConstantRange &Other) const;
428 
429  /// Return a new range representing the possible values resulting from
430  /// a binary-xor of a value in this range by an all-one value,
431  /// aka bitwise complement operation.
432  ConstantRange binaryNot() const;
433 
434  /// Return a new range representing the possible values resulting
435  /// from a binary-and of a value in this range by a value in \p Other.
436  ConstantRange binaryAnd(const ConstantRange &Other) const;
437 
438  /// Return a new range representing the possible values resulting
439  /// from a binary-or of a value in this range by a value in \p Other.
440  ConstantRange binaryOr(const ConstantRange &Other) const;
441 
442  /// Return a new range representing the possible values resulting
443  /// from a binary-xor of a value in this range by a value in \p Other.
444  ConstantRange binaryXor(const ConstantRange &Other) const;
445 
446  /// Return a new range representing the possible values resulting
447  /// from a left shift of a value in this range by a value in \p Other.
448  /// TODO: This isn't fully implemented yet.
449  ConstantRange shl(const ConstantRange &Other) const;
450 
451  /// Return a new range representing the possible values resulting from a
452  /// logical right shift of a value in this range and a value in \p Other.
453  ConstantRange lshr(const ConstantRange &Other) const;
454 
455  /// Return a new range representing the possible values resulting from a
456  /// arithmetic right shift of a value in this range and a value in \p Other.
457  ConstantRange ashr(const ConstantRange &Other) const;
458 
459  /// Perform an unsigned saturating addition of two constant ranges.
460  ConstantRange uadd_sat(const ConstantRange &Other) const;
461 
462  /// Perform a signed saturating addition of two constant ranges.
463  ConstantRange sadd_sat(const ConstantRange &Other) const;
464 
465  /// Perform an unsigned saturating subtraction of two constant ranges.
466  ConstantRange usub_sat(const ConstantRange &Other) const;
467 
468  /// Perform a signed saturating subtraction of two constant ranges.
469  ConstantRange ssub_sat(const ConstantRange &Other) const;
470 
471  /// Perform an unsigned saturating multiplication of two constant ranges.
472  ConstantRange umul_sat(const ConstantRange &Other) const;
473 
474  /// Perform a signed saturating multiplication of two constant ranges.
475  ConstantRange smul_sat(const ConstantRange &Other) const;
476 
477  /// Perform an unsigned saturating left shift of this constant range by a
478  /// value in \p Other.
479  ConstantRange ushl_sat(const ConstantRange &Other) const;
480 
481  /// Perform a signed saturating left shift of this constant range by a
482  /// value in \p Other.
483  ConstantRange sshl_sat(const ConstantRange &Other) const;
484 
485  /// Return a new range that is the logical not of the current set.
486  ConstantRange inverse() const;
487 
488  /// Calculate absolute value range. If the original range contains signed
489  /// min, then the resulting range will contain signed min if and only if
490  /// \p IntMinIsPoison is false.
491  ConstantRange abs(bool IntMinIsPoison = false) const;
492 
493  /// Represents whether an operation on the given constant range is known to
494  /// always or never overflow.
495  enum class OverflowResult {
496  /// Always overflows in the direction of signed/unsigned min value.
498  /// Always overflows in the direction of signed/unsigned max value.
500  /// May or may not overflow.
501  MayOverflow,
502  /// Never overflows.
504  };
505 
506  /// Return whether unsigned add of the two ranges always/never overflows.
507  OverflowResult unsignedAddMayOverflow(const ConstantRange &Other) const;
508 
509  /// Return whether signed add of the two ranges always/never overflows.
510  OverflowResult signedAddMayOverflow(const ConstantRange &Other) const;
511 
512  /// Return whether unsigned sub of the two ranges always/never overflows.
513  OverflowResult unsignedSubMayOverflow(const ConstantRange &Other) const;
514 
515  /// Return whether signed sub of the two ranges always/never overflows.
516  OverflowResult signedSubMayOverflow(const ConstantRange &Other) const;
517 
518  /// Return whether unsigned mul of the two ranges always/never overflows.
519  OverflowResult unsignedMulMayOverflow(const ConstantRange &Other) const;
520 
521  /// Print out the bounds to a stream.
522  void print(raw_ostream &OS) const;
523 
524  /// Allow printing from a debugger easily.
525  void dump() const;
526 };
527 
529  CR.print(OS);
530  return OS;
531 }
532 
533 /// Parse out a conservative ConstantRange from !range metadata.
534 ///
535 /// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20).
536 ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD);
537 
538 } // end namespace llvm
539 
540 #endif // LLVM_IR_CONSTANTRANGE_H
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4636
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::OverflowResult::NeverOverflows
@ NeverOverflows
Never overflows.
llvm::HexPrintStyle::Upper
@ Upper
print
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Definition: ArchiveWriter.cpp:147
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:720
contains
return AArch64::GPR64RegClass contains(Reg)
APInt.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::OverflowResult::AlwaysOverflowsLow
@ AlwaysOverflowsLow
Always overflows in the direction of signed/unsigned min value.
getBitWidth
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Definition: ValueTracking.cpp:89
llvm::dump
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Definition: SparseBitVector.h:876
llvm::getConstantRangeFromMetadata
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
Definition: ConstantRange.cpp:1726
intrinsic
QP Compare Ordered outs ins xscmpudp No intrinsic
Definition: README_P9.txt:303
llvm::APIntOps::umin
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
Definition: APInt.h:2128
llvm::ConstantRange::OverflowResult
OverflowResult
Represents whether an operation on the given constant range is known to always or never overflow.
Definition: ConstantRange.h:495
Instruction.h
shl
We currently generate a but we really shouldn eax ecx xorl edx divl ecx eax divl ecx movl eax ret A similar code sequence works for division We currently compile i32 v2 eax eax jo LBB1_2 shl
Definition: README.txt:1271
llvm::OverflowResult::MayOverflow
@ MayOverflow
May or may not overflow.
InstrTypes.h
llvm::ConstantRange::PreferredRangeType
PreferredRangeType
If represented precisely, the result of some range operations may consist of multiple disjoint ranges...
Definition: ConstantRange.h:292
llvm::ConstantRange::isSingleElement
bool isSingleElement() const
Return true if this set contains exactly one member.
Definition: ConstantRange.h:234
llvm::Instruction::CastOps
CastOps
Definition: Instruction.h:799
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::ConstantRange::Unsigned
@ Unsigned
Definition: ConstantRange.h:292
llvm::ConstantRange::getEmpty
static ConstantRange getEmpty(uint32_t BitWidth)
Create empty constant range with the given bit width.
Definition: ConstantRange.h:73
llvm::OverflowResult
OverflowResult
Definition: ValueTracking.h:487
llvm::ConstantRange::getBitWidth
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Definition: ConstantRange.h:177
uint64_t
llvm::ARM_AM::add
@ add
Definition: ARMAddressingModes.h:39
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
sub
we currently eax ecx subl eax ret We would use one fewer register if codegen d eax neg eax eax ret Note that this isn t beneficial if the load can be folded into the sub In this we want a sub
Definition: README.txt:460
llvm::operator==
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1981
llvm::ConstantRange::getFull
static ConstantRange getFull(uint32_t BitWidth)
Create full constant range with the given bit width.
Definition: ConstantRange.h:78
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::ConstantRange::getSingleElement
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
Definition: ConstantRange.h:219
llvm::APIntOps::smin
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
Definition: APInt.h:2118
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
uint32_t
Compiler.h
llvm::APIntOps::umax
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
Definition: APInt.h:2133
llvm::ConstantRange::getLower
const APInt & getLower() const
Return the lower value for this range.
Definition: ConstantRange.h:171
llvm::KnownBits
Definition: KnownBits.h:23
llvm::ConstantRange::operator==
bool operator==(const ConstantRange &CR) const
Return true if this range is equal to another range.
Definition: ConstantRange.h:261
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
LLVM_NODISCARD
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
Definition: Compiler.h:161
llvm::OverflowResult::AlwaysOverflowsHigh
@ AlwaysOverflowsHigh
Always overflows in the direction of signed/unsigned max value.
llvm::ConstantRange::getSingleMissingElement
const APInt * getSingleMissingElement() const
If this set contains all but a single element, return it, otherwise return null.
Definition: ConstantRange.h:227
llvm::ConstantRange
This class represents a range of values.
Definition: ConstantRange.h:47
llvm::ConstantRange::getNonEmpty
static ConstantRange getNonEmpty(APInt Lower, APInt Upper)
Create non-empty constant range with the given bounds.
Definition: ConstantRange.h:84
llvm::Instruction::BinaryOps
BinaryOps
Definition: Instruction.h:785
llvm::ConstantRange::print
void print(raw_ostream &OS) const
Print out the bounds to a stream.
Definition: ConstantRange.cpp:1711
lshr
Vector Shift Left don t map to llvm shl and lshr
Definition: README_P9.txt:118
llvm::abs
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition: APFloat.h:1282
llvm::ConstantRange::getUpper
const APInt & getUpper() const
Return the upper value for this range.
Definition: ConstantRange.h:174
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::APIntOps::smax
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
Definition: APInt.h:2123
llvm::ConstantRange::operator!=
bool operator!=(const ConstantRange &CR) const
Definition: ConstantRange.h:264
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37