29#define DEBUG_TYPE "iv-descriptors"
33 for (
const Use &
Use :
I->operands())
75 if (!Phi->hasOneUse())
78 const APInt *M =
nullptr;
84 int32_t Bits = (*M + 1).exactLogBase2();
101 bool IsSigned =
false;
103 uint64_t MaxBitWidth =
DL.getTypeSizeInBits(Exit->getType());
111 auto Mask = DB->getDemandedBits(Exit);
112 MaxBitWidth = Mask.getBitWidth() - Mask.countl_zero();
115 if (MaxBitWidth ==
DL.getTypeSizeInBits(Exit->getType()) && AC && DT) {
120 auto NumTypeBits =
DL.getTypeSizeInBits(Exit->getType());
121 MaxBitWidth = NumTypeBits - NumSignBits;
123 if (!Bits.isNonNegative()) {
135 return std::make_pair(
Type::getIntNTy(Exit->getContext(), MaxBitWidth),
144 Type *RecurrenceType,
146 unsigned &MinWidthCastToRecurTy) {
151 MinWidthCastToRecurTy = -1U;
153 while (!Worklist.
empty()) {
157 if (Cast->getSrcTy() == RecurrenceType) {
164 if (Cast->getDestTy() == RecurrenceType) {
169 MinWidthCastToRecurTy = std::min<unsigned>(
170 MinWidthCastToRecurTy, Cast->getSrcTy()->getScalarSizeInBits());
199 if (Exit != ExactFPMathInst || Exit->hasNUsesOrMore(3))
204 auto *Op0 = Exit->getOperand(0);
205 auto *Op1 = Exit->getOperand(1);
211 LLVM_DEBUG(
dbgs() <<
"LV: Found an ordered reduction: Phi: " << *Phi
212 <<
", ExitInst: " << *Exit <<
"\n");
221 if (Phi->getNumIncomingValues() != 2)
225 if (Phi->getParent() != TheLoop->
getHeader())
244 bool FoundReduxOp =
false;
250 bool FoundStartPHI =
false;
255 unsigned NumCmpSelectPatternInst = 0;
259 Type *RecurrenceType = Phi->getType();
261 unsigned MinWidthCastToRecurrenceType;
263 bool IsSigned =
false;
273 if (RecurrenceType->isFloatingPointTy()) {
276 }
else if (RecurrenceType->isIntegerTy()) {
280 Start =
lookThroughAnd(Phi, RecurrenceType, VisitedInsts, CastInsts);
287 VisitedInsts.
insert(Start);
316 while (!Worklist.
empty()) {
323 LLVM_DEBUG(
dbgs() <<
"Store instructions are not processed without "
324 <<
"Scalar Evolution Analysis\n");
331 const SCEV *OtherScev =
334 if (OtherScev != PtrScev) {
335 LLVM_DEBUG(
dbgs() <<
"Storing reduction value to different addresses "
336 <<
"inside the loop: " << *
SI->getPointerOperand()
345 LLVM_DEBUG(
dbgs() <<
"Storing reduction value to non-uniform address "
346 <<
"inside the loop: " << *
SI->getPointerOperand()
365 if (Cur != Phi && IsAPhi && Cur->
getParent() == Phi->getParent())
381 ExactFPMathInst = ExactFPMathInst ==
nullptr
395 CurFMF |= FCmp->getFastMathFlags();
420 if (IsAPhi && Cur != Phi && !
areAllUsesIn(Cur, VisitedInsts))
424 ++NumCmpSelectPatternInst;
426 ++NumCmpSelectPatternInst;
428 ++NumCmpSelectPatternInst;
431 FoundReduxOp |= !IsAPhi && Cur != Start;
452 if (ExitInstruction == Cur)
459 if (ExitInstruction !=
nullptr || Cur == Phi)
468 ExitInstruction = Cur;
475 InstDesc IgnoredVal(
false,
nullptr);
476 if (VisitedInsts.
insert(UI).second) {
481 if (
SI &&
SI->getPointerOperand() == Cur) {
499 FoundStartPHI =
true;
509 NumCmpSelectPatternInst != 0)
527 if (ExitInstruction &&
529 LLVM_DEBUG(
dbgs() <<
"Last store Instruction of reduction value does not "
530 "store last calculated value of the reduction: "
537 if (!ExitInstruction)
541 if (!FoundStartPHI || !FoundReduxOp || !ExitInstruction)
544 const bool IsOrdered =
573 std::tie(ComputedType, IsSigned) =
575 if (ComputedType != RecurrenceType)
593 MinWidthCastToRecurrenceType);
603 FMF, ExactFPMathInst, RecurrenceType, IsSigned,
604 IsOrdered, CastInsts, MinWidthCastToRecurrenceType);
645 Value *NonPhi =
nullptr;
648 NonPhi =
SI->getFalseValue();
650 NonPhi =
SI->getTrueValue();
708 Value *NonRdxPhi =
nullptr;
717 auto GetRecurKind = [&](
Value *V) -> std::optional<RecurKind> {
718 Type *Ty = V->getType();
723 if (!AR || AR->getLoop() != TheLoop)
726 const SCEV *Step = AR->getStepRecurrence(SE);
739 auto CheckRange = [&](
bool IsSigned) {
742 unsigned NumBits = Ty->getIntegerBitWidth();
761 <<
" valid range is " << ValidRange
762 <<
", and the range of " << *AR <<
" is " << IVRange
767 return ValidRange.
contains(IVRange);
770 if (CheckRange(
true))
772 if (CheckRange(
false))
777 "Kind must either be a FindLastIV or FindFirstIV");
779 if (CheckRange(
true))
781 if (CheckRange(
false))
786 if (
auto RK = GetRecurKind(NonRdxPhi))
796 "Expected a cmp or select or call instruction");
861 Value *TrueVal =
SI->getTrueValue();
862 Value *FalseVal =
SI->getFalseValue();
871 if (!I1 || !I1->isBinaryOp())
886 if (!IPhi || IPhi != FalseVal)
896 switch (
I->getOpcode()) {
899 case Instruction::PHI:
901 case Instruction::Sub:
904 case Instruction::Add:
907 case Instruction::Mul:
909 case Instruction::And:
911 case Instruction::Or:
913 case Instruction::Xor:
915 case Instruction::FDiv:
916 case Instruction::FMul:
918 I->hasAllowReassoc() ?
nullptr :
I);
919 case Instruction::FSub:
920 case Instruction::FAdd:
922 I->hasAllowReassoc() ?
nullptr :
I);
923 case Instruction::Select:
931 case Instruction::FCmp:
932 case Instruction::ICmp:
933 case Instruction::Call:
936 auto HasRequiredFMF = [&]() {
956 if (HasRequiredFMF())
963 "unexpected recurrence kind for maxnum");
968 "unexpected recurrence kind for minnum");
975 I->hasAllowReassoc() ?
nullptr :
I);
982 unsigned MaxNumUses) {
983 unsigned NumUses = 0;
984 for (
const Use &U :
I->operands()) {
987 if (NumUses > MaxNumUses)
1003 F.getFnAttribute(
"no-nans-fp-math").getValueAsBool());
1004 FMF.setNoSignedZeros(
1005 F.getFnAttribute(
"no-signed-zeros-fp-math").getValueAsBool());
1009 LLVM_DEBUG(
dbgs() <<
"Found an ADD reduction PHI." << *Phi <<
"\n");
1014 LLVM_DEBUG(
dbgs() <<
"Found a SUB reduction PHI." << *Phi <<
"\n");
1019 LLVM_DEBUG(
dbgs() <<
"Found a chained ADD-SUB reduction PHI." << *Phi
1025 LLVM_DEBUG(
dbgs() <<
"Found a MUL reduction PHI." << *Phi <<
"\n");
1030 LLVM_DEBUG(
dbgs() <<
"Found an OR reduction PHI." << *Phi <<
"\n");
1035 LLVM_DEBUG(
dbgs() <<
"Found an AND reduction PHI." << *Phi <<
"\n");
1040 LLVM_DEBUG(
dbgs() <<
"Found a XOR reduction PHI." << *Phi <<
"\n");
1045 LLVM_DEBUG(
dbgs() <<
"Found a SMAX reduction PHI." << *Phi <<
"\n");
1050 LLVM_DEBUG(
dbgs() <<
"Found a SMIN reduction PHI." << *Phi <<
"\n");
1055 LLVM_DEBUG(
dbgs() <<
"Found a UMAX reduction PHI." << *Phi <<
"\n");
1060 LLVM_DEBUG(
dbgs() <<
"Found a UMIN reduction PHI." << *Phi <<
"\n");
1065 LLVM_DEBUG(
dbgs() <<
"Found a conditional select reduction PHI." << *Phi
1071 LLVM_DEBUG(
dbgs() <<
"Found a FindLastIV reduction PHI." << *Phi <<
"\n");
1076 LLVM_DEBUG(
dbgs() <<
"Found a FindFirstIV reduction PHI." << *Phi <<
"\n");
1081 LLVM_DEBUG(
dbgs() <<
"Found an FMult reduction PHI." << *Phi <<
"\n");
1086 LLVM_DEBUG(
dbgs() <<
"Found an FAdd reduction PHI." << *Phi <<
"\n");
1091 LLVM_DEBUG(
dbgs() <<
"Found a float MAX reduction PHI." << *Phi <<
"\n");
1096 LLVM_DEBUG(
dbgs() <<
"Found a float MIN reduction PHI." << *Phi <<
"\n");
1101 LLVM_DEBUG(
dbgs() <<
"Found an FMulAdd reduction PHI." << *Phi <<
"\n");
1106 LLVM_DEBUG(
dbgs() <<
"Found a float MAXIMUM reduction PHI." << *Phi <<
"\n");
1111 LLVM_DEBUG(
dbgs() <<
"Found a float MINIMUM reduction PHI." << *Phi <<
"\n");
1116 LLVM_DEBUG(
dbgs() <<
"Found a float MAXIMUMNUM reduction PHI." << *Phi
1122 LLVM_DEBUG(
dbgs() <<
"Found a float MINIMUMNUM reduction PHI." << *Phi
1135 if (Phi->getParent() != TheLoop->
getHeader() ||
1136 Phi->getNumIncomingValues() != 2)
1143 if (!Preheader || !Latch)
1147 if (Phi->getBasicBlockIndex(Preheader) < 0 ||
1148 Phi->getBasicBlockIndex(Latch) < 0)
1161 if (PrevPhi->getParent() != Phi->getParent())
1163 if (!SeenPhis.
insert(PrevPhi).second)
1180 auto TryToPushSinkCandidate = [&](
Instruction *SinkCandidate) {
1182 if (Previous == SinkCandidate)
1185 if (!Seen.
insert(SinkCandidate).second)
1191 if (SinkCandidate->getParent() != PhiBB ||
1192 SinkCandidate->mayHaveSideEffects() ||
1193 SinkCandidate->mayReadFromMemory() || SinkCandidate->isTerminator())
1208 while (!WorkList.
empty()) {
1222 return Instruction::Sub;
1225 return Instruction::Add;
1227 return Instruction::Mul;
1234 return Instruction::Or;
1236 return Instruction::And;
1238 return Instruction::Xor;
1240 return Instruction::FMul;
1243 return Instruction::FAdd;
1248 return Instruction::ICmp;
1255 return Instruction::FCmp;
1281 unsigned ExpectedUses = 1;
1311 if (Cur->getOpcode() == Instruction::Sub &&
1319 unsigned ExtraPhiUses = 0;
1322 if (ExitPhi->getNumIncomingValues() != 2)
1331 else if (Inc1 == Phi)
1344 if (!isCorrectOpcode(RdxInstr) || !LoopExitInstr->hasNUses(2))
1349 if (!Phi->hasNUses(ExpectedUses + ExtraPhiUses))
1356 while (Cur != RdxInstr) {
1357 if (!Cur || !isCorrectOpcode(Cur) || !Cur->
hasNUses(ExpectedUses))
1361 Cur = getNextInstruction(Cur);
1365 return ReductionOperations;
1371 : StartValue(Start), IK(K), Step(Step), InductionBinOp(BOp) {
1372 assert(IK != IK_NoInduction &&
"Not an induction");
1376 assert(StartValue &&
"StartValue is null");
1377 assert((IK != IK_PtrInduction || StartValue->getType()->isPointerTy()) &&
1378 "StartValue is not a pointer for pointer induction");
1379 assert((IK != IK_IntInduction || StartValue->getType()->isIntegerTy()) &&
1380 "StartValue is not an integer for integer induction");
1383 assert((!getConstIntStepValue() || !getConstIntStepValue()->
isZero()) &&
1384 "Step value is zero");
1387 "StepValue is not an integer");
1390 "StepValue is not FP for FpInduction");
1391 assert((IK != IK_FpInduction ||
1393 (InductionBinOp->getOpcode() == Instruction::FAdd ||
1394 InductionBinOp->getOpcode() == Instruction::FSub))) &&
1395 "Binary opcode should be specified for FP induction");
1412 assert(Phi->getType()->isFloatingPointTy() &&
"Unexpected Phi type");
1414 if (TheLoop->
getHeader() != Phi->getParent())
1419 if (Phi->getNumIncomingValues() != 2)
1421 Value *BEValue =
nullptr, *StartValue =
nullptr;
1422 if (TheLoop->
contains(Phi->getIncomingBlock(0))) {
1423 BEValue = Phi->getIncomingValue(0);
1424 StartValue = Phi->getIncomingValue(1);
1427 "Unexpected Phi node in the loop");
1428 BEValue = Phi->getIncomingValue(1);
1429 StartValue = Phi->getIncomingValue(0);
1436 Value *Addend =
nullptr;
1437 if (BOp->
getOpcode() == Instruction::FAdd) {
1442 }
else if (BOp->
getOpcode() == Instruction::FSub)
1497 assert(CastInsts.
empty() &&
"CastInsts is expected to be empty.");
1499 assert(PSE.
getSCEV(PN) == AR &&
"Unexpected phi node SCEV expression");
1516 Value *Def =
nullptr;
1517 if (L->isLoopInvariant(Op0))
1519 else if (L->isLoopInvariant(Op1))
1529 Value *Val = PN->getIncomingValueForBlock(Latch);
1537 bool InCastSequence =
false;
1542 if (!Inst || !L->contains(Inst)) {
1547 InCastSequence =
true;
1548 if (InCastSequence) {
1551 if (!CastInsts.
empty())
1552 if (!Inst->hasOneUse())
1562 return InCastSequence;
1568 Type *PhiTy = Phi->getType();
1600 if (PhiScev != AR && SymbolicPhi) {
1613 Type *PhiTy = Phi->getType();
1619 const SCEV *PhiScev = Expr ? Expr : SE->
getSCEV(Phi);
1627 if (AR->
getLoop() != TheLoop) {
1631 dbgs() <<
"LV: PHI is a recurrence with respect to an outer loop.\n");
1639 &&
"Invalid Phi node, not present in loop header");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool getCastsForInductionPHI(PredicatedScalarEvolution &PSE, const SCEVUnknown *PhiScev, const SCEVAddRecExpr *AR, SmallVectorImpl< Instruction * > &CastInsts)
This function is called when we suspect that the update-chain of a phi node (whose symbolic SCEV expr...
static void collectCastInstrs(Loop *TheLoop, Instruction *Exit, Type *RecurrenceType, SmallPtrSetImpl< Instruction * > &Casts, unsigned &MinWidthCastToRecurTy)
Collect cast instructions that can be ignored in the vectorizer's cost model, given a reduction exit ...
static bool checkOrderedReduction(RecurKind Kind, Instruction *ExactFPMathInst, Instruction *Exit, PHINode *Phi)
static Instruction * lookThroughAnd(PHINode *Phi, Type *&RT, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI)
Determines if Phi may have been type-promoted.
static std::pair< Type *, bool > computeRecurrenceType(Instruction *Exit, DemandedBits *DB, AssumptionCache *AC, DominatorTree *DT)
Compute the minimal bit width needed to represent a reduction whose exit instruction is given by Exit...
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Class for arbitrary precision integers.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
BinaryOps getOpcode() const
This class is the base class for the comparison instructions.
This is the shared class of boolean and integer constants.
This class represents a range of values.
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
static ConstantRange getNonEmpty(APInt Lower, APInt Upper)
Create non-empty constant range with the given bounds.
A parsed version of the target data layout string in and methods for querying it.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
Convenience struct for specifying and reasoning about fast-math flags.
bool noSignedZeros() const
void setNoNaNs(bool B=true)
static FastMathFlags getFast()
@ IK_FpInduction
Floating point induction variable.
@ IK_PtrInduction
Pointer induction var. Step = C.
@ IK_IntInduction
Integer induction variable. Step = C.
static LLVM_ABI bool isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D, const SCEV *Expr=nullptr, SmallVectorImpl< Instruction * > *CastsToIgnore=nullptr)
Returns true if Phi is an induction in the loop L.
static LLVM_ABI bool isFPInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D)
Returns true if Phi is a floating point induction in the loop L.
InductionDescriptor()=default
Default constructor - creates an invalid induction.
LLVM_ABI ConstantInt * getConstIntStepValue() const
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
LLVM_ABI FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
BlockT * getHeader() const
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
Represents a single loop in the control flow graph.
bool isLoopInvariant(const Value *V, bool HasCoroSuspendInst=false) const
Return true if the specified value is loop invariant.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
ScalarEvolution * getSE() const
Returns the ScalarEvolution analysis used.
LLVM_ABI bool areAddRecsEqualWithPreds(const SCEVAddRecExpr *AR1, const SCEVAddRecExpr *AR2) const
Check if AR1 and AR2 are equal, while taking into account Equal predicates in Preds.
LLVM_ABI const SCEVAddRecExpr * getAsAddRec(Value *V)
Attempts to produce an AddRecExpr for V by adding additional SCEV predicates.
LLVM_ABI const SCEV * getSCEV(Value *V)
Returns the SCEV expression of V, in the context of the current SCEV predicate.
This POD struct holds information about a potential recurrence operation.
RecurKind getRecKind() const
Instruction * getPatternInst() const
bool isRecurrence() const
Instruction * getExactFPMathInst() const
static bool isFPMinMaxRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is a floating-point min/max kind.
static bool isFMulAddIntrinsic(Instruction *I)
Returns true if the instruction is a call to the llvm.fmuladd intrinsic.
static bool isFindFirstIVRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static LLVM_ABI bool isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop, DominatorTree *DT)
Returns true if Phi is a fixed-order recurrence.
unsigned getOpcode() const
static LLVM_ABI InstDesc isConditionalRdxPattern(Instruction *I)
Returns a struct describing if the instruction is a Select(FCmp(X, Y), (Z = X op PHINode),...
static LLVM_ABI bool hasMultipleUsesOf(Instruction *I, SmallPtrSetImpl< Instruction * > &Insts, unsigned MaxNumUses)
Returns true if instruction I has multiple uses in Insts.
static LLVM_ABI bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes, DemandedBits *DB=nullptr, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr, ScalarEvolution *SE=nullptr)
Returns true if Phi is a reduction in TheLoop.
static LLVM_ABI bool areAllUsesIn(Instruction *I, SmallPtrSetImpl< Instruction * > &Set)
Returns true if all uses of the instruction I is within the Set.
RecurrenceDescriptor()=default
LLVM_ABI SmallVector< Instruction *, 4 > getReductionOpChain(PHINode *Phi, Loop *L) const
Attempts to find a chain of operations from Phi to LoopExitInst that can be treated as a set of reduc...
static bool isAnyOfRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static LLVM_ABI InstDesc isAnyOfPattern(Loop *Loop, PHINode *OrigPhi, Instruction *I, InstDesc &Prev)
Returns a struct describing whether the instruction is either a Select(ICmp(A, B),...
static bool isFindLastIVRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
StoreInst * IntermediateStore
Reductions may store temporary or final result to an invariant address.
static LLVM_ABI InstDesc isRecurrenceInstr(Loop *L, PHINode *Phi, Instruction *I, RecurKind Kind, InstDesc &Prev, FastMathFlags FuncFMF, ScalarEvolution *SE)
Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind' for a ...
static LLVM_ABI InstDesc isFindIVPattern(RecurKind Kind, Loop *TheLoop, PHINode *OrigPhi, Instruction *I, ScalarEvolution &SE)
Returns a struct describing whether the instruction is either a Select(ICmp(A, B),...
static LLVM_ABI bool isFloatingPointRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is a floating point kind.
static bool isFindIVRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
static LLVM_ABI InstDesc isMinMaxPattern(Instruction *I, RecurKind Kind, const InstDesc &Prev)
Returns a struct describing if the instruction is a llvm.
static LLVM_ABI bool AddReductionVar(PHINode *Phi, RecurKind Kind, Loop *TheLoop, FastMathFlags FuncFMF, RecurrenceDescriptor &RedDes, DemandedBits *DB=nullptr, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr, ScalarEvolution *SE=nullptr)
Returns true if Phi is a reduction of type Kind and adds it to the RecurrenceDescriptor.
static LLVM_ABI bool isIntegerRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is an integer kind.
static bool isIntMinMaxRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is an integer min/max kind.
static bool isMinMaxRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is any min/max kind.
This node represents a polynomial recurrence on the trip count of the specified loop.
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
const Loop * getLoop() const
This class represents a constant integer value.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
This class represents an analyzed expression in the program.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI bool isKnownNegative(const SCEV *S)
Test if the given expression is known to be negative.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
ConstantRange getSignedRange(const SCEV *S)
Determine the signed range for a particular SCEV.
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI bool isKnownPositive(const SCEV *S)
Test if the given expression is known to be positive.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
ConstantRange getUnsignedRange(const SCEV *S)
Determine the unsigned range for a particular SCEV.
LLVM_ABI const SCEV * getUnknown(Value *V)
This class represents the LLVM 'select' instruction.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
LLVM Value Representation.
bool hasOneUse() const
Return true if there is exactly one use of this value.
iterator_range< user_iterator > users()
LLVM_ABI bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
const ParentTy * getParent() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMaxNum(const Opnd0 &Op0, const Opnd1 &Op1)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMinimum(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty >, MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > > m_OrdOrUnordFMin(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point minimum function.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty >, MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMinNum(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
MachineInstr * getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI 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...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
RecurKind
These are the kinds of recurrences that we support.
@ UMin
Unsigned integer min implemented in terms of select(cmp()).
@ FMinimumNum
FP min with llvm.minimumnum semantics.
@ FindLastIVUMax
FindLast reduction with select(cmp(),x,y) where one of (x,y) is increasing loop induction,...
@ FindFirstIVUMin
FindFirst reduction with select(icmp(),x,y) where one of (x,y) is a decreasing loop induction,...
@ Or
Bitwise or logical OR of integers.
@ FMinimum
FP min with llvm.minimum semantics.
@ FMaxNum
FP max with llvm.maxnum semantics including NaNs.
@ FindLastIVSMax
FindFirst reduction with select(icmp(),x,y) where one of (x,y) is a decreasing loop induction,...
@ Mul
Product of integers.
@ AnyOf
AnyOf reduction with select(cmp(),x,y) where one of (x,y) is loop invariant, and both x and y are int...
@ Xor
Bitwise or logical XOR of integers.
@ FMax
FP max implemented in terms of select(cmp()).
@ FMaximum
FP max with llvm.maximum semantics.
@ FMulAdd
Sum of float products with llvm.fmuladd(a * b + sum).
@ SMax
Signed integer max implemented in terms of select(cmp()).
@ And
Bitwise or logical AND of integers.
@ SMin
Signed integer min implemented in terms of select(cmp()).
@ FMin
FP min implemented in terms of select(cmp()).
@ FMinNum
FP min with llvm.minnum semantics including NaNs.
@ Sub
Subtraction of integers.
@ AddChainWithSubs
A chain of adds and subs.
@ FMaximumNum
FP max with llvm.maximumnum semantics.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return the number of times the sign bit of the register is replicated into the other bits.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?