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 {
45 assert(Zero.getBitWidth() == One.getBitWidth() &&
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() {
75 Zero.clearAllBits();
76 One.clearAllBits();
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() {
87 Zero.setAllBits();
88 One.clearAllBits();
89 }
90
91 /// Make all bits known to be one and discard any previous information.
92 void setAllOnes() {
93 Zero.clearAllBits();
94 One.setAllBits();
95 }
96
97 /// Make all bits known to be both zero and one. Useful before a loop that
98 /// calls intersectWith.
100 Zero.setAllBits();
101 One.setAllBits();
102 }
103
104 /// Returns true if this value is known to be negative.
105 bool isNegative() const { return One.isSignBitSet(); }
106
107 /// Returns true if this value is known to be non-negative.
108 bool isNonNegative() const { return Zero.isSignBitSet(); }
109
110 /// Returns true if this value is known to be non-zero.
111 bool isNonZero() const { return !One.isZero(); }
112
113 /// Returns true if this value is known to be positive.
114 bool isStrictlyPositive() const {
115 return Zero.isSignBitSet() && !One.isZero();
116 }
117
118 /// Make this value negative.
120 One.setSignBit();
121 }
122
123 /// Make this value non-negative.
125 Zero.setSignBit();
126 }
127
128 /// Return the minimal unsigned value possible given these KnownBits.
130 // Assume that all bits that aren't known-ones are zeros.
131 return One;
132 }
133
134 /// Return the minimal signed value possible given these KnownBits.
136 // Assume that all bits that aren't known-ones are zeros.
137 APInt Min = One;
138 // Sign bit is unknown.
139 if (Zero.isSignBitClear())
140 Min.setSignBit();
141 return Min;
142 }
143
144 /// Return the maximal unsigned value possible given these KnownBits.
146 // Assume that all bits that aren't known-zeros are ones.
147 return ~Zero;
148 }
149
150 /// Return the maximal signed value possible given these KnownBits.
152 // Assume that all bits that aren't known-zeros are ones.
153 APInt Max = ~Zero;
154 // Sign bit is unknown.
155 if (One.isSignBitClear())
156 Max.clearSignBit();
157 return Max;
158 }
159
160 /// Return known bits for a truncation of the value we're tracking.
161 KnownBits trunc(unsigned BitWidth) const {
162 return KnownBits(Zero.trunc(BitWidth), One.trunc(BitWidth));
163 }
164
165 /// Return known bits for an "any" extension of the value we're tracking,
166 /// where we don't know anything about the extended bits.
167 KnownBits anyext(unsigned BitWidth) const {
168 return KnownBits(Zero.zext(BitWidth), One.zext(BitWidth));
169 }
170
171 /// Return known bits for a zero extension of the value we're tracking.
172 KnownBits zext(unsigned BitWidth) const {
173 unsigned OldBitWidth = getBitWidth();
174 APInt NewZero = Zero.zext(BitWidth);
175 NewZero.setBitsFrom(OldBitWidth);
176 return KnownBits(NewZero, One.zext(BitWidth));
177 }
178
179 /// Return known bits for a sign extension of the value we're tracking.
180 KnownBits sext(unsigned BitWidth) const {
181 return KnownBits(Zero.sext(BitWidth), One.sext(BitWidth));
182 }
183
184 /// Return known bits for an "any" extension or truncation of the value we're
185 /// tracking.
186 KnownBits anyextOrTrunc(unsigned BitWidth) const {
187 if (BitWidth > getBitWidth())
188 return anyext(BitWidth);
189 if (BitWidth < getBitWidth())
190 return trunc(BitWidth);
191 return *this;
192 }
193
194 /// Return known bits for a zero extension or truncation of the value we're
195 /// tracking.
196 KnownBits zextOrTrunc(unsigned BitWidth) const {
197 if (BitWidth > getBitWidth())
198 return zext(BitWidth);
199 if (BitWidth < getBitWidth())
200 return trunc(BitWidth);
201 return *this;
202 }
203
204 /// Return known bits for a sign extension or truncation of the value we're
205 /// tracking.
206 KnownBits sextOrTrunc(unsigned BitWidth) const {
207 if (BitWidth > getBitWidth())
208 return sext(BitWidth);
209 if (BitWidth < getBitWidth())
210 return trunc(BitWidth);
211 return *this;
212 }
213
214 /// Return known bits for a in-register sign extension of the value we're
215 /// tracking.
216 LLVM_ABI KnownBits sextInReg(unsigned SrcBitWidth) const;
217
218 /// Insert the bits from a smaller known bits starting at bitPosition.
219 void insertBits(const KnownBits &SubBits, unsigned BitPosition) {
220 Zero.insertBits(SubBits.Zero, BitPosition);
221 One.insertBits(SubBits.One, BitPosition);
222 }
223
224 /// Return a subset of the known bits from [bitPosition,bitPosition+numBits).
225 KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
226 return KnownBits(Zero.extractBits(NumBits, BitPosition),
227 One.extractBits(NumBits, BitPosition));
228 }
229
230 /// Concatenate the bits from \p Lo onto the bottom of *this. This is
231 /// equivalent to:
232 /// (this->zext(NewWidth) << Lo.getBitWidth()) | Lo.zext(NewWidth)
233 KnownBits concat(const KnownBits &Lo) const {
234 return KnownBits(Zero.concat(Lo.Zero), One.concat(Lo.One));
235 }
236
237 /// Return KnownBits based on this, but updated given that the underlying
238 /// value is known to be greater than or equal to Val.
239 LLVM_ABI KnownBits makeGE(const APInt &Val) const;
240
241 /// Returns the minimum number of trailing zero bits.
242 unsigned countMinTrailingZeros() const { return Zero.countr_one(); }
243
244 /// Returns the minimum number of trailing one bits.
245 unsigned countMinTrailingOnes() const { return One.countr_one(); }
246
247 /// Returns the minimum number of leading zero bits.
248 unsigned countMinLeadingZeros() const { return Zero.countl_one(); }
249
250 /// Returns the minimum number of leading one bits.
251 unsigned countMinLeadingOnes() const { return One.countl_one(); }
252
253 /// Returns the number of times the sign bit is replicated into the other
254 /// bits.
255 unsigned countMinSignBits() const {
256 if (isNonNegative())
257 return countMinLeadingZeros();
258 if (isNegative())
259 return countMinLeadingOnes();
260 // Every value has at least 1 sign bit.
261 return 1;
262 }
263
264 /// Returns the maximum number of bits needed to represent all possible
265 /// signed values with these known bits. This is the inverse of the minimum
266 /// number of known sign bits. Examples for bitwidth 5:
267 /// 110?? --> 4
268 /// 0000? --> 2
269 unsigned countMaxSignificantBits() const {
270 return getBitWidth() - countMinSignBits() + 1;
271 }
272
273 /// Returns the maximum number of trailing zero bits possible.
274 unsigned countMaxTrailingZeros() const { return One.countr_zero(); }
275
276 /// Returns the maximum number of trailing one bits possible.
277 unsigned countMaxTrailingOnes() const { return Zero.countr_zero(); }
278
279 /// Returns the maximum number of leading zero bits possible.
280 unsigned countMaxLeadingZeros() const { return One.countl_zero(); }
281
282 /// Returns the maximum number of leading one bits possible.
283 unsigned countMaxLeadingOnes() const { return Zero.countl_zero(); }
284
285 /// Returns the number of bits known to be one.
286 unsigned countMinPopulation() const { return One.popcount(); }
287
288 /// Returns the maximum number of bits that could be one.
289 unsigned countMaxPopulation() const {
290 return getBitWidth() - Zero.popcount();
291 }
292
293 /// Returns the maximum number of bits needed to represent all possible
294 /// unsigned values with these known bits. This is the inverse of the
295 /// minimum number of leading zeros.
296 unsigned countMaxActiveBits() const {
298 }
299
300 /// Create known bits from a known constant.
301 static KnownBits makeConstant(const APInt &C) {
302 return KnownBits(~C, C);
303 }
304
305 /// Returns KnownBits information that is known to be true for both this and
306 /// RHS.
307 ///
308 /// When an operation is known to return one of its operands, this can be used
309 /// to combine information about the known bits of the operands to get the
310 /// information that must be true about the result.
311 KnownBits intersectWith(const KnownBits &RHS) const {
312 return KnownBits(Zero & RHS.Zero, One & RHS.One);
313 }
314
315 /// Returns KnownBits information that is known to be true for either this or
316 /// RHS or both.
317 ///
318 /// This can be used to combine different sources of information about the
319 /// known bits of a single value, e.g. information about the low bits and the
320 /// high bits of the result of a multiplication.
321 KnownBits unionWith(const KnownBits &RHS) const {
322 return KnownBits(Zero | RHS.Zero, One | RHS.One);
323 }
324
325 /// Return true if LHS and RHS have no common bits set.
326 static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS) {
327 return (LHS.Zero | RHS.Zero).isAllOnes();
328 }
329
330 /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
332 const KnownBits &RHS,
333 const KnownBits &Carry);
334
335 /// Compute known bits resulting from adding LHS and RHS.
336 LLVM_ABI static KnownBits computeForAddSub(bool Add, bool NSW, bool NUW,
337 const KnownBits &LHS,
338 const KnownBits &RHS);
339
340 /// Compute known bits results from subtracting RHS from LHS with 1-bit
341 /// Borrow.
344 const KnownBits &Borrow);
345
346 /// Compute knownbits resulting from addition of LHS and RHS.
347 static KnownBits add(const KnownBits &LHS, const KnownBits &RHS,
348 bool NSW = false, bool NUW = false) {
349 return computeForAddSub(/*Add=*/true, NSW, NUW, LHS, RHS);
350 }
351
352 /// Compute knownbits resulting from subtraction of LHS and RHS.
353 static KnownBits sub(const KnownBits &LHS, const KnownBits &RHS,
354 bool NSW = false, bool NUW = false) {
355 return computeForAddSub(/*Add=*/false, NSW, NUW, LHS, RHS);
356 }
357
358 /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
360 const KnownBits &RHS);
361
362 /// Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
364 const KnownBits &RHS);
365
366 /// Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
368 const KnownBits &RHS);
369
370 /// Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
372 const KnownBits &RHS);
373
374 /// Compute knownbits resulting from APIntOps::avgFloorS
376 const KnownBits &RHS);
377
378 /// Compute knownbits resulting from APIntOps::avgFloorU
380 const KnownBits &RHS);
381
382 /// Compute knownbits resulting from APIntOps::avgCeilS
384 const KnownBits &RHS);
385
386 /// Compute knownbits resulting from APIntOps::avgCeilU
388 const KnownBits &RHS);
389
390 /// Compute known bits resulting from multiplying LHS and RHS.
391 LLVM_ABI static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS,
392 bool NoUndefSelfMultiply = false);
393
394 /// Compute known bits from sign-extended multiply-hi.
395 LLVM_ABI static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS);
396
397 /// Compute known bits from zero-extended multiply-hi.
398 LLVM_ABI static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS);
399
400 /// Compute known bits for sdiv(LHS, RHS).
401 LLVM_ABI static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS,
402 bool Exact = false);
403
404 /// Compute known bits for udiv(LHS, RHS).
405 LLVM_ABI static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS,
406 bool Exact = false);
407
408 /// Compute known bits for urem(LHS, RHS).
409 LLVM_ABI static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS);
410
411 /// Compute known bits for srem(LHS, RHS).
412 LLVM_ABI static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS);
413
414 /// Compute known bits for umax(LHS, RHS).
415 LLVM_ABI static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS);
416
417 /// Compute known bits for umin(LHS, RHS).
418 LLVM_ABI static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS);
419
420 /// Compute known bits for smax(LHS, RHS).
421 LLVM_ABI static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS);
422
423 /// Compute known bits for smin(LHS, RHS).
424 LLVM_ABI static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS);
425
426 /// Compute known bits for abdu(LHS, RHS).
427 LLVM_ABI static KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS);
428
429 /// Compute known bits for abds(LHS, RHS).
431
432 /// Compute known bits for shl(LHS, RHS).
433 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
434 LLVM_ABI static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS,
435 bool NUW = false, bool NSW = false,
436 bool ShAmtNonZero = false);
437
438 /// Compute known bits for lshr(LHS, RHS).
439 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
440 LLVM_ABI static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS,
441 bool ShAmtNonZero = false, bool Exact = false);
442
443 /// Compute known bits for ashr(LHS, RHS).
444 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
445 LLVM_ABI static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS,
446 bool ShAmtNonZero = false, bool Exact = false);
447
448 /// Determine if these known bits always give the same ICMP_EQ result.
449 LLVM_ABI static std::optional<bool> eq(const KnownBits &LHS,
450 const KnownBits &RHS);
451
452 /// Determine if these known bits always give the same ICMP_NE result.
453 LLVM_ABI static std::optional<bool> ne(const KnownBits &LHS,
454 const KnownBits &RHS);
455
456 /// Determine if these known bits always give the same ICMP_UGT result.
457 LLVM_ABI static std::optional<bool> ugt(const KnownBits &LHS,
458 const KnownBits &RHS);
459
460 /// Determine if these known bits always give the same ICMP_UGE result.
461 LLVM_ABI static std::optional<bool> uge(const KnownBits &LHS,
462 const KnownBits &RHS);
463
464 /// Determine if these known bits always give the same ICMP_ULT result.
465 LLVM_ABI static std::optional<bool> ult(const KnownBits &LHS,
466 const KnownBits &RHS);
467
468 /// Determine if these known bits always give the same ICMP_ULE result.
469 LLVM_ABI static std::optional<bool> ule(const KnownBits &LHS,
470 const KnownBits &RHS);
471
472 /// Determine if these known bits always give the same ICMP_SGT result.
473 LLVM_ABI static std::optional<bool> sgt(const KnownBits &LHS,
474 const KnownBits &RHS);
475
476 /// Determine if these known bits always give the same ICMP_SGE result.
477 LLVM_ABI static std::optional<bool> sge(const KnownBits &LHS,
478 const KnownBits &RHS);
479
480 /// Determine if these known bits always give the same ICMP_SLT result.
481 LLVM_ABI static std::optional<bool> slt(const KnownBits &LHS,
482 const KnownBits &RHS);
483
484 /// Determine if these known bits always give the same ICMP_SLE result.
485 LLVM_ABI static std::optional<bool> sle(const KnownBits &LHS,
486 const KnownBits &RHS);
487
488 /// Update known bits based on ANDing with RHS.
490
491 /// Update known bits based on ORing with RHS.
493
494 /// Update known bits based on XORing with RHS.
496
497 /// Shift known bits left by ShAmt. Shift in bits are unknown.
498 KnownBits &operator<<=(unsigned ShAmt) {
499 Zero <<= ShAmt;
500 One <<= ShAmt;
501 return *this;
502 }
503
504 /// Shift known bits right by ShAmt. Shifted in bits are unknown.
505 KnownBits &operator>>=(unsigned ShAmt) {
506 Zero.lshrInPlace(ShAmt);
507 One.lshrInPlace(ShAmt);
508 return *this;
509 }
510
511 /// Compute known bits for the absolute value.
512 LLVM_ABI KnownBits abs(bool IntMinIsPoison = false) const;
513
514 KnownBits byteSwap() const {
515 return KnownBits(Zero.byteSwap(), One.byteSwap());
516 }
517
518 KnownBits reverseBits() const {
519 return KnownBits(Zero.reverseBits(), One.reverseBits());
520 }
521
522 /// Compute known bits for X & -X, which has only the lowest bit set of X set.
523 /// The name comes from the X86 BMI instruction
524 LLVM_ABI KnownBits blsi() const;
525
526 /// Compute known bits for X ^ (X - 1), which has all bits up to and including
527 /// the lowest set bit of X set. The name comes from the X86 BMI instruction.
528 LLVM_ABI KnownBits blsmsk() const;
529
530 bool operator==(const KnownBits &Other) const {
531 return Zero == Other.Zero && One == Other.One;
532 }
533
534 bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
535
536 LLVM_ABI void print(raw_ostream &OS) const;
537
538#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
539 LLVM_DUMP_METHOD void dump() const;
540#endif
541
542private:
543 // Internal helper for getting the initial KnownBits for an `srem` or `urem`
544 // operation with the low-bits set.
545 static KnownBits remGetLowBits(const KnownBits &LHS, const KnownBits &RHS);
546};
547
549 LHS &= RHS;
550 return LHS;
551}
552
554 RHS &= LHS;
555 return std::move(RHS);
556}
557
559 LHS |= RHS;
560 return LHS;
561}
562
564 RHS |= LHS;
565 return std::move(RHS);
566}
567
569 LHS ^= RHS;
570 return LHS;
571}
572
574 RHS ^= LHS;
575 return std::move(RHS);
576}
577
578inline raw_ostream &operator<<(raw_ostream &OS, const KnownBits &Known) {
579 Known.print(OS);
580 return OS;
581}
582
583} // end namespace llvm
584
585#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
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
Definition APInt.h:1385
void setSignBit()
Set the sign bit to 1.
Definition APInt.h:1340
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.
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.
Definition ModRef.h:68
@ Add
Sum of integers.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
constexpr unsigned BitWidth
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:1847
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:851
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition KnownBits.h:301
static LLVM_ABI KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
unsigned countMaxTrailingOnes() const
Returns the maximum number of trailing one bits possible.
Definition KnownBits.h:277
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.
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition KnownBits.h:186
LLVM_ABI KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
static LLVM_ABI KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition KnownBits.h:255
static LLVM_ABI KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition KnownBits.h:108
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.
void makeNonNegative()
Make this value non-negative.
Definition KnownBits.h:124
static LLVM_ABI KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
Definition KnownBits.h:251
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition KnownBits.h:242
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
static LLVM_ABI KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
static LLVM_ABI KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
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:274
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.
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...
APInt getSignedMaxValue() const
Return the maximal signed value possible given these KnownBits.
Definition KnownBits.h:151
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...
void makeNegative()
Make this value negative.
Definition KnownBits.h:119
KnownBits & operator>>=(unsigned ShAmt)
Shift known bits right by ShAmt. Shifted in bits are unknown.
Definition KnownBits.h:505
void setAllConflict()
Make all bits known to be both zero and one.
Definition KnownBits.h:99
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition KnownBits.h:161
KnownBits byteSwap() const
Definition KnownBits.h:514
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.
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition KnownBits.h:289
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition KnownBits.h:86
KnownBits reverseBits() const
Definition KnownBits.h:518
LLVM_ABI KnownBits & operator|=(const KnownBits &RHS)
Update known bits based on ORing with RHS.
LLVM_ABI void print(raw_ostream &OS) const
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition KnownBits.h:233
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).
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition KnownBits.h:172
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
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:321
static LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
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:111
static LLVM_ABI KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
bool operator==(const KnownBits &Other) const
Definition KnownBits.h:530
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition KnownBits.h:225
unsigned countMaxActiveBits() const
Returns the maximum number of bits needed to represent all possible unsigned values with these known ...
Definition KnownBits.h:296
static LLVM_ABI KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition KnownBits.h:311
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition KnownBits.h:180
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
Definition KnownBits.h:245
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.
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:347
KnownBits & operator<<=(unsigned ShAmt)
Shift known bits left by ShAmt. Shift in bits are unknown.
Definition KnownBits.h:498
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition KnownBits.h:196
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition KnownBits.h:248
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition KnownBits.h:145
KnownBits()=default
static LLVM_ABI KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
static LLVM_ABI KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
LLVM_ABI KnownBits & operator&=(const KnownBits &RHS)
Update known bits based on ANDing with RHS.
static LLVM_ABI KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
static LLVM_ABI KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
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.
static LLVM_ABI KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
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.
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition KnownBits.h:129
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:114
static LLVM_ABI KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
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.
static LLVM_ABI KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
bool operator!=(const KnownBits &Other) const
Definition KnownBits.h:534
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.
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS)
Return true if LHS and RHS have no common bits set.
Definition KnownBits.h:326
bool isNegative() const
Returns true if this value is known to be negative.
Definition KnownBits.h:105
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:353
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition KnownBits.h:280
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:219
static LLVM_ABI KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
static LLVM_ABI KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
static LLVM_ABI KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
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:167
LLVM_ABI KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
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.
unsigned countMaxSignificantBits() const
Returns the maximum number of bits needed to represent all possible signed values with these known bi...
Definition KnownBits.h:269
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.
unsigned countMinPopulation() const
Returns the number of bits known to be one.
Definition KnownBits.h:286
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.
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:283
APInt getSignedMinValue() const
Return the minimal signed value possible given these KnownBits.
Definition KnownBits.h:135
LLVM_ABI KnownBits & operator^=(const KnownBits &RHS)
Update known bits based on XORing with RHS.
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).
static LLVM_ABI KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
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:206
static LLVM_ABI KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition KnownBits.h:60