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