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 Type *&MinWidthCastToRecurTy) {
155 MinWidthCastToRecurTy =
nullptr;
157 while (!Worklist.
empty()) {
161 if (Cast->getSrcTy() == RecurrenceType) {
168 if (Cast->getDestTy() == RecurrenceType) {
174 if (!MinWidthCastToRecurTy ||
177 MinWidthCastToRecurTy = SrcTy;
206 if (Exit != ExactFPMathInst || Exit->hasNUsesOrMore(3))
211 auto *Op0 = Exit->getOperand(0);
212 auto *Op1 = Exit->getOperand(1);
218 LLVM_DEBUG(
dbgs() <<
"LV: Found an ordered reduction: Phi: " << *Phi
219 <<
", ExitInst: " << *Exit <<
"\n");
232 FMF |= FCmp->getFastMathFlags();
237static std::optional<FastMathFlags>
239 bool HasRequiredFMF =
FPOp &&
FPOp->hasNoNaNs() &&
FPOp->hasNoSignedZeros();
247 if (Sel && (!Ty->isIEEELikeFPTy() ||
248 Sel->getFunction()->getDenormalMode(Ty->getFltSemantics()) !=
270 return FPOp->getFastMathFlags();
275 Type *Ty = Phi->getType()->getScalarType();
277 if (Phi->getNumIncomingValues() != 2 ||
278 Phi->getParent() != TheLoop->
getHeader() ||
279 (!Ty->isIntegerTy() && !Ty->isFloatingPointTy()) || !Latch)
309 Value *BackedgeValue = Phi->getIncomingValueForBlock(Latch);
315 while (!WorkList.empty()) {
316 Value *Cur = WorkList.pop_back_val();
317 if (!Chain.insert(Cur).second)
341 Chain.insert(
SI->getCondition());
343 if (
A == Phi ||
B == Phi)
351 bool AMatches = IA && TheLoop->
contains(IA) && GetMinMaxRK(
A,
X,
Y) == RK;
352 bool BMatches = IB && TheLoop->
contains(IB) && GetMinMaxRK(
B,
X,
Y) == RK;
353 if (AMatches == BMatches)
355 WorkList.push_back(AMatches ?
A :
B);
364 return !Chain.contains(U) && TheLoop->contains(U) &&
365 GetMinMaxRK(U, A, B) == RecurKind::None;
367 if (PhiHasInvalidUses) {
370 auto *UI = cast<Instruction>(U);
371 return UI != Phi && TheLoop->contains(UI);
377 nullptr, Phi->getType(),
true);
384 for (
User *U :
V->users()) {
385 if (Chain.contains(U))
388 if (!
I || (!TheLoop->
contains(
I) &&
V != BackedgeValue))
398 if (GetMinMaxRK(
I,
A,
B) != RK)
400 for (
User *IU :
I->users()) {
403 else if (!Chain.contains(IU))
411 const SCEV *StorePtrSCEV =
nullptr;
417 (StorePtrSCEV && StorePtrSCEV != Ptr))
420 if (!IntermediateStore)
421 IntermediateStore =
SI;
422 else if (IntermediateStore->
getParent() !=
SI->getParent())
425 IntermediateStore =
SI;
435 if (IntermediateStore &&
449 unsigned NumNonReduxInputs = 0;
450 for (
const Value *
Op : Phi->operands()) {
452 if (++NumNonReduxInputs > 1)
454 }
else if (
Op != HeaderPhi) {
459 return NumNonReduxInputs == 1;
466 if (Phi->getNumIncomingValues() != 2)
470 if (Phi->getParent() != TheLoop->
getHeader())
491 bool FoundReduxOp =
false;
497 bool FoundStartPHI =
false;
509 [[maybe_unused]]
unsigned NumNonPHIUsers = 0;
510 bool FoundFindLastLikePhi =
false;
513 Type *RecurrenceType = Phi->getType();
515 Type *MinWidthCastToRecurrenceType =
nullptr;
517 bool IsSigned =
false;
540 Start =
lookThroughAnd(Phi, RecurrenceType, VisitedInsts, CastInsts);
547 VisitedInsts.
insert(Start);
576 while (!Worklist.
empty()) {
583 LLVM_DEBUG(
dbgs() <<
"Store instructions are not processed without "
584 <<
"Scalar Evolution Analysis\n");
591 const SCEV *OtherScev =
594 if (OtherScev != PtrScev) {
595 LLVM_DEBUG(
dbgs() <<
"Storing reduction value to different addresses "
596 <<
"inside the loop: " << *
SI->getPointerOperand()
605 LLVM_DEBUG(
dbgs() <<
"Storing reduction value to non-uniform address "
606 <<
"inside the loop: " << *
SI->getPointerOperand()
627 if (Cur != Phi && IsAPhi && Cur->
getParent() == Phi->getParent())
642 ExactFPMathInst = ExactFPMathInst ==
nullptr
672 if (IsAPhi && Cur != Phi) {
678 FoundFindLastLikePhi =
681 if (!FoundFindLastLikePhi)
693 FoundReduxOp |= (!IsAPhi || FoundFindLastLikePhi) && Cur != Start;
712 if (ExitInstruction == Cur)
719 if (ExitInstruction !=
nullptr || Cur == Phi)
728 ExitInstruction = Cur;
735 InstDesc IgnoredVal(
false,
nullptr);
736 if (VisitedInsts.
insert(UI).second) {
741 if (
SI &&
SI->getPointerOperand() == Cur) {
756 FoundStartPHI =
true;
764 assert((!FoundFindLastLikePhi ||
766 "Unexpectedly matched a 'find-last-like' phi");
792 if (ExitInstruction &&
794 LLVM_DEBUG(
dbgs() <<
"Last store Instruction of reduction value does not "
795 "store last calculated value of the reduction: "
802 if (!ExitInstruction)
806 if (!FoundStartPHI || !FoundReduxOp || !ExitInstruction)
809 const bool IsOrdered =
838 std::tie(ComputedType, IsSigned) =
840 if (ComputedType != RecurrenceType)
858 MinWidthCastToRecurrenceType);
869 FMF, ExactFPMathInst, RecurrenceType, IsSigned,
870 IsOrdered, CastInsts, MinWidthCastToRecurrenceType);
912 Value *NonPhi =
nullptr;
915 NonPhi =
SI->getFalseValue();
917 NonPhi =
SI->getTrueValue();
989 Value *TrueVal, *FalseVal;
1003 if (!I1 || !I1->isBinaryOp())
1018 if (!IPhi || IPhi != FalseVal)
1029 switch (
I->getOpcode()) {
1032 case Instruction::PHI:
1034 case Instruction::Sub:
1037 case Instruction::Add:
1040 case Instruction::Mul:
1042 case Instruction::And:
1044 case Instruction::Or:
1046 case Instruction::Xor:
1048 case Instruction::FDiv:
1049 case Instruction::FMul:
1051 I->hasAllowReassoc() ?
nullptr :
I);
1052 case Instruction::FSub:
1055 I,
I->hasAllowReassoc() ?
nullptr :
I);
1056 case Instruction::FAdd:
1059 I,
I->hasAllowReassoc() ?
nullptr :
I);
1060 case Instruction::Select:
1069 case Instruction::FCmp:
1070 case Instruction::ICmp:
1071 case Instruction::Call:
1076 I->hasAllowReassoc() ?
nullptr :
I);
1083 unsigned MaxNumUses) {
1084 unsigned NumUses = 0;
1085 for (
const Use &U :
I->operands()) {
1088 if (NumUses > MaxNumUses)
1101 LLVM_DEBUG(
dbgs() <<
"Found an ADD reduction PHI." << *Phi <<
"\n");
1105 LLVM_DEBUG(
dbgs() <<
"Found a SUB reduction PHI." << *Phi <<
"\n");
1110 LLVM_DEBUG(
dbgs() <<
"Found a chained ADD-SUB reduction PHI." << *Phi
1115 LLVM_DEBUG(
dbgs() <<
"Found a MUL reduction PHI." << *Phi <<
"\n");
1119 LLVM_DEBUG(
dbgs() <<
"Found an OR reduction PHI." << *Phi <<
"\n");
1123 LLVM_DEBUG(
dbgs() <<
"Found an AND reduction PHI." << *Phi <<
"\n");
1127 LLVM_DEBUG(
dbgs() <<
"Found a XOR reduction PHI." << *Phi <<
"\n");
1134 "Expected a min/max recurrence kind");
1135 LLVM_DEBUG(
dbgs() <<
"Found a min/max reduction PHI." << *Phi <<
"\n");
1136 RedDes = std::move(RD);
1140 LLVM_DEBUG(
dbgs() <<
"Found a conditional select reduction PHI." << *Phi
1146 LLVM_DEBUG(
dbgs() <<
"Found a Find reduction PHI." << *Phi <<
"\n");
1150 LLVM_DEBUG(
dbgs() <<
"Found an FMult reduction PHI." << *Phi <<
"\n");
1154 LLVM_DEBUG(
dbgs() <<
"Found an FSub reduction PHI." << *Phi <<
"\n");
1158 LLVM_DEBUG(
dbgs() <<
"Found an FAdd reduction PHI." << *Phi <<
"\n");
1163 LLVM_DEBUG(
dbgs() <<
"Found a chained FADD-FSUB chained reduction PHI."
1169 LLVM_DEBUG(
dbgs() <<
"Found an FMulAdd reduction PHI." << *Phi <<
"\n");
1181 if (Phi->getParent() != TheLoop->
getHeader() ||
1182 Phi->getNumIncomingValues() != 2)
1189 if (!Preheader || !Latch)
1193 if (Phi->getBasicBlockIndex(Preheader) < 0 ||
1194 Phi->getBasicBlockIndex(Latch) < 0)
1207 if (PrevPhi->getParent() != Phi->getParent())
1209 if (!SeenPhis.
insert(PrevPhi).second)
1218 if (!TheLoop->
contains(Previous)) {
1220 "loop-invariant latch value must dominate the header phi");
1233 auto TryToPushSinkCandidate = [&](
Instruction *SinkCandidate) {
1235 if (Previous == SinkCandidate)
1238 if (!Seen.
insert(SinkCandidate).second)
1244 if (SinkCandidate->getParent() != PhiBB ||
1245 SinkCandidate->mayHaveSideEffects() ||
1246 SinkCandidate->mayReadFromMemory() || SinkCandidate->isTerminator())
1261 while (!WorkList.
empty()) {
1264 if (!TryToPushSinkCandidate(
User))
1275 return Instruction::Sub;
1278 return Instruction::Add;
1280 return Instruction::Mul;
1282 return Instruction::Or;
1284 return Instruction::And;
1286 return Instruction::Xor;
1288 return Instruction::FMul;
1292 return Instruction::FAdd;
1294 return Instruction::FSub;
1299 return Instruction::ICmp;
1306 return Instruction::FCmp;
1337 unsigned ExpectedUses = 1;
1366 if (Cur->getOpcode() == Instruction::Sub &&
1370 if (Cur->getOpcode() == Instruction::FSub &&
1378 unsigned ExtraPhiUses = 0;
1381 if (ExitPhi->getNumIncomingValues() != 2)
1390 else if (Inc1 == Phi)
1403 if (!isCorrectOpcode(RdxInstr) || !LoopExitInstr->hasNUses(2))
1408 if (!Phi->hasNUses(ExpectedUses + ExtraPhiUses))
1415 while (Cur != RdxInstr) {
1416 if (!Cur || !isCorrectOpcode(Cur) || !Cur->
hasNUses(ExpectedUses))
1420 Cur = getNextInstruction(Cur);
1424 return ReductionOperations;
1431 : StartValue(Start), IK(
K), Step(Step), InductionBinOp(BOp) {
1432 assert(IK != IK_NoInduction &&
"Not an induction");
1436 assert(StartValue &&
"StartValue is null");
1437 assert((IK != IK_PtrInduction || StartValue->getType()->isPointerTy()) &&
1438 "StartValue is not a pointer for pointer induction");
1439 assert((IK != IK_IntInduction || StartValue->getType()->isIntegerTy()) &&
1440 "StartValue is not an integer for integer induction");
1443 assert((!getConstStepValue() || !getConstStepValue()->
isZero()) &&
1444 "Step value is zero");
1447 "StepValue is not an integer");
1450 "StepValue is not FP for FpInduction");
1451 assert((IK != IK_FpInduction ||
1453 (InductionBinOp->getOpcode() == Instruction::FAdd ||
1454 InductionBinOp->getOpcode() == Instruction::FSub))) &&
1455 "Binary opcode should be specified for FP induction");
1470 return ConstStep->getValue()->getValue();
1479 assert(Phi->getType()->isFloatingPointTy() &&
"Unexpected Phi type");
1481 if (TheLoop->
getHeader() != Phi->getParent())
1486 if (Phi->getNumIncomingValues() != 2)
1488 Value *BEValue =
nullptr, *StartValue =
nullptr;
1489 if (TheLoop->
contains(Phi->getIncomingBlock(0))) {
1490 BEValue = Phi->getIncomingValue(0);
1491 StartValue = Phi->getIncomingValue(1);
1494 "Unexpected Phi node in the loop");
1495 BEValue = Phi->getIncomingValue(1);
1496 StartValue = Phi->getIncomingValue(0);
1503 Value *Addend =
nullptr;
1504 if (BOp->
getOpcode() == Instruction::FAdd) {
1509 }
else if (BOp->
getOpcode() == Instruction::FSub)
1565 assert(CastInsts.
empty() &&
"CastInsts is expected to be empty.");
1574 "Unexpected phi node SCEV expression");
1590 Value *Def =
nullptr;
1591 if (L->isLoopInvariant(Op0))
1593 else if (L->isLoopInvariant(Op1))
1603 Value *Val = PN->getIncomingValueForBlock(Latch);
1611 bool InCastSequence =
false;
1616 if (!Inst || !L->contains(Inst)) {
1623 InCastSequence =
true;
1624 if (InCastSequence) {
1627 if (!CastInsts.
empty())
1628 if (!Inst->hasOneUse())
1638 return InCastSequence;
1644 Type *PhiTy = Phi->getType();
1679 if (PhiScev != AR && SymbolicPhi) {
1692 Type *PhiTy = Phi->getType();
1698 const SCEV *PhiScev = Expr ? Expr : SE->
getSCEV(Phi);
1707 dbgs() <<
"LV: PHI is not a poly recurrence for requested loop.\n");
1715 "Invalid Phi node, not present in loop header");
1731 CastsToIgnore, Preds);
1739 nullptr,
nullptr, Preds);
1758 BasicBlock *Preheader = L->getLoopPreheader();
1774 if (UI != PN && L->contains(UI))
1782 [&](
Use &Incoming,
bool ) {
1783 return Incoming != PN ? Incoming.get() : nullptr;
1793 Value *Step =
nullptr;
1798 if (!StepMatch || !L->isLoopInvariant(Step))
1802 if (StepSCEV->isZero())
1812 if (
GEP->hasNoUnsignedWrap() ||
1816 if (OBO->hasNoUnsignedWrap())
1818 if (OBO->hasNoSignedWrap())
1822 LLVM_DEBUG(
dbgs() <<
"LV: Found a conditional induction phi: HeaderPHI: "
1823 << *PN <<
", StepInst: " << *StepInst <<
"\n");
1826 StepSCEV, NoWrapFlags);
1832 const Loop &L)
const {
1833 assert(L.contains(HeaderPHI) &&
1834 "The provided loop does not contain this conditional induction");
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, ArrayRef< const SCEVPredicate * > NoWrapPreds)
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 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 void collectCastInstrs(Loop *TheLoop, Instruction *Exit, Type *RecurrenceType, SmallPtrSetImpl< Instruction * > &Casts, Type *&MinWidthCastToRecurTy)
Collect cast instructions that can be ignored in the vectorizer's cost model, given a reduction exit ...
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)
SmallVector< MachineOperand, 4 > Cond
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
Class for arbitrary precision integers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
BinaryOps getOpcode() const
SCEVFlags getSCEVNoWrapFlags() const
Returns the SCEV no-wrap flags that apply to StepInst.
LLVM_ABI SCEVUse getUnconditionalAddRec(ScalarEvolution &SE, const Loop &L) const
Returns an over-approximation of the conditional induction as a SCEVAddRec assuming the condition is ...
static LLVM_ABI bool isConditionalInductionPHI(PHINode *PN, const Loop *L, ConditionalInductionDescriptor &Desc, ScalarEvolution &SE)
Returns true if PN is a conditional induction variable in the loop L.
const SCEV * getStartSCEV() const
Returns a SCEV expression for the initial value of the conditional induction PHI.
const SCEV * getStepSCEV() const
Returns a SCEV expression for the step of the conditional induction PHI.
ConditionalInductionDescriptor()=default
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...
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.
LLVM_ABI std::optional< APInt > getConstStepValue() const
static LLVM_ABI bool isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE, InductionDescriptor &D, ArrayRef< const SCEVPredicate * > NoWrapPreds={}, const SCEV *Expr=nullptr, SmallVectorImpl< Instruction * > *CastsToIgnore=nullptr)
Returns true if Phi is an induction in the loop L.
@ IK_FpInduction
Floating point induction variable.
@ IK_PtrInduction
Pointer induction var. Step = C.
@ IK_IntInduction
Integer induction variable. Step = C.
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 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...
iterator_range< user_iterator > users()
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 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.
LLVM_ABI bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
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, ArrayRef< const SCEVPredicate * > ExtraPreds={}) const
Check if AR1 and AR2 are equal, while taking into account Equal predicates in Preds and ExtraPreds.
LLVM_ABI const SCEVAddRecExpr * getAsAddRec(Value *V, SmallVectorImpl< const SCEVPredicate * > *WrapPredsAdded=nullptr)
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(cond,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 a Select(Cond, X, Y) where one of (X,...
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 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 class represents a composition of other SCEV predicates, and is the class that most clients will...
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.
static constexpr auto FlagNUW
static constexpr auto FlagNSW
Type * getType() const
Return the LLVM type of this SCEV expression.
static constexpr auto FlagNone
The main scalar evolution driver.
const DataLayout & getDataLayout() const
Return the DataLayout associated with the module this SCEV instance is operating on.
LLVM_ABI bool isKnownNonNegative(const SCEV *S)
Test if the given expression is known to be non-negative.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
static SCEVFlags setFlags(SCEVFlags Flags, SCEVFlags OnFlags)
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
LLVM_ABI SCEVUse getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEVFlagsPair Flags)
Get an add recurrence expression for the specified loop.
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)
LLVM_ABI const SCEV * rewriteUsingPredicate(const SCEV *S, const Loop *L, const SCEVPredicate &A)
Re-writes the SCEV according to the Predicates in A.
This class represents the LLVM 'select' instruction.
const Value * getCondition() const
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)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Value * getValueOperand()
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.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element 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 isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
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.
Type * getType() const
All values are typed, get the type of this value.
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.
auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_FMinimum(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)
auto m_FMaximum(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
match_combine_or< FMaxMin_match< LHS, RHS, ofmin_pred_ty >, FMaxMin_match< LHS, RHS, ufmin_pred_ty > > m_OrdOrUnordFMin(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point minimum function.
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const DataLayout &DL, const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type and canonical index type.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< FMaxMin_match< LHS, RHS, ofmax_pred_ty >, FMaxMin_match< LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(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)
SCEVUseT< const SCEV * > SCEVUse
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=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...
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=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.
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.
FPOp
The floating-point operations supported by the folding helpers.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
T * find_singleton(R &&Range, Predicate P, bool AllowRepeats=false)
Return the single value in Range that satisfies P(<member of Range> *, AllowRepeats)->T * returning n...
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.
@ FMaxSelectNoFMF
FMax as select(cmp()) lacking nnan or nsz, on IEEE types with IEEE denormals.
@ 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(cond,x,y) where one of (x,y) is loop invariant, and both x and y are inte...
@ Xor
Bitwise or logical XOR of integers.
@ FindLast
FindLast reduction with select(cmp(),x,y) where x and y.
@ FMax
FP max as select(cmp()) with nnan/nsz, or llvm.maxnum.
@ FMinSelectNoFMF
FMin as select(cmp()) lacking nnan or nsz, on IEEE types with IEEE denormals.
@ 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 as select(cmp()) with nnan/nsz, or llvm.minnum.
@ 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
SCEVFlags
SCEVFlags are bitfield indices into SCEV's SubclassData.
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.
LLVM_ABI SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
static constexpr DenormalMode getIEEE()
The no-wrap flags to apply when creating a SCEV expression, to the expression and use respectively.
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?