LLVM 17.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 /// Resets the known state of all bits.
66 void resetAll() {
69 }
70
71 /// Returns true if value is all zero.
72 bool isZero() const {
73 assert(!hasConflict() && "KnownBits conflict!");
74 return Zero.isAllOnes();
75 }
76
77 /// Returns true if value is all one bits.
78 bool isAllOnes() const {
79 assert(!hasConflict() && "KnownBits conflict!");
80 return One.isAllOnes();
81 }
82
83 /// Make all bits known to be zero and discard any previous information.
84 void setAllZero() {
87 }
88
89 /// Make all bits known to be one and discard any previous information.
90 void setAllOnes() {
93 }
94
95 /// Returns true if this value is known to be negative.
96 bool isNegative() const { return One.isSignBitSet(); }
97
98 /// Returns true if this value is known to be non-negative.
99 bool isNonNegative() const { return Zero.isSignBitSet(); }
100
101 /// Returns true if this value is known to be non-zero.
102 bool isNonZero() const { return !One.isZero(); }
103
104 /// Returns true if this value is known to be positive.
105 bool isStrictlyPositive() const {
106 return Zero.isSignBitSet() && !One.isZero();
107 }
108
109 /// Make this value negative.
111 One.setSignBit();
112 }
113
114 /// Make this value non-negative.
117 }
118
119 /// Return the minimal unsigned value possible given these KnownBits.
121 // Assume that all bits that aren't known-ones are zeros.
122 return One;
123 }
124
125 /// Return the minimal signed value possible given these KnownBits.
127 // Assume that all bits that aren't known-ones are zeros.
128 APInt Min = One;
129 // Sign bit is unknown.
130 if (Zero.isSignBitClear())
131 Min.setSignBit();
132 return Min;
133 }
134
135 /// Return the maximal unsigned value possible given these KnownBits.
137 // Assume that all bits that aren't known-zeros are ones.
138 return ~Zero;
139 }
140
141 /// Return the maximal signed value possible given these KnownBits.
143 // Assume that all bits that aren't known-zeros are ones.
144 APInt Max = ~Zero;
145 // Sign bit is unknown.
146 if (One.isSignBitClear())
147 Max.clearSignBit();
148 return Max;
149 }
150
151 /// Return known bits for a truncation of the value we're tracking.
152 KnownBits trunc(unsigned BitWidth) const {
154 }
155
156 /// Return known bits for an "any" extension of the value we're tracking,
157 /// where we don't know anything about the extended bits.
158 KnownBits anyext(unsigned BitWidth) const {
160 }
161
162 /// Return known bits for a zero extension of the value we're tracking.
163 KnownBits zext(unsigned BitWidth) const {
164 unsigned OldBitWidth = getBitWidth();
165 APInt NewZero = Zero.zext(BitWidth);
166 NewZero.setBitsFrom(OldBitWidth);
167 return KnownBits(NewZero, One.zext(BitWidth));
168 }
169
170 /// Return known bits for a sign extension of the value we're tracking.
171 KnownBits sext(unsigned BitWidth) const {
173 }
174
175 /// Return known bits for an "any" extension or truncation of the value we're
176 /// tracking.
178 if (BitWidth > getBitWidth())
179 return anyext(BitWidth);
180 if (BitWidth < getBitWidth())
181 return trunc(BitWidth);
182 return *this;
183 }
184
185 /// Return known bits for a zero extension or truncation of the value we're
186 /// tracking.
188 if (BitWidth > getBitWidth())
189 return zext(BitWidth);
190 if (BitWidth < getBitWidth())
191 return trunc(BitWidth);
192 return *this;
193 }
194
195 /// Return known bits for a sign extension or truncation of the value we're
196 /// tracking.
198 if (BitWidth > getBitWidth())
199 return sext(BitWidth);
200 if (BitWidth < getBitWidth())
201 return trunc(BitWidth);
202 return *this;
203 }
204
205 /// Return known bits for a in-register sign extension of the value we're
206 /// tracking.
207 KnownBits sextInReg(unsigned SrcBitWidth) const;
208
209 /// Insert the bits from a smaller known bits starting at bitPosition.
210 void insertBits(const KnownBits &SubBits, unsigned BitPosition) {
211 Zero.insertBits(SubBits.Zero, BitPosition);
212 One.insertBits(SubBits.One, BitPosition);
213 }
214
215 /// Return a subset of the known bits from [bitPosition,bitPosition+numBits).
216 KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
217 return KnownBits(Zero.extractBits(NumBits, BitPosition),
218 One.extractBits(NumBits, BitPosition));
219 }
220
221 /// Concatenate the bits from \p Lo onto the bottom of *this. This is
222 /// equivalent to:
223 /// (this->zext(NewWidth) << Lo.getBitWidth()) | Lo.zext(NewWidth)
224 KnownBits concat(const KnownBits &Lo) const {
225 return KnownBits(Zero.concat(Lo.Zero), One.concat(Lo.One));
226 }
227
228 /// Return KnownBits based on this, but updated given that the underlying
229 /// value is known to be greater than or equal to Val.
230 KnownBits makeGE(const APInt &Val) const;
231
232 /// Returns the minimum number of trailing zero bits.
233 unsigned countMinTrailingZeros() const { return Zero.countr_one(); }
234
235 /// Returns the minimum number of trailing one bits.
236 unsigned countMinTrailingOnes() const { return One.countr_one(); }
237
238 /// Returns the minimum number of leading zero bits.
239 unsigned countMinLeadingZeros() const { return Zero.countl_one(); }
240
241 /// Returns the minimum number of leading one bits.
242 unsigned countMinLeadingOnes() const { return One.countl_one(); }
243
244 /// Returns the number of times the sign bit is replicated into the other
245 /// bits.
246 unsigned countMinSignBits() const {
247 if (isNonNegative())
248 return countMinLeadingZeros();
249 if (isNegative())
250 return countMinLeadingOnes();
251 // Every value has at least 1 sign bit.
252 return 1;
253 }
254
255 /// Returns the maximum number of bits needed to represent all possible
256 /// signed values with these known bits. This is the inverse of the minimum
257 /// number of known sign bits. Examples for bitwidth 5:
258 /// 110?? --> 4
259 /// 0000? --> 2
260 unsigned countMaxSignificantBits() const {
261 return getBitWidth() - countMinSignBits() + 1;
262 }
263
264 /// Returns the maximum number of trailing zero bits possible.
265 unsigned countMaxTrailingZeros() const { return One.countr_zero(); }
266
267 /// Returns the maximum number of trailing one bits possible.
268 unsigned countMaxTrailingOnes() const { return Zero.countr_zero(); }
269
270 /// Returns the maximum number of leading zero bits possible.
271 unsigned countMaxLeadingZeros() const { return One.countl_zero(); }
272
273 /// Returns the maximum number of leading one bits possible.
274 unsigned countMaxLeadingOnes() const { return Zero.countl_zero(); }
275
276 /// Returns the number of bits known to be one.
277 unsigned countMinPopulation() const { return One.popcount(); }
278
279 /// Returns the maximum number of bits that could be one.
280 unsigned countMaxPopulation() const {
281 return getBitWidth() - Zero.popcount();
282 }
283
284 /// Returns the maximum number of bits needed to represent all possible
285 /// unsigned values with these known bits. This is the inverse of the
286 /// minimum number of leading zeros.
287 unsigned countMaxActiveBits() const {
289 }
290
291 /// Create known bits from a known constant.
292 static KnownBits makeConstant(const APInt &C) {
293 return KnownBits(~C, C);
294 }
295
296 /// Returns KnownBits information that is known to be true for both this and
297 /// RHS.
298 ///
299 /// When an operation is known to return one of its operands, this can be used
300 /// to combine information about the known bits of the operands to get the
301 /// information that must be true about the result.
303 return KnownBits(Zero & RHS.Zero, One & RHS.One);
304 }
305
306 /// Returns KnownBits information that is known to be true for either this or
307 /// RHS or both.
308 ///
309 /// This can be used to combine different sources of information about the
310 /// known bits of a single value, e.g. information about the low bits and the
311 /// high bits of the result of a multiplication.
313 return KnownBits(Zero | RHS.Zero, One | RHS.One);
314 }
315
316 /// Compute known bits common to LHS and RHS.
317 LLVM_DEPRECATED("use intersectWith instead", "intersectWith")
319 return LHS.intersectWith(RHS);
320 }
321
322 /// Return true if LHS and RHS have no common bits set.
323 static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS) {
324 return (LHS.Zero | RHS.Zero).isAllOnes();
325 }
326
327 /// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
329 const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry);
330
331 /// Compute known bits resulting from adding LHS and RHS.
332 static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS,
333 KnownBits RHS);
334
335 /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
336 static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS);
337
338 /// Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
339 static KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS);
340
341 /// Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
342 static KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS);
343
344 /// Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
345 static KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS);
346
347 /// Compute known bits resulting from multiplying LHS and RHS.
348 static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS,
349 bool NoUndefSelfMultiply = false);
350
351 /// Compute known bits from sign-extended multiply-hi.
352 static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS);
353
354 /// Compute known bits from zero-extended multiply-hi.
355 static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS);
356
357 /// Compute known bits for sdiv(LHS, RHS).
358 static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS,
359 bool Exact = false);
360
361 /// Compute known bits for udiv(LHS, RHS).
362 static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS,
363 bool Exact = false);
364
365 /// Compute known bits for urem(LHS, RHS).
366 static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS);
367
368 /// Compute known bits for srem(LHS, RHS).
369 static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS);
370
371 /// Compute known bits for umax(LHS, RHS).
372 static KnownBits umax(const KnownBits &LHS, const KnownBits &RHS);
373
374 /// Compute known bits for umin(LHS, RHS).
375 static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS);
376
377 /// Compute known bits for smax(LHS, RHS).
378 static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS);
379
380 /// Compute known bits for smin(LHS, RHS).
381 static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS);
382
383 /// Compute known bits for shl(LHS, RHS).
384 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
385 static KnownBits shl(const KnownBits &LHS, const KnownBits &RHS,
386 bool NUW = false, bool NSW = false,
387 bool ShAmtNonZero = false);
388
389 /// Compute known bits for lshr(LHS, RHS).
390 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
391 static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS,
392 bool ShAmtNonZero = false);
393
394 /// Compute known bits for ashr(LHS, RHS).
395 /// NOTE: RHS (shift amount) bitwidth doesn't need to be the same as LHS.
396 static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS,
397 bool ShAmtNonZero = false);
398
399 /// Determine if these known bits always give the same ICMP_EQ result.
400 static std::optional<bool> eq(const KnownBits &LHS, const KnownBits &RHS);
401
402 /// Determine if these known bits always give the same ICMP_NE result.
403 static std::optional<bool> ne(const KnownBits &LHS, const KnownBits &RHS);
404
405 /// Determine if these known bits always give the same ICMP_UGT result.
406 static std::optional<bool> ugt(const KnownBits &LHS, const KnownBits &RHS);
407
408 /// Determine if these known bits always give the same ICMP_UGE result.
409 static std::optional<bool> uge(const KnownBits &LHS, const KnownBits &RHS);
410
411 /// Determine if these known bits always give the same ICMP_ULT result.
412 static std::optional<bool> ult(const KnownBits &LHS, const KnownBits &RHS);
413
414 /// Determine if these known bits always give the same ICMP_ULE result.
415 static std::optional<bool> ule(const KnownBits &LHS, const KnownBits &RHS);
416
417 /// Determine if these known bits always give the same ICMP_SGT result.
418 static std::optional<bool> sgt(const KnownBits &LHS, const KnownBits &RHS);
419
420 /// Determine if these known bits always give the same ICMP_SGE result.
421 static std::optional<bool> sge(const KnownBits &LHS, const KnownBits &RHS);
422
423 /// Determine if these known bits always give the same ICMP_SLT result.
424 static std::optional<bool> slt(const KnownBits &LHS, const KnownBits &RHS);
425
426 /// Determine if these known bits always give the same ICMP_SLE result.
427 static std::optional<bool> sle(const KnownBits &LHS, const KnownBits &RHS);
428
429 /// Update known bits based on ANDing with RHS.
431
432 /// Update known bits based on ORing with RHS.
434
435 /// Update known bits based on XORing with RHS.
437
438 /// Compute known bits for the absolute value.
439 KnownBits abs(bool IntMinIsPoison = false) const;
440
442 return KnownBits(Zero.byteSwap(), One.byteSwap());
443 }
444
447 }
448
449 /// Compute known bits for X & -X, which has only the lowest bit set of X set.
450 /// The name comes from the X86 BMI instruction
451 KnownBits blsi() const;
452
453 /// Compute known bits for X ^ (X - 1), which has all bits up to and including
454 /// the lowest set bit of X set. The name comes from the X86 BMI instruction.
455 KnownBits blsmsk() const;
456
457 bool operator==(const KnownBits &Other) const {
458 return Zero == Other.Zero && One == Other.One;
459 }
460
461 bool operator!=(const KnownBits &Other) const { return !(*this == Other); }
462
463 void print(raw_ostream &OS) const;
464 void dump() const;
465
466private:
467 // Internal helper for getting the initial KnownBits for an `srem` or `urem`
468 // operation with the low-bits set.
469 static KnownBits remGetLowBits(const KnownBits &LHS, const KnownBits &RHS);
470};
471
473 LHS &= RHS;
474 return LHS;
475}
476
478 RHS &= LHS;
479 return std::move(RHS);
480}
481
483 LHS |= RHS;
484 return LHS;
485}
486
488 RHS |= LHS;
489 return std::move(RHS);
490}
491
493 LHS ^= RHS;
494 return LHS;
495}
496
498 RHS ^= LHS;
499 return std::move(RHS);
500}
501
503 Known.print(OS);
504 return OS;
505}
506
507} // end namespace llvm
508
509#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:145
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:75
APInt zext(unsigned width) const
Zero extend to a new width.
Definition: APInt.cpp:972
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:1368
APInt trunc(unsigned width) const
Truncate to new width.
Definition: APInt.cpp:897
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Definition: APInt.h:354
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition: APInt.h:366
void setSignBit()
Set the sign bit to 1.
Definition: APInt.h:1322
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1443
APInt concat(const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
Definition: APInt.h:935
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:1231
void clearAllBits()
Set every bit to 0.
Definition: APInt.h:1379
APInt reverseBits() const
Definition: APInt.cpp:728
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:359
void setAllBits()
Set every bit to 1.
Definition: APInt.h:1301
APInt sext(unsigned width) const
Sign extend to a new width.
Definition: APInt.cpp:945
APInt byteSwap() const
Definition: APInt.cpp:706
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
Definition: APInt.h:324
APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition: APInt.cpp:444
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:331
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:2062
APInt operator^(APInt a, const APInt &b)
Definition: APInt.h:2102
@ Add
Sum of integers.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:292
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:184
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:1946
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2082
Definition: BitVector.h:858
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition: KnownBits.h:292
static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
Definition: KnownBits.cpp:622
unsigned countMaxTrailingOnes() const
Returns the maximum number of trailing one bits possible.
Definition: KnownBits.h:268
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:353
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition: KnownBits.h:177
KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
Definition: KnownBits.cpp:88
static KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
Definition: KnownBits.cpp:742
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition: KnownBits.h:246
static KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
Definition: KnownBits.cpp:141
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition: KnownBits.h:99
bool isZero() const
Returns true if value is all zero.
Definition: KnownBits.h:72
KnownBits blsi() const
Compute known bits for X & -X, which has only the lowest bit set of X set.
Definition: KnownBits.cpp:959
void makeNonNegative()
Make this value non-negative.
Definition: KnownBits.h:115
static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits common to LHS and RHS.
Definition: KnownBits.h:318
static KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
Definition: KnownBits.cpp:631
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
Definition: KnownBits.h:242
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Definition: KnownBits.h:233
static KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
Definition: KnownBits.cpp:625
static KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
Definition: KnownBits.cpp:888
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:265
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:361
KnownBits makeGE(const APInt &Val) const
Return KnownBits based on this, but updated given that the underlying value is known to be greater th...
Definition: KnownBits.cpp:105
APInt getSignedMaxValue() const
Return the maximal signed value possible given these KnownBits.
Definition: KnownBits.h:142
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:970
void makeNegative()
Make this value negative.
Definition: KnownBits.h:110
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition: KnownBits.h:152
KnownBits byteSwap() const
Definition: KnownBits.h:441
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:401
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition: KnownBits.h:280
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition: KnownBits.h:84
KnownBits reverseBits() const
Definition: KnownBits.h:445
KnownBits & operator|=(const KnownBits &RHS)
Update known bits based on ORing with RHS.
Definition: KnownBits.cpp:942
void print(raw_ostream &OS) const
Definition: KnownBits.cpp:980
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition: KnownBits.h:224
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:117
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition: KnownBits.h:163
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:66
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:312
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition: KnownBits.h:102
bool operator==(const KnownBits &Other) const
Definition: KnownBits.h:457
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition: KnownBits.h:216
unsigned countMaxActiveBits() const
Returns the maximum number of bits needed to represent all possible unsigned values with these known ...
Definition: KnownBits.h:287
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
Definition: KnownBits.h:302
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition: KnownBits.h:171
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
Definition: KnownBits.h:236
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition: KnownBits.h:187
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition: KnownBits.h:239
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition: KnownBits.h:136
KnownBits()=default
static KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false)
Compute known bits for lshr(LHS, RHS).
Definition: KnownBits.cpp:259
static KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
Definition: KnownBits.cpp:154
KnownBits & operator&=(const KnownBits &RHS)
Update known bits based on ANDing with RHS.
Definition: KnownBits.cpp:934
static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
Definition: KnownBits.cpp:733
static KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
Definition: KnownBits.cpp:907
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:367
static KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
Definition: KnownBits.cpp:846
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:407
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition: KnownBits.h:120
static KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false)
Compute known bits for ashr(LHS, RHS).
Definition: KnownBits.cpp:305
void dump() const
Definition: KnownBits.cpp:994
bool isStrictlyPositive() const
Returns true if this value is known to be positive.
Definition: KnownBits.h:105
static KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
Definition: KnownBits.cpp:787
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:383
bool operator!=(const KnownBits &Other) const
Definition: KnownBits.h:461
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:387
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS)
Return true if LHS and RHS have no common bits set.
Definition: KnownBits.h:323
bool isNegative() const
Returns true if this value is known to be negative.
Definition: KnownBits.h:96
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:271
void setAllOnes()
Make all bits known to be one and discard any previous information.
Definition: KnownBits.h:90
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
Definition: KnownBits.h:210
static KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
Definition: KnownBits.cpp:628
static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
Definition: KnownBits.cpp:635
KnownBits anyext(unsigned BitWidth) const
Return known bits for an "any" extension of the value we're tracking, where we don't know anything ab...
Definition: KnownBits.h:158
KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
Definition: KnownBits.cpp:415
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:411
unsigned countMaxSignificantBits() const
Returns the maximum number of bits needed to represent all possible signed values with these known bi...
Definition: KnownBits.h:260
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:391
unsigned countMinPopulation() const
Returns the number of bits known to be one.
Definition: KnownBits.h:277
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:377
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:274
APInt getSignedMinValue() const
Return the minimal signed value possible given these KnownBits.
Definition: KnownBits.h:126
KnownBits & operator^=(const KnownBits &RHS)
Update known bits based on XORing with RHS.
Definition: KnownBits.cpp:950
static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS, KnownBits RHS)
Compute known bits resulting from adding LHS and RHS.
Definition: KnownBits.cpp:57
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:174
static KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
Definition: KnownBits.cpp:135
bool isAllOnes() const
Returns true if value is all one bits.
Definition: KnownBits.h:78
KnownBits sextOrTrunc(unsigned BitWidth) const
Return known bits for a sign extension or truncation of the value we're tracking.
Definition: KnownBits.h:197
const APInt & getConstant() const
Returns the value when all bits have a known value.
Definition: KnownBits.h:57