LLVM 21.0.0git
ValueTracking.h
Go to the documentation of this file.
1//===- llvm/Analysis/ValueTracking.h - Walk computations --------*- 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 routines that help analyze properties that chains of
10// computations have.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_VALUETRACKING_H
15#define LLVM_ANALYSIS_VALUETRACKING_H
16
19#include "llvm/IR/Constants.h"
20#include "llvm/IR/DataLayout.h"
21#include "llvm/IR/FMF.h"
23#include "llvm/IR/InstrTypes.h"
24#include "llvm/IR/Intrinsics.h"
25#include <cassert>
26#include <cstdint>
27
28namespace llvm {
29
30class Operator;
31class AddOperator;
32class AssumptionCache;
33class DominatorTree;
34class GEPOperator;
35class WithOverflowInst;
36struct KnownBits;
37class Loop;
38class LoopInfo;
39class MDNode;
40class StringRef;
41class TargetLibraryInfo;
42template <typename T> class ArrayRef;
43
44constexpr unsigned MaxAnalysisRecursionDepth = 6;
45
46/// Determine which bits of V are known to be either zero or one and return
47/// them in the KnownZero/KnownOne bit sets.
48///
49/// This function is defined on values with integer type, values with pointer
50/// type, and vectors of integers. In the case
51/// where V is a vector, the known zero and known one values are the
52/// same width as the vector element, and the bit is set only if it is true
53/// for all of the elements in the vector.
54void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL,
55 unsigned Depth = 0, AssumptionCache *AC = nullptr,
56 const Instruction *CxtI = nullptr,
57 const DominatorTree *DT = nullptr,
58 bool UseInstrInfo = true);
59
60/// Returns the known bits rather than passing by reference.
62 unsigned Depth = 0, AssumptionCache *AC = nullptr,
63 const Instruction *CxtI = nullptr,
64 const DominatorTree *DT = nullptr,
65 bool UseInstrInfo = true);
66
67/// Returns the known bits rather than passing by reference.
68KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
69 const DataLayout &DL, unsigned Depth = 0,
70 AssumptionCache *AC = nullptr,
71 const Instruction *CxtI = nullptr,
72 const DominatorTree *DT = nullptr,
73 bool UseInstrInfo = true);
74
75KnownBits computeKnownBits(const Value *V, const APInt &DemandedElts,
76 unsigned Depth, const SimplifyQuery &Q);
77
78KnownBits computeKnownBits(const Value *V, unsigned Depth,
79 const SimplifyQuery &Q);
80
81void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
82 const SimplifyQuery &Q);
83
84/// Compute known bits from the range metadata.
85/// \p KnownZero the set of bits that are known to be zero
86/// \p KnownOne the set of bits that are known to be one
87void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known);
88
89/// Merge bits known from context-dependent facts into Known.
90void computeKnownBitsFromContext(const Value *V, KnownBits &Known,
91 unsigned Depth, const SimplifyQuery &Q);
92
93/// Using KnownBits LHS/RHS produce the known bits for logic op (and/xor/or).
95 const KnownBits &KnownLHS,
96 const KnownBits &KnownRHS,
97 unsigned Depth, const SimplifyQuery &SQ);
98
99/// Adjust \p Known for the given select \p Arm to include information from the
100/// select \p Cond.
102 bool Invert, unsigned Depth,
103 const SimplifyQuery &Q);
104
105/// Return true if LHS and RHS have no common bits set.
107 const WithCache<const Value *> &RHSCache,
108 const SimplifyQuery &SQ);
109
110/// Return true if the given value is known to have exactly one bit set when
111/// defined. For vectors return true if every element is known to be a power
112/// of two when defined. Supports values with integer or pointer type and
113/// vectors of integers. If 'OrZero' is set, then return true if the given
114/// value is either a power of two or zero.
115bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
116 bool OrZero = false, unsigned Depth = 0,
117 AssumptionCache *AC = nullptr,
118 const Instruction *CxtI = nullptr,
119 const DominatorTree *DT = nullptr,
120 bool UseInstrInfo = true);
121
122bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,
123 const SimplifyQuery &Q);
124
126
128
129/// Return true if the given value is known to be non-zero when defined. For
130/// vectors, return true if every element is known to be non-zero when
131/// defined. For pointers, if the context instruction and dominator tree are
132/// specified, perform context-sensitive analysis and return true if the
133/// pointer couldn't possibly be null at the specified instruction.
134/// Supports values with integer or pointer type and vectors of integers.
135bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0);
136
137/// Return true if the two given values are negation.
138/// Currently can recoginze Value pair:
139/// 1: <X, Y> if X = sub (0, Y) or Y = sub (0, X)
140/// 2: <X, Y> if X = sub (A, B) and Y = sub (B, A)
141bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW = false,
142 bool AllowPoison = true);
143
144/// Return true iff:
145/// 1. X is poison implies Y is poison.
146/// 2. X is true implies Y is false.
147/// 3. X is false implies Y is true.
148/// Otherwise, return false.
149bool isKnownInversion(const Value *X, const Value *Y);
150
151/// Returns true if the give value is known to be non-negative.
152bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ,
153 unsigned Depth = 0);
154
155/// Returns true if the given value is known be positive (i.e. non-negative
156/// and non-zero).
157bool isKnownPositive(const Value *V, const SimplifyQuery &SQ,
158 unsigned Depth = 0);
159
160/// Returns true if the given value is known be negative (i.e. non-positive
161/// and non-zero).
162bool isKnownNegative(const Value *V, const SimplifyQuery &SQ,
163 unsigned Depth = 0);
164
165/// Return true if the given values are known to be non-equal when defined.
166/// Supports scalar integer types only.
167bool isKnownNonEqual(const Value *V1, const Value *V2, const SimplifyQuery &SQ,
168 unsigned Depth = 0);
169
170/// Return true if 'V & Mask' is known to be zero. We use this predicate to
171/// simplify operations downstream. Mask is known to be zero for bits that V
172/// cannot have.
173///
174/// This function is defined on values with integer type, values with pointer
175/// type, and vectors of integers. In the case
176/// where V is a vector, the mask, known zero, and known one values are the
177/// same width as the vector element, and the bit is set only if it is true
178/// for all of the elements in the vector.
179bool MaskedValueIsZero(const Value *V, const APInt &Mask,
180 const SimplifyQuery &SQ, unsigned Depth = 0);
181
182/// Return the number of times the sign bit of the register is replicated into
183/// the other bits. We know that at least 1 bit is always equal to the sign
184/// bit (itself), but other cases can give us information. For example,
185/// immediately after an "ashr X, 2", we know that the top 3 bits are all
186/// equal to each other, so we return 3. For vectors, return the number of
187/// sign bits for the vector element with the mininum number of known sign
188/// bits.
189unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL,
190 unsigned Depth = 0, AssumptionCache *AC = nullptr,
191 const Instruction *CxtI = nullptr,
192 const DominatorTree *DT = nullptr,
193 bool UseInstrInfo = true);
194
195/// Get the upper bound on bit size for this Value \p Op as a signed integer.
196/// i.e. x == sext(trunc(x to MaxSignificantBits) to bitwidth(x)).
197/// Similar to the APInt::getSignificantBits function.
198unsigned ComputeMaxSignificantBits(const Value *Op, const DataLayout &DL,
199 unsigned Depth = 0,
200 AssumptionCache *AC = nullptr,
201 const Instruction *CxtI = nullptr,
202 const DominatorTree *DT = nullptr);
203
204/// Map a call instruction to an intrinsic ID. Libcalls which have equivalent
205/// intrinsics are treated as-if they were intrinsics.
207 const TargetLibraryInfo *TLI);
208
209/// Given an exploded icmp instruction, return true if the comparison only
210/// checks the sign bit. If it only checks the sign bit, set TrueIfSigned if
211/// the result of the comparison is true when the input value is signed.
213 bool &TrueIfSigned);
214
215/// Returns a pair of values, which if passed to llvm.is.fpclass, returns the
216/// same result as an fcmp with the given operands.
217///
218/// If \p LookThroughSrc is true, consider the input value when computing the
219/// mask.
220///
221/// If \p LookThroughSrc is false, ignore the source value (i.e. the first pair
222/// element will always be LHS.
223std::pair<Value *, FPClassTest> fcmpToClassTest(CmpInst::Predicate Pred,
224 const Function &F, Value *LHS,
225 Value *RHS,
226 bool LookThroughSrc = true);
227std::pair<Value *, FPClassTest> fcmpToClassTest(CmpInst::Predicate Pred,
228 const Function &F, Value *LHS,
229 const APFloat *ConstRHS,
230 bool LookThroughSrc = true);
231
232/// Compute the possible floating-point classes that \p LHS could be based on
233/// fcmp \Pred \p LHS, \p RHS.
234///
235/// \returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
236///
237/// If the compare returns an exact class test, ClassesIfTrue == ~ClassesIfFalse
238///
239/// This is a less exact version of fcmpToClassTest (e.g. fcmpToClassTest will
240/// only succeed for a test of x > 0 implies positive, but not x > 1).
241///
242/// If \p LookThroughSrc is true, consider the input value when computing the
243/// mask. This may look through sign bit operations.
244///
245/// If \p LookThroughSrc is false, ignore the source value (i.e. the first pair
246/// element will always be LHS.
247///
248std::tuple<Value *, FPClassTest, FPClassTest>
250 Value *RHS, bool LookThroughSrc = true);
251std::tuple<Value *, FPClassTest, FPClassTest>
253 FPClassTest RHS, bool LookThroughSrc = true);
254std::tuple<Value *, FPClassTest, FPClassTest>
256 const APFloat &RHS, bool LookThroughSrc = true);
257
259 /// Floating-point classes the value could be one of.
261
262 /// std::nullopt if the sign bit is unknown, true if the sign bit is
263 /// definitely set or false if the sign bit is definitely unset.
264 std::optional<bool> SignBit;
265
267 return KnownFPClasses == Other.KnownFPClasses && SignBit == Other.SignBit;
268 }
269
270 /// Return true if it's known this can never be one of the mask entries.
271 bool isKnownNever(FPClassTest Mask) const {
272 return (KnownFPClasses & Mask) == fcNone;
273 }
274
275 bool isKnownAlways(FPClassTest Mask) const { return isKnownNever(~Mask); }
276
277 bool isUnknown() const {
278 return KnownFPClasses == fcAllFlags && !SignBit;
279 }
280
281 /// Return true if it's known this can never be a nan.
282 bool isKnownNeverNaN() const {
283 return isKnownNever(fcNan);
284 }
285
286 /// Return true if it's known this must always be a nan.
287 bool isKnownAlwaysNaN() const { return isKnownAlways(fcNan); }
288
289 /// Return true if it's known this can never be an infinity.
290 bool isKnownNeverInfinity() const {
291 return isKnownNever(fcInf);
292 }
293
294 /// Return true if it's known this can never be +infinity.
296 return isKnownNever(fcPosInf);
297 }
298
299 /// Return true if it's known this can never be -infinity.
301 return isKnownNever(fcNegInf);
302 }
303
304 /// Return true if it's known this can never be a subnormal
307 }
308
309 /// Return true if it's known this can never be a positive subnormal
312 }
313
314 /// Return true if it's known this can never be a negative subnormal
317 }
318
319 /// Return true if it's known this can never be a zero. This means a literal
320 /// [+-]0, and does not include denormal inputs implicitly treated as [+-]0.
321 bool isKnownNeverZero() const {
322 return isKnownNever(fcZero);
323 }
324
325 /// Return true if it's known this can never be a literal positive zero.
326 bool isKnownNeverPosZero() const {
327 return isKnownNever(fcPosZero);
328 }
329
330 /// Return true if it's known this can never be a negative zero. This means a
331 /// literal -0 and does not include denormal inputs implicitly treated as -0.
332 bool isKnownNeverNegZero() const {
333 return isKnownNever(fcNegZero);
334 }
335
336 /// Return true if it's know this can never be interpreted as a zero. This
337 /// extends isKnownNeverZero to cover the case where the assumed
338 /// floating-point mode for the function interprets denormals as zero.
339 bool isKnownNeverLogicalZero(const Function &F, Type *Ty) const;
340
341 /// Return true if it's know this can never be interpreted as a negative zero.
342 bool isKnownNeverLogicalNegZero(const Function &F, Type *Ty) const;
343
344 /// Return true if it's know this can never be interpreted as a positive zero.
345 bool isKnownNeverLogicalPosZero(const Function &F, Type *Ty) const;
346
351
352 /// Return true if we can prove that the analyzed floating-point value is
353 /// either NaN or never less than -0.0.
354 ///
355 /// NaN --> true
356 /// +0 --> true
357 /// -0 --> true
358 /// x > +0 --> true
359 /// x < -0 --> false
362 }
363
364 /// Return true if we can prove that the analyzed floating-point value is
365 /// either NaN or never greater than -0.0.
366 /// NaN --> true
367 /// +0 --> true
368 /// -0 --> true
369 /// x > +0 --> false
370 /// x < -0 --> true
373 }
374
376 KnownFPClasses = KnownFPClasses | RHS.KnownFPClasses;
377
378 if (SignBit != RHS.SignBit)
379 SignBit = std::nullopt;
380 return *this;
381 }
382
383 void knownNot(FPClassTest RuleOut) {
384 KnownFPClasses = KnownFPClasses & ~RuleOut;
385 if (isKnownNever(fcNan) && !SignBit) {
387 SignBit = false;
388 else if (isKnownNever(fcPositive))
389 SignBit = true;
390 }
391 }
392
393 void fneg() {
395 if (SignBit)
396 SignBit = !*SignBit;
397 }
398
399 void fabs() {
402
405
408
411
413 }
414
415 /// Return true if the sign bit must be 0, ignoring the sign of nans.
416 bool signBitIsZeroOrNaN() const {
417 return isKnownNever(fcNegative);
418 }
419
420 /// Assume the sign bit is zero.
423 SignBit = false;
424 }
425
426 /// Assume the sign bit is one.
429 SignBit = true;
430 }
431
432 void copysign(const KnownFPClass &Sign) {
433 // Don't know anything about the sign of the source. Expand the possible set
434 // to its opposite sign pair.
441 if (KnownFPClasses & fcInf)
443
444 // Sign bit is exactly preserved even for nans.
445 SignBit = Sign.SignBit;
446
447 // Clear sign bits based on the input sign mask.
448 if (Sign.isKnownNever(fcPositive | fcNan) || (SignBit && *SignBit))
450 if (Sign.isKnownNever(fcNegative | fcNan) || (SignBit && !*SignBit))
452 }
453
454 // Propagate knowledge that a non-NaN source implies the result can also not
455 // be a NaN. For unconstrained operations, signaling nans are not guaranteed
456 // to be quieted but cannot be introduced.
457 void propagateNaN(const KnownFPClass &Src, bool PreserveSign = false) {
458 if (Src.isKnownNever(fcNan)) {
460 if (PreserveSign)
461 SignBit = Src.SignBit;
462 } else if (Src.isKnownNever(fcSNan))
464 }
465
466 /// Propagate knowledge from a source value that could be a denormal or
467 /// zero. We have to be conservative since output flushing is not guaranteed,
468 /// so known-never-zero may not hold.
469 ///
470 /// This assumes a copy-like operation and will replace any currently known
471 /// information.
472 void propagateDenormal(const KnownFPClass &Src, const Function &F, Type *Ty);
473
474 /// Report known classes if \p Src is evaluated through a potentially
475 /// canonicalizing operation. We can assume signaling nans will not be
476 /// introduced, but cannot assume a denormal will be flushed under FTZ/DAZ.
477 ///
478 /// This assumes a copy-like operation and will replace any currently known
479 /// information.
480 void propagateCanonicalizingSrc(const KnownFPClass &Src, const Function &F,
481 Type *Ty);
482
483 void resetAll() { *this = KnownFPClass(); }
484};
485
487 LHS |= RHS;
488 return LHS;
489}
490
492 RHS |= LHS;
493 return std::move(RHS);
494}
495
496/// Determine which floating-point classes are valid for \p V, and return them
497/// in KnownFPClass bit sets.
498///
499/// This function is defined on values with floating-point type, values vectors
500/// of floating-point type, and arrays of floating-point type.
501
502/// \p InterestedClasses is a compile time optimization hint for which floating
503/// point classes should be queried. Queries not specified in \p
504/// InterestedClasses should be reliable if they are determined during the
505/// query.
506KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts,
507 FPClassTest InterestedClasses, unsigned Depth,
508 const SimplifyQuery &SQ);
509
510KnownFPClass computeKnownFPClass(const Value *V, FPClassTest InterestedClasses,
511 unsigned Depth, const SimplifyQuery &SQ);
512
514 const Value *V, const DataLayout &DL,
515 FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
516 const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
517 const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
518 bool UseInstrInfo = true) {
519 return computeKnownFPClass(
520 V, InterestedClasses, Depth,
521 SimplifyQuery(DL, TLI, DT, AC, CxtI, UseInstrInfo));
522}
523
524/// Wrapper to account for known fast math flags at the use instruction.
525inline KnownFPClass
526computeKnownFPClass(const Value *V, const APInt &DemandedElts,
527 FastMathFlags FMF, FPClassTest InterestedClasses,
528 unsigned Depth, const SimplifyQuery &SQ) {
529 if (FMF.noNaNs())
530 InterestedClasses &= ~fcNan;
531 if (FMF.noInfs())
532 InterestedClasses &= ~fcInf;
533
534 KnownFPClass Result =
535 computeKnownFPClass(V, DemandedElts, InterestedClasses, Depth, SQ);
536
537 if (FMF.noNaNs())
538 Result.KnownFPClasses &= ~fcNan;
539 if (FMF.noInfs())
540 Result.KnownFPClasses &= ~fcInf;
541 return Result;
542}
543
545 FPClassTest InterestedClasses,
546 unsigned Depth,
547 const SimplifyQuery &SQ) {
548 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
549 APInt DemandedElts =
550 FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
551 return computeKnownFPClass(V, DemandedElts, FMF, InterestedClasses, Depth,
552 SQ);
553}
554
555/// Return true if we can prove that the specified FP value is never equal to
556/// -0.0. Users should use caution when considering PreserveSign
557/// denormal-fp-math.
558inline bool cannotBeNegativeZero(const Value *V, unsigned Depth,
559 const SimplifyQuery &SQ) {
561 return Known.isKnownNeverNegZero();
562}
563
564/// Return true if we can prove that the specified FP value is either NaN or
565/// never less than -0.0.
566///
567/// NaN --> true
568/// +0 --> true
569/// -0 --> true
570/// x > +0 --> true
571/// x < -0 --> false
572inline bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth,
573 const SimplifyQuery &SQ) {
574 KnownFPClass Known =
576 return Known.cannotBeOrderedLessThanZero();
577}
578
579/// Return true if the floating-point scalar value is not an infinity or if
580/// the floating-point vector value has no infinities. Return false if a value
581/// could ever be infinity.
582inline bool isKnownNeverInfinity(const Value *V, unsigned Depth,
583 const SimplifyQuery &SQ) {
585 return Known.isKnownNeverInfinity();
586}
587
588/// Return true if the floating-point value can never contain a NaN or infinity.
589inline bool isKnownNeverInfOrNaN(const Value *V, unsigned Depth,
590 const SimplifyQuery &SQ) {
592 return Known.isKnownNeverNaN() && Known.isKnownNeverInfinity();
593}
594
595/// Return true if the floating-point scalar value is not a NaN or if the
596/// floating-point vector value has no NaN elements. Return false if a value
597/// could ever be NaN.
598inline bool isKnownNeverNaN(const Value *V, unsigned Depth,
599 const SimplifyQuery &SQ) {
601 return Known.isKnownNeverNaN();
602}
603
604/// Return false if we can prove that the specified FP value's sign bit is 0.
605/// Return true if we can prove that the specified FP value's sign bit is 1.
606/// Otherwise return std::nullopt.
607inline std::optional<bool> computeKnownFPSignBit(const Value *V, unsigned Depth,
608 const SimplifyQuery &SQ) {
610 return Known.SignBit;
611}
612
613/// If the specified value can be set by repeating the same byte in memory,
614/// return the i8 value that it is represented with. This is true for all i8
615/// values obviously, but is also true for i32 0, i32 -1, i16 0xF0F0, double
616/// 0.0 etc. If the value can't be handled with a repeated byte store (e.g.
617/// i16 0x1234), return null. If the value is entirely undef and padding,
618/// return undef.
619Value *isBytewiseValue(Value *V, const DataLayout &DL);
620
621/// Given an aggregate and an sequence of indices, see if the scalar value
622/// indexed is already around as a register, for example if it were inserted
623/// directly into the aggregate.
624///
625/// If InsertBefore is not empty, this function will duplicate (modified)
626/// insertvalues when a part of a nested struct is extracted.
627Value *FindInsertedValue(
628 Value *V, ArrayRef<unsigned> idx_range,
629 std::optional<BasicBlock::iterator> InsertBefore = std::nullopt);
630
631/// Analyze the specified pointer to see if it can be expressed as a base
632/// pointer plus a constant offset. Return the base and offset to the caller.
633///
634/// This is a wrapper around Value::stripAndAccumulateConstantOffsets that
635/// creates and later unpacks the required APInt.
637 const DataLayout &DL,
638 bool AllowNonInbounds = true) {
639 APInt OffsetAPInt(DL.getIndexTypeSizeInBits(Ptr->getType()), 0);
640 Value *Base =
641 Ptr->stripAndAccumulateConstantOffsets(DL, OffsetAPInt, AllowNonInbounds);
642
643 Offset = OffsetAPInt.getSExtValue();
644 return Base;
645}
646inline const Value *
648 const DataLayout &DL,
649 bool AllowNonInbounds = true) {
650 return GetPointerBaseWithConstantOffset(const_cast<Value *>(Ptr), Offset, DL,
651 AllowNonInbounds);
652}
653
654/// Returns true if the GEP is based on a pointer to a string (array of
655// \p CharSize integers) and is indexing into this string.
656bool isGEPBasedOnPointerToString(const GEPOperator *GEP, unsigned CharSize = 8);
657
658/// Represents offset+length into a ConstantDataArray.
660 /// ConstantDataArray pointer. nullptr indicates a zeroinitializer (a valid
661 /// initializer, it just doesn't fit the ConstantDataArray interface).
663
664 /// Slice starts at this Offset.
666
667 /// Length of the slice.
669
670 /// Moves the Offset and adjusts Length accordingly.
671 void move(uint64_t Delta) {
672 assert(Delta < Length);
673 Offset += Delta;
674 Length -= Delta;
675 }
676
677 /// Convenience accessor for elements in the slice.
678 uint64_t operator[](unsigned I) const {
679 return Array == nullptr ? 0 : Array->getElementAsInteger(I + Offset);
680 }
681};
682
683/// Returns true if the value \p V is a pointer into a ConstantDataArray.
684/// If successful \p Slice will point to a ConstantDataArray info object
685/// with an appropriate offset.
686bool getConstantDataArrayInfo(const Value *V, ConstantDataArraySlice &Slice,
687 unsigned ElementSize, uint64_t Offset = 0);
688
689/// This function computes the length of a null-terminated C string pointed to
690/// by V. If successful, it returns true and returns the string in Str. If
691/// unsuccessful, it returns false. This does not include the trailing null
692/// character by default. If TrimAtNul is set to false, then this returns any
693/// trailing null characters as well as any other characters that come after
694/// it.
695bool getConstantStringInfo(const Value *V, StringRef &Str,
696 bool TrimAtNul = true);
697
698/// If we can compute the length of the string pointed to by the specified
699/// pointer, return 'len+1'. If we can't, return 0.
700uint64_t GetStringLength(const Value *V, unsigned CharSize = 8);
701
702/// This function returns call pointer argument that is considered the same by
703/// aliasing rules. You CAN'T use it to replace one value with another. If
704/// \p MustPreserveNullness is true, the call must preserve the nullness of
705/// the pointer.
706const Value *getArgumentAliasingToReturnedPointer(const CallBase *Call,
707 bool MustPreserveNullness);
709 bool MustPreserveNullness) {
710 return const_cast<Value *>(getArgumentAliasingToReturnedPointer(
711 const_cast<const CallBase *>(Call), MustPreserveNullness));
712}
713
714/// {launder,strip}.invariant.group returns pointer that aliases its argument,
715/// and it only captures pointer by returning it.
716/// These intrinsics are not marked as nocapture, because returning is
717/// considered as capture. The arguments are not marked as returned neither,
718/// because it would make it useless. If \p MustPreserveNullness is true,
719/// the intrinsic must preserve the nullness of the pointer.
721 const CallBase *Call, bool MustPreserveNullness);
722
723/// This method strips off any GEP address adjustments, pointer casts
724/// or `llvm.threadlocal.address` from the specified value \p V, returning the
725/// original object being addressed. Note that the returned value has pointer
726/// type if the specified value does. If the \p MaxLookup value is non-zero, it
727/// limits the number of instructions to be stripped off.
728const Value *getUnderlyingObject(const Value *V, unsigned MaxLookup = 6);
729inline Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6) {
730 // Force const to avoid infinite recursion.
731 const Value *VConst = V;
732 return const_cast<Value *>(getUnderlyingObject(VConst, MaxLookup));
733}
734
735/// Like getUnderlyingObject(), but will try harder to find a single underlying
736/// object. In particular, this function also looks through selects and phis.
737const Value *getUnderlyingObjectAggressive(const Value *V);
738
739/// This method is similar to getUnderlyingObject except that it can
740/// look through phi and select instructions and return multiple objects.
741///
742/// If LoopInfo is passed, loop phis are further analyzed. If a pointer
743/// accesses different objects in each iteration, we don't look through the
744/// phi node. E.g. consider this loop nest:
745///
746/// int **A;
747/// for (i)
748/// for (j) {
749/// A[i][j] = A[i-1][j] * B[j]
750/// }
751///
752/// This is transformed by Load-PRE to stash away A[i] for the next iteration
753/// of the outer loop:
754///
755/// Curr = A[0]; // Prev_0
756/// for (i: 1..N) {
757/// Prev = Curr; // Prev = PHI (Prev_0, Curr)
758/// Curr = A[i];
759/// for (j: 0..N) {
760/// Curr[j] = Prev[j] * B[j]
761/// }
762/// }
763///
764/// Since A[i] and A[i-1] are independent pointers, getUnderlyingObjects
765/// should not assume that Curr and Prev share the same underlying object thus
766/// it shouldn't look through the phi above.
767void getUnderlyingObjects(const Value *V,
768 SmallVectorImpl<const Value *> &Objects,
769 const LoopInfo *LI = nullptr, unsigned MaxLookup = 6);
770
771/// This is a wrapper around getUnderlyingObjects and adds support for basic
772/// ptrtoint+arithmetic+inttoptr sequences.
773bool getUnderlyingObjectsForCodeGen(const Value *V,
774 SmallVectorImpl<Value *> &Objects);
775
776/// Returns unique alloca where the value comes from, or nullptr.
777/// If OffsetZero is true check that V points to the begining of the alloca.
778AllocaInst *findAllocaForValue(Value *V, bool OffsetZero = false);
779inline const AllocaInst *findAllocaForValue(const Value *V,
780 bool OffsetZero = false) {
781 return findAllocaForValue(const_cast<Value *>(V), OffsetZero);
782}
783
784/// Return true if the only users of this pointer are lifetime markers.
785bool onlyUsedByLifetimeMarkers(const Value *V);
786
787/// Return true if the only users of this pointer are lifetime markers or
788/// droppable instructions.
790
791/// Return true if the instruction doesn't potentially cross vector lanes. This
792/// condition is weaker than checking that the instruction is lanewise: lanewise
793/// means that the same operation is splatted across all lanes, but we also
794/// include the case where there is a different operation on each lane, as long
795/// as the operation only uses data from that lane. An example of an operation
796/// that is not lanewise, but doesn't cross vector lanes is insertelement.
797bool isNotCrossLaneOperation(const Instruction *I);
798
799/// Return true if the instruction does not have any effects besides
800/// calculating the result and does not have undefined behavior.
801///
802/// This method never returns true for an instruction that returns true for
803/// mayHaveSideEffects; however, this method also does some other checks in
804/// addition. It checks for undefined behavior, like dividing by zero or
805/// loading from an invalid pointer (but not for undefined results, like a
806/// shift with a shift amount larger than the width of the result). It checks
807/// for malloc and alloca because speculatively executing them might cause a
808/// memory leak. It also returns false for instructions related to control
809/// flow, specifically terminators and PHI nodes.
810///
811/// If the CtxI is specified this method performs context-sensitive analysis
812/// and returns true if it is safe to execute the instruction immediately
813/// before the CtxI. If the instruction has (transitive) operands that don't
814/// dominate CtxI, the analysis is performed under the assumption that these
815/// operands will also be speculated to a point before CxtI.
816///
817/// If the CtxI is NOT specified this method only looks at the instruction
818/// itself and its operands, so if this method returns true, it is safe to
819/// move the instruction as long as the correct dominance relationships for
820/// the operands and users hold.
821///
822/// This method can return true for instructions that read memory;
823/// for such instructions, moving them may change the resulting value.
824bool isSafeToSpeculativelyExecute(const Instruction *I,
825 const Instruction *CtxI = nullptr,
826 AssumptionCache *AC = nullptr,
827 const DominatorTree *DT = nullptr,
828 const TargetLibraryInfo *TLI = nullptr,
829 bool UseVariableInfo = true);
830
833 AssumptionCache *AC = nullptr,
834 const DominatorTree *DT = nullptr,
835 const TargetLibraryInfo *TLI = nullptr,
836 bool UseVariableInfo = true) {
837 // Take an iterator, and unwrap it into an Instruction *.
838 return isSafeToSpeculativelyExecute(I, &*CtxI, AC, DT, TLI, UseVariableInfo);
839}
840
841/// Don't use information from its non-constant operands. This helper is used
842/// when its operands are going to be replaced.
843inline bool
845 return isSafeToSpeculativelyExecute(I, nullptr, nullptr, nullptr, nullptr,
846 /*UseVariableInfo=*/false);
847}
848
849/// This returns the same result as isSafeToSpeculativelyExecute if Opcode is
850/// the actual opcode of Inst. If the provided and actual opcode differ, the
851/// function (virtually) overrides the opcode of Inst with the provided
852/// Opcode. There are come constraints in this case:
853/// * If Opcode has a fixed number of operands (eg, as binary operators do),
854/// then Inst has to have at least as many leading operands. The function
855/// will ignore all trailing operands beyond that number.
856/// * If Opcode allows for an arbitrary number of operands (eg, as CallInsts
857/// do), then all operands are considered.
858/// * The virtual instruction has to satisfy all typing rules of the provided
859/// Opcode.
860/// * This function is pessimistic in the following sense: If one actually
861/// materialized the virtual instruction, then isSafeToSpeculativelyExecute
862/// may say that the materialized instruction is speculatable whereas this
863/// function may have said that the instruction wouldn't be speculatable.
864/// This behavior is a shortcoming in the current implementation and not
865/// intentional.
867 unsigned Opcode, const Instruction *Inst, const Instruction *CtxI = nullptr,
868 AssumptionCache *AC = nullptr, const DominatorTree *DT = nullptr,
869 const TargetLibraryInfo *TLI = nullptr, bool UseVariableInfo = true);
870
871/// Returns true if the result or effects of the given instructions \p I
872/// depend values not reachable through the def use graph.
873/// * Memory dependence arises for example if the instruction reads from
874/// memory or may produce effects or undefined behaviour. Memory dependent
875/// instructions generally cannot be reorderd with respect to other memory
876/// dependent instructions.
877/// * Control dependence arises for example if the instruction may fault
878/// if lifted above a throwing call or infinite loop.
879bool mayHaveNonDefUseDependency(const Instruction &I);
880
881/// Return true if it is an intrinsic that cannot be speculated but also
882/// cannot trap.
883bool isAssumeLikeIntrinsic(const Instruction *I);
884
885/// Return true if it is valid to use the assumptions provided by an
886/// assume intrinsic, I, at the point in the control-flow identified by the
887/// context instruction, CxtI. By default, ephemeral values of the assumption
888/// are treated as an invalid context, to prevent the assumption from being used
889/// to optimize away its argument. If the caller can ensure that this won't
890/// happen, it can call with AllowEphemerals set to true to get more valid
891/// assumptions.
892bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI,
893 const DominatorTree *DT = nullptr,
894 bool AllowEphemerals = false);
895
896enum class OverflowResult {
897 /// Always overflows in the direction of signed/unsigned min value.
899 /// Always overflows in the direction of signed/unsigned max value.
901 /// May or may not overflow.
903 /// Never overflows.
905};
906
907OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS,
908 const SimplifyQuery &SQ,
909 bool IsNSW = false);
910OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS,
911 const SimplifyQuery &SQ);
913computeOverflowForUnsignedAdd(const WithCache<const Value *> &LHS,
914 const WithCache<const Value *> &RHS,
915 const SimplifyQuery &SQ);
916OverflowResult computeOverflowForSignedAdd(const WithCache<const Value *> &LHS,
917 const WithCache<const Value *> &RHS,
918 const SimplifyQuery &SQ);
919/// This version also leverages the sign bit of Add if known.
921 const SimplifyQuery &SQ);
922OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS,
923 const SimplifyQuery &SQ);
924OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS,
925 const SimplifyQuery &SQ);
926
927/// Returns true if the arithmetic part of the \p WO 's result is
928/// used only along the paths control dependent on the computation
929/// not overflowing, \p WO being an <op>.with.overflow intrinsic.
930bool isOverflowIntrinsicNoWrap(const WithOverflowInst *WO,
931 const DominatorTree &DT);
932
933/// Determine the possible constant range of vscale with the given bit width,
934/// based on the vscale_range function attribute.
935ConstantRange getVScaleRange(const Function *F, unsigned BitWidth);
936
937/// Determine the possible constant range of an integer or vector of integer
938/// value. This is intended as a cheap, non-recursive check.
939ConstantRange computeConstantRange(const Value *V, bool ForSigned,
940 bool UseInstrInfo = true,
941 AssumptionCache *AC = nullptr,
942 const Instruction *CtxI = nullptr,
943 const DominatorTree *DT = nullptr,
944 unsigned Depth = 0);
945
946/// Combine constant ranges from computeConstantRange() and computeKnownBits().
947ConstantRange
948computeConstantRangeIncludingKnownBits(const WithCache<const Value *> &V,
949 bool ForSigned, const SimplifyQuery &SQ);
950
951/// Return true if this function can prove that the instruction I will
952/// always transfer execution to one of its successors (including the next
953/// instruction that follows within a basic block). E.g. this is not
954/// guaranteed for function calls that could loop infinitely.
955///
956/// In other words, this function returns false for instructions that may
957/// transfer execution or fail to transfer execution in a way that is not
958/// captured in the CFG nor in the sequence of instructions within a basic
959/// block.
960///
961/// Undefined behavior is assumed not to happen, so e.g. division is
962/// guaranteed to transfer execution to the following instruction even
963/// though division by zero might cause undefined behavior.
964bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I);
965
966/// Returns true if this block does not contain a potential implicit exit.
967/// This is equivelent to saying that all instructions within the basic block
968/// are guaranteed to transfer execution to their successor within the basic
969/// block. This has the same assumptions w.r.t. undefined behavior as the
970/// instruction variant of this function.
971bool isGuaranteedToTransferExecutionToSuccessor(const BasicBlock *BB);
972
973/// Return true if every instruction in the range (Begin, End) is
974/// guaranteed to transfer execution to its static successor. \p ScanLimit
975/// bounds the search to avoid scanning huge blocks.
978 unsigned ScanLimit = 32);
979
980/// Same as previous, but with range expressed via iterator_range.
982 iterator_range<BasicBlock::const_iterator> Range, unsigned ScanLimit = 32);
983
984/// Return true if this function can prove that the instruction I
985/// is executed for every iteration of the loop L.
986///
987/// Note that this currently only considers the loop header.
988bool isGuaranteedToExecuteForEveryIteration(const Instruction *I,
989 const Loop *L);
990
991/// Return true if \p PoisonOp's user yields poison or raises UB if its
992/// operand \p PoisonOp is poison.
993///
994/// If \p PoisonOp is a vector or an aggregate and the operation's result is a
995/// single value, any poison element in /p PoisonOp should make the result
996/// poison or raise UB.
997///
998/// To filter out operands that raise UB on poison, you can use
999/// getGuaranteedNonPoisonOp.
1000bool propagatesPoison(const Use &PoisonOp);
1001
1002/// Insert operands of I into Ops such that I will trigger undefined behavior
1003/// if I is executed and that operand has a poison value.
1004void getGuaranteedNonPoisonOps(const Instruction *I,
1005 SmallVectorImpl<const Value *> &Ops);
1006
1007/// Insert operands of I into Ops such that I will trigger undefined behavior
1008/// if I is executed and that operand is not a well-defined value
1009/// (i.e. has undef bits or poison).
1010void getGuaranteedWellDefinedOps(const Instruction *I,
1011 SmallVectorImpl<const Value *> &Ops);
1012
1013/// Return true if the given instruction must trigger undefined behavior
1014/// when I is executed with any operands which appear in KnownPoison holding
1015/// a poison value at the point of execution.
1016bool mustTriggerUB(const Instruction *I,
1017 const SmallPtrSetImpl<const Value *> &KnownPoison);
1018
1019/// Return true if this function can prove that if Inst is executed
1020/// and yields a poison value or undef bits, then that will trigger
1021/// undefined behavior.
1022///
1023/// Note that this currently only considers the basic block that is
1024/// the parent of Inst.
1025bool programUndefinedIfUndefOrPoison(const Instruction *Inst);
1026bool programUndefinedIfPoison(const Instruction *Inst);
1027
1028/// canCreateUndefOrPoison returns true if Op can create undef or poison from
1029/// non-undef & non-poison operands.
1030/// For vectors, canCreateUndefOrPoison returns true if there is potential
1031/// poison or undef in any element of the result when vectors without
1032/// undef/poison poison are given as operands.
1033/// For example, given `Op = shl <2 x i32> %x, <0, 32>`, this function returns
1034/// true. If Op raises immediate UB but never creates poison or undef
1035/// (e.g. sdiv I, 0), canCreatePoison returns false.
1036///
1037/// \p ConsiderFlagsAndMetadata controls whether poison producing flags and
1038/// metadata on the instruction are considered. This can be used to see if the
1039/// instruction could still introduce undef or poison even without poison
1040/// generating flags and metadata which might be on the instruction.
1041/// (i.e. could the result of Op->dropPoisonGeneratingFlags() still create
1042/// poison or undef)
1043///
1044/// canCreatePoison returns true if Op can create poison from non-poison
1045/// operands.
1046bool canCreateUndefOrPoison(const Operator *Op,
1047 bool ConsiderFlagsAndMetadata = true);
1048bool canCreatePoison(const Operator *Op, bool ConsiderFlagsAndMetadata = true);
1049
1050/// Return true if V is poison given that ValAssumedPoison is already poison.
1051/// For example, if ValAssumedPoison is `icmp X, 10` and V is `icmp X, 5`,
1052/// impliesPoison returns true.
1053bool impliesPoison(const Value *ValAssumedPoison, const Value *V);
1054
1055/// Return true if this function can prove that V does not have undef bits
1056/// and is never poison. If V is an aggregate value or vector, check whether
1057/// all elements (except padding) are not undef or poison.
1058/// Note that this is different from canCreateUndefOrPoison because the
1059/// function assumes Op's operands are not poison/undef.
1060///
1061/// If CtxI and DT are specified this method performs flow-sensitive analysis
1062/// and returns true if it is guaranteed to be never undef or poison
1063/// immediately before the CtxI.
1064bool isGuaranteedNotToBeUndefOrPoison(const Value *V,
1065 AssumptionCache *AC = nullptr,
1066 const Instruction *CtxI = nullptr,
1067 const DominatorTree *DT = nullptr,
1068 unsigned Depth = 0);
1069
1070/// Returns true if V cannot be poison, but may be undef.
1071bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC = nullptr,
1072 const Instruction *CtxI = nullptr,
1073 const DominatorTree *DT = nullptr,
1074 unsigned Depth = 0);
1075
1078 const DominatorTree *DT = nullptr,
1079 unsigned Depth = 0) {
1080 // Takes an iterator as a position, passes down to Instruction *
1081 // implementation.
1082 return isGuaranteedNotToBePoison(V, AC, &*CtxI, DT, Depth);
1083}
1084
1085/// Returns true if V cannot be undef, but may be poison.
1086bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC = nullptr,
1087 const Instruction *CtxI = nullptr,
1088 const DominatorTree *DT = nullptr,
1089 unsigned Depth = 0);
1090
1091/// Return true if undefined behavior would provable be executed on the path to
1092/// OnPathTo if Root produced a posion result. Note that this doesn't say
1093/// anything about whether OnPathTo is actually executed or whether Root is
1094/// actually poison. This can be used to assess whether a new use of Root can
1095/// be added at a location which is control equivalent with OnPathTo (such as
1096/// immediately before it) without introducing UB which didn't previously
1097/// exist. Note that a false result conveys no information.
1098bool mustExecuteUBIfPoisonOnPathTo(Instruction *Root,
1099 Instruction *OnPathTo,
1100 DominatorTree *DT);
1101
1102/// Convert an integer comparison with a constant RHS into an equivalent
1103/// form with the strictness flipped predicate. Return the new predicate and
1104/// corresponding constant RHS if possible. Otherwise return std::nullopt.
1105/// E.g., (icmp sgt X, 0) -> (icmp sle X, 1).
1106std::optional<std::pair<CmpPredicate, Constant *>>
1107getFlippedStrictnessPredicateAndConstant(CmpPredicate Pred, Constant *C);
1108
1109/// Specific patterns of select instructions we can match.
1112 SPF_SMIN, /// Signed minimum
1113 SPF_UMIN, /// Unsigned minimum
1114 SPF_SMAX, /// Signed maximum
1115 SPF_UMAX, /// Unsigned maximum
1116 SPF_FMINNUM, /// Floating point minnum
1117 SPF_FMAXNUM, /// Floating point maxnum
1118 SPF_ABS, /// Absolute value
1119 SPF_NABS /// Negated absolute value
1121
1122/// Behavior when a floating point min/max is given one NaN and one
1123/// non-NaN as input.
1125 SPNB_NA = 0, /// NaN behavior not applicable.
1126 SPNB_RETURNS_NAN, /// Given one NaN input, returns the NaN.
1127 SPNB_RETURNS_OTHER, /// Given one NaN input, returns the non-NaN.
1128 SPNB_RETURNS_ANY /// Given one NaN input, can return either (or
1129 /// it has been determined that no operands can
1130 /// be NaN).
1132
1135 SelectPatternNaNBehavior NaNBehavior; /// Only applicable if Flavor is
1136 /// SPF_FMINNUM or SPF_FMAXNUM.
1137 bool Ordered; /// When implementing this min/max pattern as
1138 /// fcmp; select, does the fcmp have to be
1139 /// ordered?
1140
1141 /// Return true if \p SPF is a min or a max pattern.
1143 return SPF != SPF_UNKNOWN && SPF != SPF_ABS && SPF != SPF_NABS;
1144 }
1145};
1146
1147/// Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind
1148/// and providing the out parameter results if we successfully match.
1149///
1150/// For ABS/NABS, LHS will be set to the input to the abs idiom. RHS will be
1151/// the negation instruction from the idiom.
1152///
1153/// If CastOp is not nullptr, also match MIN/MAX idioms where the type does
1154/// not match that of the original select. If this is the case, the cast
1155/// operation (one of Trunc,SExt,Zext) that must be done to transform the
1156/// type of LHS and RHS into the type of V is returned in CastOp.
1157///
1158/// For example:
1159/// %1 = icmp slt i32 %a, i32 4
1160/// %2 = sext i32 %a to i64
1161/// %3 = select i1 %1, i64 %2, i64 4
1162///
1163/// -> LHS = %a, RHS = i32 4, *CastOp = Instruction::SExt
1164///
1165SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS,
1166 Instruction::CastOps *CastOp = nullptr,
1167 unsigned Depth = 0);
1168
1170 const Value *&RHS) {
1171 Value *L = const_cast<Value *>(LHS);
1172 Value *R = const_cast<Value *>(RHS);
1173 auto Result = matchSelectPattern(const_cast<Value *>(V), L, R);
1174 LHS = L;
1175 RHS = R;
1176 return Result;
1177}
1178
1179/// Determine the pattern that a select with the given compare as its
1180/// predicate and given values as its true/false operands would match.
1181SelectPatternResult matchDecomposedSelectPattern(
1182 CmpInst *CmpI, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS,
1183 Instruction::CastOps *CastOp = nullptr, unsigned Depth = 0);
1184
1185/// Determine the pattern for predicate `X Pred Y ? X : Y`.
1186SelectPatternResult
1188 SelectPatternNaNBehavior NaNBehavior = SPNB_NA,
1189 bool Ordered = false);
1190
1191/// Return the canonical comparison predicate for the specified
1192/// minimum/maximum flavor.
1193CmpInst::Predicate getMinMaxPred(SelectPatternFlavor SPF, bool Ordered = false);
1194
1195/// Convert given `SPF` to equivalent min/max intrinsic.
1196/// Caller must ensure `SPF` is an integer min or max pattern.
1198
1199/// Return the inverse minimum/maximum flavor of the specified flavor.
1200/// For example, signed minimum is the inverse of signed maximum.
1202
1204
1205/// Return the minimum or maximum constant value for the specified integer
1206/// min/max flavor and type.
1207APInt getMinMaxLimit(SelectPatternFlavor SPF, unsigned BitWidth);
1208
1209/// Check if the values in \p VL are select instructions that can be converted
1210/// to a min or max (vector) intrinsic. Returns the intrinsic ID, if such a
1211/// conversion is possible, together with a bool indicating whether all select
1212/// conditions are only used by the selects. Otherwise return
1213/// Intrinsic::not_intrinsic.
1214std::pair<Intrinsic::ID, bool>
1215canConvertToMinOrMaxIntrinsic(ArrayRef<Value *> VL);
1216
1217/// Attempt to match a simple first order recurrence cycle of the form:
1218/// %iv = phi Ty [%Start, %Entry], [%Inc, %backedge]
1219/// %inc = binop %iv, %step
1220/// OR
1221/// %iv = phi Ty [%Start, %Entry], [%Inc, %backedge]
1222/// %inc = binop %step, %iv
1223///
1224/// A first order recurrence is a formula with the form: X_n = f(X_(n-1))
1225///
1226/// A couple of notes on subtleties in that definition:
1227/// * The Step does not have to be loop invariant. In math terms, it can
1228/// be a free variable. We allow recurrences with both constant and
1229/// variable coefficients. Callers may wish to filter cases where Step
1230/// does not dominate P.
1231/// * For non-commutative operators, we will match both forms. This
1232/// results in some odd recurrence structures. Callers may wish to filter
1233/// out recurrences where the phi is not the LHS of the returned operator.
1234/// * Because of the structure matched, the caller can assume as a post
1235/// condition of the match the presence of a Loop with P's parent as it's
1236/// header *except* in unreachable code. (Dominance decays in unreachable
1237/// code.)
1238///
1239/// NOTE: This is intentional simple. If you want the ability to analyze
1240/// non-trivial loop conditons, see ScalarEvolution instead.
1241bool matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO, Value *&Start,
1242 Value *&Step);
1243
1244/// Analogous to the above, but starting from the binary operator
1245bool matchSimpleRecurrence(const BinaryOperator *I, PHINode *&P, Value *&Start,
1246 Value *&Step);
1247
1248/// Return true if RHS is known to be implied true by LHS. Return false if
1249/// RHS is known to be implied false by LHS. Otherwise, return std::nullopt if
1250/// no implication can be made. A & B must be i1 (boolean) values or a vector of
1251/// such values. Note that the truth table for implication is the same as <=u on
1252/// i1 values (but not
1253/// <=s!). The truth table for both is:
1254/// | T | F (B)
1255/// T | T | F
1256/// F | T | T
1257/// (A)
1258std::optional<bool> isImpliedCondition(const Value *LHS, const Value *RHS,
1259 const DataLayout &DL,
1260 bool LHSIsTrue = true,
1261 unsigned Depth = 0);
1262std::optional<bool> isImpliedCondition(const Value *LHS, CmpPredicate RHSPred,
1263 const Value *RHSOp0, const Value *RHSOp1,
1264 const DataLayout &DL,
1265 bool LHSIsTrue = true,
1266 unsigned Depth = 0);
1267
1268/// Return the boolean condition value in the context of the given instruction
1269/// if it is known based on dominating conditions.
1270std::optional<bool> isImpliedByDomCondition(const Value *Cond,
1271 const Instruction *ContextI,
1272 const DataLayout &DL);
1273std::optional<bool> isImpliedByDomCondition(CmpPredicate Pred, const Value *LHS,
1274 const Value *RHS,
1275 const Instruction *ContextI,
1276 const DataLayout &DL);
1277
1278/// Call \p InsertAffected on all Values whose known bits / value may be
1279/// affected by the condition \p Cond. Used by AssumptionCache and
1280/// DomConditionCache.
1281void findValuesAffectedByCondition(Value *Cond, bool IsAssume,
1282 function_ref<void(Value *)> InsertAffected);
1283
1284} // end namespace llvm
1285
1286#endif // LLVM_ANALYSIS_VALUETRACKING_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool End
Definition: ELF_riscv.cpp:480
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Hexagon Common GEP
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition: APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition: APInt.h:234
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1542
an instruction to allocate memory on the stack
Definition: Instructions.h:63
A cache of @llvm.assume calls within a function.
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:178
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:177
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1112
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Definition: Constants.h:696
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Definition: Constants.cpp:3115
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
bool noInfs() const
Definition: FMF.h:67
bool noNaNs() const
Definition: FMF.h:66
Metadata node.
Definition: Metadata.h:1073
This is a utility class that provides an abstraction for the common functionality between Instruction...
Definition: Operator.h:32
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
@ 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
bool haveNoCommonBitsSet(const WithCache< const Value * > &LHSCache, const WithCache< const Value * > &RHSCache, const SimplifyQuery &SQ)
Return true if LHS and RHS have no common bits set.
bool mustExecuteUBIfPoisonOnPathTo(Instruction *Root, Instruction *OnPathTo, DominatorTree *DT)
Return true if undefined behavior would provable be executed on the path to OnPathTo if Root produced...
Intrinsic::ID getInverseMinMaxIntrinsic(Intrinsic::ID MinMaxID)
@ Offset
Definition: DWP.cpp:480
OverflowResult
@ NeverOverflows
Never overflows.
@ AlwaysOverflowsHigh
Always overflows in the direction of signed/unsigned max value.
@ AlwaysOverflowsLow
Always overflows in the direction of signed/unsigned min value.
@ MayOverflow
May or may not overflow.
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
bool canCreatePoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
bool mustTriggerUB(const Instruction *I, const SmallPtrSetImpl< const Value * > &KnownPoison)
Return true if the given instruction must trigger undefined behavior when I is executed with any oper...
bool isSafeToSpeculativelyExecuteWithVariableReplaced(const Instruction *I)
Don't use information from its non-constant operands.
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS, bool &TrueIfSigned)
Given an exploded icmp instruction, return true if the comparison only checks the sign bit.
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call, bool MustPreserveNullness)
This function returns call pointer argument that is considered the same by aliasing rules.
bool isAssumeLikeIntrinsic(const Instruction *I)
Return true if it is an intrinsic that cannot be speculated but also cannot trap.
AllocaInst * findAllocaForValue(Value *V, bool OffsetZero=false)
Returns unique alloca where the value comes from, or nullptr.
APInt getMinMaxLimit(SelectPatternFlavor SPF, unsigned BitWidth)
Return the minimum or maximum constant value for the specified integer min/max flavor and type.
bool isKnownNeverInfinity(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if the floating-point scalar value is not an infinity or if the floating-point vector val...
void getGuaranteedNonPoisonOps(const Instruction *I, SmallVectorImpl< const Value * > &Ops)
Insert operands of I into Ops such that I will trigger undefined behavior if I is executed and that o...
bool isOnlyUsedInZeroComparison(const Instruction *CxtI)
bool getConstantStringInfo(const Value *V, StringRef &Str, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
bool onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V)
Return true if the only users of this pointer are lifetime markers or droppable instructions.
bool getUnderlyingObjectsForCodeGen(const Value *V, SmallVectorImpl< Value * > &Objects)
This is a wrapper around getUnderlyingObjects and adds support for basic ptrtoint+arithmetic+inttoptr...
std::pair< Intrinsic::ID, bool > canConvertToMinOrMaxIntrinsic(ArrayRef< Value * > VL)
Check if the values in VL are select instructions that can be converted to a min or max (vector) intr...
bool getConstantDataArrayInfo(const Value *V, ConstantDataArraySlice &Slice, unsigned ElementSize, uint64_t Offset=0)
Returns true if the value V is a pointer into a ConstantDataArray.
bool isGuaranteedToExecuteForEveryIteration(const Instruction *I, const Loop *L)
Return true if this function can prove that the instruction I is executed for every iteration of the ...
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL, bool AllowNonInbounds=true)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset.
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined.
bool isKnownNeverInfOrNaN(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if the floating-point value can never contain a NaN or infinity.
CmpInst::Predicate getMinMaxPred(SelectPatternFlavor SPF, bool Ordered=false)
Return the canonical comparison predicate for the specified minimum/maximum flavor.
void computeKnownBitsFromContext(const Value *V, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q)
Merge bits known from context-dependent facts into Known.
bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
ConstantRange computeConstantRange(const Value *V, bool ForSigned, bool UseInstrInfo=true, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Determine the possible constant range of an integer or vector of integer value.
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if 'V & Mask' is known to be zero.
bool isOverflowIntrinsicNoWrap(const WithOverflowInst *WO, const DominatorTree &DT)
Returns true if the arithmetic part of the WO 's result is used only along the paths control dependen...
bool matchSimpleRecurrence(const PHINode *P, BinaryOperator *&BO, Value *&Start, Value *&Step)
Attempt to match a simple first order recurrence cycle of the form: iv = phi Ty [Start,...
bool isSafeToSpeculativelyExecuteWithOpcode(unsigned Opcode, const Instruction *Inst, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr, bool UseVariableInfo=true)
This returns the same result as isSafeToSpeculativelyExecute if Opcode is the actual opcode of Inst.
KnownBits analyzeKnownBitsFromAndXorOr(const Operator *I, const KnownBits &KnownLHS, const KnownBits &KnownRHS, unsigned Depth, const SimplifyQuery &SQ)
Using KnownBits LHS/RHS produce the known bits for logic op (and/xor/or).
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ, bool IsNSW=false)
SelectPatternFlavor getInverseMinMaxFlavor(SelectPatternFlavor SPF)
Return the inverse minimum/maximum flavor of the specified flavor.
constexpr unsigned MaxAnalysisRecursionDepth
Definition: ValueTracking.h:44
bool isKnownNegative(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the given value is known be negative (i.e.
void getGuaranteedWellDefinedOps(const Instruction *I, SmallVectorImpl< const Value * > &Ops)
Insert operands of I into Ops such that I will trigger undefined behavior if I is executed and that o...
FPClassTest fneg(FPClassTest Mask)
Return the test mask which returns true if the value's sign bit is flipped.
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
std::tuple< Value *, FPClassTest, FPClassTest > fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, Value *RHS, bool LookThroughSrc=true)
Compute the possible floating-point classes that LHS could be based on fcmp \Pred LHS,...
SelectPatternFlavor
Specific patterns of select instructions we can match.
@ SPF_ABS
Floating point maxnum.
@ SPF_NABS
Absolute value.
@ SPF_FMAXNUM
Floating point minnum.
@ SPF_UMIN
Signed minimum.
@ SPF_UMAX
Signed maximum.
@ SPF_SMAX
Unsigned minimum.
@ SPF_UNKNOWN
@ SPF_FMINNUM
Unsigned maximum.
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call, bool MustPreserveNullness)
{launder,strip}.invariant.group returns pointer that aliases its argument, and it only captures point...
void adjustKnownBitsForSelectArm(KnownBits &Known, Value *Cond, Value *Arm, bool Invert, unsigned Depth, const SimplifyQuery &Q)
Adjust Known for the given select Arm to include information from the select Cond.
bool impliesPoison(const Value *ValAssumedPoison, const Value *V)
Return true if V is poison given that ValAssumedPoison is already poison.
SelectPatternResult getSelectPattern(CmpInst::Predicate Pred, SelectPatternNaNBehavior NaNBehavior=SPNB_NA, bool Ordered=false)
Determine the pattern for predicate X Pred Y ? X : Y.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
bool programUndefinedIfPoison(const Instruction *Inst)
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
bool programUndefinedIfUndefOrPoison(const Instruction *Inst)
Return true if this function can prove that if Inst is executed and yields a poison value or undef bi...
bool isSafeToSpeculativelyExecute(const Instruction *I, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr, bool UseVariableInfo=true)
Return true if the instruction does not have any effects besides calculating the result and does not ...
uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'.
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)
Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...
bool canCreateUndefOrPoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
canCreateUndefOrPoison returns true if Op can create undef or poison from non-undef & non-poison oper...
bool isKnownInversion(const Value *X, const Value *Y)
Return true iff:
bool isNotCrossLaneOperation(const Instruction *I)
Return true if the instruction doesn't potentially cross vector lanes.
bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
bool onlyUsedByLifetimeMarkers(const Value *V)
Return true if the only users of this pointer are lifetime markers.
Intrinsic::ID getIntrinsicForCallSite(const CallBase &CB, const TargetLibraryInfo *TLI)
Map a call instruction to an intrinsic ID.
@ Other
Any other memory.
const Value * getUnderlyingObjectAggressive(const Value *V)
Like getUnderlyingObject(), but will try harder to find a single underlying object.
Intrinsic::ID getMinMaxIntrinsic(SelectPatternFlavor SPF)
Convert given SPF to equivalent min/max intrinsic.
OverflowResult computeOverflowForSignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const SimplifyQuery &SQ)
bool propagatesPoison(const Use &PoisonOp)
Return true if PoisonOp's user yields poison or raises UB if its operand PoisonOp is poison.
@ Add
Sum of integers.
ConstantRange computeConstantRangeIncludingKnownBits(const WithCache< const Value * > &V, bool ForSigned, const SimplifyQuery &SQ)
Combine constant ranges from computeConstantRange() and computeKnownBits().
SelectPatternNaNBehavior
Behavior when a floating point min/max is given one NaN and one non-NaN as input.
@ SPNB_RETURNS_NAN
NaN behavior not applicable.
@ SPNB_RETURNS_OTHER
Given one NaN input, returns the NaN.
@ SPNB_RETURNS_ANY
Given one NaN input, returns the non-NaN.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
bool isKnownNonEqual(const Value *V1, const Value *V2, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the given values are known to be non-equal when defined.
DWARFExpression::Operation Op
bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:217
SelectPatternResult matchDecomposedSelectPattern(CmpInst *CmpI, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Determine the pattern that a select with the given compare as its predicate and given values as its t...
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const SimplifyQuery &SQ)
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
std::pair< Value *, FPClassTest > fcmpToClassTest(CmpInst::Predicate Pred, const Function &F, Value *LHS, Value *RHS, bool LookThroughSrc=true)
Returns a pair of values, which if passed to llvm.is.fpclass, returns the same result as an fcmp with...
Value * isBytewiseValue(Value *V, const DataLayout &DL)
If the specified value can be set by repeating the same byte in memory, return the i8 value that it i...
std::optional< std::pair< CmpPredicate, Constant * > > getFlippedStrictnessPredicateAndConstant(CmpPredicate Pred, Constant *C)
Convert an integer comparison with a constant RHS into an equivalent form with the strictness flipped...
void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, const LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
std::optional< bool > computeKnownFPSignBit(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return false if we can prove that the specified FP value's sign bit is 0.
bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if we can prove that the specified FP value is either NaN or never less than -0....
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits.
bool cannotBeNegativeZero(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if we can prove that the specified FP value is never equal to -0.0.
OverflowResult computeOverflowForUnsignedAdd(const WithCache< const Value * > &LHS, const WithCache< const Value * > &RHS, const SimplifyQuery &SQ)
bool isKnownNeverNaN(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
std::optional< bool > isImpliedByDomCondition(const Value *Cond, const Instruction *ContextI, const DataLayout &DL)
Return the boolean condition value in the context of the given instruction if it is known based on do...
bool isGEPBasedOnPointerToString(const GEPOperator *GEP, unsigned CharSize=8)
Returns true if the GEP is based on a pointer to a string (array of.
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2112
bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, unsigned Depth, const SimplifyQuery &SQ)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
Value * FindInsertedValue(Value *V, ArrayRef< unsigned > idx_range, std::optional< BasicBlock::iterator > InsertBefore=std::nullopt)
Given an aggregate and an sequence of indices, see if the scalar value indexed is already around as a...
bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW=false, bool AllowPoison=true)
Return true if the two given values are negation.
bool isKnownPositive(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the given value is known be positive (i.e.
bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Returns true if the give value is known to be non-negative.
unsigned ComputeMaxSignificantBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Get the upper bound on bit size for this Value Op as a signed integer.
bool mayHaveNonDefUseDependency(const Instruction &I)
Returns true if the result or effects of the given instructions I depend values not reachable through...
std::optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsTrue=true, unsigned Depth=0)
Return true if RHS is known to be implied true by LHS.
void findValuesAffectedByCondition(Value *Cond, bool IsAssume, function_ref< void(Value *)> InsertAffected)
Call InsertAffected on all Values whose known bits / value may be affected by the condition Cond.
Represents offset+length into a ConstantDataArray.
uint64_t Length
Length of the slice.
uint64_t Offset
Slice starts at this Offset.
uint64_t operator[](unsigned I) const
Convenience accessor for elements in the slice.
void move(uint64_t Delta)
Moves the Offset and adjusts Length accordingly.
const ConstantDataArray * Array
ConstantDataArray pointer.
bool isKnownAlwaysNaN() const
Return true if it's known this must always be a nan.
FPClassTest KnownFPClasses
Floating-point classes the value could be one of.
bool isKnownNeverInfinity() const
Return true if it's known this can never be an infinity.
bool cannotBeOrderedGreaterThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never greater tha...
static constexpr FPClassTest OrderedGreaterThanZeroMask
static constexpr FPClassTest OrderedLessThanZeroMask
void knownNot(FPClassTest RuleOut)
bool isKnownNeverZero() const
Return true if it's known this can never be a zero.
void copysign(const KnownFPClass &Sign)
bool isKnownNeverSubnormal() const
Return true if it's known this can never be a subnormal.
bool isKnownAlways(FPClassTest Mask) const
bool isKnownNeverLogicalNegZero(const Function &F, Type *Ty) const
Return true if it's know this can never be interpreted as a negative zero.
bool isKnownNeverLogicalPosZero(const Function &F, Type *Ty) const
Return true if it's know this can never be interpreted as a positive zero.
KnownFPClass & operator|=(const KnownFPClass &RHS)
void propagateCanonicalizingSrc(const KnownFPClass &Src, const Function &F, Type *Ty)
Report known classes if Src is evaluated through a potentially canonicalizing operation.
void propagateDenormal(const KnownFPClass &Src, const Function &F, Type *Ty)
Propagate knowledge from a source value that could be a denormal or zero.
bool isUnknown() const
bool isKnownNeverNegInfinity() const
Return true if it's known this can never be -infinity.
bool isKnownNeverNegSubnormal() const
Return true if it's known this can never be a negative subnormal.
bool isKnownNeverPosZero() const
Return true if it's known this can never be a literal positive zero.
std::optional< bool > SignBit
std::nullopt if the sign bit is unknown, true if the sign bit is definitely set or false if the sign ...
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
bool isKnownNever(FPClassTest Mask) const
Return true if it's known this can never be one of the mask entries.
bool isKnownNeverNegZero() const
Return true if it's known this can never be a negative zero.
bool isKnownNeverLogicalZero(const Function &F, Type *Ty) const
Return true if it's know this can never be interpreted as a zero.
void propagateNaN(const KnownFPClass &Src, bool PreserveSign=false)
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
void signBitMustBeOne()
Assume the sign bit is one.
void signBitMustBeZero()
Assume the sign bit is zero.
bool isKnownNeverPosInfinity() const
Return true if it's known this can never be +infinity.
bool operator==(KnownFPClass Other) const
bool signBitIsZeroOrNaN() const
Return true if the sign bit must be 0, ignoring the sign of nans.
bool isKnownNeverPosSubnormal() const
Return true if it's known this can never be a positive subnormal.
SelectPatternFlavor Flavor
bool Ordered
Only applicable if Flavor is SPF_FMINNUM or SPF_FMAXNUM.
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
SelectPatternNaNBehavior NaNBehavior