LLVM 19.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 <optional>
19
20namespace llvm {
21
22// Struct for tracking the known zeros and ones of a value.
23struct KnownBits {
26
27private:
28 // Internal constructor for creating a KnownBits from two APInts.
30 : Zero(std::move(Zero)), One(std::move(One)) {}
31
32public:
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!");
52 return Zero.popcount() + One.popcount() == getBitWidth();
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 /// Returns true if we don't know the sign bit.
66 bool isSignUnknown() const {
67 return !Zero.isSignBitSet() && !One.isSignBitSet();
68 }
69
70 /// Resets the known state of all bits.
71 void resetAll() {
74 }
75
76 /// Returns true if value is all zero.
77 bool isZero() const {
78 assert(!hasConflict() && "KnownBits conflict!");
79 return Zero.isAllOnes();
80 }
81
82 /// Returns true if value is all one bits.
83 bool isAllOnes() const {
84 assert(!hasConflict() && "KnownBits conflict!");
85 return One.isAllOnes();
86 }
87
88 /// Make all bits known to be zero and discard any previous information.
89 void setAllZero() {
92 }
93
94 /// Make all bits known to be one and discard any previous information.
95 void setAllOnes() {
98 }
99
100 /// Returns true if this value is known to be negative.
101 bool isNegative() const { return One.isSignBitSet(); }
102
103 /// Returns true if this value is known to be non-negative.
104 bool isNonNegative() const { return Zero.isSignBitSet(); }
105
106 /// Returns true if this value is known to be non-zero.
107 bool isNonZero() const { return !One.isZero(); }
108
109 /// Returns true if this value is known to be positive.
110 bool isStrictlyPositive() const {
111 return Zero.isSignBitSet() && !One.isZero();
112 }
113
114 /// Make this value negative.
116 One.setSignBit();
117 }
118
119 /// Make this value non-negative.
122 }
123
124 /// Return the minimal unsigned value possible given these KnownBits.
126 // Assume that all bits that aren't known-ones are zeros.
127 return One;
128 }
129
130 /// Return the minimal signed value possible given these KnownBits.
132 // Assume that all bits that aren't known-ones are zeros.
133 APInt Min = One;
134 // Sign bit is unknown.
135 if (Zero.isSignBitClear())
136 Min.setSignBit();
137 return Min;
138 }
139
140 /// Return the maximal unsigned value possible given these KnownBits.
142 // Assume that all bits that aren't known-zeros are ones.
143 return ~Zero;
144 }
145
146 /// Return the maximal signed value possible given these KnownBits.
148 // Assume that all bits that aren't known-zeros are ones.
149 APInt Max = ~Zero;
150 // Sign bit is unknown.
151 if (One.isSignBitClear())
152 Max.clearSignBit();
153 return Max;
154 }
155
156 /// Return known bits for a truncation of the value we're tracking.
157 KnownBits trunc(unsigned BitWidth) const {
159 }
160
161 /// Return known bits for an "any" extension of the value we're tracking,
162 /// where we don't know anything about the extended bits.
163 KnownBits anyext(unsigned BitWidth) const {
165 }
166
167 /// Return known bits for a zero extension of the value we're tracking.
168 KnownBits zext(unsigned BitWidth) const {
169 unsigned OldBitWidth = getBitWidth();
170 APInt NewZero = Zero.zext(BitWidth);
171 NewZero.setBitsFrom(OldBitWidth);
172 return KnownBits(NewZero, One.zext(BitWidth));
173 }
174
175 /// Return known bits for a sign extension of the value we're tracking.
176 KnownBits sext(unsigned BitWidth) const {
178 }
179
180 /// Return known bits for an "any" extension or truncation of the value we're
181 /// tracking.
183 if (BitWidth > getBitWidth())
184 return anyext(BitWidth);
185 if (BitWidth < getBitWidth())
186 return trunc(BitWidth);
187 return *this;
188 }
189
190 /// Return known bits for a zero extension or truncation of the value we're
191 /// tracking.
193 if (BitWidth > getBitWidth())
194 return zext(BitWidth);
195 if (BitWidth < getBitWidth())
196 return trunc(BitWidth);
197 return *this;
198 }
199
200 /// Return known bits for a sign extension or truncation of the value we're
201 /// tracking.
203 if (BitWidth > getBitWidth())
204 return sext(BitWidth);
205 if (BitWidth < getBitWidth())
206 return trunc(BitWidth);
207 return *this;
208 }
209
210 /// Return known bits for a in-register sign extension of the value we're
211 /// tracking.
212 KnownBits sextInReg(unsigned SrcBitWidth) const;
213
214 /// Insert the bits from a smaller known bits starting at bitPosition.
215 void insertBits(const KnownBits &SubBits, unsigned BitPosition) {
216 Zero.insertBits(SubBits.Zero, BitPosition);
217 One.insertBits(SubBits.One, BitPosition);
218 }
219
220 /// Return a subset of the known bits from [bitPosition,bitPosition+numBits).
221 KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
222 return KnownBits(Zero.extractBits(NumBits, BitPosition),
223 One.extractBits(NumBits, BitPosition));
224 }
225
226 /// Concatenate the bits from \p Lo onto the bottom of *this. This is
227 /// equivalent to:
228 /// (this->zext(NewWidth) << Lo.getBitWidth()) | Lo.zext(NewWidth)
229 KnownBits concat(const KnownBits &Lo) const {
230 return KnownBits(Zero.concat(Lo.Zero), One.concat(Lo.One));
231 }
232
233 /// Return KnownBits based on this, but updated given that the underlying
234 /// value is known to be greater than or equal to Val.
235 KnownBits makeGE(const APInt &Val) const;
236
237 /// Returns the minimum number of trailing zero bits.
238 unsigned countMinTrailingZeros() const { return Zero.countr_one(); }
239
240 /// Returns the minimum number of trailing one bits.
241 unsigned countMinTrailingOnes() const { return One.countr_one(); }
242
243 /// Returns the minimum number of leading zero bits.
244 unsigned countMinLeadingZeros() const { return Zero.countl_one(); }
245
246 /// Returns the minimum number of leading one bits.
247 unsigned countMinLeadingOnes() const { return One.countl_one(); }
248
249 /// Returns the number of times the sign bit is replicated into the other
250 /// bits.
251 unsigned countMinSignBits() const {
252 if (isNonNegative())
253 return countMinLeadingZeros();
254 if (isNegative())
255 return countMinLeadingOnes();
256 // Every value has at least 1 sign bit.
257 return 1;
258 }
259
260 /// Returns the maximum number of bits needed to represent all possible
261 /// signed values with these known bits. This is the inverse of the minimum
262 /// number of known sign bits. Examples for bitwidth 5:
263 /// 110?? --> 4
264 /// 0000? --> 2
265 unsigned countMaxSignificantBits() const {
266 return getBitWidth() - countMinSignBits() + 1;
267 }
268
269 /// Returns the maximum number of trailing zero bits possible.
270 unsigned countMaxTrailingZeros() const { return One.countr_zero(); }
271
272 /// Returns the maximum number of trailing one bits possible.
273 unsigned countMaxTrailingOnes() const { return Zero.countr_zero(); }
274
275 /// Returns the maximum number of leading zero bits possible.
276 unsigned countMaxLeadingZeros() const { return One.countl_zero(); }
277
278 /// Returns the maximum number of leading one bits possible.
279 unsigned countMaxLeadingOnes() const { return Zero.countl_zero(); }
280
281 /// Returns the number of bits known to be one.
282 unsigned countMinPopulation() const { return One.popcount(); }
283
284 /// Returns the maximum number of bits that could be one.
285 unsigned countMaxPopulation() const {
286 return getBitWidth() - Zero.popcount();
287 }
288
289 /// Returns the maximum number of bits needed to represent all possible
290 /// unsigned values with these known bits. This is the inverse of the
291 /// minimum number of leading zeros.
292 unsigned countMaxActiveBits() const {
294 }
295
296 /// Create known bits from a known constant.
297 static KnownBits makeConstant(const APInt &C) {
298 return KnownBits(~C, C);
299 }
300
301 /// Returns KnownBits information that is known to be true for both this and
302 /// RHS.
303 ///
304 /// When an operation is known to return one of its operands, this can be used
305 /// to combine information about the known bits of the operands to get the
306 /// information that must be true about the result.
308 return KnownBits(Zero & RHS.Zero, One & RHS.One);
309 }
310
311 /// Returns KnownBits information that is known to be true for either this or
312 /// RHS or both.
313 ///
314 /// This can be used to combine different sources of information about the
315 /// known bits of a single value, e.g. information about the low bits and the
316 /// high bits of the result of a multiplication.
318 return KnownBits(Zero | RHS.Zero, One | RHS.One);
319 }
320
321 /// Compute known bits common to LHS and RHS.
322 LLVM_DEPRECATED("use intersectWith instead", "intersectWith")
324 return LHS.intersectWith(RHS);
325 }
326
327 /// Return true if LHS and RHS have no common bits set.
328 static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS) {
329 return (LHS.Zero | RHS.Zero).isAllOnes();
330 }
331
332 /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
334 const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry);
335
336 /// Compute known bits resulting from adding LHS and RHS.
337 static KnownBits computeForAddSub(bool Add, bool NSW, bool NUW,
338 const KnownBits &LHS, const KnownBits &RHS);
339
340 /// Compute known bits results from subtracting RHS from LHS with 1-bit
341 /// Borrow.
343 const KnownBits &Borrow);
344
345 /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
346 static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS);
347
348 /// Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
349 static KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS);
350
351 /// Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
352 static KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS);
353
354 /// Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
355 static KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS);
356
357 /// Compute knownbits resulting from APIntOps::avgFloorS
358 static KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS);
359
360 /// Compute knownbits resulting from APIntOps::avgFloorU
361 static KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS);
362
363 /// Compute knownbits resulting from APIntOps::avgCeilS
364 static KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS);
365
366 /// Compute knownbits resulting from APIntOps::avgCeilU
367 static KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS);
368
369 /// Compute known bits resulting from multiplying LHS and RHS.
370 static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS,
371 bool NoUndefSelfMultiply = false);
372
373 /// Compute known bits from sign-extended multiply-hi.
374 static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS);
375
376 /// Compute known bits from zero-extended multiply-hi.
377 static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS);
378
379 /// Compute known bits for sdiv(LHS, RHS).
380 static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS,
381 bool Exact = false);
382
383 /// Compute known bits for udiv(LHS, RHS).
384 static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS,
385 bool Exact = false);
386
387 /// Compute known bits for urem(LHS, RHS).
388 static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS);
389
390 /// Compute known bits for srem(LHS, RHS).
391 static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS);
392
393 /// Compute known bits for umax(LHS, RHS).
394 static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS);
395
396 /// Compute known bits for umin(LHS, RHS).
397 static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS);
398
399 /// Compute known bits for smax(LHS, RHS).
400 static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS);
401
402 /// Compute known bits for smin(LHS, RHS).
403 static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS);
404
405 /// Compute known bits for abdu(LHS, RHS).
406 static KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS);
407
408 /// Compute known bits for abds(LHS, RHS).
410
411 /// Compute known bits for shl(LHS, RHS).
412 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
413 static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS,
414 bool NUW = false, bool NSW = false,
415 bool ShAmtNonZero = false);
416
417 /// Compute known bits for lshr(LHS, RHS).
418 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
419 static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS,
420 bool ShAmtNonZero = false, bool Exact = false);
421
422 /// Compute known bits for ashr(LHS, RHS).
423 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
424 static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS,
425 bool ShAmtNonZero = false, bool Exact = false);
426
427 /// Determine if these known bits always give the same ICMP_EQ result.
428 static std::optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS);
429
430 /// Determine if these known bits always give the same ICMP_NE result.
431 static std::optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS);
432
433 /// Determine if these known bits always give the same ICMP_UGT result.
434 static std::optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS);
435
436 /// Determine if these known bits always give the same ICMP_UGE result.
437 static std::optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS);
438
439 /// Determine if these known bits always give the same ICMP_ULT result.
440 static std::optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS);
441
442 /// Determine if these known bits always give the same ICMP_ULE result.
443 static std::optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS);
444
445 /// Determine if these known bits always give the same ICMP_SGT result.
446 static std::optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS);
447
448 /// Determine if these known bits always give the same ICMP_SGE result.
449 static std::optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS);
450
451 /// Determine if these known bits always give the same ICMP_SLT result.
452 static std::optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS);
453
454 /// Determine if these known bits always give the same ICMP_SLE result.
455 static std::optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS);
456
457 /// Update known bits based on ANDing with RHS.
459
460 /// Update known bits based on ORing with RHS.
462
463 /// Update known bits based on XORing with RHS.
465
466 /// Compute known bits for the absolute value.
467 KnownBits abs(bool IntMinIsPoison = false) const;
468
470 return KnownBits(Zero.byteSwap(), One.byteSwap());
471 }
472
475 }
476
477 /// Compute known bits for X & -X, which has only the lowest bit set of X set.
478 /// The name comes from the X86 BMI instruction
479 KnownBits blsi() const;
480
481 /// Compute known bits for X ^ (X - 1), which has all bits up to and including
482 /// the lowest set bit of X set. The name comes from the X86 BMI instruction.
483 KnownBits blsmsk() const;
484
485 bool operator==(const KnownBits &Other) const {
486 return Zero == Other.Zero && One == Other.One;
487 }
488
489 bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
490
491 void print(raw_ostream &OS) const;
492 void dump() const;
493
494private:
495 // Internal helper for getting the initial KnownBits for an `srem` or `urem`
496 // operation with the low-bits set.
497 static KnownBits remGetLowBits(const KnownBits &LHS, const KnownBits &RHS);
498};
499
501 LHS &= RHS;
502 return LHS;
503}
504
506 RHS &= LHS;
507 return std::move(RHS);
508}
509
511 LHS |= RHS;
512 return LHS;
513}
514
516 RHS |= LHS;
517 return std::move(RHS);
518}
519
521 LHS ^= RHS;
522 return LHS;
523}
524
526 RHS ^= LHS;
527 return std::move(RHS);
528}
529
531 Known.print(OS);
532 return OS;
533}
534
535} // end namespace llvm
536
537#endif
aarch64 promote const
This file implements a class to represent arbitrary precision integral constant values and operations...
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:157
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:76
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:981
unsigned popcount() const
Count the number of bits set.
Definition: APInt.h:1627
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
Definition: APInt.h:1364
APInt trunc(unsigned width) const
Truncate to new width.
Definition: APInt.cpp:906
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition: APInt.h:349
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition: APInt.h:358
void setSignBit()
Set the sign bit to 1.
Definition: APInt.h:1318
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1446
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
Definition: APInt.h:925
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:1227
void clearAllBits()
Set every bit to 0.
Definition: APInt.h:1375
APInt reverseBits() const
Definition: APInt.cpp:737
unsigned countr_zero() const
Count the number of trailing zero bits.
Definition: APInt.h:1596
unsigned countl_zero() const
The APInt version of std::countl_zero.
Definition: APInt.h:1555
unsigned countl_one() const
Count the number of leading one bits.
Definition: APInt.h:1572
void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
Definition: APInt.cpp:368
void setAllBits()
Set every bit to 1.
Definition: APInt.h:1297
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:954
APInt byteSwap() const
Definition: APInt.cpp:715
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
Definition: APInt.h:319
APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition: APInt.cpp:453
unsigned countr_one() const
Count the number of trailing one bits.
Definition: APInt.h:1613
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
Definition: APInt.h:326
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
APInt operator&(APInt a, const APInt &b)
Definition: APInt.h:2060
APInt operator^(APInt a, const APInt &b)
Definition: APInt.h:2100
@ Other
Any other memory.
@ Add
Sum of integers.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:293
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
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:1849
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2080
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition: KnownBits.h:297
static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
Definition: KnownBits.cpp:764
unsigned countMaxTrailingOnes() const
Returns the maximum number of trailing one bits possible.
Definition: KnownBits.h:273
static std::optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
Definition: KnownBits.cpp:494
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition: KnownBits.h:182
KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
Definition: KnownBits.cpp:155
static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
Definition: KnownBits.cpp:915
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition: KnownBits.h:251
static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
Definition: KnownBits.cpp:208
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition: KnownBits.h:104
bool isZero() const
Returns true if value is all zero.
Definition: KnownBits.h:77
KnownBits blsi() const
Compute known bits for X & -X, which has only the lowest bit set of X set.
Definition: KnownBits.cpp:1132
void makeNonNegative()
Make this value non-negative.
Definition: KnownBits.h:120
static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits common to LHS and RHS.
Definition: KnownBits.h:323
static KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
Definition: KnownBits.cpp:773
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
Definition: KnownBits.h:247
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition: KnownBits.h:238
static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
Definition: KnownBits.cpp:434
static KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
Definition: KnownBits.cpp:767
static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
Definition: KnownBits.cpp:1061
bool isUnknown() const
Returns true if we don't know any bits.
Definition: KnownBits.h:63
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition: KnownBits.h:270
static std::optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
Definition: KnownBits.cpp:502
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:172
APInt getSignedMaxValue() const
Return the maximal signed value possible given these KnownBits.
Definition: KnownBits.h:147
KnownBits blsmsk() const
Compute known bits for X ^ (X - 1), which has all bits up to and including the lowest set bit of X se...
Definition: KnownBits.cpp:1143
void makeNegative()
Make this value negative.
Definition: KnownBits.h:115
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition: KnownBits.h:157
KnownBits byteSwap() const
Definition: KnownBits.h:469
bool hasConflict() const
Returns true if there is conflicting information.
Definition: KnownBits.h:47
static std::optional< bool > sge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGE result.
Definition: KnownBits.cpp:542
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition: KnownBits.h:285
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition: KnownBits.h:89
KnownBits reverseBits() const
Definition: KnownBits.h:473
KnownBits & operator|=(const KnownBits &RHS)
Update known bits based on ORing with RHS.
Definition: KnownBits.cpp:1115
void print(raw_ostream &OS) const
Definition: KnownBits.cpp:1153
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition: KnownBits.h:229
unsigned getBitWidth() const
Get the bit width of this value.
Definition: KnownBits.h:40
static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
Definition: KnownBits.cpp:184
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition: KnownBits.h:168
bool isConstant() const
Returns true if we know the value of all bits.
Definition: KnownBits.h:50
void resetAll()
Resets the known state of all bits.
Definition: KnownBits.h:71
KnownBits unionWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for either this or RHS or both.
Definition: KnownBits.h:317
static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
Definition: KnownBits.cpp:376
bool isSignUnknown() const
Returns true if we don't know the sign bit.
Definition: KnownBits.h:66
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition: KnownBits.h:107
static KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
Definition: KnownBits.cpp:234
bool operator==(const KnownBits &Other) const
Definition: KnownBits.h:485
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition: KnownBits.h:221
unsigned countMaxActiveBits() const
Returns the maximum number of bits needed to represent all possible unsigned values with these known ...
Definition: KnownBits.h:292
static KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
Definition: KnownBits.cpp:793
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition: KnownBits.h:307
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition: KnownBits.h:176
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
Definition: KnownBits.h:241
static KnownBits computeForSubBorrow(const KnownBits &LHS, KnownBits RHS, const KnownBits &Borrow)
Compute known bits results from subtracting RHS from LHS with 1-bit Borrow.
Definition: KnownBits.cpp:143
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition: KnownBits.h:192
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition: KnownBits.h:244
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition: KnownBits.h:141
KnownBits()=default
static KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
Definition: KnownBits.cpp:253
static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
Definition: KnownBits.cpp:221
KnownBits & operator&=(const KnownBits &RHS)
Update known bits based on ANDing with RHS.
Definition: KnownBits.cpp:1107
static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
Definition: KnownBits.cpp:906
static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
Definition: KnownBits.cpp:1080
static std::optional< bool > ugt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGT result.
Definition: KnownBits.cpp:508
static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
Definition: KnownBits.cpp:1019
static std::optional< bool > slt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLT result.
Definition: KnownBits.cpp:548
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition: KnownBits.h:125
static KnownBits computeForAddSub(bool Add, bool NSW, bool NUW, const KnownBits &LHS, const KnownBits &RHS)
Compute known bits resulting from adding LHS and RHS.
Definition: KnownBits.cpp:57
void dump() const
Definition: KnownBits.cpp:1167
bool isStrictlyPositive() const
Returns true if this value is known to be positive.
Definition: KnownBits.h:110
static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
Definition: KnownBits.cpp:960
static std::optional< bool > ult(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULT result.
Definition: KnownBits.cpp:524
static KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
Definition: KnownBits.cpp:788
bool operator!=(const KnownBits &Other) const
Definition: KnownBits.h:489
static std::optional< bool > ule(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULE result.
Definition: KnownBits.cpp:528
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS)
Return true if LHS and RHS have no common bits set.
Definition: KnownBits.h:328
bool isNegative() const
Returns true if this value is known to be negative.
Definition: KnownBits.h:101
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
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition: KnownBits.h:276
void setAllOnes()
Make all bits known to be one and discard any previous information.
Definition: KnownBits.h:95
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
Definition: KnownBits.h:215
static KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
Definition: KnownBits.cpp:803
static KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
Definition: KnownBits.cpp:770
static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
Definition: KnownBits.cpp:808
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:163
KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
Definition: KnownBits.cpp:556
static std::optional< bool > sle(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLE result.
Definition: KnownBits.cpp:552
unsigned countMaxSignificantBits() const
Returns the maximum number of bits needed to represent all possible signed values with these known bi...
Definition: KnownBits.h:265
static std::optional< bool > sgt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGT result.
Definition: KnownBits.cpp:532
unsigned countMinPopulation() const
Returns the number of bits known to be one.
Definition: KnownBits.h:282
static std::optional< bool > uge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGE result.
Definition: KnownBits.cpp:518
KnownBits(unsigned BitWidth)
Create a known bits object of BitWidth bits initialized to unknown.
Definition: KnownBits.h:37
unsigned countMaxLeadingOnes() const
Returns the maximum number of leading one bits possible.
Definition: KnownBits.h:279
APInt getSignedMinValue() const
Return the minimal signed value possible given these KnownBits.
Definition: KnownBits.h:131
KnownBits & operator^=(const KnownBits &RHS)
Update known bits based on XORing with RHS.
Definition: KnownBits.cpp:1123
static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
Definition: KnownBits.cpp:291
static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
Definition: KnownBits.cpp:202
bool isAllOnes() const
Returns true if value is all one bits.
Definition: KnownBits.h:83
KnownBits sextOrTrunc(unsigned BitWidth) const
Return known bits for a sign extension or truncation of the value we're tracking.
Definition: KnownBits.h:202
static KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.
Definition: KnownBits.cpp:798
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition: KnownBits.h:57