LLVM 22.0.0git
IVDescriptors.h
Go to the documentation of this file.
1//===- llvm/Analysis/IVDescriptors.h - IndVar Descriptors -------*- 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 "describes" induction and recurrence variables.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_ANALYSIS_IVDESCRIPTORS_H
14#define LLVM_ANALYSIS_IVDESCRIPTORS_H
15
19#include "llvm/IR/ValueHandle.h"
21
22namespace llvm {
23
24class AssumptionCache;
25class DemandedBits;
26class DominatorTree;
27class Loop;
28class PredicatedScalarEvolution;
29class ScalarEvolution;
30class SCEV;
31class StoreInst;
32
33/// These are the kinds of recurrences that we support.
34enum class RecurKind {
35 // clang-format off
36 None, ///< Not a recurrence.
37 Add, ///< Sum of integers.
38 Sub, ///< Subtraction of integers
39 AddChainWithSubs, ///< A chain of adds and subs
40 Mul, ///< Product of integers.
41 Or, ///< Bitwise or logical OR of integers.
42 And, ///< Bitwise or logical AND of integers.
43 Xor, ///< Bitwise or logical XOR of integers.
44 SMin, ///< Signed integer min implemented in terms of select(cmp()).
45 SMax, ///< Signed integer max implemented in terms of select(cmp()).
46 UMin, ///< Unsigned integer min implemented in terms of select(cmp()).
47 UMax, ///< Unsigned integer max implemented in terms of select(cmp()).
48 FAdd, ///< Sum of floats.
49 FMul, ///< Product of floats.
50 FMin, ///< FP min implemented in terms of select(cmp()).
51 FMax, ///< FP max implemented in terms of select(cmp()).
52 FMinNum, ///< FP min with llvm.minnum semantics including NaNs.
53 FMaxNum, ///< FP max with llvm.maxnum semantics including NaNs.
54 FMinimum, ///< FP min with llvm.minimum semantics
55 FMaximum, ///< FP max with llvm.maximum semantics
56 FMinimumNum, ///< FP min with llvm.minimumnum semantics
57 FMaximumNum, ///< FP max with llvm.maximumnum semantics
58 FMulAdd, ///< Sum of float products with llvm.fmuladd(a * b + sum).
59 AnyOf, ///< AnyOf reduction with select(cmp(),x,y) where one of (x,y) is
60 ///< loop invariant, and both x and y are integer type.
61 FindFirstIVSMin, /// FindFirst reduction with select(icmp(),x,y) where one of
62 ///< (x,y) is a decreasing loop induction, and both x and y
63 ///< are integer type, producing a SMin reduction.
64 FindFirstIVUMin, /// FindFirst reduction with select(icmp(),x,y) where one of
65 ///< (x,y) is a decreasing loop induction, and both x and y
66 ///< are integer type, producing a UMin reduction.
67 FindLastIVSMax, ///< FindLast reduction with select(cmp(),x,y) where one of
68 ///< (x,y) is increasing loop induction, and both x and y
69 ///< are integer type, producing a SMax reduction.
70 FindLastIVUMax, ///< FindLast reduction with select(cmp(),x,y) where one of
71 ///< (x,y) is increasing loop induction, and both x and y
72 ///< are integer type, producing a UMax reduction.
73 // clang-format on
74 // TODO: Any_of and FindLast reduction need not be restricted to integer type
75 // only.
76};
77
78/// The RecurrenceDescriptor is used to identify recurrences variables in a
79/// loop. Reduction is a special case of recurrence that has uses of the
80/// recurrence variable outside the loop. The method isReductionPHI identifies
81/// reductions that are basic recurrences.
82///
83/// Basic recurrences are defined as the summation, product, OR, AND, XOR, min,
84/// or max of a set of terms. For example: for(i=0; i<n; i++) { total +=
85/// array[i]; } is a summation of array elements. Basic recurrences are a
86/// special case of chains of recurrences (CR). See ScalarEvolution for CR
87/// references.
88
89/// This struct holds information about recurrence variables.
91public:
93
95 RecurKind K, FastMathFlags FMF, Instruction *ExactFP,
96 Type *RT, bool Signed, bool Ordered,
98 unsigned MinWidthCastToRecurTy)
99 : IntermediateStore(Store), StartValue(Start), LoopExitInstr(Exit),
100 Kind(K), FMF(FMF), ExactFPMathInst(ExactFP), RecurrenceType(RT),
101 IsSigned(Signed), IsOrdered(Ordered),
102 MinWidthCastToRecurrenceType(MinWidthCastToRecurTy) {
103 CastInsts.insert_range(CI);
104 }
105
106 /// This POD struct holds information about a potential recurrence operation.
107 class InstDesc {
108 public:
109 InstDesc(bool IsRecur, Instruction *I, Instruction *ExactFP = nullptr)
110 : IsRecurrence(IsRecur), PatternLastInst(I),
111 RecKind(RecurKind::None), ExactFPMathInst(ExactFP) {}
112
113 InstDesc(Instruction *I, RecurKind K, Instruction *ExactFP = nullptr)
114 : IsRecurrence(true), PatternLastInst(I), RecKind(K),
115 ExactFPMathInst(ExactFP) {}
116
117 bool isRecurrence() const { return IsRecurrence; }
118
119 bool needsExactFPMath() const { return ExactFPMathInst != nullptr; }
120
121 Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
122
123 RecurKind getRecKind() const { return RecKind; }
124
125 Instruction *getPatternInst() const { return PatternLastInst; }
126
127 private:
128 // Is this instruction a recurrence candidate.
129 bool IsRecurrence;
130 // The last instruction in a min/max pattern (select of the select(icmp())
131 // pattern), or the current recurrence instruction otherwise.
132 Instruction *PatternLastInst;
133 // If this is a min/max pattern.
134 RecurKind RecKind;
135 // Recurrence does not allow floating-point reassociation.
136 Instruction *ExactFPMathInst;
137 };
138
139 /// Returns a struct describing if the instruction 'I' can be a recurrence
140 /// variable of type 'Kind' for a Loop \p L and reduction PHI \p Phi.
141 /// If the recurrence is a min/max pattern of select(icmp()) this function
142 /// advances the instruction pointer 'I' from the compare instruction to the
143 /// select instruction and stores this pointer in 'PatternLastInst' member of
144 /// the returned struct.
145 LLVM_ABI static InstDesc
147 InstDesc &Prev, FastMathFlags FuncFMF, ScalarEvolution *SE);
148
149 /// Returns true if instruction I has multiple uses in Insts
152 unsigned MaxNumUses);
153
154 /// Returns true if all uses of the instruction I is within the Set.
155 LLVM_ABI static bool areAllUsesIn(Instruction *I,
157
158 /// Returns a struct describing if the instruction is a llvm.(s/u)(min/max),
159 /// llvm.minnum/maxnum or a Select(ICmp(X, Y), X, Y) pair of instructions
160 /// corresponding to a min(X, Y) or max(X, Y), matching the recurrence kind \p
161 /// Kind. \p Prev specifies the description of an already processed select
162 /// instruction, so its corresponding cmp can be matched to it.
163 LLVM_ABI static InstDesc isMinMaxPattern(Instruction *I, RecurKind Kind,
164 const InstDesc &Prev);
165
166 /// Returns a struct describing whether the instruction is either a
167 /// Select(ICmp(A, B), X, Y), or
168 /// Select(FCmp(A, B), X, Y)
169 /// where one of (X, Y) is a loop invariant integer and the other is a PHI
170 /// value. \p Prev specifies the description of an already processed select
171 /// instruction, so its corresponding cmp can be matched to it.
172 LLVM_ABI static InstDesc isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
173 Instruction *I, InstDesc &Prev);
174
175 /// Returns a struct describing whether the instruction is either a
176 /// Select(ICmp(A, B), X, Y), or
177 /// Select(FCmp(A, B), X, Y)
178 /// where one of (X, Y) is an increasing (FindLast) or decreasing (FindFirst)
179 /// loop induction variable, and the other is a PHI value.
180 // TODO: Support non-monotonic variable. FindLast does not need be restricted
181 // to increasing loop induction variables.
182 LLVM_ABI static InstDesc isFindIVPattern(RecurKind Kind, Loop *TheLoop,
183 PHINode *OrigPhi, Instruction *I,
184 ScalarEvolution &SE);
185
186 /// Returns a struct describing if the instruction is a
187 /// Select(FCmp(X, Y), (Z = X op PHINode), PHINode) instruction pattern.
189
190 /// Returns the opcode corresponding to the RecurrenceKind.
191 LLVM_ABI static unsigned getOpcode(RecurKind Kind);
192
193 /// Returns true if Phi is a reduction of type Kind and adds it to the
194 /// RecurrenceDescriptor. If either \p DB is non-null or \p AC and \p DT are
195 /// non-null, the minimal bit width needed to compute the reduction will be
196 /// computed.
197 LLVM_ABI static bool
198 AddReductionVar(PHINode *Phi, RecurKind Kind, Loop *TheLoop,
199 FastMathFlags FuncFMF, RecurrenceDescriptor &RedDes,
200 DemandedBits *DB = nullptr, AssumptionCache *AC = nullptr,
201 DominatorTree *DT = nullptr, ScalarEvolution *SE = nullptr);
202
203 /// Returns true if Phi is a reduction in TheLoop. The RecurrenceDescriptor
204 /// is returned in RedDes. If either \p DB is non-null or \p AC and \p DT are
205 /// non-null, the minimal bit width needed to compute the reduction will be
206 /// computed. If \p SE is non-null, store instructions to loop invariant
207 /// addresses are processed.
208 LLVM_ABI static bool
209 isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes,
210 DemandedBits *DB = nullptr, AssumptionCache *AC = nullptr,
211 DominatorTree *DT = nullptr, ScalarEvolution *SE = nullptr);
212
213 /// Returns true if Phi is a fixed-order recurrence. A fixed-order recurrence
214 /// is a non-reduction recurrence relation in which the value of the
215 /// recurrence in the current loop iteration equals a value defined in a
216 /// previous iteration (e.g. if the value is defined in the previous
217 /// iteration, we refer to it as first-order recurrence, if it is defined in
218 /// the iteration before the previous, we refer to it as second-order
219 /// recurrence and so on). Note that this function optimistically assumes that
220 /// uses of the recurrence can be re-ordered if necessary and users need to
221 /// check and perform the re-ordering.
222 LLVM_ABI static bool isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop,
223 DominatorTree *DT);
224
225 RecurKind getRecurrenceKind() const { return Kind; }
226
227 unsigned getOpcode() const { return getOpcode(getRecurrenceKind()); }
228
229 FastMathFlags getFastMathFlags() const { return FMF; }
230
231 TrackingVH<Value> getRecurrenceStartValue() const { return StartValue; }
232
233 Instruction *getLoopExitInstr() const { return LoopExitInstr; }
234
235 /// Returns true if the recurrence has floating-point math that requires
236 /// precise (ordered) operations.
237 bool hasExactFPMath() const { return ExactFPMathInst != nullptr; }
238
239 /// Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
240 Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
241
242 /// Returns true if the recurrence kind is an integer kind.
244
245 /// Returns true if the recurrence kind is a floating point kind.
247
248 /// Returns true if the recurrence kind is an integer min/max kind.
250 return Kind == RecurKind::UMin || Kind == RecurKind::UMax ||
251 Kind == RecurKind::SMin || Kind == RecurKind::SMax;
252 }
253
254 /// Returns true if the recurrence kind is a floating-point min/max kind.
256 return Kind == RecurKind::FMin || Kind == RecurKind::FMax ||
257 Kind == RecurKind::FMinNum || Kind == RecurKind::FMaxNum ||
258 Kind == RecurKind::FMinimum || Kind == RecurKind::FMaximum ||
260 }
261
262 /// Returns true if the recurrence kind is any min/max kind.
265 }
266
267 /// Returns true if the recurrence kind is of the form
268 /// select(cmp(),x,y) where one of (x,y) is loop invariant.
270 return Kind == RecurKind::AnyOf;
271 }
272
273 /// Returns true if the recurrence kind is of the form
274 /// select(cmp(),x,y) where one of (x,y) is decreasing loop induction.
276 return Kind == RecurKind::FindFirstIVSMin ||
278 }
279
280 /// Returns true if the recurrence kind is of the form
281 /// select(cmp(),x,y) where one of (x,y) is increasing loop induction.
283 return Kind == RecurKind::FindLastIVSMax ||
285 }
286
287 /// Returns true if recurrece kind is a signed redux kind.
289 return Kind == RecurKind::SMax || Kind == RecurKind::SMin ||
292 }
293
294 /// Returns true if the recurrence kind is of the form
295 /// select(cmp(),x,y) where one of (x,y) is an increasing or decreasing loop
296 /// induction.
298 return isFindFirstIVRecurrenceKind(Kind) ||
300 }
301
302 /// Returns the type of the recurrence. This type can be narrower than the
303 /// actual type of the Phi if the recurrence has been type-promoted.
304 Type *getRecurrenceType() const { return RecurrenceType; }
305
306 /// Returns the sentinel value for FindFirstIV & FindLastIV recurrences to
307 /// replace the start value.
309 Type *Ty = StartValue->getType();
310 unsigned BW = Ty->getIntegerBitWidth();
311 if (isFindLastIVRecurrenceKind(Kind)) {
312 return ConstantInt::get(Ty, isSignedRecurrenceKind(Kind)
314 : APInt::getMinValue(BW));
315 }
316 return ConstantInt::get(Ty, isSignedRecurrenceKind(Kind)
318 : APInt::getMaxValue(BW));
319 }
320
321 /// Returns a reference to the instructions used for type-promoting the
322 /// recurrence.
323 const SmallPtrSet<Instruction *, 8> &getCastInsts() const { return CastInsts; }
324
325 /// Returns the minimum width used by the recurrence in bits.
327 return MinWidthCastToRecurrenceType;
328 }
329
330 /// Returns true if all source operands of the recurrence are SExtInsts.
331 bool isSigned() const { return IsSigned; }
332
333 /// Expose an ordered FP reduction to the instance users.
334 bool isOrdered() const { return IsOrdered; }
335
336 /// Attempts to find a chain of operations from Phi to LoopExitInst that can
337 /// be treated as a set of reductions instructions for in-loop reductions.
339 Loop *L) const;
340
341 /// Returns true if the instruction is a call to the llvm.fmuladd intrinsic.
343 return isa<IntrinsicInst>(I) &&
344 cast<IntrinsicInst>(I)->getIntrinsicID() == Intrinsic::fmuladd;
345 }
346
347 /// Reductions may store temporary or final result to an invariant address.
348 /// If there is such a store in the loop then, after successfull run of
349 /// AddReductionVar method, this field will be assigned the last met store.
351
352private:
353 // The starting value of the recurrence.
354 // It does not have to be zero!
355 TrackingVH<Value> StartValue;
356 // The instruction who's value is used outside the loop.
357 Instruction *LoopExitInstr = nullptr;
358 // The kind of the recurrence.
360 // The fast-math flags on the recurrent instructions. We propagate these
361 // fast-math flags into the vectorized FP instructions we generate.
362 FastMathFlags FMF;
363 // First instance of non-reassociative floating-point in the PHI's use-chain.
364 Instruction *ExactFPMathInst = nullptr;
365 // The type of the recurrence.
366 Type *RecurrenceType = nullptr;
367 // True if all source operands of the recurrence are SExtInsts.
368 bool IsSigned = false;
369 // True if this recurrence can be treated as an in-order reduction.
370 // Currently only a non-reassociative FAdd can be considered in-order,
371 // if it is also the only FAdd in the PHI's use chain.
372 bool IsOrdered = false;
373 // Instructions used for type-promoting the recurrence.
375 // The minimum width used by the recurrence.
376 unsigned MinWidthCastToRecurrenceType;
377};
378
379/// A struct for saving information about induction variables.
381public:
382 /// This enum represents the kinds of inductions that we support.
384 IK_NoInduction, ///< Not an induction variable.
385 IK_IntInduction, ///< Integer induction variable. Step = C.
386 IK_PtrInduction, ///< Pointer induction var. Step = C.
387 IK_FpInduction ///< Floating point induction variable.
388 };
389
390public:
391 /// Default constructor - creates an invalid induction.
393
394 Value *getStartValue() const { return StartValue; }
395 InductionKind getKind() const { return IK; }
396 const SCEV *getStep() const { return Step; }
397 BinaryOperator *getInductionBinOp() const { return InductionBinOp; }
399
400 /// Returns true if \p Phi is an induction in the loop \p L. If \p Phi is an
401 /// induction, the induction descriptor \p D will contain the data describing
402 /// this induction. Since Induction Phis can only be present inside loop
403 /// headers, the function will assert if it is passed a Phi whose parent is
404 /// not the loop header. If by some other means the caller has a better SCEV
405 /// expression for \p Phi than the one returned by the ScalarEvolution
406 /// analysis, it can be passed through \p Expr. If the def-use chain
407 /// associated with the phi includes casts (that we know we can ignore
408 /// under proper runtime checks), they are passed through \p CastsToIgnore.
409 LLVM_ABI static bool
410 isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE,
411 InductionDescriptor &D, const SCEV *Expr = nullptr,
412 SmallVectorImpl<Instruction *> *CastsToIgnore = nullptr);
413
414 /// Returns true if \p Phi is a floating point induction in the loop \p L.
415 /// If \p Phi is an induction, the induction descriptor \p D will contain
416 /// the data describing this induction.
417 LLVM_ABI static bool isFPInductionPHI(PHINode *Phi, const Loop *L,
418 ScalarEvolution *SE,
420
421 /// Returns true if \p Phi is a loop \p L induction, in the context associated
422 /// with the run-time predicate of PSE. If \p Assume is true, this can add
423 /// further SCEV predicates to \p PSE in order to prove that \p Phi is an
424 /// induction.
425 /// If \p Phi is an induction, \p D will contain the data describing this
426 /// induction.
427 LLVM_ABI static bool isInductionPHI(PHINode *Phi, const Loop *L,
430 bool Assume = false);
431
432 /// Returns floating-point induction operator that does not allow
433 /// reassociation (transforming the induction requires an override of normal
434 /// floating-point rules).
436 if (IK == IK_FpInduction && InductionBinOp &&
437 !InductionBinOp->hasAllowReassoc())
438 return InductionBinOp;
439 return nullptr;
440 }
441
442 /// Returns binary opcode of the induction operator.
444 return InductionBinOp ? InductionBinOp->getOpcode()
445 : Instruction::BinaryOpsEnd;
446 }
447
448 /// Returns a reference to the type cast instructions in the induction
449 /// update chain, that are redundant when guarded with a runtime
450 /// SCEV overflow check.
452 return RedundantCasts;
453 }
454
455private:
456 /// Private constructor - used by \c isInductionPHI.
457 InductionDescriptor(Value *Start, InductionKind K, const SCEV *Step,
458 BinaryOperator *InductionBinOp = nullptr,
459 SmallVectorImpl<Instruction *> *Casts = nullptr);
460
461 /// Start value.
462 TrackingVH<Value> StartValue;
463 /// Induction kind.
465 /// Step value.
466 const SCEV *Step = nullptr;
467 // Instruction that advances induction variable.
468 BinaryOperator *InductionBinOp = nullptr;
469 // Instructions used for type-casts of the induction variable,
470 // that are redundant when guarded with a runtime SCEV overflow check.
471 SmallVector<Instruction *, 2> RedundantCasts;
472};
473
474} // end namespace llvm
475
476#endif // LLVM_ANALYSIS_IVDESCRIPTORS_H
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition: Compiler.h:213
#define I(x, y, z)
Definition: MD5.cpp:58
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:206
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:209
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:216
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:219
A cache of @llvm.assume calls within a function.
BinaryOps getOpcode() const
Definition: InstrTypes.h:374
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:165
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:22
A struct for saving information about induction variables.
BinaryOperator * getInductionBinOp() const
InductionKind getKind() const
const SCEV * getStep() const
InductionKind
This enum represents the kinds of inductions that we support.
@ IK_NoInduction
Not an induction variable.
@ 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.
Instruction::BinaryOps getInductionOpcode() const
Returns binary opcode of the induction operator.
const SmallVectorImpl< Instruction * > & getCastInsts() const
Returns a reference to the type cast instructions in the induction update chain, that are redundant w...
Value * getStartValue() const
Instruction * getExactFPMathInst()
Returns floating-point induction operator that does not allow reassociation (transforming the inducti...
InductionDescriptor()=default
Default constructor - creates an invalid induction.
LLVM_ABI ConstantInt * getConstIntStepValue() const
LLVM_ABI bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:40
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
This POD struct holds information about a potential recurrence operation.
InstDesc(bool IsRecur, Instruction *I, Instruction *ExactFP=nullptr)
Instruction * getPatternInst() const
InstDesc(Instruction *I, RecurKind K, Instruction *ExactFP=nullptr)
Instruction * getExactFPMathInst() const
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: IVDescriptors.h:90
static bool isFPMinMaxRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is a floating-point min/max kind.
Instruction * getExactFPMathInst() const
Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
static bool isFMulAddIntrinsic(Instruction *I)
Returns true if the instruction is a call to the llvm.fmuladd intrinsic.
FastMathFlags getFastMathFlags() const
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.
static bool isSignedRecurrenceKind(RecurKind Kind)
Returns true if recurrece kind is a signed redux kind.
bool hasExactFPMath() const
Returns true if the recurrence has floating-point math that requires precise (ordered) operations.
Instruction * getLoopExitInstr() const
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.
RecurrenceDescriptor(Value *Start, Instruction *Exit, StoreInst *Store, RecurKind K, FastMathFlags FMF, Instruction *ExactFP, Type *RT, bool Signed, bool Ordered, SmallPtrSetImpl< Instruction * > &CI, unsigned MinWidthCastToRecurTy)
Definition: IVDescriptors.h:94
Type * getRecurrenceType() const
Returns the type of the recurrence.
const SmallPtrSet< Instruction *, 8 > & getCastInsts() const
Returns a reference to the instructions used for type-promoting the recurrence.
static LLVM_ABI bool areAllUsesIn(Instruction *I, SmallPtrSetImpl< Instruction * > &Set)
Returns true if all uses of the instruction I is within the Set.
unsigned getMinWidthCastToRecurrenceTypeInBits() const
Returns the minimum width used by the recurrence in bits.
TrackingVH< Value > getRecurrenceStartValue() const
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,...
bool isSigned() const
Returns true if all source operands of the recurrence are SExtInsts.
RecurKind getRecurrenceKind() const
bool isOrdered() const
Expose an ordered FP reduction to the instance users.
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.
Value * getSentinelValue() const
Returns the sentinel value for FindFirstIV & FindLastIV recurrences to replace the start value.
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 class represents an analyzed expression in the program.
The main scalar evolution driver.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:380
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:541
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
An instruction for storing to memory.
Definition: Instructions.h:296
Value handle that tracks a Value across RAUW.
Definition: ValueHandle.h:332
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM_ABI unsigned getIntegerBitWidth() const
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ None
Definition: CodeGenData.h:107
RecurKind
These are the kinds of recurrences that we support.
Definition: IVDescriptors.h:34
@ 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,...
@ 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.
@ None
Not a recurrence.
@ 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).
@ FMul
Product of floats.
@ SMax
Signed integer max implemented in terms of select(cmp()).
@ 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.
@ Add
Sum of integers.
@ AddChainWithSubs
A chain of adds and subs.
@ FAdd
Sum of floats.
@ FMaximumNum
FP max with llvm.maximumnum semantics.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
Matching combinators.