47std::pair<Constant *, unsigned>
48BinOpSameOpcodeHelper::isBinOpWithConstant(
const Instruction *
I) {
49 [[maybe_unused]]
unsigned Opcode =
I->getOpcode();
58 if (
Constant *
C = GetConstant(BinOp->getOperand(1)))
62 if (Constant *
C = GetConstant(BinOp->getOperand(0)))
67bool BinOpSameOpcodeHelper::InterchangeableInfo::trySet(
68 MaskType OpcodeInMaskForm, MaskType InterchangeableMask) {
69 if (Mask & InterchangeableMask) {
70 SeenBefore |= OpcodeInMaskForm;
71 Mask &= InterchangeableMask;
77unsigned BinOpSameOpcodeHelper::InterchangeableInfo::getOpcode()
const {
78 MaskType Candidate =
Mask & SeenBefore;
79 if (Candidate & MainOpBIT)
80 return I->getOpcode();
81 if (Candidate & ShlBIT)
82 return Instruction::Shl;
83 if (Candidate & AShrBIT)
84 return Instruction::AShr;
85 if (Candidate & MulBIT)
86 return Instruction::Mul;
87 if (Candidate & AddBIT)
88 return Instruction::Add;
89 if (Candidate & SubBIT)
90 return Instruction::Sub;
91 if (Candidate & FAddBIT)
92 return Instruction::FAdd;
93 if (Candidate & FSubBIT)
94 return Instruction::FSub;
95 if (Candidate & AndBIT)
96 return Instruction::And;
97 if (Candidate & OrBIT)
98 return Instruction::Or;
99 if (Candidate & XorBIT)
100 return Instruction::Xor;
104bool BinOpSameOpcodeHelper::InterchangeableInfo::hasCandidateOpcode(
105 unsigned Opcode)
const {
106 MaskType Candidate =
Mask & SeenBefore;
108 case Instruction::Shl:
109 return Candidate & ShlBIT;
110 case Instruction::AShr:
111 return Candidate & AShrBIT;
112 case Instruction::Mul:
113 return Candidate & MulBIT;
114 case Instruction::Add:
115 return Candidate & AddBIT;
116 case Instruction::Sub:
117 return Candidate & SubBIT;
118 case Instruction::And:
119 return Candidate & AndBIT;
120 case Instruction::Or:
121 return Candidate & OrBIT;
122 case Instruction::Xor:
123 return Candidate & XorBIT;
124 case Instruction::FAdd:
125 return Candidate & FAddBIT;
126 case Instruction::FSub:
127 return Candidate & FSubBIT;
128 case Instruction::LShr:
129 case Instruction::FMul:
130 case Instruction::SDiv:
131 case Instruction::UDiv:
132 case Instruction::FDiv:
133 case Instruction::SRem:
134 case Instruction::URem:
135 case Instruction::FRem:
144 const Instruction *To)
const {
146 unsigned FromOpcode =
I->getOpcode();
147 if (FromOpcode == ToOpcode)
150 auto [
C, Pos] = isBinOpWithConstant(
I);
151 Type *RHSType =
I->getOperand(Pos)->getType();
157 "Cannot convert the instruction.");
158 RHS = ConstantFP::get(RHSType, -CFP->getValueAPF());
161 const APInt &FromCIValue = CI->getValue();
162 unsigned FromCIValueBitWidth = FromCIValue.
getBitWidth();
163 switch (FromOpcode) {
164 case Instruction::Shl:
165 if (ToOpcode == Instruction::Add && FromCIValue.
isOne())
166 return {
I->getOperand(0),
I->getOperand(0)};
167 if (ToOpcode == Instruction::Mul) {
168 RHS = ConstantInt::get(RHSType,
172 assert(FromCIValue.
isZero() &&
"Cannot convert the instruction.");
177 case Instruction::Mul:
179 if (ToOpcode == Instruction::Shl) {
180 RHS = ConstantInt::get(
181 RHSType, APInt(FromCIValueBitWidth, FromCIValue.
logBase2()));
183 assert(FromCIValue.
isOne() &&
"Cannot convert the instruction.");
188 case Instruction::Add:
189 case Instruction::Sub:
190 if (FromCIValue.
isZero()) {
195 "Cannot convert the instruction.");
196 APInt NegatedVal = APInt(FromCIValue);
198 RHS = ConstantInt::get(RHSType, NegatedVal);
201 case Instruction::And:
207 assert(FromCIValue.
isZero() &&
"Cannot convert the instruction.");
222bool BinOpSameOpcodeHelper::isValidForAlternation(
const Instruction *
I)
const {
227bool BinOpSameOpcodeHelper::initializeAltOp(
const Instruction *
I) {
230 if (!isValidForAlternation(
I))
238 "BinOpSameOpcodeHelper only accepts BinaryOperator.");
239 unsigned Opcode =
I->getOpcode();
240 MaskType OpcodeInMaskForm;
244 case Instruction::Shl:
245 OpcodeInMaskForm = ShlBIT;
247 case Instruction::AShr:
248 OpcodeInMaskForm = AShrBIT;
250 case Instruction::Mul:
251 OpcodeInMaskForm = MulBIT;
253 case Instruction::Add:
254 OpcodeInMaskForm = AddBIT;
256 case Instruction::Sub:
257 OpcodeInMaskForm = SubBIT;
259 case Instruction::And:
260 OpcodeInMaskForm = AndBIT;
262 case Instruction::Or:
263 OpcodeInMaskForm = OrBIT;
265 case Instruction::Xor:
266 OpcodeInMaskForm = XorBIT;
268 case Instruction::FAdd:
269 OpcodeInMaskForm = FAddBIT;
271 case Instruction::FSub:
272 OpcodeInMaskForm = FSubBIT;
275 return MainOp.equal(Opcode) || (initializeAltOp(
I) && AltOp.equal(Opcode));
277 MaskType InterchangeableMask = OpcodeInMaskForm;
278 auto [
C, Pos] = isBinOpWithConstant(
I);
280 constexpr MaskType CanBeAll =
281 XorBIT | OrBIT | AndBIT | SubBIT | AddBIT | MulBIT | AShrBIT | ShlBIT;
282 const APInt &CIValue = CI->getValue();
284 case Instruction::Shl:
286 InterchangeableMask = CIValue.
isZero() ? CanBeAll : MulBIT | ShlBIT;
288 InterchangeableMask |= AddBIT;
290 case Instruction::Mul:
291 if (CIValue.
isOne()) {
292 InterchangeableMask = CanBeAll;
296 InterchangeableMask = MulBIT | ShlBIT;
298 case Instruction::Add:
299 case Instruction::Sub:
300 InterchangeableMask = CIValue.
isZero() ? CanBeAll : SubBIT | AddBIT;
302 case Instruction::And:
304 InterchangeableMask = CanBeAll;
306 case Instruction::Xor:
308 InterchangeableMask = XorBIT | OrBIT | SubBIT | AddBIT;
312 InterchangeableMask = CanBeAll;
315 }
else if (
C && Pos == 1) {
323 InterchangeableMask = FSubBIT | FAddBIT;
325 return MainOp.trySet(OpcodeInMaskForm, InterchangeableMask) ||
326 (initializeAltOp(
I) &&
327 AltOp.trySet(OpcodeInMaskForm, InterchangeableMask));
333static std::optional<std::pair<bool, APInt>>
335 const unsigned BW =
C.getBitWidth();
342 return std::make_pair(
false,
C);
344 return std::make_pair(
true,
C);
348 return std::make_pair(
false, Min);
350 return std::make_pair(
true,
C);
355 return std::make_pair(
false,
C);
357 return std::make_pair(
true, Max);
362 return std::make_pair(
true,
C);
364 return std::make_pair(
false, Max);
369 return std::make_pair(
true, Min);
371 return std::make_pair(
false,
C);
379CmpSamePredicateHelper::MaskType
381 MaskType M = getBit(Pred);
385 const auto &[IsComplement,
K] = *Family;
393 M |= IsComplement ? HiU : LoU;
395 M |= IsComplement ? LoU : HiU;
396 if (
K.isMinSignedValue())
397 M |= IsComplement ? HiS : LoS;
398 if (
K.isMaxSignedValue())
399 M |= IsComplement ? LoS : HiS;
403APInt CmpSamePredicateHelper::getFamilyConstant(
bool IsComplement,
426static std::optional<std::pair<CmpInst::Predicate, APInt>>
429 TI && TI->getType()->isIntOrIntVectorTy(1))
430 return std::make_pair(
436 return std::make_pair(CI->getPredicate(), *
C);
440CmpSamePredicateHelper::MaskType
441CmpSamePredicateHelper::getLaneMask(
const Instruction *
I) {
442 if (std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
444 MaskType M = getFormsMask(Cmp->first, Cmp->second);
449 return getBit(CI->getPredicate());
457 std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
461 std::optional<std::pair<bool, APInt>> Family =
463 return Family && Family->second.isZero();
468 SeenBefore |= getBit(CI->getPredicate());
469 Mask &= getLaneMask(
I);
475 MaskType Candidate = Mask & SeenBefore;
508 return ConstantInt::get(
I->getOperand(0)->getType(), 1);
510 std::optional<std::pair<bool, APInt>> Family =
512 assert(Family &&
"Expected a boundary family for a convertible compare.");
513 const auto &[IsComplement,
K] = *Family;
514 return ConstantInt::get(
I->getOperand(0)->getType(),
515 getFamilyConstant(IsComplement,
K, Pred));
525 if (
I->getOpcode() !=
Op->getOpcode())
532 IOp->getIntrinsicID()) !=
538 assert(MainOp &&
"MainOp cannot be nullptr.");
541 if (MainOp->getOpcode() == Instruction::Select &&
544 if (MainOp->getOpcode() == Instruction::ICmp &&
548 assert(AltOp &&
"AltOp cannot be nullptr.");
552 if (!
I->isBinaryOp() || !MainOp->isBinaryOp())
559 if (AltConverter.
add(
I) && AltConverter.
add(AltOp) &&
565 return Converter.hasAltOp() ? AltOp : MainOp;
569 constexpr std::array<unsigned, 8> MulDiv = {
570 Instruction::Mul, Instruction::FMul, Instruction::SDiv,
571 Instruction::UDiv, Instruction::FDiv, Instruction::SRem,
572 Instruction::URem, Instruction::FRem};
578 constexpr std::array<unsigned, 4> AddSub = {
579 Instruction::Add, Instruction::Sub, Instruction::FAdd, Instruction::FSub};
589 assert(
valid() &&
"InstructionsState is invalid.");
603 return C &&
C->getValue().getActiveBits() <=
610 if (
getOpcode() == Instruction::GetElementPtr)
612 GEP && (
GEP->getNumOperands() != 2 ||
613 GEP->getSourceElementType() !=
616 if (
I->getParent() != MainOp->getParent() &&
623 if (!
I->isBinaryOp() || !MainOp->isBinaryOp())
633 (
I->getOpcode() == Instruction::FMul ||
634 I->getOpcode() == Instruction::FAdd) &&
636 return is_contained(VL, Op);
643 (
I->getOpcode() == Instruction::FMul ||
644 I->getOpcode() == Instruction::FAdd) &&
649 bool HasFMulOrFAdd =
false;
657 HasFMulOrFAdd =
true;
659 return HasFMulOrFAdd;
663 assert(
valid() &&
"InstructionsState is invalid.");
669 auto CheckForTransformedOpcode = [](
const Instruction *RefOp,
672 case Instruction::Add:
673 switch (ExpandingOp->getOpcode()) {
674 case Instruction::Shl:
691 return CheckForTransformedOpcode(MainOp, ExpandingOp);
696 switch (
I->getOpcode()) {
697 case Instruction::Shl:
706 assert(
valid() &&
"InstructionsState is invalid.");
716 auto IsNonSchedulableCopyableElement = [
this](
Value *V) {
718 return !
I ||
isa<PHINode>(
I) ||
I->getParent() != MainOp->getParent() ||
723 !MainOp->comesBefore(
I));
726 return IsNonSchedulableCopyableElement(V);
745 if (Inst->getOpcode() == Opcode)
759 BaseOp0 == Op0 || BaseOp1 == Op1 ||
770 "Assessing comparisons of different types?");
780 return (BasePred == Pred &&
782 (BasePred == SwappedPred &&
799 (VL.
size() == 2 && InstCnt < 2))
814 unsigned AltOpcode = Opcode;
817 bool SwappedPredsCompatible = IsCmpOp && [&]() {
819 UniquePreds.
insert(BasePred);
820 UniqueNonSwappedPreds.
insert(BasePred);
821 for (
Value *V : VL) {
828 UniqueNonSwappedPreds.
insert(CurrentPred);
829 if (!UniquePreds.
contains(CurrentPred) &&
830 !UniquePreds.
contains(SwappedCurrentPred))
831 UniquePreds.
insert(CurrentPred);
836 return UniqueNonSwappedPreds.
size() > 2 && UniquePreds.
size() == 2;
842 InterchangeablePred =
854 bool AnyPoison = InstCnt != VL.
size();
864 unsigned InstOpcode =
I->getOpcode();
866 if (BinOpHelper.
add(
I))
871 Value *Op1 =
I->getOperand(0);
874 if (InstOpcode == Opcode || InstOpcode == AltOpcode)
876 if (Opcode == AltOpcode) {
879 "Cast isn't safe for alternation, logic needs to be updated!");
880 AltOpcode = InstOpcode;
887 Type *Ty0 = BaseInst->getOperand(0)->getType();
888 Type *Ty1 = Inst->getOperand(0)->getType();
890 assert(InstOpcode == Opcode &&
"Expected same CmpInst opcode.");
891 assert(InstOpcode == AltOpcode &&
892 "Alternate instructions are only supported by BinaryOperator "
900 if ((VL.
size() == 2 || SwappedPredsCompatible) &&
901 (BasePred == CurrentPred || BasePred == SwappedCurrentPred))
909 if (MainOp != AltOp) {
912 }
else if (BasePred != CurrentPred) {
915 "CmpInst isn't safe for alternation, logic needs to be updated!");
920 if (BasePred == CurrentPred || BasePred == SwappedCurrentPred ||
921 AltPred == CurrentPred || AltPred == SwappedCurrentPred)
936 }
else if (InstOpcode == Opcode) {
937 assert(InstOpcode == AltOpcode &&
938 "Alternate instructions are only supported by BinaryOperator and "
941 if (Gep->getNumOperands() != 2 ||
949 if (!LI->isSimple() || !BaseLI->isSimple())
959 if (
Call->hasOperandBundles() &&
961 !std::equal(
Call->op_begin() +
Call->getBundleOperandsStartIndex(),
962 Call->op_begin() +
Call->getBundleOperandsEndIndex(),
971 if (Mappings.
size() != BaseMappings.
size() ||
972 Mappings.
front().ISA != BaseMappings.
front().ISA ||
973 Mappings.
front().ScalarName != BaseMappings.
front().ScalarName ||
974 Mappings.
front().VectorName != BaseMappings.
front().VectorName ||
975 Mappings.
front().Shape.VF != BaseMappings.
front().Shape.VF ||
976 Mappings.
front().Shape.Parameters !=
977 BaseMappings.
front().Shape.Parameters)
991 assert(MainOp &&
"Cannot find MainOp with Opcode from BinOpHelper.");
993 assert(AltOp &&
"Cannot find AltOp with Opcode from BinOpHelper.");
1007 InterchangeablePred != BasePred) {
1012 return CI && CI->getPredicate() == InterchangeablePred;
1015 "Expected an instruction with the shared predicate.");
1019 "Incorrect implementation of allSameOpcode.");
1026 "Invalid InstructionsState.");
1030std::pair<Instruction *, SmallVector<Value *>>
1033 assert(SelectedOp &&
"Cannot convert the instruction.");
1034 if (
I->isBinaryOp()) {
1036 return std::make_pair(SelectedOp,
Converter.getOperand(SelectedOp));
1047 I, MainCI->getPredicate()))
1048 return std::make_pair(SelectedOp,
1059 assert(MainP != AltP &&
"Expected different main/alternate predicates.");
1068 assert((MainP ==
P || AltP ==
P || MainP == SwappedP || AltP == SwappedP) &&
1069 "CmpInst expected to match either main or alternate predicate or "
1071 return MainP !=
P && MainP != SwappedP;
1081 const unsigned NumLanes = VL.
size();
1093 if (!
I || !
I->hasOneUse() ||
I->getOpcode() != LaneOpcodes[Lane] ||
1104 if (GetChainLink(Lane, Columns[0][Lane]))
1106 Instruction *Link = GetChainLink(Lane, Columns[1][Lane]);
1109 std::swap(Columns[0][Lane], Columns[1][Lane]);
1113 return GetChainLink(Lane, Columns[0][Lane]) !=
nullptr;
1117 Instruction *Link = GetChainLink(Lane, Columns[0][Lane]);
1126 NewColumn[Lane] = Link->
getOperand(1 - RunningOp);
1127 Columns[0][Lane] = Link->
getOperand(RunningOp);
1129 Columns.
insert(std::next(Columns.
begin()), std::move(NewColumn));
1132 "Normalization guarantees at least one peeled level.");
1133 SubLanes.
resize(NumLanes);
1135 if (LaneOpcodes[Lane] == Instruction::Sub ||
1136 LaneOpcodes[Lane] == Instruction::FSub)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
uint64_t IntrinsicInst * II
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
This file implements the C++20 <bit> header.
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned logBase2() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
bool isOne() const
Determine if this is a value of 1.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
unsigned getBundleOperandsStartIndex() const
Return the index of the first bundle operand in the Use array.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Predicate getPredicate() const
Return the predicate for this instruction.
bool isIntPredicate() const
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
This is an important base class in LLVM.
This instruction compares its operands according to the predicate given to the constructor.
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static bool isFMulAddIntrinsic(Instruction *I)
Returns true if the instruction is a call to the llvm.fmuladd intrinsic.
A vector that has set insertion semantics.
size_type size() const
Determine the number of elements in the SetVector.
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
bool insert(const value_type &X)
Insert a new element into the SetVector.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
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.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Value * getOperand(unsigned i) const
The Vector Function Database.
static SmallVector< VFInfo, 8 > getMappings(const CallInst &CI)
Retrieve all the VFInfo instances associated to the CallInst CI.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
Helper class that determines VL can use the same opcode.
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.
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 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,...
bool add(const Instruction *I)
Intersects the convertible predicate set of the comparison lane I (an icmp or a trunc to i1) with the...
static bool canConvertTo(const Instruction *I, CmpInst::Predicate Pred)
Checks if the comparison lane I can be expressed with the predicate Pred by adjusting its constant op...
Main data required for vectorization of instructions.
Instruction * getMainOp() const
Instruction * getMatchingMainOpOrAltOp(Instruction *I) const
Checks if the instruction matches either the main or alternate opcode.
unsigned getAltOpcode() const
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.
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 isAltShuffle() const
Some of the instructions in the list have alternate opcodes.
Instruction * getAltOp() const
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: ...
bool isMulDivLikeOp() const
Checks if main/alt instructions are mul/div/rem/fmul/fdiv/frem operations.
unsigned getOpcode() const
The main/alternate opcodes for the list of instructions.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
A private "module" namespace for types and utilities used by this pass.
static std::optional< std::pair< bool, APInt > > getCmpBoundaryFamily(CmpInst::Predicate Pred, const APInt &C)
If the comparison (Pred, X, C) is a single-element or single-complement range check,...
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)
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...
static std::optional< std::pair< CmpInst::Predicate, APInt > > getLaneConstantCmp(const Instruction *I)
Returns the predicate and the compared constant of the comparison lane I, treating trunc X to i1 as a...
bool allSameOpcode(ArrayRef< Value * > VL)
bool isValidForAlternation(unsigned Opcode)
static bool areCompatibleCmpOps(Value *BaseOp0, Value *BaseOp1, Value *Op0, Value *Op1, const TargetLibraryInfo &TLI)
Checks if the provided operands of 2 cmp instructions are compatible, i.e.
static Instruction * findInstructionWithOpcode(ArrayRef< Value * > VL, unsigned Opcode)
Find an instruction with a specific opcode in VL.
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 isCommutative(const Instruction *I, const Value *ValWithUses, bool IsCopyable)
bool isReassocChainLink(const Instruction *I)
Intrinsic::ID isEquivalentIntrinsicID(Intrinsic::ID LHS, Intrinsic::ID RHS)
Checks if LHS and RHS are the same intrinsic, or one is llvm.fma and the other is llvm....
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....
bool isVectorLikeInstWithConstOps(Value *V)
Checks if V is one of vector-like instructions, i.e.
bool doesNotNeedToBeScheduled(Value *V)
Checks if the specified value does not require scheduling.
bool isConstant(Value *V)
bool isAbsorbableFMulOrFAdd(ArrayRef< Value * > VL, Value *V)
Checks if V is a single-use fmul/fadd with operands outside VL.
static bool isCmpSameOrSwapped(const CmpInst *BaseCI, const CmpInst *CI, const TargetLibraryInfo &TLI)
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
auto binary_search(R &&Range, T &&Value)
Provide wrappers to std::binary_search which take ranges instead of having to pass begin/end explicit...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
auto make_isa_range(RangeT &&Range)
Return a range over Range containing only elements for which isa<T> holds, casting each of them to T.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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...
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.