LLVM  16.0.0git
KnownBits.h
Go to the documentation of this file.
1 //===- llvm/Support/KnownBits.h - Stores known zeros/ones -------*- 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 // This file contains a class for representing known zeros and ones used by
10 // computeKnownBits.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_KNOWNBITS_H
15 #define LLVM_SUPPORT_KNOWNBITS_H
16 
17 #include "llvm/ADT/APInt.h"
18 #include "llvm/ADT/Optional.h"
19 
20 namespace llvm {
21 
22 // Struct for tracking the known zeros and ones of a value.
23 struct KnownBits {
26 
27 private:
28  // Internal constructor for creating a KnownBits from two APInts.
30  : Zero(std::move(Zero)), One(std::move(One)) {}
31 
32 public:
33  // Default construct Zero and One.
34  KnownBits() = default;
35 
36  /// Create a known bits object of BitWidth bits initialized to unknown.
37  KnownBits(unsigned BitWidth) : Zero(BitWidth, 0), One(BitWidth, 0) {}
38 
39  /// Get the bit width of this value.
40  unsigned getBitWidth() const {
42  "Zero and One should have the same width!");
43  return Zero.getBitWidth();
44  }
45 
46  /// Returns true if there is conflicting information.
47  bool hasConflict() const { return Zero.intersects(One); }
48 
49  /// Returns true if we know the value of all bits.
50  bool isConstant() const {
51  assert(!hasConflict() && "KnownBits conflict!");
53  }
54 
55  /// Returns the value when all bits have a known value. This just returns One
56  /// with a protective assertion.
57  const APInt &getConstant() const {
58  assert(isConstant() && "Can only get value when all bits are known");
59  return One;
60  }
61 
62  /// Returns true if we don't know any bits.
63  bool isUnknown() const { return Zero.isZero() && One.isZero(); }
64 
65  /// Resets the known state of all bits.
66  void resetAll() {
68  One.clearAllBits();
69  }
70 
71  /// Returns true if value is all zero.
72  bool isZero() const {
73  assert(!hasConflict() && "KnownBits conflict!");
74  return Zero.isAllOnes();
75  }
76 
77  /// Returns true if value is all one bits.
78  bool isAllOnes() const {
79  assert(!hasConflict() && "KnownBits conflict!");
80  return One.isAllOnes();
81  }
82 
83  /// Make all bits known to be zero and discard any previous information.
84  void setAllZero() {
85  Zero.setAllBits();
86  One.clearAllBits();
87  }
88 
89  /// Make all bits known to be one and discard any previous information.
90  void setAllOnes() {
92  One.setAllBits();
93  }
94 
95  /// Returns true if this value is known to be negative.
96  bool isNegative() const { return One.isSignBitSet(); }
97 
98  /// Returns true if this value is known to be non-negative.
99  bool isNonNegative() const { return Zero.isSignBitSet(); }
100 
101  /// Returns true if this value is known to be non-zero.
102  bool isNonZero() const { return !One.isZero(); }
103 
104  /// Returns true if this value is known to be positive.
105  bool isStrictlyPositive() const {
106  return Zero.isSignBitSet() && !One.isZero();
107  }
108 
109  /// Make this value negative.
110  void makeNegative() {
111  One.setSignBit();
112  }
113 
114  /// Make this value non-negative.
116  Zero.setSignBit();
117  }
118 
119  /// Return the minimal unsigned value possible given these KnownBits.
120  APInt getMinValue() const {
121  // Assume that all bits that aren't known-ones are zeros.
122  return One;
123  }
124 
125  /// Return the minimal signed value possible given these KnownBits.
127  // Assume that all bits that aren't known-ones are zeros.
128  APInt Min = One;
129  // Sign bit is unknown.
130  if (Zero.isSignBitClear())
131  Min.setSignBit();
132  return Min;
133  }
134 
135  /// Return the maximal unsigned value possible given these KnownBits.
136  APInt getMaxValue() const {
137  // Assume that all bits that aren't known-zeros are ones.
138  return ~Zero;
139  }
140 
141  /// Return the maximal signed value possible given these KnownBits.
143  // Assume that all bits that aren't known-zeros are ones.
144  APInt Max = ~Zero;
145  // Sign bit is unknown.
146  if (One.isSignBitClear())
147  Max.clearSignBit();
148  return Max;
149  }
150 
151  /// Return known bits for a truncation of the value we're tracking.
152  KnownBits trunc(unsigned BitWidth) const {
154  }
155 
156  /// Return known bits for an "any" extension of the value we're tracking,
157  /// where we don't know anything about the extended bits.
158  KnownBits anyext(unsigned BitWidth) const {
160  }
161 
162  /// Return known bits for a zero extension of the value we're tracking.
163  KnownBits zext(unsigned BitWidth) const {
164  unsigned OldBitWidth = getBitWidth();
165  APInt NewZero = Zero.zext(BitWidth);
166  NewZero.setBitsFrom(OldBitWidth);
167  return KnownBits(NewZero, One.zext(BitWidth));
168  }
169 
170  /// Return known bits for a sign extension of the value we're tracking.
171  KnownBits sext(unsigned BitWidth) const {
173  }
174 
175  /// Return known bits for an "any" extension or truncation of the value we're
176  /// tracking.
177  KnownBits anyextOrTrunc(unsigned BitWidth) const {
178  if (BitWidth > getBitWidth())
179  return anyext(BitWidth);
180  if (BitWidth < getBitWidth())
181  return trunc(BitWidth);
182  return *this;
183  }
184 
185  /// Return known bits for a zero extension or truncation of the value we're
186  /// tracking.
187  KnownBits zextOrTrunc(unsigned BitWidth) const {
188  if (BitWidth > getBitWidth())
189  return zext(BitWidth);
190  if (BitWidth < getBitWidth())
191  return trunc(BitWidth);
192  return *this;
193  }
194 
195  /// Return known bits for a sign extension or truncation of the value we're
196  /// tracking.
197  KnownBits sextOrTrunc(unsigned BitWidth) const {
198  if (BitWidth > getBitWidth())
199  return sext(BitWidth);
200  if (BitWidth < getBitWidth())
201  return trunc(BitWidth);
202  return *this;
203  }
204 
205  /// Return known bits for a in-register sign extension of the value we're
206  /// tracking.
207  KnownBits sextInReg(unsigned SrcBitWidth) const;
208 
209  /// Insert the bits from a smaller known bits starting at bitPosition.
210  void insertBits(const KnownBits &SubBits, unsigned BitPosition) {
211  Zero.insertBits(SubBits.Zero, BitPosition);
212  One.insertBits(SubBits.One, BitPosition);
213  }
214 
215  /// Return a subset of the known bits from [bitPosition,bitPosition+numBits).
216  KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
217  return KnownBits(Zero.extractBits(NumBits, BitPosition),
218  One.extractBits(NumBits, BitPosition));
219  }
220 
221  /// Concatenate the bits from \p Lo onto the bottom of *this. This is
222  /// equivalent to:
223  /// (this->zext(NewWidth) << Lo.getBitWidth()) | Lo.zext(NewWidth)
224  KnownBits concat(const KnownBits &Lo) const {
225  return KnownBits(Zero.concat(Lo.Zero), One.concat(Lo.One));
226  }
227 
228  /// Return KnownBits based on this, but updated given that the underlying
229  /// value is known to be greater than or equal to Val.
230  KnownBits makeGE(const APInt &Val) const;
231 
232  /// Returns the minimum number of trailing zero bits.
233  unsigned countMinTrailingZeros() const {
234  return Zero.countTrailingOnes();
235  }
236 
237  /// Returns the minimum number of trailing one bits.
238  unsigned countMinTrailingOnes() const {
239  return One.countTrailingOnes();
240  }
241 
242  /// Returns the minimum number of leading zero bits.
243  unsigned countMinLeadingZeros() const {
244  return Zero.countLeadingOnes();
245  }
246 
247  /// Returns the minimum number of leading one bits.
248  unsigned countMinLeadingOnes() const {
249  return One.countLeadingOnes();
250  }
251 
252  /// Returns the number of times the sign bit is replicated into the other
253  /// bits.
254  unsigned countMinSignBits() const {
255  if (isNonNegative())
256  return countMinLeadingZeros();
257  if (isNegative())
258  return countMinLeadingOnes();
259  // Every value has at least 1 sign bit.
260  return 1;
261  }
262 
263  /// Returns the maximum number of bits needed to represent all possible
264  /// signed values with these known bits. This is the inverse of the minimum
265  /// number of known sign bits. Examples for bitwidth 5:
266  /// 110?? --> 4
267  /// 0000? --> 2
268  unsigned countMaxSignificantBits() const {
269  return getBitWidth() - countMinSignBits() + 1;
270  }
271 
272  /// Returns the maximum number of trailing zero bits possible.
273  unsigned countMaxTrailingZeros() const {
274  return One.countTrailingZeros();
275  }
276 
277  /// Returns the maximum number of trailing one bits possible.
278  unsigned countMaxTrailingOnes() const {
279  return Zero.countTrailingZeros();
280  }
281 
282  /// Returns the maximum number of leading zero bits possible.
283  unsigned countMaxLeadingZeros() const {
284  return One.countLeadingZeros();
285  }
286 
287  /// Returns the maximum number of leading one bits possible.
288  unsigned countMaxLeadingOnes() const {
289  return Zero.countLeadingZeros();
290  }
291 
292  /// Returns the number of bits known to be one.
293  unsigned countMinPopulation() const {
294  return One.countPopulation();
295  }
296 
297  /// Returns the maximum number of bits that could be one.
298  unsigned countMaxPopulation() const {
299  return getBitWidth() - Zero.countPopulation();
300  }
301 
302  /// Returns the maximum number of bits needed to represent all possible
303  /// unsigned values with these known bits. This is the inverse of the
304  /// minimum number of leading zeros.
305  unsigned countMaxActiveBits() const {
306  return getBitWidth() - countMinLeadingZeros();
307  }
308 
309  /// Create known bits from a known constant.
310  static KnownBits makeConstant(const APInt &C) {
311  return KnownBits(~C, C);
312  }
313 
314  /// Compute known bits common to LHS and RHS.
315  static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS) {
316  return KnownBits(LHS.Zero & RHS.Zero, LHS.One & RHS.One);
317  }
318 
319  /// Return true if LHS and RHS have no common bits set.
320  static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS) {
321  return (LHS.Zero | RHS.Zero).isAllOnes();
322  }
323 
324  /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
326  const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry);
327 
328  /// Compute known bits resulting from adding LHS and RHS.
329  static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS,
330  KnownBits RHS);
331 
332  /// Compute known bits resulting from multiplying LHS and RHS.
333  static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS,
334  bool NoUndefSelfMultiply = false);
335 
336  /// Compute known bits from sign-extended multiply-hi.
337  static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS);
338 
339  /// Compute known bits from zero-extended multiply-hi.
340  static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS);
341 
342  /// Compute known bits for udiv(LHS, RHS).
343  static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS);
344 
345  /// Compute known bits for urem(LHS, RHS).
346  static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS);
347 
348  /// Compute known bits for srem(LHS, RHS).
349  static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS);
350 
351  /// Compute known bits for umax(LHS, RHS).
352  static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS);
353 
354  /// Compute known bits for umin(LHS, RHS).
355  static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS);
356 
357  /// Compute known bits for smax(LHS, RHS).
358  static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS);
359 
360  /// Compute known bits for smin(LHS, RHS).
361  static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS);
362 
363  /// Compute known bits for shl(LHS, RHS).
364  /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
365  static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS);
366 
367  /// Compute known bits for lshr(LHS, RHS).
368  /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
369  static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS);
370 
371  /// Compute known bits for ashr(LHS, RHS).
372  /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
373  static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS);
374 
375  /// Determine if these known bits always give the same ICMP_EQ result.
376  static Optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS);
377 
378  /// Determine if these known bits always give the same ICMP_NE result.
379  static Optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS);
380 
381  /// Determine if these known bits always give the same ICMP_UGT result.
382  static Optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS);
383 
384  /// Determine if these known bits always give the same ICMP_UGE result.
385  static Optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS);
386 
387  /// Determine if these known bits always give the same ICMP_ULT result.
388  static Optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS);
389 
390  /// Determine if these known bits always give the same ICMP_ULE result.
391  static Optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS);
392 
393  /// Determine if these known bits always give the same ICMP_SGT result.
394  static Optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS);
395 
396  /// Determine if these known bits always give the same ICMP_SGE result.
397  static Optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS);
398 
399  /// Determine if these known bits always give the same ICMP_SLT result.
400  static Optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS);
401 
402  /// Determine if these known bits always give the same ICMP_SLE result.
403  static Optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS);
404 
405  /// Update known bits based on ANDing with RHS.
407 
408  /// Update known bits based on ORing with RHS.
410 
411  /// Update known bits based on XORing with RHS.
413 
414  /// Compute known bits for the absolute value.
415  KnownBits abs(bool IntMinIsPoison = false) const;
416 
418  return KnownBits(Zero.byteSwap(), One.byteSwap());
419  }
420 
423  }
424 
425  bool operator==(const KnownBits &Other) const {
426  return Zero == Other.Zero && One == Other.One;
427  }
428 
429  bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
430 
431  void print(raw_ostream &OS) const;
432  void dump() const;
433 };
434 
436  LHS &= RHS;
437  return LHS;
438 }
439 
441  RHS &= LHS;
442  return std::move(RHS);
443 }
444 
446  LHS |= RHS;
447  return LHS;
448 }
449 
451  RHS |= LHS;
452  return std::move(RHS);
453 }
454 
456  LHS ^= RHS;
457  return LHS;
458 }
459 
461  RHS ^= LHS;
462  return std::move(RHS);
463 }
464 
465 } // end namespace llvm
466 
467 #endif
llvm::KnownBits::countMaxActiveBits
unsigned countMaxActiveBits() const
Returns the maximum number of bits needed to represent all possible unsigned values with these known ...
Definition: KnownBits.h:305
llvm::KnownBits::concat
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition: KnownBits.h:224
llvm::KnownBits::anyext
KnownBits anyext(unsigned BitWidth) const
Return known bits for an "any" extension of the value we're tracking, where we don't know anything ab...
Definition: KnownBits.h:158
llvm::APInt::reverseBits
APInt reverseBits() const
Definition: APInt.cpp:729
llvm::KnownBits::shl
static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for shl(LHS, RHS).
Definition: KnownBits.cpp:167
llvm::APInt::setAllBits
void setAllBits()
Set every bit to 1.
Definition: APInt.h:1269
llvm::APInt::clearAllBits
void clearAllBits()
Set every bit to 0.
Definition: APInt.h:1347
llvm::KnownBits::lshr
static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for lshr(LHS, RHS).
Definition: KnownBits.cpp:221
llvm::KnownBits::print
void print(raw_ostream &OS) const
Definition: KnownBits.cpp:626
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::APInt::insertBits
void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
Definition: APInt.cpp:359
Optional.h
llvm::APInt::byteSwap
APInt byteSwap() const
Definition: APInt.cpp:707
llvm::KnownBits::trunc
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition: KnownBits.h:152
llvm::KnownBits::resetAll
void resetAll()
Resets the known state of all bits.
Definition: KnownBits.h:66
llvm::KnownBits::getMinValue
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition: KnownBits.h:120
llvm::KnownBits::insertBits
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
Definition: KnownBits.h:210
llvm::KnownBits::byteSwap
KnownBits byteSwap()
Definition: KnownBits.h:417
llvm::KnownBits::Zero
APInt Zero
Definition: KnownBits.h:24
llvm::KnownBits::isUnknown
bool isUnknown() const
Returns true if we don't know any bits.
Definition: KnownBits.h:63
llvm::KnownBits::countMaxLeadingOnes
unsigned countMaxLeadingOnes() const
Returns the maximum number of leading one bits possible.
Definition: KnownBits.h:288
llvm::KnownBits::makeGE
KnownBits makeGE(const APInt &Val) const
Return KnownBits based on this, but updated given that the underlying value is known to be greater th...
Definition: KnownBits.cpp:105
llvm::KnownBits::anyextOrTrunc
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition: KnownBits.h:177
llvm::KnownBits::isNonZero
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition: KnownBits.h:102
llvm::KnownBits::ult
static Optional< bool > ult(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULT result.
Definition: KnownBits.cpp:363
APInt.h
llvm::KnownBits::getConstant
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition: KnownBits.h:57
llvm::APInt::getBitWidth
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1411
llvm::KnownBits::operator!=
bool operator!=(const KnownBits &Other) const
Definition: KnownBits.h:429
llvm::Optional< bool >
llvm::KnownBits::isZero
bool isZero() const
Returns true if value is all zero.
Definition: KnownBits.h:72
llvm::APInt::intersects
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
Definition: APInt.h:1199
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::APInt::countPopulation
unsigned countPopulation() const
Count the number of bits set.
Definition: APInt.h:1571
llvm::KnownBits::countMinTrailingZeros
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition: KnownBits.h:233
llvm::KnownBits::makeNegative
void makeNegative()
Make this value negative.
Definition: KnownBits.h:110
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::KnownBits::isNonNegative
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition: KnownBits.h:99
llvm::KnownBits::mulhu
static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
Definition: KnownBits.cpp:522
llvm::KnownBits::haveNoCommonBitsSet
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS)
Return true if LHS and RHS have no common bits set.
Definition: KnownBits.h:320
llvm::KnownBits::operator&=
KnownBits & operator&=(const KnownBits &RHS)
Update known bits based on ANDing with RHS.
Definition: KnownBits.cpp:601
llvm::KnownBits::umax
static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
Definition: KnownBits.cpp:117
llvm::APInt::isZero
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition: APInt.h:359
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::APInt::concat
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
Definition: APInt.h:908
llvm::KnownBits::One
APInt One
Definition: KnownBits.h:25
llvm::KnownBits::smin
static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
Definition: KnownBits.cpp:154
llvm::KnownBits::hasConflict
bool hasConflict() const
Returns true if there is conflicting information.
Definition: KnownBits.h:47
llvm::KnownBits::abs
KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
Definition: KnownBits.cpp:395
llvm::APInt::isAllOnes
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition: APInt.h:347
llvm::KnownBits::computeForAddCarry
static KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry)
Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
Definition: KnownBits.cpp:50
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::APInt::isSignBitClear
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
Definition: APInt.h:331
llvm::KnownBits::isNegative
bool isNegative() const
Returns true if this value is known to be negative.
Definition: KnownBits.h:96
llvm::KnownBits::sext
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition: KnownBits.h:171
llvm::APInt::countTrailingZeros
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
Definition: APInt.h:1543
llvm::APInt::setSignBit
void setSignBit()
Set the sign bit to 1.
Definition: APInt.h:1290
llvm::KnownBits::sle
static Optional< bool > sle(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLE result.
Definition: KnownBits.cpp:391
llvm::KnownBits::eq
static Optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
Definition: KnownBits.cpp:333
llvm::KnownBits::dump
void dump() const
Definition: KnownBits.cpp:629
llvm::KnownBits::uge
static Optional< bool > uge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGE result.
Definition: KnownBits.cpp:357
llvm::KnownBits::isAllOnes
bool isAllOnes() const
Returns true if value is all one bits.
Definition: KnownBits.h:78
llvm::KnownBits::reverseBits
KnownBits reverseBits()
Definition: KnownBits.h:421
llvm::KnownBits::operator|=
KnownBits & operator|=(const KnownBits &RHS)
Update known bits based on ORing with RHS.
Definition: KnownBits.cpp:609
llvm::operator|
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2022
llvm::KnownBits::countMinLeadingOnes
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
Definition: KnownBits.h:248
llvm::KnownBits::slt
static Optional< bool > slt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLT result.
Definition: KnownBits.cpp:387
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
llvm::KnownBits::extractBits
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition: KnownBits.h:216
llvm::KnownBits::ule
static Optional< bool > ule(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULE result.
Definition: KnownBits.cpp:367
llvm::KnownBits::getMaxValue
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition: KnownBits.h:136
llvm::KnownBits::countMaxLeadingZeros
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition: KnownBits.h:283
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::KnownBits::countMaxTrailingZeros
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition: KnownBits.h:273
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1666
llvm::KnownBits::countMinLeadingZeros
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition: KnownBits.h:243
llvm::APInt::extractBits
APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition: APInt.cpp:444
llvm::KnownBits::countMinSignBits
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition: KnownBits.h:254
llvm::KnownBits::countMaxPopulation
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition: KnownBits.h:298
llvm::KnownBits::urem
static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
Definition: KnownBits.cpp:549
llvm::KnownBits::KnownBits
KnownBits(unsigned BitWidth)
Create a known bits object of BitWidth bits initialized to unknown.
Definition: KnownBits.h:37
llvm::KnownBits::ashr
static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for ashr(LHS, RHS).
Definition: KnownBits.cpp:274
llvm::KnownBits::computeForAddSub
static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS, KnownBits RHS)
Compute known bits resulting from adding LHS and RHS.
Definition: KnownBits.cpp:57
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::KnownBits::sextInReg
KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
Definition: KnownBits.cpp:88
llvm::KnownBits::zext
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition: KnownBits.h:163
llvm::KnownBits::smax
static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
Definition: KnownBits.cpp:141
llvm::APInt::zext
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:973
llvm::operator^
APInt operator^(APInt a, const APInt &b)
Definition: APInt.h:2042
llvm::KnownBits::mulhs
static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
Definition: KnownBits.cpp:513
llvm::operator&
APInt operator&(APInt a, const APInt &b)
Definition: APInt.h:2002
llvm::KnownBits::ne
static Optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
Definition: KnownBits.cpp:341
llvm::KnownBits::zextOrTrunc
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition: KnownBits.h:187
llvm::APInt::countLeadingZeros
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
Definition: APInt.h:1504
llvm::KnownBits::KnownBits
KnownBits()=default
std
Definition: BitVector.h:851
llvm::APInt::trunc
APInt trunc(unsigned width) const
Truncate to new width.
Definition: APInt.cpp:898
llvm::KnownBits
Definition: KnownBits.h:23
llvm::KnownBits::udiv
static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for udiv(LHS, RHS).
Definition: KnownBits.cpp:531
llvm::KnownBits::countMinPopulation
unsigned countMinPopulation() const
Returns the number of bits known to be one.
Definition: KnownBits.h:293
llvm::KnownBits::countMaxTrailingOnes
unsigned countMaxTrailingOnes() const
Returns the maximum number of trailing one bits possible.
Definition: KnownBits.h:278
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::KnownBits::setAllZero
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition: KnownBits.h:84
llvm::APInt::sext
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:946
llvm::KnownBits::isStrictlyPositive
bool isStrictlyPositive() const
Returns true if this value is known to be positive.
Definition: KnownBits.h:105
llvm::KnownBits::getSignedMinValue
APInt getSignedMinValue() const
Return the minimal signed value possible given these KnownBits.
Definition: KnownBits.h:126
llvm::KnownBits::operator^=
KnownBits & operator^=(const KnownBits &RHS)
Update known bits based on XORing with RHS.
Definition: KnownBits.cpp:617
llvm::KnownBits::umin
static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
Definition: KnownBits.cpp:135
llvm::KnownBits::setAllOnes
void setAllOnes()
Make all bits known to be one and discard any previous information.
Definition: KnownBits.h:90
llvm::KnownBits::mul
static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
Definition: KnownBits.cpp:415
llvm::APInt::isSignBitSet
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
Definition: APInt.h:324
llvm::APInt::countTrailingOnes
unsigned countTrailingOnes() const
Count the number of trailing one bits.
Definition: APInt.h:1559
llvm::KnownBits::commonBits
static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits common to LHS and RHS.
Definition: KnownBits.h:315
llvm::KnownBits::countMaxSignificantBits
unsigned countMaxSignificantBits() const
Returns the maximum number of bits needed to represent all possible signed values with these known bi...
Definition: KnownBits.h:268
llvm::KnownBits::srem
static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
Definition: KnownBits.cpp:570
llvm::KnownBits::makeConstant
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition: KnownBits.h:310
llvm::KnownBits::isConstant
bool isConstant() const
Returns true if we know the value of all bits.
Definition: KnownBits.h:50
llvm::KnownBits::sge
static Optional< bool > sge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGE result.
Definition: KnownBits.cpp:381
llvm::KnownBits::operator==
bool operator==(const KnownBits &Other) const
Definition: KnownBits.h:425
llvm::KnownBits::getSignedMaxValue
APInt getSignedMaxValue() const
Return the maximal signed value possible given these KnownBits.
Definition: KnownBits.h:142
llvm::KnownBits::countMinTrailingOnes
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
Definition: KnownBits.h:238
llvm::KnownBits::getBitWidth
unsigned getBitWidth() const
Get the bit width of this value.
Definition: KnownBits.h:40
llvm::APInt::setBitsFrom
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
Definition: APInt.h:1336
llvm::KnownBits::ugt
static Optional< bool > ugt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGT result.
Definition: KnownBits.cpp:347
llvm::KnownBits::sextOrTrunc
KnownBits sextOrTrunc(unsigned BitWidth) const
Return known bits for a sign extension or truncation of the value we're tracking.
Definition: KnownBits.h:197
llvm::APInt::countLeadingOnes
unsigned countLeadingOnes() const
Count the number of leading one bits.
Definition: APInt.h:1520
llvm::KnownBits::makeNonNegative
void makeNonNegative()
Make this value non-negative.
Definition: KnownBits.h:115
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1247
llvm::KnownBits::sgt
static Optional< bool > sgt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGT result.
Definition: KnownBits.cpp:371