LLVM 24.0.0git
SLPCompatibilityAnalysis.h
Go to the documentation of this file.
1//===- SLPCompatibilityAnalysis.h - SLP same-opcode helpers ----*- 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// Internal header used by SLPVectorizer.cpp. It declares the same-opcode
10// compatibility primitives that decide whether a group of values can be
11// treated as sharing the same (or an interchangeable/alternate) opcode. These
12// do not depend on BoUpSLP or any other SLP-private type.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
18
19#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/STLExtras.h"
24#include "llvm/IR/Instruction.h"
26
27#include <cstdint>
28#include <utility>
29
30namespace llvm {
31class APInt;
32class BasicBlock;
33class Constant;
34class ConstantInt;
35class DominatorTree;
36class LoopInfo;
38class Value;
39} // namespace llvm
40
41namespace llvm::slpvectorizer {
42
43/// \returns true if \p Opcode is allowed as part of the main/alternate
44/// instruction for SLP vectorization.
45///
46/// Example of unsupported opcode is SDIV that can potentially cause UB if the
47/// "shuffled out" lane would result in division by zero.
48bool isValidForAlternation(unsigned Opcode);
49
50/// Helper class that determines VL can use the same opcode.
51/// Alternate instruction is supported. In addition, it supports interchangeable
52/// instruction. An interchangeable instruction is an instruction that can be
53/// converted to another instruction with same semantics. For example, x << 1 is
54/// equal to x * 2. x * 1 is equal to x | 0.
56 using MaskType = std::uint_fast32_t;
57 /// Sort SupportedOp because it is used by binary_search.
58 constexpr static unsigned SupportedOp[] = {
59 Instruction::Add, Instruction::FAdd, Instruction::Sub, Instruction::FSub,
60 Instruction::Mul, Instruction::Shl, Instruction::AShr, Instruction::And,
61 Instruction::Or, Instruction::Xor};
62 static_assert(llvm::is_sorted_constexpr(SupportedOp) &&
63 "SupportedOp is not sorted.");
64 enum : MaskType {
65 ShlBIT = 1,
66 AShrBIT = 1 << 1,
67 MulBIT = 1 << 2,
68 AddBIT = 1 << 3,
69 SubBIT = 1 << 4,
70 AndBIT = 1 << 5,
71 OrBIT = 1 << 6,
72 XorBIT = 1 << 7,
73 FAddBIT = 1 << 8,
74 FSubBIT = 1 << 9,
75 MainOpBIT = 1 << 10,
77 };
78 /// Return a non-nullptr if either operand of I is a ConstantInt (for the
79 /// integer opcodes) or a ConstantFP (for FAdd/FSub).
80 /// The second return value represents the operand position. We check the
81 /// right-hand side first (1). If the right hand side is not a constant and
82 /// the instruction is neither Sub, FSub, Shl, nor AShr, we then check the
83 /// left hand side (0).
84 static std::pair<Constant *, unsigned>
85 isBinOpWithConstant(const Instruction *I);
86 struct InterchangeableInfo {
87 const Instruction *I = nullptr;
88 /// The bit it sets represents whether MainOp can be converted to.
89 MaskType Mask = MainOpBIT | XorBIT | OrBIT | AndBIT | SubBIT | AddBIT |
90 MulBIT | AShrBIT | ShlBIT | FSubBIT | FAddBIT;
91 /// We cannot create an interchangeable instruction that does not exist in
92 /// VL. For example, VL [x + 0, y * 1] can be converted to [x << 0, y << 0],
93 /// but << does not exist in VL. In the end, we convert VL to [x * 1, y *
94 /// 1]. SeenBefore is used to know what operations have been seen before.
95 MaskType SeenBefore = 0;
96 InterchangeableInfo(const Instruction *I) : I(I) {}
97 /// Return false allows BinOpSameOpcodeHelper to find an alternate
98 /// instruction. Directly setting the mask will destroy the mask state,
99 /// preventing us from determining which instruction it should convert to.
100 bool trySet(MaskType OpcodeInMaskForm, MaskType InterchangeableMask);
101 bool equal(unsigned Opcode) {
102 return Opcode == I->getOpcode() && trySet(MainOpBIT, MainOpBIT);
103 }
104 unsigned getOpcode() const;
105 bool hasDefinedOpcode() const { return (Mask & SeenBefore) > 0; }
106 /// Return true if the instruction can be converted to \p Opcode.
107 bool hasCandidateOpcode(unsigned Opcode) const;
109 };
110 InterchangeableInfo MainOp;
111 InterchangeableInfo AltOp;
112 bool isValidForAlternation(const Instruction *I) const;
113 bool initializeAltOp(const Instruction *I);
114
115public:
117 const Instruction *AltOp = nullptr)
118 : MainOp(MainOp), AltOp(AltOp) {}
119 bool add(const Instruction *I);
120 unsigned getMainOpcode() const { return MainOp.getOpcode(); }
121 bool hasDefinedMainOpcode() const { return MainOp.hasDefinedOpcode(); }
122 /// Checks if the list of potential opcodes includes \p Opcode.
123 bool hasCandidateOpcode(unsigned Opcode) const {
124 return MainOp.hasCandidateOpcode(Opcode);
125 }
126 bool hasAltOp() const { return AltOp.I; }
127 unsigned getAltOpcode() const {
128 return hasAltOp() ? AltOp.getOpcode() : getMainOpcode();
129 }
130 bool hasDefinedAltOpcode() const {
131 return !hasAltOp() || AltOp.hasDefinedOpcode();
132 }
134 return MainOp.getOperand(I);
135 }
136};
137
138/// Helper class that determines whether a list of integer comparisons can
139/// share a single predicate. InstCombine canonicalizes single-element and
140/// single-complement range comparisons to eq/ne at the type boundaries
141/// (e.g. x <u 1 becomes x == 0); such lanes are interchangeable with the
142/// rest of the list by adjusting the compared constant. InstCombine also
143/// canonicalizes icmp ne (and X, 1), 0 to trunc X to i1, such lanes are
144/// treated as the original comparison or as icmp eq (and X, 1), 1. An i1
145/// constant lane is the comparison of constants with any predicate.
147 using MaskType = std::uint16_t;
148 /// Bit i represents predicate ICMP_EQ + i.
149 static constexpr unsigned NumPreds = CmpInst::ICMP_SLE - CmpInst::ICMP_EQ + 1;
150 static constexpr MaskType AllPreds = (1 << NumPreds) - 1;
151 /// Intersection of the per-lane convertible predicate sets.
152 MaskType Mask = AllPreds;
153 /// Predicates present in the list natively. The shared predicate must be
154 /// one of them: the main op must be an actual instruction with this
155 /// predicate.
156 MaskType SeenBefore = 0;
157
158 static constexpr MaskType getBit(CmpInst::Predicate P) {
159 return static_cast<MaskType>(1) << (P - CmpInst::ICMP_EQ);
160 }
161 /// Returns the mask of the predicates that can express the comparison
162 /// (Pred, X, C) with an adjusted constant C, including Pred itself.
163 static MaskType getFormsMask(CmpInst::Predicate Pred, const APInt &C);
164 /// Returns the constant of the (Pred, X, C') form equivalent to the
165 /// boundary family (IsComplement, K). Pred must be in the family mask.
166 static APInt getFamilyConstant(bool IsComplement, const APInt &K,
168 /// Returns the mask of the predicates that can express the comparison
169 /// lane \p V, or 0 if \p V is not a comparison lane.
170 static MaskType getLaneMask(const Value *V);
171
172public:
173 /// Intersects the convertible predicate set of the comparison lane \p V
174 /// (an icmp, a trunc to i1 or an i1 constant) with the running set.
175 /// Returns false when the intersection becomes empty.
176 bool add(const Value *V);
177 /// Returns the shared predicate, preferring the predicate of
178 /// \p Preferred when the whole list can use it, or BAD_ICMP_PREDICATE
179 /// when the list cannot share a natively present predicate.
180 CmpInst::Predicate getPredicate(const ICmpInst *Preferred) const;
181 /// Returns the predicate the whole list can share, or BAD_ICMP_PREDICATE
182 /// when it cannot share a natively present predicate.
184 const ICmpInst *Preferred);
185 /// Checks if the comparison lane \p I is the bit test of the single use
186 /// and A, B != 0 or and A, B == 0, or trunc X to i1, which is
187 /// and X, 1 != 0.
188 static bool isBitTest(const Instruction *I);
189 /// Checks if the comparison lane \p V can be expressed with the predicate
190 /// \p Pred by adjusting its constant operand.
191 static bool canConvertTo(const Value *V, CmpInst::Predicate Pred);
192 /// Returns the adjusted constant operand expressing the comparison lane
193 /// \p I with the predicate \p Pred, or nullptr if not convertible or if
194 /// \p I is a compare already using \p Pred.
197 /// Returns the constant operands expressing the i1 constant lane \p V as
198 /// the comparison \p Cmp.
200 const ICmpInst *Cmp);
201};
202
203/// Checks if \p I is a call to llvm.fma or llvm.fmuladd.
204bool isFMAOrFMulAdd(const Instruction *I);
205
206/// How the FP identity ops of the copyable lanes produce the lane values:
207/// exactly, inexactly (a NaN may be quieted and a subnormal flushed, so the
208/// vector is valid only for FP math) or with the original values blended in.
210
211/// Main data required for vectorization of instructions.
213 /// MainOp and AltOp are primarily determined by getSameOpcode. Currently,
214 /// only BinaryOperator, CastInst, and CmpInst support alternate instructions
215 /// (i.e., AltOp is not equal to MainOp; this can be checked using
216 /// isAltShuffle).
217 /// A rare exception is TrySplitNode, where the InstructionsState is derived
218 /// from getMainAltOpsNoStateVL.
219 /// For those InstructionsState that use alternate instructions, the resulting
220 /// vectorized output ultimately comes from a shufflevector. For example,
221 /// given a vector list (VL):
222 /// VL[0] = add i32 a, e
223 /// VL[1] = sub i32 b, f
224 /// VL[2] = add i32 c, g
225 /// VL[3] = sub i32 d, h
226 /// The vectorized result would be:
227 /// intermediated_0 = add <4 x i32> <a, b, c, d>, <e, f, g, h>
228 /// intermediated_1 = sub <4 x i32> <a, b, c, d>, <e, f, g, h>
229 /// result = shufflevector <4 x i32> intermediated_0,
230 /// <4 x i32> intermediated_1,
231 /// <4 x i32> <i32 0, i32 5, i32 2, i32 7>
232 /// Since shufflevector is used in the final result, when calculating the cost
233 /// (getEntryCost), we must account for the usage of shufflevector in
234 /// GetVectorCost.
235 Instruction *MainOp = nullptr;
236 Instruction *AltOp = nullptr;
237 /// Whether the instruction state represents copyable instructions.
238 bool HasCopyables = false;
239 /// Index of the operand modeling the copyable values: the addend for
240 /// fma/fmuladd (retried with a multiplicand), the first operand otherwise.
241 unsigned CopyableOpIdx = 0;
242 /// Whether copyable single-use fmuls/fadds are modeled as
243 /// fmuladd(a, b, -0.0)/fmuladd(1.0, a, b), absorbing the binop instead of
244 /// computing and gathering its result.
245 bool AbsorbCopyableFMulOrFAdd = false;
246 /// How the FP identity ops produce the values of the copyable lanes.
247 FPCopyables FPCopyablesKind = FPCopyables::Exact;
248 /// Whether the matching instructions are in different blocks of a region,
249 /// so the instructions from other blocks are not copyable.
250 bool IsRegion = false;
251
252public:
254 assert(valid() && "InstructionsState is invalid.");
255 return MainOp;
256 }
257
259 assert(valid() && "InstructionsState is invalid.");
260 return AltOp;
261 }
262
263 /// The main/alternate opcodes for the list of instructions.
264 unsigned getOpcode() const { return getMainOp()->getOpcode(); }
265
266 unsigned getAltOpcode() const { return getAltOp()->getOpcode(); }
267
268 /// Some of the instructions in the list have alternate opcodes.
269 bool isAltShuffle() const { return getMainOp() != getAltOp(); }
270
271 /// Checks if \p I is the same operation as \p Op, distinguishing calls by
272 /// intrinsic ID (all calls share the Call opcode, so e.g. umax != smax).
273 static bool isSameOperation(const Instruction *I, const Instruction *Op);
274
275 /// Checks if the instruction matches either the main or alternate opcode.
276 /// \returns
277 /// - MainOp if \param I matches MainOp's opcode directly or can be converted
278 /// to it
279 /// - AltOp if \param I matches AltOp's opcode directly or can be converted to
280 /// it
281 /// - nullptr if \param I cannot be matched or converted to either opcode
283
284 /// Checks if main/alt instructions are shift operations.
285 bool isShiftOp() const {
286 return getMainOp()->isShift() && getAltOp()->isShift();
287 }
288
289 /// Checks if main/alt instructions are bitwise logic operations.
290 bool isBitwiseLogicOp() const {
292 }
293
294 /// Checks if main/alt instructions are mul/div/rem/fmul/fdiv/frem operations.
295 bool isMulDivLikeOp() const;
296
297 /// Checks if main/alt instructions are add/sub/fadd/fsub operations.
298 bool isAddSubLikeOp() const;
299
300 /// Checks for an add/sub-like operation or an fneg, which models a
301 /// flattened fadd reduction chain link: the link is dropped and its
302 /// operand joins a sign-flipped combine, which may form an fma as well.
303 bool isAddSubOrFNegLikeOp() const;
304
305 /// Checks if main/alt instructions are cmp operations.
306 bool isCmpOp() const {
307 return (getOpcode() == Instruction::ICmp ||
308 getOpcode() == Instruction::FCmp) &&
309 getAltOpcode() == getOpcode();
310 }
311
312 /// Checks if the current state is valid, i.e. has non-null MainOp
313 bool valid() const { return MainOp && AltOp; }
314
315 explicit operator bool() const { return valid(); }
316
319 bool HasCopyables = false, bool IsRegion = false)
320 : MainOp(MainOp), AltOp(AltOp), HasCopyables(HasCopyables),
321 CopyableOpIdx(MainOp && isFMAOrFMulAdd(MainOp) ? 2 : 0),
322 IsRegion(IsRegion) {}
323 static InstructionsState invalid() { return {nullptr, nullptr}; }
324
325 /// Checks if the value is a copyable element.
326 bool isCopyableElement(Value *V) const;
327
328 /// Checks if the value \p V is a transformed instruction, compatible either
329 /// with main or alternate ops.
330 bool isExpandedBinOp(Value *V) const;
331
332 /// Checks if the operand at index \p Idx of instruction \p I is an expanded
333 /// operand.
334 bool isExpandedOperand(Instruction *I, unsigned Idx) const;
335
336 /// Checks if the value is non-schedulable.
337 bool isNonSchedulable(Value *V) const;
338
339 /// Checks if the state represents copyable instructions.
341 assert(valid() && "InstructionsState is invalid.");
342 return HasCopyables;
343 }
344
345 /// Returns the index of the operand the copyable value is modeled in.
346 unsigned getCopyableOpIdx() const {
347 assert(valid() && "InstructionsState is invalid.");
348 return CopyableOpIdx;
349 }
350
351 /// Sets the index of the operand the copyable value is modeled in.
352 void setCopyableOpIdx(unsigned Idx) {
353 assert((Idx == 0 || Idx == 2) && "Unexpected copyable operand index.");
354 CopyableOpIdx = Idx;
355 }
356
357 /// Checks if copyable fmuls/fadds are absorbed as fmuladd(a, b, -0.0) or
358 /// fmuladd(1.0, a, b).
360 assert(valid() && "InstructionsState is invalid.");
361 return AbsorbCopyableFMulOrFAdd;
362 }
363
364 /// Sets the absorbed-fmul/fadd modeling for copyable fmuls/fadds.
365 void setAbsorbCopyableFMulOrFAdd(bool Absorb) {
366 AbsorbCopyableFMulOrFAdd = Absorb;
367 }
368
369 /// Returns how the FP identity ops produce the values of the copyable lanes.
371 assert(valid() && "InstructionsState is invalid.");
372 return FPCopyablesKind;
373 }
374
375 /// Sets how the FP identity ops produce the values of the copyable lanes.
376 void setFPCopyables(FPCopyables Kind) { FPCopyablesKind = Kind; }
377};
378
379/// Checks if \p V is a single-use fmul/fadd with operands outside \p VL.
381
382/// Checks if \p V is a copyable single-use fmul/fadd, absorbable as
383/// fmuladd(a, b, -0.0) or fmuladd(1.0, a, b).
384bool isAbsorbableCopyableFMulOrFAdd(const InstructionsState &S, Value *V);
385
386/// Checks if every copyable in \p VL is an absorbable fmul/fadd: the binops
387/// die instead of being computed and gathered. Operand order is normalized
388/// when the operands are built.
390
391/// \returns analysis of the Instructions in \p VL described in
392/// InstructionsState, the Opcode that we suppose the whole list
393/// could be vectorized even if its structure is diverse.
394InstructionsState getSameOpcode(ArrayRef<Value *> VL,
395 const TargetLibraryInfo &TLI);
396
397/// Checks if the instructions in \p VL are in different reachable blocks of
398/// the same loop (or all of them are out of loops), i.e. can be the scalars
399/// of a region.
401 const LoopInfo &LI);
402
403/// \returns the entry block of the region, if the non-schedulable
404/// instructions \p VL with the state \p S, built for the region scalars, are
405/// executed as often as the entry block and can be vectorized before the first
406/// of them in the entry block, nullptr otherwise.
407BasicBlock *getSESERegionEntry(ArrayRef<Value *> VL, const InstructionsState &S,
408 const DominatorTree &DT, const LoopInfo &LI);
409
410/// \returns the main or alternate operation from \p S matching \p I, together
411/// with the operands of \p I adjusted to the selected operation.
412std::pair<Instruction *, SmallVector<Value *>>
413convertTo(Instruction *I, const InstructionsState &S);
414
415/// Checks if the specified instruction \p I is an alternate operation for
416/// the given \p MainOp and \p AltOp instructions.
418 Instruction *AltOp, const TargetLibraryInfo &TLI);
419
420/// Peel the per-lane associative chains of an alternate node into operand
421/// columns. Lanes peel in lockstep and only chain links with the lane's own
422/// opcode, so every combine level keeps the root's main/alt opcode pattern
423/// and a subtract lane never becomes an add of a negated leaf. Only the
424/// leading (running) column peels: peeling a subtracted subtract would flip
425/// signs. \p SubLanes records the subtract lanes for the realignment sign
426/// query. Returns the flattened columns, empty when no level peels.
428 const InstructionsState &S, const TargetLibraryInfo &TLI,
430 SmallVectorImpl<Value *> &ReassocScalars, SmallBitVector &SubLanes);
431
432/// Returns main/alternate instructions for the given \p VL. Unlike
433/// getSameOpcode supports non-compatible instructions for better SplitVectorize
434/// node support.
435/// \returns first main/alt instructions, if only poisons and instruction with
436/// only 2 opcodes exists. Returns pair of nullptr otherwise.
437std::pair<Instruction *, Instruction *>
439
440/// Detects an extractvalue bundle that can be widened by vectorizing the
441/// underlying struct-returning calls.
442///
443/// \p VL is a bundle whose state \p S is Instruction::ExtractValue. The
444/// bundle is acceptable for widening into one struct-of-vectors call only
445/// when:
446/// - every element of \p VL is an ExtractValueInst,
447/// - every ExtractValueInst extracts the same struct field (its
448/// getIndices() matches the main op's indices),
449/// - the aggregate operands form a uniform set of CallInsts (per
450/// getSameOpcode) that is not an alt-shuffle and whose return type is
451/// a literal struct, and
452/// - every user of every such call is itself an ExtractValueInst, so the
453/// external-use extraction code can rebuild scalars via extractvalue +
454/// extractelement without needing an insertvalue chain.
455///
456/// On success returns true and fills \p Indices with the common field
457/// index path and \p Calls with the per-lane aggregate calls (in VL order),
458/// for the caller to feed as the operand of the new tree entry. Otherwise
459/// returns false and leaves the output parameters untouched.
460bool checkEVsForVecCalls(ArrayRef<Value *> VL, const InstructionsState &S,
461 const TargetLibraryInfo &TLI,
464} // namespace llvm::slpvectorizer
465
466#endif // LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
const TargetLowering & TLI
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:61
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
This is the shared class of boolean and integer constants.
Definition Constants.h:87
This is an important base class in LLVM.
Definition Constant.h:44
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
This instruction compares its operands according to the predicate given to the constructor.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool isShift() const
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
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.
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition Value.h:75
SmallVector< Value * > getOperand(const Instruction *I) const
bool hasCandidateOpcode(unsigned Opcode) const
Checks if the list of potential opcodes includes Opcode.
BinOpSameOpcodeHelper(const Instruction *MainOp, const Instruction *AltOp=nullptr)
Helper class that determines whether a list of integer comparisons can share a single predicate.
static CmpInst::Predicate getSharedPredicate(ArrayRef< Value * > VL, const ICmpInst *Preferred)
Returns the predicate the whole list can share, or BAD_ICMP_PREDICATE when it cannot share a natively...
static SmallVector< Value * > getConstantLaneOperands(const Value *V, const ICmpInst *Cmp)
Returns the constant operands expressing the i1 constant lane V as the comparison Cmp.
static Constant * getAdjustedConstant(const Instruction *I, CmpInst::Predicate Pred)
Returns the adjusted constant operand expressing the comparison lane I with the predicate Pred,...
CmpInst::Predicate getPredicate(const ICmpInst *Preferred) const
Returns the shared predicate, preferring the predicate of Preferred when the whole list can use it,...
static bool isBitTest(const Instruction *I)
Checks if the comparison lane I is the bit test of the single use and A, B != 0 or and A,...
static bool canConvertTo(const Value *V, CmpInst::Predicate Pred)
Checks if the comparison lane V can be expressed with the predicate Pred by adjusting its constant op...
bool add(const Value *V)
Intersects the convertible predicate set of the comparison lane V (an icmp, a trunc to i1 or an i1 co...
Instruction * getMatchingMainOpOrAltOp(Instruction *I) const
Checks if the instruction matches either the main or alternate opcode.
bool areInstructionsWithCopyableElements() const
Checks if the state represents copyable instructions.
void setAbsorbCopyableFMulOrFAdd(bool Absorb)
Sets the absorbed-fmul/fadd modeling for copyable fmuls/fadds.
bool isCmpOp() const
Checks if main/alt instructions are cmp operations.
static bool isSameOperation(const Instruction *I, const Instruction *Op)
Checks if I is the same operation as Op, distinguishing calls by intrinsic ID (all calls share the Ca...
bool valid() const
Checks if the current state is valid, i.e. has non-null MainOp.
bool isExpandedBinOp(Value *V) const
Checks if the value V is a transformed instruction, compatible either with main or alternate ops.
bool isAddSubLikeOp() const
Checks if main/alt instructions are add/sub/fadd/fsub operations.
InstructionsState(Instruction *MainOp, Instruction *AltOp, bool HasCopyables=false, bool IsRegion=false)
bool isShiftOp() const
Checks if main/alt instructions are shift operations.
bool isExpandedOperand(Instruction *I, unsigned Idx) const
Checks if the operand at index Idx of instruction I is an expanded operand.
bool isCopyableElement(Value *V) const
Checks if the value is a copyable element.
bool hasAbsorbedCopyableFMulOrFAdd() const
Checks if copyable fmuls/fadds are absorbed as fmuladd(a, b, -0.0) or fmuladd(1.0,...
bool isAltShuffle() const
Some of the instructions in the list have alternate opcodes.
void setCopyableOpIdx(unsigned Idx)
Sets the index of the operand the copyable value is modeled in.
bool isNonSchedulable(Value *V) const
Checks if the value is non-schedulable.
bool isAddSubOrFNegLikeOp() const
Checks for an add/sub-like operation or an fneg, which models a flattened fadd reduction chain link: ...
void setFPCopyables(FPCopyables Kind)
Sets how the FP identity ops produce the values of the copyable lanes.
unsigned getCopyableOpIdx() const
Returns the index of the operand the copyable value is modeled in.
bool isBitwiseLogicOp() const
Checks if main/alt instructions are bitwise logic operations.
bool isMulDivLikeOp() const
Checks if main/alt instructions are mul/div/rem/fmul/fdiv/frem operations.
FPCopyables getFPCopyables() const
Returns how the FP identity ops produce the values of the copyable lanes.
unsigned getOpcode() const
The main/alternate opcodes for the list of instructions.
A private "module" namespace for types and utilities used by this pass.
SmallVector< SmallVector< Value * > > scanAltAssociativeOperands(const InstructionsState &S, const TargetLibraryInfo &TLI, ArrayRef< Value * > VL, ArrayRef< Value * > Op0, ArrayRef< Value * > Op1, SmallVectorImpl< Value * > &ReassocScalars, SmallBitVector &SubLanes)
Peel the per-lane associative chains of an alternate node into operand columns.
std::pair< Instruction *, SmallVector< Value * > > convertTo(Instruction *I, const InstructionsState &S)
std::pair< Instruction *, Instruction * > getMainAltOpsNoStateVL(ArrayRef< Value * > VL)
Returns main/alternate instructions for the given VL.
bool isAlternateInstruction(Instruction *I, Instruction *MainOp, Instruction *AltOp, const TargetLibraryInfo &TLI)
Checks if the specified instruction I is an alternate operation for the given MainOp and AltOp instru...
bool isValidForAlternation(unsigned Opcode)
bool hasOnlyAbsorbableCopyableFMulOrFAdds(ArrayRef< Value * > VL)
Checks if every copyable in VL is an absorbable fmul/fadd: the binops die instead of being computed a...
bool checkEVsForVecCalls(ArrayRef< Value * > VL, const InstructionsState &S, const TargetLibraryInfo &TLI, SmallVectorImpl< unsigned > &Indices, SmallVectorImpl< Value * > &Calls)
Detects an extractvalue bundle that can be widened by vectorizing the underlying struct-returning cal...
BasicBlock * getSESERegionEntry(ArrayRef< Value * > VL, const InstructionsState &S, const DominatorTree &DT, const LoopInfo &LI)
bool isFMAOrFMulAdd(const Instruction *I)
Checks if I is a call to llvm.fma or llvm.fmuladd.
InstructionsState getSameOpcode(ArrayRef< Value * > VL, const TargetLibraryInfo &TLI)
bool isAbsorbableCopyableFMulOrFAdd(const InstructionsState &S, Value *V)
Checks if V is a copyable single-use fmul/fadd, absorbable as fmuladd(a, b, -0.0) or fmuladd(1....
FPCopyables
How the FP identity ops of the copyable lanes produce the lane values: exactly, inexactly (a NaN may ...
bool areRegionScalars(ArrayRef< Value * > VL, const DominatorTree &DT, const LoopInfo &LI)
Checks if the instructions in VL are in different reachable blocks of the same loop (or all of them a...
bool isAbsorbableFMulOrFAdd(ArrayRef< Value * > VL, Value *V)
Checks if V is a single-use fmul/fadd with operands outside VL.
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool is_sorted_constexpr(R &&Range, Cmp C=Cmp{})
Check if elements in a range R are sorted with respect to a comparator C.
Definition STLExtras.h:2000
DWARFExpression::Operation Op
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
Definition STLExtras.h:2162