LLVM 23.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;
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 FAddChainWithSubs, ///< A chain of fadds and fsubs.
50 FSub, ///< Subtraction of floats.
51 FMul, ///< Product of floats.
52 FMin, ///< FP min implemented in terms of select(cmp()).
53 FMax, ///< FP max implemented in terms of select(cmp()).
54 FMinNum, ///< FP min with llvm.minnum semantics including NaNs.
55 FMaxNum, ///< FP max with llvm.maxnum semantics including NaNs.
56 FMinimum, ///< FP min with llvm.minimum semantics
57 FMaximum, ///< FP max with llvm.maximum semantics
58 FMinimumNum, ///< FP min with llvm.minimumnum semantics
59 FMaximumNum, ///< FP max with llvm.maximumnum semantics
60 FMulAdd, ///< Sum of float products with llvm.fmuladd(a * b + sum).
61 AnyOf, ///< AnyOf reduction with select(cmp(),x,y) where one of (x,y) is
62 ///< loop invariant, and both x and y are integer type.
63 FindIV, ///< FindIV reduction with select(icmp(),x,y) where one of (x,y) is
64 ///< a loop induction variable (increasing or decreasing), and both
65 ///< x and y are integer type. The signedness and direction are
66 ///< stored separately.
67 FindLast, ///< FindLast reduction with select(cmp(),x,y) where x and y
68 ///< are an integer type, one is the current recurrence value,
69 ///< and the other is an arbitrary value.
70 // clang-format on
71 // TODO: Any_of and FindLast reduction need not be restricted to integer type
72 // only.
73};
74
75/// The RecurrenceDescriptor is used to identify recurrences variables in a
76/// loop. Reduction is a special case of recurrence that has uses of the
77/// recurrence variable outside the loop. The method isReductionPHI identifies
78/// reductions that are basic recurrences.
79///
80/// Basic recurrences are defined as the summation, product, OR, AND, XOR, min,
81/// or max of a set of terms. For example: for(i=0; i<n; i++) { total +=
82/// array[i]; } is a summation of array elements. Basic recurrences are a
83/// special case of chains of recurrences (CR). See ScalarEvolution for CR
84/// references.
85
86/// This struct holds information about recurrence variables.
88public:
90
92 RecurKind K, FastMathFlags FMF, Instruction *ExactFP,
93 Type *RT, bool Signed, bool Ordered,
95 unsigned MinWidthCastToRecurTy,
96 bool PhiHasUsesOutsideReductionChain = false)
97 : IntermediateStore(Store), StartValue(Start), LoopExitInstr(Exit),
98 Kind(K), FMF(FMF), ExactFPMathInst(ExactFP), RecurrenceType(RT),
99 IsSigned(Signed), IsOrdered(Ordered),
100 PhiHasUsesOutsideReductionChain(PhiHasUsesOutsideReductionChain),
101 MinWidthCastToRecurrenceType(MinWidthCastToRecurTy) {
102 CastInsts.insert_range(CI);
103 assert(
104 (!PhiHasUsesOutsideReductionChain || isMinMaxRecurrenceKind(K)) &&
105 "Only min/max recurrences are allowed to have multiple uses currently");
106 }
107
108 /// Simpler constructor for min/max recurrences that don't track cast
109 /// instructions.
111 RecurKind K, FastMathFlags FMF, Instruction *ExactFP,
112 Type *RT, bool IsMultiUse = false)
113 : IntermediateStore(Store), StartValue(Start), LoopExitInstr(Exit),
114 Kind(K), FMF(FMF), ExactFPMathInst(ExactFP), RecurrenceType(RT),
115 PhiHasUsesOutsideReductionChain(IsMultiUse) {}
116
117 /// This POD struct holds information about a potential recurrence operation.
118 class InstDesc {
119 public:
120 InstDesc(bool IsRecur, Instruction *I, Instruction *ExactFP = nullptr)
121 : IsRecurrence(IsRecur), PatternLastInst(I),
122 RecKind(RecurKind::None), ExactFPMathInst(ExactFP) {}
123
124 InstDesc(Instruction *I, RecurKind K, Instruction *ExactFP = nullptr)
125 : IsRecurrence(true), PatternLastInst(I), RecKind(K),
126 ExactFPMathInst(ExactFP) {}
127
128 bool isRecurrence() const { return IsRecurrence; }
129
130 bool needsExactFPMath() const { return ExactFPMathInst != nullptr; }
131
132 Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
133
134 RecurKind getRecKind() const { return RecKind; }
135
136 Instruction *getPatternInst() const { return PatternLastInst; }
137
138 private:
139 // Is this instruction a recurrence candidate.
140 bool IsRecurrence;
141 // The last instruction in a min/max pattern (select of the select(icmp())
142 // pattern), or the current recurrence instruction otherwise.
143 Instruction *PatternLastInst;
144 // If this is a min/max pattern.
145 RecurKind RecKind;
146 // Recurrence does not allow floating-point reassociation.
147 Instruction *ExactFPMathInst;
148 };
149
150 /// Returns a struct describing if the instruction 'I' can be a recurrence
151 /// variable of type 'Kind' for a Loop \p L and reduction PHI \p Phi.
152 /// If the recurrence is a min/max pattern of select(icmp()) this function
153 /// advances the instruction pointer 'I' from the compare instruction to the
154 /// select instruction and stores this pointer in 'PatternLastInst' member of
155 /// the returned struct.
156 LLVM_ABI static InstDesc isRecurrenceInstr(Loop *L, PHINode *Phi,
157 Instruction *I, RecurKind Kind,
158 InstDesc &Prev,
159 ScalarEvolution *SE);
160
161 /// Returns true if instruction I has multiple uses in Insts
164 unsigned MaxNumUses);
165
166 /// Returns true if all uses of the instruction I is within the Set.
167 LLVM_ABI static bool areAllUsesIn(Instruction *I,
169
170 /// Returns a struct describing whether the instruction is either a
171 /// Select(ICmp(A, B), X, Y), or
172 /// Select(FCmp(A, B), X, Y)
173 /// where one of (X, Y) is a loop invariant integer and the other is a PHI
174 /// value. \p Prev specifies the description of an already processed select
175 /// instruction, so its corresponding cmp can be matched to it.
176 LLVM_ABI static InstDesc isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
177 Instruction *I, InstDesc &Prev);
178
179 /// Returns a struct describing whether the instruction is either a
180 /// Select(ICmp(A, B), X, Y), or
181 /// Select(FCmp(A, B), X, Y)
182 /// where one of (X, Y) is an increasing (FindLastIV) or decreasing
183 /// (FindFirstIV) loop induction variable, or an arbitrary integer value
184 /// (FindLast), and the other is a PHI value.
185 LLVM_ABI static InstDesc isFindPattern(Loop *TheLoop, PHINode *OrigPhi,
187
188 /// Returns a struct describing if the instruction is a
189 /// Select(FCmp(X, Y), (Z = X op PHINode), PHINode) instruction pattern.
191
192 /// Returns the opcode corresponding to the RecurrenceKind.
193 LLVM_ABI static unsigned getOpcode(RecurKind Kind);
194
195 /// Returns true if Phi is a reduction of type Kind and adds it to the
196 /// RecurrenceDescriptor. If either \p DB is non-null or \p AC and \p DT are
197 /// non-null, the minimal bit width needed to compute the reduction will be
198 /// computed.
199 LLVM_ABI static bool
200 AddReductionVar(PHINode *Phi, RecurKind Kind, Loop *TheLoop,
201 RecurrenceDescriptor &RedDes, DemandedBits *DB = nullptr,
202 AssumptionCache *AC = nullptr, DominatorTree *DT = nullptr,
203 ScalarEvolution *SE = nullptr);
204
205 /// Returns true if Phi is a reduction in TheLoop. The RecurrenceDescriptor
206 /// is returned in RedDes. If either \p DB is non-null or \p AC and \p DT are
207 /// non-null, the minimal bit width needed to compute the reduction will be
208 /// computed. If \p SE is non-null, store instructions to loop invariant
209 /// addresses are processed.
210 LLVM_ABI static bool
211 isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes,
212 DemandedBits *DB = nullptr, AssumptionCache *AC = nullptr,
213 DominatorTree *DT = nullptr, ScalarEvolution *SE = nullptr);
214
215 /// Returns true if Phi is a fixed-order recurrence. A fixed-order recurrence
216 /// is a non-reduction recurrence relation in which the value of the
217 /// recurrence in the current loop iteration equals a value defined in a
218 /// previous iteration (e.g. if the value is defined in the previous
219 /// iteration, we refer to it as first-order recurrence, if it is defined in
220 /// the iteration before the previous, we refer to it as second-order
221 /// recurrence and so on). Note that this function optimistically assumes that
222 /// uses of the recurrence can be re-ordered if necessary and users need to
223 /// check and perform the re-ordering.
224 LLVM_ABI static bool isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop,
225 DominatorTree *DT);
226
227 RecurKind getRecurrenceKind() const { return Kind; }
228
229 unsigned getOpcode() const { return getOpcode(getRecurrenceKind()); }
230
231 FastMathFlags getFastMathFlags() const { return FMF; }
232
233 TrackingVH<Value> getRecurrenceStartValue() const { return StartValue; }
234
235 Instruction *getLoopExitInstr() const { return LoopExitInstr; }
236
237 /// Returns true if the recurrence has floating-point math that requires
238 /// precise (ordered) operations.
239 bool hasExactFPMath() const { return ExactFPMathInst != nullptr; }
240
241 /// Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
242 Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
243
244 /// Returns true if the recurrence kind is an integer kind.
246
247 /// Returns true if the recurrence kind is a floating point kind.
249
250 /// Returns true if the recurrence kind is for a sub operation.
251 LLVM_ABI static bool isSubRecurrenceKind(RecurKind Kind);
252
253 /// Returns true if the recurrence kind is an integer min/max kind.
255 return Kind == RecurKind::UMin || Kind == RecurKind::UMax ||
256 Kind == RecurKind::SMin || Kind == RecurKind::SMax;
257 }
258
259 /// Returns true if the recurrence kind is a floating-point minnum/maxnum
260 /// kind.
262 return Kind == RecurKind::FMinNum || Kind == RecurKind::FMaxNum;
263 }
264
265 /// Returns true if the recurrence kind is a floating-point min/max kind.
267 return Kind == RecurKind::FMin || Kind == RecurKind::FMax ||
268 Kind == RecurKind::FMinimum || Kind == RecurKind::FMaximum ||
271 }
272
273 /// Returns true if the recurrence kind is any min/max kind.
276 }
277
278 /// Returns true if the recurrence kind is of the form
279 /// select(cmp(),x,y) where one of (x,y) is loop invariant.
281 return Kind == RecurKind::AnyOf;
282 }
283
284 /// Returns true if the recurrence kind is of the form
285 /// select(cmp(),x,y) where one of (x,y) is a loop induction variable.
287 return Kind == RecurKind::FindIV;
288 }
289
290 /// Returns true if the recurrence kind is of the form
291 /// select(cmp(),x,y) where one of (x,y) is an arbitrary value and the
292 /// other is a recurrence.
294 return Kind == RecurKind::FindLast;
295 }
296
297 static bool isFindRecurrenceKind(RecurKind Kind) {
299 }
300
301 /// Returns the type of the recurrence. This type can be narrower than the
302 /// actual type of the Phi if the recurrence has been type-promoted.
303 Type *getRecurrenceType() const { return RecurrenceType; }
304
305 /// Returns a reference to the instructions used for type-promoting the
306 /// recurrence.
307 const SmallPtrSet<Instruction *, 8> &getCastInsts() const { return CastInsts; }
308
309 /// Returns the minimum width used by the recurrence in bits.
311 return MinWidthCastToRecurrenceType;
312 }
313
314 /// Returns true if all source operands of the recurrence are SExtInsts.
315 bool isSigned() const { return IsSigned; }
316
317 /// Expose an ordered FP reduction to the instance users.
318 bool isOrdered() const { return IsOrdered; }
319
320 /// Returns true if the reduction PHI has any uses outside the reduction
321 /// chain. This is relevant for min/max reductions that are part of a FindIV
322 /// pattern.
324 return PhiHasUsesOutsideReductionChain;
325 }
326
327 /// Attempts to find a chain of operations from Phi to LoopExitInst that can
328 /// be treated as a set of reductions instructions for in-loop reductions.
330 Loop *L) const;
331
332 /// Returns true if the instruction is a call to the llvm.fmuladd intrinsic.
334 return isa<IntrinsicInst>(I) &&
335 cast<IntrinsicInst>(I)->getIntrinsicID() == Intrinsic::fmuladd;
336 }
337
338 /// Reductions may store temporary or final result to an invariant address.
339 /// If there is such a store in the loop then, after successfull run of
340 /// AddReductionVar method, this field will be assigned the last met store.
342
343private:
344 // The starting value of the recurrence.
345 // It does not have to be zero!
346 TrackingVH<Value> StartValue;
347 // The instruction who's value is used outside the loop.
348 Instruction *LoopExitInstr = nullptr;
349 // The kind of the recurrence.
351 // The fast-math flags on the recurrent instructions. We propagate these
352 // fast-math flags into the vectorized FP instructions we generate.
353 FastMathFlags FMF;
354 // First instance of non-reassociative floating-point in the PHI's use-chain.
355 Instruction *ExactFPMathInst = nullptr;
356 // The type of the recurrence.
357 Type *RecurrenceType = nullptr;
358 // True if all source operands of the recurrence are SExtInsts.
359 bool IsSigned = false;
360 // True if this recurrence can be treated as an in-order reduction.
361 // Currently only a non-reassociative FAdd can be considered in-order,
362 // if it is also the only FAdd in the PHI's use chain.
363 bool IsOrdered = false;
364 // True if the reduction PHI has in-loop users outside the reduction chain.
365 // This is relevant for min/max reductions that are part of a FindIV pattern.
366 bool PhiHasUsesOutsideReductionChain = false;
367 // Instructions used for type-promoting the recurrence.
369 // The minimum width used by the recurrence.
370 unsigned MinWidthCastToRecurrenceType;
371};
372
373/// A struct for saving information about induction variables.
375public:
376 /// This enum represents the kinds of inductions that we support.
378 IK_NoInduction, ///< Not an induction variable.
379 IK_IntInduction, ///< Integer induction variable. Step = C.
380 IK_PtrInduction, ///< Pointer induction var. Step = C.
381 IK_FpInduction ///< Floating point induction variable.
382 };
383
384public:
385 /// Default constructor - creates an invalid induction.
387
388 /// Returns the canonical integer induction for type \p Ty with start = 0
389 /// and step = 1.
392
393 Value *getStartValue() const { return StartValue; }
394 InductionKind getKind() const { return IK; }
395 const SCEV *getStep() const { return Step; }
396 BinaryOperator *getInductionBinOp() const { return InductionBinOp; }
398
399 /// Returns true if \p Phi is an induction in the loop \p L. If \p Phi is an
400 /// induction, the induction descriptor \p D will contain the data describing
401 /// this induction. Since Induction Phis can only be present inside loop
402 /// headers, the function will assert if it is passed a Phi whose parent is
403 /// not the loop header. If by some other means the caller has a better SCEV
404 /// expression for \p Phi than the one returned by the ScalarEvolution
405 /// analysis, it can be passed through \p Expr. If the def-use chain
406 /// associated with the phi includes casts (that we know we can ignore
407 /// under proper runtime checks), they are passed through \p CastsToIgnore.
408 LLVM_ABI static bool
409 isInductionPHI(PHINode *Phi, const Loop *L, ScalarEvolution *SE,
410 InductionDescriptor &D, const SCEV *Expr = nullptr,
411 SmallVectorImpl<Instruction *> *CastsToIgnore = nullptr);
412
413 /// Returns true if \p Phi is a floating point induction in the loop \p L.
414 /// If \p Phi is an induction, the induction descriptor \p D will contain
415 /// the data describing this induction.
416 LLVM_ABI static bool isFPInductionPHI(PHINode *Phi, const Loop *L,
417 ScalarEvolution *SE,
419
420 /// Returns true if \p Phi is a loop \p L induction, in the context associated
421 /// with the run-time predicate of PSE. If \p Assume is true, this can add
422 /// further SCEV predicates to \p PSE in order to prove that \p Phi is an
423 /// induction.
424 /// If \p Phi is an induction, \p D will contain the data describing this
425 /// induction.
426 LLVM_ABI static bool isInductionPHI(PHINode *Phi, const Loop *L,
429 bool Assume = false);
430
431 /// Returns floating-point induction operator that does not allow
432 /// reassociation (transforming the induction requires an override of normal
433 /// floating-point rules).
435 if (IK == IK_FpInduction && InductionBinOp &&
436 !InductionBinOp->hasAllowReassoc())
437 return InductionBinOp;
438 return nullptr;
439 }
440
441 /// Returns binary opcode of the induction operator.
443 return InductionBinOp ? InductionBinOp->getOpcode()
444 : Instruction::BinaryOpsEnd;
445 }
446
447 /// Returns an ArrayRef to the type cast instructions in the induction
448 /// update chain, that are redundant when guarded with a runtime
449 /// SCEV overflow check.
450 ArrayRef<Instruction *> getCastInsts() const { return RedundantCasts; }
451
452private:
453 /// Private constructor - used by \c isInductionPHI and
454 /// \c getCanonicalIntInduction.
455 InductionDescriptor(Value *Start, InductionKind K, const SCEV *Step,
456 BinaryOperator *InductionBinOp = nullptr,
457 SmallVectorImpl<Instruction *> *Casts = nullptr);
458
459 /// Start value.
460 TrackingVH<Value> StartValue;
461 /// Induction kind.
462 InductionKind IK = IK_NoInduction;
463 /// Step value.
464 const SCEV *Step = nullptr;
465 // Instruction that advances induction variable.
466 BinaryOperator *InductionBinOp = nullptr;
467 // Instructions used for type-casts of the induction variable,
468 // that are redundant when guarded with a runtime SCEV overflow check.
469 SmallVector<Instruction *, 2> RedundantCasts;
470};
471
472} // end namespace llvm
473
474#endif // LLVM_ANALYSIS_IVDESCRIPTORS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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:57
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A cache of @llvm.assume calls within a function.
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:159
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
A struct for saving information about induction variables.
BinaryOperator * getInductionBinOp() const
InductionKind getKind() const
static LLVM_ABI InductionDescriptor getCanonicalIntInduction(Type *Ty, ScalarEvolution &SE)
Returns the canonical integer induction for type Ty with start = 0 and step = 1.
const SCEV * getStep() const
ArrayRef< Instruction * > getCastInsts() const
Returns an ArrayRef to the type cast instructions in the induction update chain, that are redundant w...
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.
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
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 ...
InstDesc(bool IsRecur, Instruction *I, Instruction *ExactFP=nullptr)
InstDesc(Instruction *I, RecurKind K, Instruction *ExactFP=nullptr)
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.
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 isFPMinMaxNumRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is a floating-point minnum/maxnum kind.
static LLVM_ABI bool isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop, DominatorTree *DT)
Returns true if Phi is a fixed-order recurrence.
bool hasExactFPMath() const
Returns true if the recurrence has floating-point math that requires precise (ordered) operations.
Instruction * getLoopExitInstr() 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.
Type * getRecurrenceType() const
Returns the type of the recurrence.
bool hasUsesOutsideReductionChain() const
Returns true if the reduction PHI has any uses outside the reduction chain.
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.
static bool isFindLastRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is of the form select(cmp(),x,y) where one of (x,...
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 LLVM_ABI bool isSubRecurrenceKind(RecurKind Kind)
Returns true if the recurrence kind is for a sub operation.
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 bool isFindRecurrenceKind(RecurKind Kind)
RecurrenceDescriptor(Value *Start, Instruction *Exit, StoreInst *Store, RecurKind K, FastMathFlags FMF, Instruction *ExactFP, Type *RT, bool IsMultiUse=false)
Simpler constructor for min/max recurrences that don't track cast instructions.
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 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 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.
RecurrenceDescriptor(Value *Start, Instruction *Exit, StoreInst *Store, RecurKind K, FastMathFlags FMF, Instruction *ExactFP, Type *RT, bool Signed, bool Ordered, SmallPtrSetImpl< Instruction * > &CI, unsigned MinWidthCastToRecurTy, bool PhiHasUsesOutsideReductionChain=false)
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...
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...
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 handle that tracks a Value across RAUW.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
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...
Definition Casting.h:547
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 ...
@ 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.
@ 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.
@ 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).
@ 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()).
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Matching combinators.