LLVM  14.0.0git
LoopVectorizationLegality.h
Go to the documentation of this file.
1 //===- llvm/Transforms/Vectorize/LoopVectorizationLegality.h ----*- 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 /// \file
10 /// This file defines the LoopVectorizationLegality class. Original code
11 /// in Loop Vectorizer has been moved out to its own file for modularity
12 /// and reusability.
13 ///
14 /// Currently, it works for innermost loop vectorization. Extending this to
15 /// outer loop vectorization is a TODO item.
16 ///
17 /// Also provides:
18 /// 1) LoopVectorizeHints class which keeps a number of loop annotations
19 /// locally for easy look up. It has the ability to write them back as
20 /// loop metadata, upon request.
21 /// 2) LoopVectorizationRequirements class for lazy bail out for the purpose
22 /// of reporting useful failure to vectorize message.
23 //
24 //===----------------------------------------------------------------------===//
25 
26 #ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONLEGALITY_H
27 #define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONLEGALITY_H
28 
29 #include "llvm/ADT/MapVector.h"
32 #include "llvm/Support/TypeSize.h"
34 
35 namespace llvm {
36 
37 /// Utility class for getting and setting loop vectorizer hints in the form
38 /// of loop metadata.
39 /// This class keeps a number of loop annotations locally (as member variables)
40 /// and can, upon request, write them back as metadata on the loop. It will
41 /// initially scan the loop for existing metadata, and will update the local
42 /// values based on information in the loop.
43 /// We cannot write all values to metadata, as the mere presence of some info,
44 /// for example 'force', means a decision has been made. So, we need to be
45 /// careful NOT to add them if the user hasn't specifically asked so.
47  enum HintKind {
48  HK_WIDTH,
49  HK_INTERLEAVE,
50  HK_FORCE,
51  HK_ISVECTORIZED,
52  HK_PREDICATE,
53  HK_SCALABLE
54  };
55 
56  /// Hint - associates name and validation with the hint value.
57  struct Hint {
58  const char *Name;
59  unsigned Value; // This may have to change for non-numeric values.
60  HintKind Kind;
61 
62  Hint(const char *Name, unsigned Value, HintKind Kind)
63  : Name(Name), Value(Value), Kind(Kind) {}
64 
65  bool validate(unsigned Val);
66  };
67 
68  /// Vectorization width.
69  Hint Width;
70 
71  /// Vectorization interleave factor.
72  Hint Interleave;
73 
74  /// Vectorization forced
75  Hint Force;
76 
77  /// Already Vectorized
78  Hint IsVectorized;
79 
80  /// Vector Predicate
81  Hint Predicate;
82 
83  /// Says whether we should use fixed width or scalable vectorization.
84  Hint Scalable;
85 
86  /// Return the loop metadata prefix.
87  static StringRef Prefix() { return "llvm.loop."; }
88 
89  /// True if there is any unsafe math in the loop.
90  bool PotentiallyUnsafe = false;
91 
92 public:
93  enum ForceKind {
94  FK_Undefined = -1, ///< Not selected.
95  FK_Disabled = 0, ///< Forcing disabled.
96  FK_Enabled = 1, ///< Forcing enabled.
97  };
98 
100  /// Not selected.
102  /// Disables vectorization with scalable vectors.
104  /// Vectorize loops using scalable vectors or fixed-width vectors, but favor
105  /// scalable vectors when the cost-model is inconclusive. This is the
106  /// default when the scalable.enable hint is enabled through a pragma.
108  /// Vectorize loops using scalable vectors or fixed-width vectors, but
109  /// favor fixed-width vectors when the cost is inconclusive.
111  };
112 
113  LoopVectorizeHints(const Loop *L, bool InterleaveOnlyWhenForced,
115 
116  /// Mark the loop L as already vectorized by setting the width to 1.
117  void setAlreadyVectorized();
118 
119  bool allowVectorization(Function *F, Loop *L,
120  bool VectorizeOnlyWhenForced) const;
121 
122  /// Dumps all the hint information.
123  void emitRemarkWithHints() const;
124 
126  return ElementCount::get(Width.Value,
128  }
129  unsigned getInterleave() const {
130  if (Interleave.Value)
131  return Interleave.Value;
132  // If interleaving is not explicitly set, assume that if we do not want
133  // unrolling, we also don't want any interleaving.
135  return 1;
136  return 0;
137  }
138  unsigned getIsVectorized() const { return IsVectorized.Value; }
139  unsigned getPredicate() const { return Predicate.Value; }
140  enum ForceKind getForce() const {
141  if ((ForceKind)Force.Value == FK_Undefined &&
143  return FK_Disabled;
144  return (ForceKind)Force.Value;
145  }
146 
147  /// \return true if the cost-model for scalable vectorization should
148  /// favor vectorization with scalable vectors over fixed-width vectors when
149  /// the cost-model is inconclusive.
151  return Scalable.Value == SK_PreferScalable;
152  }
153 
154  /// \return true if scalable vectorization has been explicitly enabled.
156  return Scalable.Value == SK_PreferFixedWidth ||
157  Scalable.Value == SK_PreferScalable;
158  }
159 
160  /// \return true if scalable vectorization has been explicitly disabled.
162  return Scalable.Value == SK_FixedWidthOnly;
163  }
164 
165  /// If hints are provided that force vectorization, use the AlwaysPrint
166  /// pass name to force the frontend to print the diagnostic.
167  const char *vectorizeAnalysisPassName() const;
168 
169  /// When enabling loop hints are provided we allow the vectorizer to change
170  /// the order of operations that is given by the scalar loop. This is not
171  /// enabled by default because can be unsafe or inefficient. For example,
172  /// reordering floating-point operations will change the way round-off
173  /// error accumulates in the loop.
174  bool allowReordering() const;
175 
176  bool isPotentiallyUnsafe() const {
177  // Avoid FP vectorization if the target is unsure about proper support.
178  // This may be related to the SIMD unit in the target not handling
179  // IEEE 754 FP ops properly, or bad single-to-double promotions.
180  // Otherwise, a sequence of vectorized loops, even without reduction,
181  // could lead to different end results on the destination vectors.
182  return getForce() != LoopVectorizeHints::FK_Enabled && PotentiallyUnsafe;
183  }
184 
185  void setPotentiallyUnsafe() { PotentiallyUnsafe = true; }
186 
187 private:
188  /// Find hints specified in the loop metadata and update local values.
189  void getHintsFromMetadata();
190 
191  /// Checks string hint with one operand and set value if valid.
192  void setHint(StringRef Name, Metadata *Arg);
193 
194  /// The loop these hints belong to.
195  const Loop *TheLoop;
196 
197  /// Interface to emit optimization remarks.
199 };
200 
201 /// This holds vectorization requirements that must be verified late in
202 /// the process. The requirements are set by legalize and costmodel. Once
203 /// vectorization has been determined to be possible and profitable the
204 /// requirements can be verified by looking for metadata or compiler options.
205 /// For example, some loops require FP commutativity which is only allowed if
206 /// vectorization is explicitly specified or if the fast-math compiler option
207 /// has been provided.
208 /// Late evaluation of these requirements allows helpful diagnostics to be
209 /// composed that tells the user what need to be done to vectorize the loop. For
210 /// example, by specifying #pragma clang loop vectorize or -ffast-math. Late
211 /// evaluation should be used only when diagnostics can generated that can be
212 /// followed by a non-expert user.
214 public:
215  /// Track the 1st floating-point instruction that can not be reassociated.
217  if (I && !ExactFPMathInst)
218  ExactFPMathInst = I;
219  }
220 
221  void addRuntimePointerChecks(unsigned Num) { NumRuntimePointerChecks = Num; }
222 
223 
224  Instruction *getExactFPInst() { return ExactFPMathInst; }
225 
226  unsigned getNumRuntimePointerChecks() const {
227  return NumRuntimePointerChecks;
228  }
229 
230 private:
231  unsigned NumRuntimePointerChecks = 0;
232  Instruction *ExactFPMathInst = nullptr;
233 };
234 
235 /// LoopVectorizationLegality checks if it is legal to vectorize a loop, and
236 /// to what vectorization factor.
237 /// This class does not look at the profitability of vectorization, only the
238 /// legality. This class has two main kinds of checks:
239 /// * Memory checks - The code in canVectorizeMemory checks if vectorization
240 /// will change the order of memory accesses in a way that will change the
241 /// correctness of the program.
242 /// * Scalars checks - The code in canVectorizeInstrs and canVectorizeMemory
243 /// checks for a number of different conditions, such as the availability of a
244 /// single induction variable, that all types are supported and vectorize-able,
245 /// etc. This code reflects the capabilities of InnerLoopVectorizer.
246 /// This class is also used by InnerLoopVectorizer for identifying
247 /// induction variable and the different reduction variables.
249 public:
253  Function *F, std::function<const LoopAccessInfo &(Loop &)> *GetLAA,
257  : TheLoop(L), LI(LI), PSE(PSE), TTI(TTI), TLI(TLI), DT(DT),
258  GetLAA(GetLAA), ORE(ORE), Requirements(R), Hints(H), DB(DB), AC(AC),
259  BFI(BFI), PSI(PSI) {}
260 
261  /// ReductionList contains the reduction descriptors for all
262  /// of the reductions that were found in the loop.
264 
265  /// InductionList saves induction variables and maps them to the
266  /// induction descriptor.
268 
269  /// RecurrenceSet contains the phi nodes that are recurrences other than
270  /// inductions and reductions.
272 
273  /// Returns true if it is legal to vectorize this loop.
274  /// This does not mean that it is profitable to vectorize this
275  /// loop, only that it is legal to do so.
276  /// Temporarily taking UseVPlanNativePath parameter. If true, take
277  /// the new code path being implemented for outer loop vectorization
278  /// (should be functional for inner loop vectorization) based on VPlan.
279  /// If false, good old LV code.
280  bool canVectorize(bool UseVPlanNativePath);
281 
282  /// Returns true if it is legal to vectorize the FP math operations in this
283  /// loop. Vectorizing is legal if we allow reordering of FP operations, or if
284  /// we can use in-order reductions.
285  bool canVectorizeFPMath(bool EnableStrictReductions);
286 
287  /// Return true if we can vectorize this loop while folding its tail by
288  /// masking, and mark all respective loads/stores for masking.
289  /// This object's state is only modified iff this function returns true.
291 
292  /// Returns the primary induction variable.
293  PHINode *getPrimaryInduction() { return PrimaryInduction; }
294 
295  /// Returns the reduction variables found in the loop.
296  ReductionList &getReductionVars() { return Reductions; }
297 
298  /// Returns the induction variables found in the loop.
299  InductionList &getInductionVars() { return Inductions; }
300 
301  /// Return the first-order recurrences found in the loop.
302  RecurrenceSet &getFirstOrderRecurrences() { return FirstOrderRecurrences; }
303 
304  /// Return the set of instructions to sink to handle first-order recurrences.
306 
307  /// Returns the widest induction type.
308  Type *getWidestInductionType() { return WidestIndTy; }
309 
310  /// Returns True if V is a Phi node of an induction variable in this loop.
311  bool isInductionPhi(const Value *V);
312 
313  /// Returns True if V is a cast that is part of an induction def-use chain,
314  /// and had been proven to be redundant under a runtime guard (in other
315  /// words, the cast has the same SCEV expression as the induction phi).
316  bool isCastedInductionVariable(const Value *V);
317 
318  /// Returns True if V can be considered as an induction variable in this
319  /// loop. V can be the induction phi, or some redundant cast in the def-use
320  /// chain of the inducion phi.
321  bool isInductionVariable(const Value *V);
322 
323  /// Returns True if PN is a reduction variable in this loop.
324  bool isReductionVariable(PHINode *PN) { return Reductions.count(PN); }
325 
326  /// Returns True if Phi is a first-order recurrence in this loop.
327  bool isFirstOrderRecurrence(const PHINode *Phi);
328 
329  /// Return true if the block BB needs to be predicated in order for the loop
330  /// to be vectorized.
331  bool blockNeedsPredication(BasicBlock *BB) const;
332 
333  /// Check if this pointer is consecutive when vectorizing. This happens
334  /// when the last index of the GEP is the induction variable, or that the
335  /// pointer itself is an induction variable.
336  /// This check allows us to vectorize A[idx] into a wide load/store.
337  /// Returns:
338  /// 0 - Stride is unknown or non-consecutive.
339  /// 1 - Address is consecutive.
340  /// -1 - Address is consecutive, and decreasing.
341  /// NOTE: This method must only be used before modifying the original scalar
342  /// loop. Do not use after invoking 'createVectorizedLoopSkeleton' (PR34965).
343  int isConsecutivePtr(Type *AccessTy, Value *Ptr) const;
344 
345  /// Returns true if the value V is uniform within the loop.
346  bool isUniform(Value *V);
347 
348  /// A uniform memory op is a load or store which accesses the same memory
349  /// location on all lanes.
352  if (!Ptr)
353  return false;
354  // Note: There's nothing inherent which prevents predicated loads and
355  // stores from being uniform. The current lowering simply doesn't handle
356  // it; in particular, the cost model distinguishes scatter/gather from
357  // scalar w/predication, and we currently rely on the scalar path.
358  return isUniform(Ptr) && !blockNeedsPredication(I.getParent());
359  }
360 
361  /// Returns the information that we collected about runtime memory check.
363  return LAI->getRuntimePointerChecking();
364  }
365 
366  const LoopAccessInfo *getLAI() const { return LAI; }
367 
368  bool isSafeForAnyVectorWidth() const {
369  return LAI->getDepChecker().isSafeForAnyVectorWidth();
370  }
371 
372  unsigned getMaxSafeDepDistBytes() { return LAI->getMaxSafeDepDistBytes(); }
373 
376  }
377 
378  bool hasStride(Value *V) { return LAI->hasStride(V); }
379 
380  /// Returns true if vector representation of the instruction \p I
381  /// requires mask.
382  bool isMaskRequired(const Instruction *I) const {
383  return MaskedOp.contains(I);
384  }
385 
386  unsigned getNumStores() const { return LAI->getNumStores(); }
387  unsigned getNumLoads() const { return LAI->getNumLoads(); }
388 
389  /// Returns all assume calls in predicated blocks. They need to be dropped
390  /// when flattening the CFG.
392  return ConditionalAssumes;
393  }
394 
395 private:
396  /// Return true if the pre-header, exiting and latch blocks of \p Lp and all
397  /// its nested loops are considered legal for vectorization. These legal
398  /// checks are common for inner and outer loop vectorization.
399  /// Temporarily taking UseVPlanNativePath parameter. If true, take
400  /// the new code path being implemented for outer loop vectorization
401  /// (should be functional for inner loop vectorization) based on VPlan.
402  /// If false, good old LV code.
403  bool canVectorizeLoopNestCFG(Loop *Lp, bool UseVPlanNativePath);
404 
405  /// Set up outer loop inductions by checking Phis in outer loop header for
406  /// supported inductions (int inductions). Return false if any of these Phis
407  /// is not a supported induction or if we fail to find an induction.
408  bool setupOuterLoopInductions();
409 
410  /// Return true if the pre-header, exiting and latch blocks of \p Lp
411  /// (non-recursive) are considered legal for vectorization.
412  /// Temporarily taking UseVPlanNativePath parameter. If true, take
413  /// the new code path being implemented for outer loop vectorization
414  /// (should be functional for inner loop vectorization) based on VPlan.
415  /// If false, good old LV code.
416  bool canVectorizeLoopCFG(Loop *Lp, bool UseVPlanNativePath);
417 
418  /// Check if a single basic block loop is vectorizable.
419  /// At this point we know that this is a loop with a constant trip count
420  /// and we only need to check individual instructions.
421  bool canVectorizeInstrs();
422 
423  /// When we vectorize loops we may change the order in which
424  /// we read and write from memory. This method checks if it is
425  /// legal to vectorize the code, considering only memory constrains.
426  /// Returns true if the loop is vectorizable
427  bool canVectorizeMemory();
428 
429  /// Return true if we can vectorize this loop using the IF-conversion
430  /// transformation.
431  bool canVectorizeWithIfConvert();
432 
433  /// Return true if we can vectorize this outer loop. The method performs
434  /// specific checks for outer loop vectorization.
435  bool canVectorizeOuterLoop();
436 
437  /// Return true if all of the instructions in the block can be speculatively
438  /// executed, and record the loads/stores that require masking.
439  /// \p SafePtrs is a list of addresses that are known to be legal and we know
440  /// that we can read from them without segfault.
441  /// \p MaskedOp is a list of instructions that have to be transformed into
442  /// calls to the appropriate masked intrinsic when the loop is vectorized.
443  /// \p ConditionalAssumes is a list of assume instructions in predicated
444  /// blocks that must be dropped if the CFG gets flattened.
445  bool blockCanBePredicated(
448  SmallPtrSetImpl<Instruction *> &ConditionalAssumes) const;
449 
450  /// Updates the vectorization state by adding \p Phi to the inductions list.
451  /// This can set \p Phi as the main induction of the loop if \p Phi is a
452  /// better choice for the main induction than the existing one.
453  void addInductionPhi(PHINode *Phi, const InductionDescriptor &ID,
454  SmallPtrSetImpl<Value *> &AllowedExit);
455 
456  /// If an access has a symbolic strides, this maps the pointer value to
457  /// the stride symbol.
458  const ValueToValueMap *getSymbolicStrides() const {
459  // FIXME: Currently, the set of symbolic strides is sometimes queried before
460  // it's collected. This happens from canVectorizeWithIfConvert, when the
461  // pointer is checked to reference consecutive elements suitable for a
462  // masked access.
463  return LAI ? &LAI->getSymbolicStrides() : nullptr;
464  }
465 
466  /// The loop that we evaluate.
467  Loop *TheLoop;
468 
469  /// Loop Info analysis.
470  LoopInfo *LI;
471 
472  /// A wrapper around ScalarEvolution used to add runtime SCEV checks.
473  /// Applies dynamic knowledge to simplify SCEV expressions in the context
474  /// of existing SCEV assumptions. The analysis will also add a minimal set
475  /// of new predicates if this is required to enable vectorization and
476  /// unrolling.
477  PredicatedScalarEvolution &PSE;
478 
479  /// Target Transform Info.
480  TargetTransformInfo *TTI;
481 
482  /// Target Library Info.
483  TargetLibraryInfo *TLI;
484 
485  /// Dominator Tree.
486  DominatorTree *DT;
487 
488  // LoopAccess analysis.
489  std::function<const LoopAccessInfo &(Loop &)> *GetLAA;
490 
491  // And the loop-accesses info corresponding to this loop. This pointer is
492  // null until canVectorizeMemory sets it up.
493  const LoopAccessInfo *LAI = nullptr;
494 
495  /// Interface to emit optimization remarks.
496  OptimizationRemarkEmitter *ORE;
497 
498  // --- vectorization state --- //
499 
500  /// Holds the primary induction variable. This is the counter of the
501  /// loop.
502  PHINode *PrimaryInduction = nullptr;
503 
504  /// Holds the reduction variables.
505  ReductionList Reductions;
506 
507  /// Holds all of the induction variables that we found in the loop.
508  /// Notice that inductions don't need to start at zero and that induction
509  /// variables can be pointers.
510  InductionList Inductions;
511 
512  /// Holds all the casts that participate in the update chain of the induction
513  /// variables, and that have been proven to be redundant (possibly under a
514  /// runtime guard). These casts can be ignored when creating the vectorized
515  /// loop body.
516  SmallPtrSet<Instruction *, 4> InductionCastsToIgnore;
517 
518  /// Holds the phi nodes that are first-order recurrences.
519  RecurrenceSet FirstOrderRecurrences;
520 
521  /// Holds instructions that need to sink past other instructions to handle
522  /// first-order recurrences.
523  MapVector<Instruction *, Instruction *> SinkAfter;
524 
525  /// Holds the widest induction type encountered.
526  Type *WidestIndTy = nullptr;
527 
528  /// Allowed outside users. This holds the variables that can be accessed from
529  /// outside the loop.
530  SmallPtrSet<Value *, 4> AllowedExit;
531 
532  /// Vectorization requirements that will go through late-evaluation.
533  LoopVectorizationRequirements *Requirements;
534 
535  /// Used to emit an analysis of any legality issues.
536  LoopVectorizeHints *Hints;
537 
538  /// The demanded bits analysis is used to compute the minimum type size in
539  /// which a reduction can be computed.
540  DemandedBits *DB;
541 
542  /// The assumption cache analysis is used to compute the minimum type size in
543  /// which a reduction can be computed.
544  AssumptionCache *AC;
545 
546  /// While vectorizing these instructions we have to generate a
547  /// call to the appropriate masked intrinsic
548  SmallPtrSet<const Instruction *, 8> MaskedOp;
549 
550  /// Assume instructions in predicated blocks must be dropped if the CFG gets
551  /// flattened.
552  SmallPtrSet<Instruction *, 8> ConditionalAssumes;
553 
554  /// BFI and PSI are used to check for profile guided size optimizations.
555  BlockFrequencyInfo *BFI;
556  ProfileSummaryInfo *PSI;
557 };
558 
559 } // namespace llvm
560 
561 #endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONLEGALITY_H
llvm::LoopVectorizationLegality::RecurrenceSet
SmallPtrSet< const PHINode *, 8 > RecurrenceSet
RecurrenceSet contains the phi nodes that are recurrences other than inductions and reductions.
Definition: LoopVectorizationLegality.h:271
llvm::hasUnrollTransformation
TransformationMode hasUnrollTransformation(const Loop *L)
Definition: LoopUtils.cpp:360
llvm::LoopVectorizeHints::setPotentiallyUnsafe
void setPotentiallyUnsafe()
Definition: LoopVectorizationLegality.h:185
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::LoopVectorizationLegality::getSinkAfter
MapVector< Instruction *, Instruction * > & getSinkAfter()
Return the set of instructions to sink to handle first-order recurrences.
Definition: LoopVectorizationLegality.h:305
llvm::LoopVectorizationLegality::getNumLoads
unsigned getNumLoads() const
Definition: LoopVectorizationLegality.h:387
llvm::ElementCount
Definition: TypeSize.h:386
llvm::hasDisableAllTransformsHint
bool hasDisableAllTransformsHint(const Loop *L)
Look for the loop attribute that disables all transformation heuristic.
Definition: LoopUtils.cpp:352
llvm::Function
Definition: Function.h:62
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
llvm::LoopVectorizationLegality::getLAI
const LoopAccessInfo * getLAI() const
Definition: LoopVectorizationLegality.h:366
llvm::LoopVectorizeHints::getPredicate
unsigned getPredicate() const
Definition: LoopVectorizationLegality.h:139
TypeSize.h
llvm::PredicatedScalarEvolution
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
Definition: ScalarEvolution.h:2115
llvm::LoopVectorizationRequirements::addRuntimePointerChecks
void addRuntimePointerChecks(unsigned Num)
Definition: LoopVectorizationLegality.h:221
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
LoopAccessAnalysis.h
MapVector.h
llvm::LoopVectorizeHints::SK_Unspecified
@ SK_Unspecified
Not selected.
Definition: LoopVectorizationLegality.h:101
llvm::LoopVectorizationLegality
LoopVectorizationLegality checks if it is legal to vectorize a loop, and to what vectorization factor...
Definition: LoopVectorizationLegality.h:248
OptimizationRemarkEmitter.h
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
llvm::LoopVectorizationLegality::isInductionVariable
bool isInductionVariable(const Value *V)
Returns True if V can be considered as an induction variable in this loop.
Definition: LoopVectorizationLegality.cpp:946
llvm::MemoryDepChecker::getMaxSafeVectorWidthInBits
uint64_t getMaxSafeVectorWidthInBits() const
Return the number of elements that are safe to operate on simultaneously, multiplied by the size of t...
Definition: LoopAccessAnalysis.h:210
llvm::LoopVectorizeHints::SK_FixedWidthOnly
@ SK_FixedWidthOnly
Disables vectorization with scalable vectors.
Definition: LoopVectorizationLegality.h:103
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::LoopVectorizeHints::getWidth
ElementCount getWidth() const
Definition: LoopVectorizationLegality.h:125
llvm::LoopVectorizationLegality::canVectorizeFPMath
bool canVectorizeFPMath(bool EnableStrictReductions)
Returns true if it is legal to vectorize the FP math operations in this loop.
Definition: LoopVectorizationLegality.cpp:906
llvm::LoopVectorizeHints::getIsVectorized
unsigned getIsVectorized() const
Definition: LoopVectorizationLegality.h:138
llvm::MapVector< PHINode *, RecurrenceDescriptor >
llvm::SmallPtrSet< const PHINode *, 8 >
llvm::LoopVectorizeHints::isScalableVectorizationExplicitlyEnabled
bool isScalableVectorizationExplicitlyEnabled() const
Definition: LoopVectorizationLegality.h:155
llvm::RISCVFeatures::validate
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
Definition: RISCVBaseInfo.cpp:95
llvm::LoopVectorizationLegality::isInductionPhi
bool isInductionPhi(const Value *V)
Returns True if V is a Phi node of an induction variable in this loop.
Definition: LoopVectorizationLegality.cpp:932
llvm::LoopVectorizationLegality::prepareToFoldTailByMasking
bool prepareToFoldTailByMasking()
Return true if we can vectorize this loop while folding its tail by masking, and mark all respective ...
Definition: LoopVectorizationLegality.cpp:1253
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::LoopVectorizationRequirements::getNumRuntimePointerChecks
unsigned getNumRuntimePointerChecks() const
Definition: LoopVectorizationLegality.h:226
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::LoopVectorizationRequirements
This holds vectorization requirements that must be verified late in the process.
Definition: LoopVectorizationLegality.h:213
llvm::LoopVectorizeHints::FK_Undefined
@ FK_Undefined
Not selected.
Definition: LoopVectorizationLegality.h:94
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
llvm::InductionDescriptor
A struct for saving information about induction variables.
Definition: IVDescriptors.h:289
llvm::LinearPolySize< ElementCount >::get
static ElementCount get(ScalarTy MinVal, bool Scalable)
Definition: TypeSize.h:290
llvm::LoopVectorizationLegality::ReductionList
MapVector< PHINode *, RecurrenceDescriptor > ReductionList
ReductionList contains the reduction descriptors for all of the reductions that were found in the loo...
Definition: LoopVectorizationLegality.h:263
llvm::AAResults
Definition: AliasAnalysis.h:508
llvm::LoopAccessInfo::getNumLoads
unsigned getNumLoads() const
Definition: LoopAccessAnalysis.h:549
llvm::LoopVectorizeHints::vectorizeAnalysisPassName
const char * vectorizeAnalysisPassName() const
If hints are provided that force vectorization, use the AlwaysPrint pass name to force the frontend t...
Definition: LoopVectorizationLegality.cpp:211
llvm::LoopVectorizationRequirements::addExactFPMathInst
void addExactFPMathInst(Instruction *I)
Track the 1st floating-point instruction that can not be reassociated.
Definition: LoopVectorizationLegality.h:216
llvm::LoopVectorizationLegality::blockNeedsPredication
bool blockNeedsPredication(BasicBlock *BB) const
Return true if the block BB needs to be predicated in order for the loop to be vectorized.
Definition: LoopVectorizationLegality.cpp:954
llvm::Instruction
Definition: Instruction.h:45
llvm::LoopVectorizeHints::getForce
enum ForceKind getForce() const
Definition: LoopVectorizationLegality.h:140
llvm::LoopAccessInfo::hasStride
bool hasStride(Value *V) const
Pointer has a symbolic stride.
Definition: LoopAccessAnalysis.h:571
LoopUtils.h
llvm::LoopVectorizationLegality::isFirstOrderRecurrence
bool isFirstOrderRecurrence(const PHINode *Phi)
Returns True if Phi is a first-order recurrence in this loop.
Definition: LoopVectorizationLegality.cpp:950
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::LoopVectorizationLegality::hasStride
bool hasStride(Value *V)
Definition: LoopVectorizationLegality.h:378
llvm::LoopVectorizationLegality::getConditionalAssumes
const SmallPtrSetImpl< Instruction * > & getConditionalAssumes() const
Returns all assume calls in predicated blocks.
Definition: LoopVectorizationLegality.h:391
llvm::LoopAccessInfo::getSymbolicStrides
const ValueToValueMap & getSymbolicStrides() const
If an access has a symbolic strides, this maps the pointer value to the stride symbol.
Definition: LoopAccessAnalysis.h:568
llvm::LoopVectorizeHints
Utility class for getting and setting loop vectorizer hints in the form of loop metadata.
Definition: LoopVectorizationLegality.h:46
llvm::LoopVectorizeHints::SK_PreferScalable
@ SK_PreferScalable
Vectorize loops using scalable vectors or fixed-width vectors, but favor scalable vectors when the co...
Definition: LoopVectorizationLegality.h:107
llvm::RuntimePointerChecking
Holds information about the memory runtime legality checks to verify that a group of pointers do not ...
Definition: LoopAccessAnalysis.h:368
llvm::LoopVectorizationLegality::isMaskRequired
bool isMaskRequired(const Instruction *I) const
Returns true if vector representation of the instruction I requires mask.
Definition: LoopVectorizationLegality.h:382
uint64_t
llvm::LoopVectorizeHints::FK_Enabled
@ FK_Enabled
Forcing enabled.
Definition: LoopVectorizationLegality.h:96
llvm::LoopVectorizationLegality::isCastedInductionVariable
bool isCastedInductionVariable(const Value *V)
Returns True if V is a cast that is part of an induction def-use chain, and had been proven to be red...
Definition: LoopVectorizationLegality.cpp:941
llvm::LoopVectorizeHints::getInterleave
unsigned getInterleave() const
Definition: LoopVectorizationLegality.h:129
llvm::LoopVectorizeHints::allowVectorization
bool allowVectorization(Function *F, Loop *L, bool VectorizeOnlyWhenForced) const
Definition: LoopVectorizationLegality.cpp:152
llvm::DenseMap< const Value *, Value * >
llvm::DemandedBits
Definition: DemandedBits.h:40
llvm::LoopAccessInfo::getRuntimePointerChecking
const RuntimePointerChecking * getRuntimePointerChecking() const
Definition: LoopAccessAnalysis.h:529
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::LoopVectorizationLegality::getFirstOrderRecurrences
RecurrenceSet & getFirstOrderRecurrences()
Return the first-order recurrences found in the loop.
Definition: LoopVectorizationLegality.h:302
llvm::LoopAccessInfo
Drive the analysis of memory accesses in the loop.
Definition: LoopAccessAnalysis.h:515
llvm::LoopVectorizationLegality::LoopVectorizationLegality
LoopVectorizationLegality(Loop *L, PredicatedScalarEvolution &PSE, DominatorTree *DT, TargetTransformInfo *TTI, TargetLibraryInfo *TLI, AAResults *AA, Function *F, std::function< const LoopAccessInfo &(Loop &)> *GetLAA, LoopInfo *LI, OptimizationRemarkEmitter *ORE, LoopVectorizationRequirements *R, LoopVectorizeHints *H, DemandedBits *DB, AssumptionCache *AC, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI)
Definition: LoopVectorizationLegality.h:250
llvm::LoopVectorizationLegality::getReductionVars
ReductionList & getReductionVars()
Returns the reduction variables found in the loop.
Definition: LoopVectorizationLegality.h:296
llvm::TM_Disable
@ TM_Disable
The transformation should not be applied.
Definition: LoopUtils.h:275
llvm::LoopVectorizationLegality::isReductionVariable
bool isReductionVariable(PHINode *PN)
Returns True if PN is a reduction variable in this loop.
Definition: LoopVectorizationLegality.h:324
llvm::LoopVectorizationLegality::getNumStores
unsigned getNumStores() const
Definition: LoopVectorizationLegality.h:386
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::LoopVectorizationRequirements::getExactFPInst
Instruction * getExactFPInst()
Definition: LoopVectorizationLegality.h:224
llvm::LoopVectorizationLegality::isUniform
bool isUniform(Value *V)
Returns true if the value V is uniform within the loop.
Definition: LoopVectorizationLegality.cpp:439
llvm::LoopAccessInfo::getDepChecker
const MemoryDepChecker & getDepChecker() const
the Memory Dependence Checker which can determine the loop-independent and loop-carried dependences b...
Definition: LoopAccessAnalysis.h:557
llvm::LoopInfo
Definition: LoopInfo.h:1083
llvm::OptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: OptimizationRemarkEmitter.h:33
llvm::LoopVectorizationLegality::isConsecutivePtr
int isConsecutivePtr(Type *AccessTy, Value *Ptr) const
Check if this pointer is consecutive when vectorizing.
Definition: LoopVectorizationLegality.cpp:422
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
llvm::LoopVectorizeHints::ScalableForceKind
ScalableForceKind
Definition: LoopVectorizationLegality.h:99
llvm::LoopVectorizationLegality::getInductionVars
InductionList & getInductionVars()
Returns the induction variables found in the loop.
Definition: LoopVectorizationLegality.h:299
llvm::LoopVectorizeHints::emitRemarkWithHints
void emitRemarkWithHints() const
Dumps all the hint information.
Definition: LoopVectorizationLegality.cpp:185
llvm::LoopVectorizationLegality::getRuntimePointerChecking
const RuntimePointerChecking * getRuntimePointerChecking() const
Returns the information that we collected about runtime memory check.
Definition: LoopVectorizationLegality.h:362
llvm::LoopAccessInfo::getMaxSafeDepDistBytes
uint64_t getMaxSafeDepDistBytes() const
Definition: LoopAccessAnalysis.h:547
llvm::LoopVectorizationLegality::isUniformMemOp
bool isUniformMemOp(Instruction &I)
A uniform memory op is a load or store which accesses the same memory location on all lanes.
Definition: LoopVectorizationLegality.h:350
llvm::LoopAccessInfo::getNumStores
unsigned getNumStores() const
Definition: LoopAccessAnalysis.h:548
llvm::MapVector::count
size_type count(const KeyT &Key) const
Definition: MapVector.h:142
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MemoryDepChecker::isSafeForAnyVectorWidth
bool isSafeForAnyVectorWidth() const
Return true if the number of elements that are safe to operate on simultaneously is not bounded.
Definition: LoopAccessAnalysis.h:200
H
#define H(x, y, z)
Definition: MD5.cpp:58
llvm::LoopVectorizeHints::ForceKind
ForceKind
Definition: LoopVectorizationLegality.h:93
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::LoopVectorizationLegality::getMaxSafeVectorWidthInBits
uint64_t getMaxSafeVectorWidthInBits() const
Definition: LoopVectorizationLegality.h:374
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
llvm::LoopVectorizeHints::LoopVectorizeHints
LoopVectorizeHints(const Loop *L, bool InterleaveOnlyWhenForced, OptimizationRemarkEmitter &ORE)
Definition: LoopVectorizationLegality.cpp:96
llvm::LoopVectorizeHints::setAlreadyVectorized
void setAlreadyVectorized()
Mark the loop L as already vectorized by setting the width to 1.
Definition: LoopVectorizationLegality.cpp:133
llvm::LoopVectorizeHints::isScalableVectorizationDisabled
bool isScalableVectorizationDisabled() const
Definition: LoopVectorizationLegality.h:161
llvm::LoopVectorizationLegality::isSafeForAnyVectorWidth
bool isSafeForAnyVectorWidth() const
Definition: LoopVectorizationLegality.h:368
llvm::PHINode
Definition: Instructions.h:2633
llvm::LoopVectorizeHints::allowReordering
bool allowReordering() const
When enabling loop hints are provided we allow the vectorizer to change the order of operations that ...
Definition: LoopVectorizationLegality.cpp:221
llvm::SmallPtrSetImpl< Instruction * >
llvm::getLoadStorePointerOperand
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
Definition: Instructions.h:5299
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::LoopVectorizationLegality::getPrimaryInduction
PHINode * getPrimaryInduction()
Returns the primary induction variable.
Definition: LoopVectorizationLegality.h:293
llvm::LoopVectorizeHints::SK_PreferFixedWidth
@ SK_PreferFixedWidth
Vectorize loops using scalable vectors or fixed-width vectors, but favor fixed-width vectors when the...
Definition: LoopVectorizationLegality.h:110
llvm::LoopVectorizationLegality::getMaxSafeDepDistBytes
unsigned getMaxSafeDepDistBytes()
Definition: LoopVectorizationLegality.h:372
llvm::LoopVectorizeHints::FK_Disabled
@ FK_Disabled
Forcing disabled.
Definition: LoopVectorizationLegality.h:95
llvm::LoopVectorizeHints::isScalableVectorizationPreferred
bool isScalableVectorizationPreferred() const
Definition: LoopVectorizationLegality.h:150
llvm::LoopVectorizationLegality::canVectorize
bool canVectorize(bool UseVPlanNativePath)
Returns true if it is legal to vectorize this loop.
Definition: LoopVectorizationLegality.cpp:1159
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::LoopVectorizationLegality::getWidestInductionType
Type * getWidestInductionType()
Returns the widest induction type.
Definition: LoopVectorizationLegality.h:308
llvm::LoopVectorizeHints::isPotentiallyUnsafe
bool isPotentiallyUnsafe() const
Definition: LoopVectorizationLegality.h:176
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::LoopVectorizationLegality::InductionList
MapVector< PHINode *, InductionDescriptor > InductionList
InductionList saves induction variables and maps them to the induction descriptor.
Definition: LoopVectorizationLegality.h:267