16#ifndef LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
17#define LLVM_LIB_TRANSFORMS_VECTORIZE_SLPVECTORIZER_SLPCOMPATIBILITYANALYSIS_H
56 using MaskType = std::uint_fast32_t;
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};
63 "SupportedOp is not sorted.");
84 static std::pair<Constant *, unsigned>
86 struct InterchangeableInfo {
89 MaskType Mask = MainOpBIT | XorBIT | OrBIT | AndBIT | SubBIT | AddBIT |
90 MulBIT | AShrBIT | ShlBIT | FSubBIT | FAddBIT;
95 MaskType SeenBefore = 0;
100 bool trySet(MaskType OpcodeInMaskForm, MaskType InterchangeableMask);
101 bool equal(
unsigned Opcode) {
102 return Opcode ==
I->getOpcode() && trySet(MainOpBIT, MainOpBIT);
104 unsigned getOpcode()
const;
105 bool hasDefinedOpcode()
const {
return (Mask & SeenBefore) > 0; }
110 InterchangeableInfo MainOp;
111 InterchangeableInfo AltOp;
118 : MainOp(MainOp), AltOp(AltOp) {}
124 return MainOp.hasCandidateOpcode(Opcode);
131 return !
hasAltOp() || AltOp.hasDefinedOpcode();
134 return MainOp.getOperand(
I);
147 using MaskType = std::uint16_t;
150 static constexpr MaskType AllPreds = (1 << NumPreds) - 1;
152 MaskType Mask = AllPreds;
156 MaskType SeenBefore = 0;
166 static APInt getFamilyConstant(
bool IsComplement,
const APInt &
K,
170 static MaskType getLaneMask(
const Value *
V);
238 bool HasCopyables =
false;
241 unsigned CopyableOpIdx = 0;
245 bool AbsorbCopyableFMulOrFAdd =
false;
250 bool IsRegion =
false;
254 assert(
valid() &&
"InstructionsState is invalid.");
259 assert(
valid() &&
"InstructionsState is invalid.");
307 return (
getOpcode() == Instruction::ICmp ||
313 bool valid()
const {
return MainOp && AltOp; }
319 bool HasCopyables =
false,
bool IsRegion =
false)
320 : MainOp(MainOp), AltOp(AltOp), HasCopyables(HasCopyables),
322 IsRegion(IsRegion) {}
341 assert(
valid() &&
"InstructionsState is invalid.");
347 assert(
valid() &&
"InstructionsState is invalid.");
348 return CopyableOpIdx;
353 assert((Idx == 0 || Idx == 2) &&
"Unexpected copyable operand index.");
360 assert(
valid() &&
"InstructionsState is invalid.");
361 return AbsorbCopyableFMulOrFAdd;
366 AbsorbCopyableFMulOrFAdd = Absorb;
371 assert(
valid() &&
"InstructionsState is invalid.");
372 return FPCopyablesKind;
412std::pair<Instruction *, SmallVector<Value *>>
437std::pair<Instruction *, Instruction *>
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file implements the SmallBitVector class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLE
signed less or equal
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
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.
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.
SmallVector< Value * > getOperand(const Instruction *I) const
bool hasDefinedMainOpcode() const
unsigned getAltOpcode() const
bool hasDefinedAltOpcode() const
bool add(const Instruction *I)
bool hasCandidateOpcode(unsigned Opcode) const
Checks if the list of potential opcodes includes Opcode.
BinOpSameOpcodeHelper(const Instruction *MainOp, const Instruction *AltOp=nullptr)
unsigned getMainOpcode() const
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 * getMainOp() const
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.
unsigned getAltOpcode() const
bool isCmpOp() const
Checks if main/alt instructions are cmp operations.
static InstructionsState invalid()
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.
Instruction * getAltOp() const
InstructionsState()=delete
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.
@ LLVM_MARK_AS_BITMASK_ENUM
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.
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.