LLVM 22.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"
19#include <optional>
20
21namespace llvm {
22
23// Struct for tracking the known zeros and ones of a value.
24struct KnownBits {
27
28private:
29 // Internal constructor for creating a KnownBits from two APInts.
31 : Zero(std::move(Zero)), One(std::move(One)) {}
32
33 // Flip the range of values: [-0x80000000, 0x7FFFFFFF] <-> [0, 0xFFFFFFFF]
34 static KnownBits flipSignBit(const KnownBits &Val);
35
36public:
37 // Default construct Zero and One.
38 KnownBits() = default;
39
40 /// Create a known bits object of BitWidth bits initialized to unknown.
41 KnownBits(unsigned BitWidth) : Zero(BitWidth, 0), One(BitWidth, 0) {}
42
43 /// Get the bit width of this value.
44 unsigned getBitWidth() const {
46 "Zero and One should have the same width!");
47 return Zero.getBitWidth();
48 }
49
50 /// Returns true if there is conflicting information.
51 bool hasConflict() const { return Zero.intersects(One); }
52
53 /// Returns true if we know the value of all bits.
54 bool isConstant() const {
55 return Zero.popcount() + One.popcount() == getBitWidth();
56 }
57
58 /// Returns the value when all bits have a known value. This just returns One
59 /// with a protective assertion.
60 const APInt &getConstant() const {
61 assert(isConstant() && "Can only get value when all bits are known");
62 return One;
63 }
64
65 /// Returns true if we don't know any bits.
66 bool isUnknown() const { return Zero.isZero() && One.isZero(); }
67
68 /// Returns true if we don't know the sign bit.
69 bool isSignUnknown() const {
70 return !Zero.isSignBitSet() && !One.isSignBitSet();
71 }
72
73 /// Resets the known state of all bits.
74 void resetAll() {
77 }
78
79 /// Returns true if value is all zero.
80 bool isZero() const { return Zero.isAllOnes(); }
81
82 /// Returns true if value is all one bits.
83 bool isAllOnes() const { return One.isAllOnes(); }
84
85 /// Make all bits known to be zero and discard any previous information.
86 void setAllZero() {
89 }
90
91 /// Make all bits known to be one and discard any previous information.
92 void setAllOnes() {
95 }
96
97 /// Returns true if this value is known to be negative.
98 bool isNegative() const { return One.isSignBitSet(); }
99
100 /// Returns true if this value is known to be non-negative.
101 bool isNonNegative() const { return Zero.isSignBitSet(); }
102
103 /// Returns true if this value is known to be non-zero.
104 bool isNonZero() const { return !One.isZero(); }
105
106 /// Returns true if this value is known to be positive.
107 bool isStrictlyPositive() const {
108 return Zero.isSignBitSet() && !One.isZero();
109 }
110
111 /// Make this value negative.
113 One.setSignBit();
114 }
115
116 /// Make this value non-negative.
119 }
120
121 /// Return the minimal unsigned value possible given these KnownBits.
123 // Assume that all bits that aren't known-ones are zeros.
124 return One;
125 }
126
127 /// Return the minimal signed value possible given these KnownBits.
129 // Assume that all bits that aren't known-ones are zeros.
130 APInt Min = One;
131 // Sign bit is unknown.
132 if (Zero.isSignBitClear())
133 Min.setSignBit();
134 return Min;
135 }
136
137 /// Return the maximal unsigned value possible given these KnownBits.
139 // Assume that all bits that aren't known-zeros are ones.
140 return ~Zero;
141 }
142
143 /// Return the maximal signed value possible given these KnownBits.
145 // Assume that all bits that aren't known-zeros are ones.
146 APInt Max = ~Zero;
147 // Sign bit is unknown.
148 if (One.isSignBitClear())
149 Max.clearSignBit();
150 return Max;
151 }
152
153 /// Return known bits for a truncation of the value we're tracking.
154 KnownBits trunc(unsigned BitWidth) const {
156 }
157
158 /// Return known bits for an "any" extension of the value we're tracking,
159 /// where we don't know anything about the extended bits.
160 KnownBits anyext(unsigned BitWidth) const {
162 }
163
164 /// Return known bits for a zero extension of the value we're tracking.
165 KnownBits zext(unsigned BitWidth) const {
166 unsigned OldBitWidth = getBitWidth();
167 APInt NewZero = Zero.zext(BitWidth);
168 NewZero.setBitsFrom(OldBitWidth);
169 return KnownBits(NewZero, One.zext(BitWidth));
170 }
171
172 /// Return known bits for a sign extension of the value we're tracking.
173 KnownBits sext(unsigned BitWidth) const {
175 }
176
177 /// Return known bits for an "any" extension or truncation of the value we're
178 /// tracking.
180 if (BitWidth > getBitWidth())
181 return anyext(BitWidth);
182 if (BitWidth < getBitWidth())
183 return trunc(BitWidth);
184 return *this;
185 }
186
187 /// Return known bits for a zero extension or truncation of the value we're
188 /// tracking.
190 if (BitWidth > getBitWidth())
191 return zext(BitWidth);
192 if (BitWidth < getBitWidth())
193 return trunc(BitWidth);
194 return *this;
195 }
196
197 /// Return known bits for a sign extension or truncation of the value we're
198 /// tracking.
200 if (BitWidth > getBitWidth())
201 return sext(BitWidth);
202 if (BitWidth < getBitWidth())
203 return trunc(BitWidth);
204 return *this;
205 }
206
207 /// Return known bits for a in-register sign extension of the value we're
208 /// tracking.
209 LLVM_ABI KnownBits sextInReg(unsigned SrcBitWidth) const;
210
211 /// Insert the bits from a smaller known bits starting at bitPosition.
212 void insertBits(const KnownBits &SubBits, unsigned BitPosition) {
213 Zero.insertBits(SubBits.Zero, BitPosition);
214 One.insertBits(SubBits.One, BitPosition);
215 }
216
217 /// Return a subset of the known bits from [bitPosition,bitPosition+numBits).
218 KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
219 return KnownBits(Zero.extractBits(NumBits, BitPosition),
220 One.extractBits(NumBits, BitPosition));
221 }
222
223 /// Concatenate the bits from \p Lo onto the bottom of *this. This is
224 /// equivalent to:
225 /// (this->zext(NewWidth) << Lo.getBitWidth()) | Lo.zext(NewWidth)
226 KnownBits concat(const KnownBits &Lo) const {
227 return KnownBits(Zero.concat(Lo.Zero), One.concat(Lo.One));
228 }
229
230 /// Return KnownBits based on this, but updated given that the underlying
231 /// value is known to be greater than or equal to Val.
232 LLVM_ABI KnownBits makeGE(const APInt &Val) const;
233
234 /// Returns the minimum number of trailing zero bits.
235 unsigned countMinTrailingZeros() const { return Zero.countr_one(); }
236
237 /// Returns the minimum number of trailing one bits.
238 unsigned countMinTrailingOnes() const { return One.countr_one(); }
239
240 /// Returns the minimum number of leading zero bits.
241 unsigned countMinLeadingZeros() const { return Zero.countl_one(); }
242
243 /// Returns the minimum number of leading one bits.
244 unsigned countMinLeadingOnes() const { return One.countl_one(); }
245
246 /// Returns the number of times the sign bit is replicated into the other
247 /// bits.
248 unsigned countMinSignBits() const {
249 if (isNonNegative())
250 return countMinLeadingZeros();
251 if (isNegative())
252 return countMinLeadingOnes();
253 // Every value has at least 1 sign bit.
254 return 1;
255 }
256
257 /// Returns the maximum number of bits needed to represent all possible
258 /// signed values with these known bits. This is the inverse of the minimum
259 /// number of known sign bits. Examples for bitwidth 5:
260 /// 110?? --> 4
261 /// 0000? --> 2
262 unsigned countMaxSignificantBits() const {
263 return getBitWidth() - countMinSignBits() + 1;
264 }
265
266 /// Returns the maximum number of trailing zero bits possible.
267 unsigned countMaxTrailingZeros() const { return One.countr_zero(); }
268
269 /// Returns the maximum number of trailing one bits possible.
270 unsigned countMaxTrailingOnes() const { return Zero.countr_zero(); }
271
272 /// Returns the maximum number of leading zero bits possible.
273 unsigned countMaxLeadingZeros() const { return One.countl_zero(); }
274
275 /// Returns the maximum number of leading one bits possible.
276 unsigned countMaxLeadingOnes() const { return Zero.countl_zero(); }
277
278 /// Returns the number of bits known to be one.
279 unsigned countMinPopulation() const { return One.popcount(); }
280
281 /// Returns the maximum number of bits that could be one.
282 unsigned countMaxPopulation() const {
283 return getBitWidth() - Zero.popcount();
284 }
285
286 /// Returns the maximum number of bits needed to represent all possible
287 /// unsigned values with these known bits. This is the inverse of the
288 /// minimum number of leading zeros.
289 unsigned countMaxActiveBits() const {
291 }
292
293 /// Create known bits from a known constant.
294 static KnownBits makeConstant(const APInt &C) {
295 return KnownBits(~C, C);
296 }
297
298 /// Returns KnownBits information that is known to be true for both this and
299 /// RHS.
300 ///
301 /// When an operation is known to return one of its operands, this can be used
302 /// to combine information about the known bits of the operands to get the
303 /// information that must be true about the result.
305 return KnownBits(Zero & RHS.Zero, One & RHS.One);
306 }
307
308 /// Returns KnownBits information that is known to be true for either this or
309 /// RHS or both.
310 ///
311 /// This can be used to combine different sources of information about the
312 /// known bits of a single value, e.g. information about the low bits and the
313 /// high bits of the result of a multiplication.
315 return KnownBits(Zero | RHS.Zero, One | RHS.One);
316 }
317
318 /// Return true if LHS and RHS have no common bits set.
319 static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS) {
320 return (LHS.Zero | RHS.Zero).isAllOnes();
321 }
322
323 /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
325 const KnownBits &RHS,
326 const KnownBits &Carry);
327
328 /// Compute known bits resulting from adding LHS and RHS.
329 LLVM_ABI static KnownBits computeForAddSub(bool Add, bool NSW, bool NUW,
330 const KnownBits &LHS,
331 const KnownBits &RHS);
332
333 /// Compute known bits results from subtracting RHS from LHS with 1-bit
334 /// Borrow.
337 const KnownBits &Borrow);
338
339 /// Compute knownbits resulting from addition of LHS and RHS.
340 static KnownBits add(const KnownBits &LHS, const KnownBits &RHS,
341 bool NSW = false, bool NUW = false) {
342 return computeForAddSub(/*Add=*/true, NSW, NUW, LHS, RHS);
343 }
344
345 /// Compute knownbits resulting from subtraction of LHS and RHS.
346 static KnownBits sub(const KnownBits &LHS, const KnownBits &RHS,
347 bool NSW = false, bool NUW = false) {
348 return computeForAddSub(/*Add=*/false, NSW, NUW, LHS, RHS);
349 }
350
351 /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
353 const KnownBits &RHS);
354
355 /// Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
357 const KnownBits &RHS);
358
359 /// Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
361 const KnownBits &RHS);
362
363 /// Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
365 const KnownBits &RHS);
366
367 /// Compute knownbits resulting from APIntOps::avgFloorS
369 const KnownBits &RHS);
370
371 /// Compute knownbits resulting from APIntOps::avgFloorU
373 const KnownBits &RHS);
374
375 /// Compute knownbits resulting from APIntOps::avgCeilS
377 const KnownBits &RHS);
378
379 /// Compute knownbits resulting from APIntOps::avgCeilU
381 const KnownBits &RHS);
382
383 /// Compute known bits resulting from multiplying LHS and RHS.
384 LLVM_ABI static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS,
385 bool NoUndefSelfMultiply = false);
386
387 /// Compute known bits from sign-extended multiply-hi.
388 LLVM_ABI static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS);
389
390 /// Compute known bits from zero-extended multiply-hi.
391 LLVM_ABI static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS);
392
393 /// Compute known bits for sdiv(LHS, RHS).
394 LLVM_ABI static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS,
395 bool Exact = false);
396
397 /// Compute known bits for udiv(LHS, RHS).
398 LLVM_ABI static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS,
399 bool Exact = false);
400
401 /// Compute known bits for urem(LHS, RHS).
402 LLVM_ABI static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS);
403
404 /// Compute known bits for srem(LHS, RHS).
405 LLVM_ABI static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS);
406
407 /// Compute known bits for umax(LHS, RHS).
408 LLVM_ABI static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS);
409
410 /// Compute known bits for umin(LHS, RHS).
411 LLVM_ABI static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS);
412
413 /// Compute known bits for smax(LHS, RHS).
414 LLVM_ABI static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS);
415
416 /// Compute known bits for smin(LHS, RHS).
417 LLVM_ABI static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS);
418
419 /// Compute known bits for abdu(LHS, RHS).
420 LLVM_ABI static KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS);
421
422 /// Compute known bits for abds(LHS, RHS).
424
425 /// Compute known bits for shl(LHS, RHS).
426 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
427 LLVM_ABI static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS,
428 bool NUW = false, bool NSW = false,
429 bool ShAmtNonZero = false);
430
431 /// Compute known bits for lshr(LHS, RHS).
432 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
433 LLVM_ABI static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS,
434 bool ShAmtNonZero = false, bool Exact = false);
435
436 /// Compute known bits for ashr(LHS, RHS).
437 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
438 LLVM_ABI static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS,
439 bool ShAmtNonZero = false, bool Exact = false);
440
441 /// Determine if these known bits always give the same ICMP_EQ result.
442 LLVM_ABI static std::optional<bool> eq(const KnownBits &LHS,
443 const KnownBits &RHS);
444
445 /// Determine if these known bits always give the same ICMP_NE result.
446 LLVM_ABI static std::optional<bool> ne(const KnownBits &LHS,
447 const KnownBits &RHS);
448
449 /// Determine if these known bits always give the same ICMP_UGT result.
450 LLVM_ABI static std::optional<bool> ugt(const KnownBits &LHS,
451 const KnownBits &RHS);
452
453 /// Determine if these known bits always give the same ICMP_UGE result.
454 LLVM_ABI static std::optional<bool> uge(const KnownBits &LHS,
455 const KnownBits &RHS);
456
457 /// Determine if these known bits always give the same ICMP_ULT result.
458 LLVM_ABI static std::optional<bool> ult(const KnownBits &LHS,
459 const KnownBits &RHS);
460
461 /// Determine if these known bits always give the same ICMP_ULE result.
462 LLVM_ABI static std::optional<bool> ule(const KnownBits &LHS,
463 const KnownBits &RHS);
464
465 /// Determine if these known bits always give the same ICMP_SGT result.
466 LLVM_ABI static std::optional<bool> sgt(const KnownBits &LHS,
467 const KnownBits &RHS);
468
469 /// Determine if these known bits always give the same ICMP_SGE result.
470 LLVM_ABI static std::optional<bool> sge(const KnownBits &LHS,
471 const KnownBits &RHS);
472
473 /// Determine if these known bits always give the same ICMP_SLT result.
474 LLVM_ABI static std::optional<bool> slt(const KnownBits &LHS,
475 const KnownBits &RHS);
476
477 /// Determine if these known bits always give the same ICMP_SLE result.
478 LLVM_ABI static std::optional<bool> sle(const KnownBits &LHS,
479 const KnownBits &RHS);
480
481 /// Update known bits based on ANDing with RHS.
483
484 /// Update known bits based on ORing with RHS.
486
487 /// Update known bits based on XORing with RHS.
489
490 /// Shift known bits left by ShAmt. Shift in bits are unknown.
491 KnownBits &operator<<=(unsigned ShAmt) {
492 Zero <<= ShAmt;
493 One <<= ShAmt;
494 return *this;
495 }
496
497 /// Shift known bits right by ShAmt. Shifted in bits are unknown.
498 KnownBits &operator>>=(unsigned ShAmt) {
499 Zero.lshrInPlace(ShAmt);
500 One.lshrInPlace(ShAmt);
501 return *this;
502 }
503
504 /// Compute known bits for the absolute value.
505 LLVM_ABI KnownBits abs(bool IntMinIsPoison = false) const;
506
508 return KnownBits(Zero.byteSwap(), One.byteSwap());
509 }
510
513 }
514
515 /// Compute known bits for X & -X, which has only the lowest bit set of X set.
516 /// The name comes from the X86 BMI instruction
517 LLVM_ABI KnownBits blsi() const;
518
519 /// Compute known bits for X ^ (X - 1), which has all bits up to and including
520 /// the lowest set bit of X set. The name comes from the X86 BMI instruction.
521 LLVM_ABI KnownBits blsmsk() const;
522
523 bool operator==(const KnownBits &Other) const {
524 return Zero == Other.Zero && One == Other.One;
525 }
526
527 bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
528
529 LLVM_ABI void print(raw_ostream &OS) const;
530
531#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
532 LLVM_DUMP_METHOD void dump() const;
533#endif
534
535private:
536 // Internal helper for getting the initial KnownBits for an `srem` or `urem`
537 // operation with the low-bits set.
538 static KnownBits remGetLowBits(const KnownBits &LHS, const KnownBits &RHS);
539};
540
542 LHS &= RHS;
543 return LHS;
544}
545
547 RHS &= LHS;
548 return std::move(RHS);
549}
550
552 LHS |= RHS;
553 return LHS;
554}
555
557 RHS |= LHS;
558 return std::move(RHS);
559}
560
562 LHS ^= RHS;
563 return LHS;
564}
565
567 RHS ^= LHS;
568 return std::move(RHS);
569}
570
572 Known.print(OS);
573 return OS;
574}
575
576} // end namespace llvm
577
578#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
raw_pwrite_stream & OS
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:78
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:1012
unsigned popcount() const
Count the number of bits set.
Definition: APInt.h:1670
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
Definition: APInt.h:1385
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
Definition: APInt.cpp:936
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition: APInt.h:371
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition: APInt.h:380
void setSignBit()
Set the sign bit to 1.
Definition: APInt.h:1340
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1488
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
Definition: APInt.h:947
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:1249
void clearAllBits()
Set every bit to 0.
Definition: APInt.h:1396
LLVM_ABI APInt reverseBits() const
Definition: APInt.cpp:768
unsigned countr_zero() const
Count the number of trailing zero bits.
Definition: APInt.h:1639
unsigned countl_zero() const
The APInt version of std::countl_zero.
Definition: APInt.h:1598
unsigned countl_one() const
Count the number of leading one bits.
Definition: APInt.h:1615
LLVM_ABI void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
Definition: APInt.cpp:397
void setAllBits()
Set every bit to 1.
Definition: APInt.h:1319
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:985
LLVM_ABI APInt byteSwap() const
Definition: APInt.cpp:746
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
Definition: APInt.h:341
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition: APInt.cpp:482
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
Definition: APInt.h:858
unsigned countr_one() const
Count the number of trailing one bits.
Definition: APInt.h:1656
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
Definition: APInt.h:348
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
@ 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:2123
APInt operator^(APInt a, const APInt &b)
Definition: APInt.h:2163
@ Other
Any other memory.
@ Add
Sum of integers.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:312
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:223
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:1886
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2143
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition: KnownBits.h:294
static LLVM_ABI 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:270
static LLVM_ABI 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:487
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition: KnownBits.h:179
LLVM_ABI KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
Definition: KnownBits.cpp:158
static LLVM_ABI KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
Definition: KnownBits.cpp:916
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition: KnownBits.h:248
static LLVM_ABI KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
Definition: KnownBits.cpp:211
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition: KnownBits.h:101
bool isZero() const
Returns true if value is all zero.
Definition: KnownBits.h:80
LLVM_ABI KnownBits blsi() const
Compute known bits for X & -X, which has only the lowest bit set of X set.
Definition: KnownBits.cpp:1127
void makeNonNegative()
Make this value non-negative.
Definition: KnownBits.h:117
static LLVM_ABI 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:244
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition: KnownBits.h:235
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
Definition: KnownBits.cpp:427
static LLVM_ABI KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
Definition: KnownBits.cpp:767
static LLVM_ABI KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
Definition: KnownBits.cpp:1056
bool isUnknown() const
Returns true if we don't know any bits.
Definition: KnownBits.h:66
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition: KnownBits.h:267
static LLVM_ABI 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:495
LLVM_ABI 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:175
APInt getSignedMaxValue() const
Return the maximal signed value possible given these KnownBits.
Definition: KnownBits.h:144
LLVM_ABI 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:1138
void makeNegative()
Make this value negative.
Definition: KnownBits.h:112
KnownBits & operator>>=(unsigned ShAmt)
Shift known bits right by ShAmt. Shifted in bits are unknown.
Definition: KnownBits.h:498
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition: KnownBits.h:154
KnownBits byteSwap() const
Definition: KnownBits.h:507
bool hasConflict() const
Returns true if there is conflicting information.
Definition: KnownBits.h:51
static LLVM_ABI 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:535
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition: KnownBits.h:282
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition: KnownBits.h:86
KnownBits reverseBits() const
Definition: KnownBits.h:511
LLVM_ABI KnownBits & operator|=(const KnownBits &RHS)
Update known bits based on ORing with RHS.
Definition: KnownBits.cpp:1110
LLVM_ABI void print(raw_ostream &OS) const
Definition: KnownBits.cpp:1148
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition: KnownBits.h:226
unsigned getBitWidth() const
Get the bit width of this value.
Definition: KnownBits.h:44
static LLVM_ABI KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
Definition: KnownBits.cpp:187
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition: KnownBits.h:165
bool isConstant() const
Returns true if we know the value of all bits.
Definition: KnownBits.h:54
void resetAll()
Resets the known state of all bits.
Definition: KnownBits.h:74
LLVM_DUMP_METHOD void dump() const
Definition: KnownBits.cpp:1164
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:314
static LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
Definition: KnownBits.cpp:370
bool isSignUnknown() const
Returns true if we don't know the sign bit.
Definition: KnownBits.h:69
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition: KnownBits.h:104
static LLVM_ABI KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
Definition: KnownBits.cpp:228
bool operator==(const KnownBits &Other) const
Definition: KnownBits.h:523
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition: KnownBits.h:218
unsigned countMaxActiveBits() const
Returns the maximum number of bits needed to represent all possible unsigned values with these known ...
Definition: KnownBits.h:289
static LLVM_ABI KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
Definition: KnownBits.cpp:791
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition: KnownBits.h:304
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition: KnownBits.h:173
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
Definition: KnownBits.h:238
static LLVM_ABI 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:146
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from addition of LHS and RHS.
Definition: KnownBits.h:340
KnownBits & operator<<=(unsigned ShAmt)
Shift known bits left by ShAmt. Shift in bits are unknown.
Definition: KnownBits.h:491
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition: KnownBits.h:189
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition: KnownBits.h:241
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition: KnownBits.h:138
KnownBits()=default
static LLVM_ABI KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
Definition: KnownBits.cpp:247
static LLVM_ABI KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
Definition: KnownBits.cpp:215
LLVM_ABI KnownBits & operator&=(const KnownBits &RHS)
Update known bits based on ANDing with RHS.
Definition: KnownBits.cpp:1102
static LLVM_ABI KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
Definition: KnownBits.cpp:908
static LLVM_ABI KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
Definition: KnownBits.cpp:1073
static LLVM_ABI 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:501
static LLVM_ABI KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
Definition: KnownBits.cpp:1016
static LLVM_ABI 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:541
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition: KnownBits.h:122
static LLVM_ABI 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:60
bool isStrictlyPositive() const
Returns true if this value is known to be positive.
Definition: KnownBits.h:107
static LLVM_ABI KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
Definition: KnownBits.cpp:960
static LLVM_ABI 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:517
static LLVM_ABI KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
Definition: KnownBits.cpp:787
bool operator!=(const KnownBits &Other) const
Definition: KnownBits.h:527
static LLVM_ABI 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:521
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS)
Return true if LHS and RHS have no common bits set.
Definition: KnownBits.h:319
bool isNegative() const
Returns true if this value is known to be negative.
Definition: KnownBits.h:98
static LLVM_ABI 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:53
static KnownBits sub(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from subtraction of LHS and RHS.
Definition: KnownBits.h:346
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition: KnownBits.h:273
void setAllOnes()
Make all bits known to be one and discard any previous information.
Definition: KnownBits.h:92
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
Definition: KnownBits.h:212
static LLVM_ABI KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
Definition: KnownBits.cpp:799
static LLVM_ABI KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
Definition: KnownBits.cpp:770
static LLVM_ABI KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
Definition: KnownBits.cpp:803
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:160
LLVM_ABI KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
Definition: KnownBits.cpp:549
static LLVM_ABI 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:545
unsigned countMaxSignificantBits() const
Returns the maximum number of bits needed to represent all possible signed values with these known bi...
Definition: KnownBits.h:262
static LLVM_ABI 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:525
unsigned countMinPopulation() const
Returns the number of bits known to be one.
Definition: KnownBits.h:279
static LLVM_ABI 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:511
KnownBits(unsigned BitWidth)
Create a known bits object of BitWidth bits initialized to unknown.
Definition: KnownBits.h:41
unsigned countMaxLeadingOnes() const
Returns the maximum number of leading one bits possible.
Definition: KnownBits.h:276
APInt getSignedMinValue() const
Return the minimal signed value possible given these KnownBits.
Definition: KnownBits.h:128
LLVM_ABI KnownBits & operator^=(const KnownBits &RHS)
Update known bits based on XORing with RHS.
Definition: KnownBits.cpp:1118
static LLVM_ABI 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:285
static LLVM_ABI KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
Definition: KnownBits.cpp:205
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:199
static LLVM_ABI KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.
Definition: KnownBits.cpp:795
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition: KnownBits.h:60