31#define DEBUG_TYPE "iv-descriptors"
35 for (
const Use &
Use :
I->operands())
75 if (!Phi->hasOneUse())
78 const APInt *M =
nullptr;
84 int32_t Bits = (*M + 1).exactLogBase2();
105 bool IsSigned =
false;
107 uint64_t MaxBitWidth =
DL.getTypeSizeInBits(Exit->getType());
115 auto Mask = DB->getDemandedBits(Exit);
116 MaxBitWidth = Mask.getBitWidth() - Mask.countl_zero();
119 if (MaxBitWidth ==
DL.getTypeSizeInBits(Exit->getType()) && AC && DT) {
124 auto NumTypeBits =
DL.getTypeSizeInBits(Exit->getType());
125 MaxBitWidth = NumTypeBits - NumSignBits;
127 if (!Bits.isNonNegative()) {
139 return std::make_pair(
Type::getIntNTy(Exit->getContext(), MaxBitWidth),
148 Type *RecurrenceType,
150 unsigned &MinWidthCastToRecurTy) {
155 MinWidthCastToRecurTy = -1U;
157 while (!Worklist.
empty()) {
161 if (Cast->getSrcTy() == RecurrenceType) {
168 if (Cast->getDestTy() == RecurrenceType) {
173 MinWidthCastToRecurTy = std::min<unsigned>(
174 MinWidthCastToRecurTy, Cast->getSrcTy()->getScalarSizeInBits());
203 if (Exit != ExactFPMathInst || Exit->hasNUsesOrMore(3))
208 auto *Op0 = Exit->getOperand(0);
209 auto *Op1 = Exit->getOperand(1);
215 LLVM_DEBUG(
dbgs() <<
"LV: Found an ordered reduction: Phi: " << *Phi
216 <<
", ExitInst: " << *Exit <<
"\n");
229 FMF |= FCmp->getFastMathFlags();
234static std::optional<FastMathFlags>
265 Type *Ty = Phi->getType();
267 if (Phi->getNumIncomingValues() != 2 ||
268 Phi->getParent() != TheLoop->
getHeader() ||
269 (!Ty->isIntegerTy() && !Ty->isFloatingPointTy()) || !Latch)
299 Value *BackedgeValue = Phi->getIncomingValueForBlock(Latch);
305 while (!WorkList.empty()) {
306 Value *Cur = WorkList.pop_back_val();
307 if (!Chain.insert(Cur).second)
331 Chain.insert(
SI->getCondition());
333 if (
A == Phi ||
B == Phi)
341 bool AMatches = IA && TheLoop->
contains(IA) && GetMinMaxRK(
A,
X,
Y) == RK;
342 bool BMatches = IB && TheLoop->
contains(IB) && GetMinMaxRK(
B,
X,
Y) == RK;
343 if (AMatches == BMatches)
345 WorkList.push_back(AMatches ?
A :
B);
352 bool PhiHasInvalidUses =
any_of(Phi->users(), [&](
User *U) {
354 return !Chain.contains(U) && TheLoop->contains(cast<Instruction>(U)) &&
355 GetMinMaxRK(U, A, B) == RecurKind::None;
357 if (PhiHasInvalidUses) {
364 nullptr, Phi->getType(),
true);
370 for (
Value *V : Chain) {
372 if (Chain.contains(U))
375 if (!
I || (!TheLoop->
contains(
I) && V != BackedgeValue))
385 if (GetMinMaxRK(
I,
A,
B) != RK)
387 for (
User *IU :
I->users()) {
390 else if (!Chain.contains(IU))
398 const SCEV *StorePtrSCEV =
nullptr;
404 (StorePtrSCEV && StorePtrSCEV != Ptr))
407 if (!IntermediateStore)
408 IntermediateStore =
SI;
409 else if (IntermediateStore->
getParent() !=
SI->getParent())
412 IntermediateStore =
SI;
425 unsigned NumNonReduxInputs = 0;
426 for (
const Value *
Op : Phi->operands()) {
428 if (++NumNonReduxInputs > 1)
430 }
else if (
Op != HeaderPhi) {
435 return NumNonReduxInputs == 1;
442 if (Phi->getNumIncomingValues() != 2)
446 if (Phi->getParent() != TheLoop->
getHeader())
467 bool FoundReduxOp =
false;
473 bool FoundStartPHI =
false;
477 unsigned NumCmpSelectPatternInst = 0;
485 [[maybe_unused]]
unsigned NumNonPHIUsers = 0;
486 bool FoundFindLastLikePhi =
false;
489 Type *RecurrenceType = Phi->getType();
491 unsigned MinWidthCastToRecurrenceType;
493 bool IsSigned =
false;
516 Start =
lookThroughAnd(Phi, RecurrenceType, VisitedInsts, CastInsts);
523 VisitedInsts.
insert(Start);
552 while (!Worklist.
empty()) {
559 LLVM_DEBUG(
dbgs() <<
"Store instructions are not processed without "
560 <<
"Scalar Evolution Analysis\n");
567 const SCEV *OtherScev =
570 if (OtherScev != PtrScev) {
571 LLVM_DEBUG(
dbgs() <<
"Storing reduction value to different addresses "
572 <<
"inside the loop: " << *
SI->getPointerOperand()
581 LLVM_DEBUG(
dbgs() <<
"Storing reduction value to non-uniform address "
582 <<
"inside the loop: " << *
SI->getPointerOperand()
603 if (Cur != Phi && IsAPhi && Cur->
getParent() == Phi->getParent())
618 ExactFPMathInst = ExactFPMathInst ==
nullptr
648 if (IsAPhi && Cur != Phi) {
654 FoundFindLastLikePhi =
657 if (!FoundFindLastLikePhi)
663 ++NumCmpSelectPatternInst;
666 FoundReduxOp |= (!IsAPhi || FoundFindLastLikePhi) && Cur != Start;
687 if (ExitInstruction == Cur)
694 if (ExitInstruction !=
nullptr || Cur == Phi)
703 ExitInstruction = Cur;
710 InstDesc IgnoredVal(
false,
nullptr);
711 if (VisitedInsts.
insert(UI).second) {
716 if (
SI &&
SI->getPointerOperand() == Cur) {
731 FoundStartPHI =
true;
739 assert((!FoundFindLastLikePhi ||
741 "Unexpectedly matched a 'find-last-like' phi");
758 if (ExitInstruction &&
760 LLVM_DEBUG(
dbgs() <<
"Last store Instruction of reduction value does not "
761 "store last calculated value of the reduction: "
768 if (!ExitInstruction)
772 if (!FoundStartPHI || !FoundReduxOp || !ExitInstruction)
775 const bool IsOrdered =
804 std::tie(ComputedType, IsSigned) =
806 if (ComputedType != RecurrenceType)
824 MinWidthCastToRecurrenceType);
835 FMF, ExactFPMathInst, RecurrenceType, IsSigned,
836 IsOrdered, CastInsts, MinWidthCastToRecurrenceType);
875 Value *NonPhi =
nullptr;
878 NonPhi =
SI->getFalseValue();
880 NonPhi =
SI->getTrueValue();
952 Value *TrueVal, *FalseVal;
966 if (!I1 || !I1->isBinaryOp())
981 if (!IPhi || IPhi != FalseVal)
992 switch (
I->getOpcode()) {
995 case Instruction::PHI:
997 case Instruction::Sub:
1000 case Instruction::Add:
1003 case Instruction::Mul:
1005 case Instruction::And:
1007 case Instruction::Or:
1009 case Instruction::Xor:
1011 case Instruction::FDiv:
1012 case Instruction::FMul:
1014 I->hasAllowReassoc() ?
nullptr :
I);
1015 case Instruction::FSub:
1018 I,
I->hasAllowReassoc() ?
nullptr :
I);
1019 case Instruction::FAdd:
1022 I,
I->hasAllowReassoc() ?
nullptr :
I);
1023 case Instruction::Select:
1032 case Instruction::FCmp:
1033 case Instruction::ICmp:
1034 case Instruction::Call:
1039 I->hasAllowReassoc() ?
nullptr :
I);
1046 unsigned MaxNumUses) {
1047 unsigned NumUses = 0;
1048 for (
const Use &U :
I->operands()) {
1051 if (NumUses > MaxNumUses)
1064 LLVM_DEBUG(
dbgs() <<
"Found an ADD reduction PHI." << *Phi <<
"\n");
1068 LLVM_DEBUG(
dbgs() <<
"Found a SUB reduction PHI." << *Phi <<
"\n");
1073 LLVM_DEBUG(
dbgs() <<
"Found a chained ADD-SUB reduction PHI." << *Phi
1078 LLVM_DEBUG(
dbgs() <<
"Found a MUL reduction PHI." << *Phi <<
"\n");
1082 LLVM_DEBUG(
dbgs() <<
"Found an OR reduction PHI." << *Phi <<
"\n");
1086 LLVM_DEBUG(
dbgs() <<
"Found an AND reduction PHI." << *Phi <<
"\n");
1090 LLVM_DEBUG(
dbgs() <<
"Found a XOR reduction PHI." << *Phi <<
"\n");
1097 "Expected a min/max recurrence kind");
1098 LLVM_DEBUG(
dbgs() <<
"Found a min/max reduction PHI." << *Phi <<
"\n");
1099 RedDes = std::move(RD);
1103 LLVM_DEBUG(
dbgs() <<
"Found a conditional select reduction PHI." << *Phi
1109 LLVM_DEBUG(
dbgs() <<
"Found a Find reduction PHI." << *Phi <<
"\n");
1113 LLVM_DEBUG(
dbgs() <<
"Found an FMult reduction PHI." << *Phi <<
"\n");
1117 LLVM_DEBUG(
dbgs() <<
"Found an FSub reduction PHI." << *Phi <<
"\n");
1121 LLVM_DEBUG(
dbgs() <<
"Found an FAdd reduction PHI." << *Phi <<
"\n");
1126 LLVM_DEBUG(
dbgs() <<
"Found a chained FADD-FSUB chained reduction PHI."
1132 LLVM_DEBUG(
dbgs() <<
"Found an FMulAdd reduction PHI." << *Phi <<
"\n");
1144 if (Phi->getParent() != TheLoop->
getHeader() ||
1145 Phi->getNumIncomingValues() != 2)
1152 if (!Preheader || !Latch)
1156 if (Phi->getBasicBlockIndex(Preheader) < 0 ||
1157 Phi->getBasicBlockIndex(Latch) < 0)
1170 if (PrevPhi->getParent() != Phi->getParent())
1172 if (!SeenPhis.
insert(PrevPhi).second)
1189 auto TryToPushSinkCandidate = [&](
Instruction *SinkCandidate) {
1191 if (Previous == SinkCandidate)
1194 if (!Seen.
insert(SinkCandidate).second)
1200 if (SinkCandidate->getParent() != PhiBB ||
1201 SinkCandidate->mayHaveSideEffects() ||
1202 SinkCandidate->mayReadFromMemory() || SinkCandidate->isTerminator())
1217 while (!WorkList.
empty()) {
1231 return Instruction::Sub;
1234 return Instruction::Add;
1236 return Instruction::Mul;
1238 return Instruction::Or;
1240 return Instruction::And;
1242 return Instruction::Xor;
1244 return Instruction::FMul;
1248 return Instruction::FAdd;
1250 return Instruction::FSub;
1255 return Instruction::ICmp;
1262 return Instruction::FCmp;
1293 unsigned ExpectedUses = 1;
1323 if (Cur->getOpcode() == Instruction::Sub &&
1327 if (Cur->getOpcode() == Instruction::FSub &&
1335 unsigned ExtraPhiUses = 0;
1338 if (ExitPhi->getNumIncomingValues() != 2)
1347 else if (Inc1 == Phi)
1360 if (!isCorrectOpcode(RdxInstr) || !LoopExitInstr->hasNUses(2))
1365 if (!Phi->hasNUses(ExpectedUses + ExtraPhiUses))
1372 while (Cur != RdxInstr) {
1373 if (!Cur || !isCorrectOpcode(Cur) || !Cur->
hasNUses(ExpectedUses))
1377 Cur = getNextInstruction(Cur);
1381 return ReductionOperations;
1387 : StartValue(Start), IK(K), Step(Step), InductionBinOp(BOp) {
1388 assert(IK != IK_NoInduction &&
"Not an induction");
1392 assert(StartValue &&
"StartValue is null");
1393 assert((IK != IK_PtrInduction || StartValue->getType()->isPointerTy()) &&
1394 "StartValue is not a pointer for pointer induction");
1395 assert((IK != IK_IntInduction || StartValue->getType()->isIntegerTy()) &&
1396 "StartValue is not an integer for integer induction");
1399 assert((!getConstIntStepValue() || !getConstIntStepValue()->
isZero()) &&
1400 "Step value is zero");
1403 "StepValue is not an integer");
1406 "StepValue is not FP for FpInduction");
1407 assert((IK != IK_FpInduction ||
1409 (InductionBinOp->getOpcode() == Instruction::FAdd ||
1410 InductionBinOp->getOpcode() == Instruction::FSub))) &&
1411 "Binary opcode should be specified for FP induction");
1434 assert(Phi->getType()->isFloatingPointTy() &&
"Unexpected Phi type");
1436 if (TheLoop->
getHeader() != Phi->getParent())
1441 if (Phi->getNumIncomingValues() != 2)
1443 Value *BEValue =
nullptr, *StartValue =
nullptr;
1444 if (TheLoop->
contains(Phi->getIncomingBlock(0))) {
1445 BEValue = Phi->getIncomingValue(0);
1446 StartValue = Phi->getIncomingValue(1);
1449 "Unexpected Phi node in the loop");
1450 BEValue = Phi->getIncomingValue(1);
1451 StartValue = Phi->getIncomingValue(0);
1458 Value *Addend =
nullptr;
1459 if (BOp->
getOpcode() == Instruction::FAdd) {
1464 }
else if (BOp->
getOpcode() == Instruction::FSub)
1519 assert(CastInsts.
empty() &&
"CastInsts is expected to be empty.");
1521 assert(PSE.
getSCEV(PN) == AR &&
"Unexpected phi node SCEV expression");
1538 Value *Def =
nullptr;
1539 if (L->isLoopInvariant(Op0))
1541 else if (L->isLoopInvariant(Op1))
1551 Value *Val = PN->getIncomingValueForBlock(Latch);
1559 bool InCastSequence =
false;
1564 if (!Inst || !L->contains(Inst)) {
1569 InCastSequence =
true;
1570 if (InCastSequence) {
1573 if (!CastInsts.
empty())
1574 if (!Inst->hasOneUse())
1584 return InCastSequence;
1590 Type *PhiTy = Phi->getType();
1622 if (PhiScev != AR && SymbolicPhi) {
1635 Type *PhiTy = Phi->getType();
1641 const SCEV *PhiScev = Expr ? Expr : SE->
getSCEV(Phi);
1650 dbgs() <<
"LV: PHI is not a poly recurrence for requested loop.\n");
1658 "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< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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 std::optional< FastMathFlags > hasRequiredFastMathFlags(FPMathOperator *FPOp, RecurKind &RK)
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 bool isFindLastLikePhi(PHINode *Phi, PHINode *HeaderPhi, SmallPtrSetImpl< Instruction * > &ReductionInstrs)
static Instruction * lookThroughAnd(PHINode *Phi, Type *&RT, SmallPtrSetImpl< Instruction * > &Visited, SmallPtrSetImpl< Instruction * > &CI)
Determines if Phi may have been type-promoted.
static FastMathFlags collectMinMaxFMF(Value *V)
static RecurrenceDescriptor getMinMaxRecurrence(PHINode *Phi, Loop *TheLoop, ScalarEvolution *SE)
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)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
Class for arbitrary precision integers.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
BinaryOps getOpcode() const
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
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.
Utility class for floating point operations which can have information about relaxed accuracy require...
bool hasNoNaNs() const
Test if this operation's arguments and results are assumed not-NaN.
bool hasNoSignedZeros() const
Test if this operation can ignore the sign of zero.
Convenience struct for specifying and reasoning about fast-math flags.
static FastMathFlags getFast()
A struct for saving information about induction variables.
static LLVM_ABI InductionDescriptor getCanonicalIntInduction(Type *Ty, ScalarEvolution &SE)
Returns the canonical integer induction for type Ty with start = 0 and step = 1.
@ 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 bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
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) 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
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
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 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 LLVM_ABI bool isSubRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is for a sub operation.
StoreInst * IntermediateStore
Reductions may store temporary or final result to an invariant address.
static bool isFindRecurrenceKind(RecurKind Kind)
static LLVM_ABI bool isFloatingPointRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is a floating point kind.
static LLVM_ABI InstDesc isRecurrenceInstr(Loop *L, PHINode *Phi, Instruction *I, RecurKind Kind, InstDesc &Prev, ScalarEvolution *SE)
Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind' for a ...
static LLVM_ABI bool AddReductionVar(PHINode *Phi, RecurKind Kind, Loop *TheLoop, 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 InstDesc isFindPattern(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 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 Loop * getLoop() const
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 const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
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 isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
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.
bool contains(ConstPtrType Ptr) const
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.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
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)
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
auto m_Cmp()
Matches any compare instruction and ignore it.
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)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
match_bind< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
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)
auto m_Value()
Match an arbitrary value and ignore it.
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)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
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)
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)
specificloop_ty m_SpecificLoop(const Loop *L)
SCEVAffineAddRec_match< Op0_t, Op1_t, match_isa< const Loop > > m_scev_AffineAddRec(const Op0_t &Op0, const Op1_t &Op1)
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)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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.
@ FindIV
FindIV reduction with select(icmp(),x,y) where one of (x,y) is a loop induction variable (increasing ...
@ Or
Bitwise or logical OR of integers.
@ FMinimum
FP min with llvm.minimum semantics.
@ FMaxNum
FP max with llvm.maxnum semantics including NaNs.
@ Mul
Product of integers.
@ FSub
Subtraction of floats.
@ FAddChainWithSubs
A chain of fadds and fsubs.
@ 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.
@ FindLast
FindLast reduction with select(cmp(),x,y) where x and y.
@ 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()).
DWARFExpression::Operation Op
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?