46std::pair<Constant *, unsigned>
47BinOpSameOpcodeHelper::isBinOpWithConstant(
const Instruction *
I) {
48 [[maybe_unused]]
unsigned Opcode =
I->getOpcode();
57 if (
Constant *
C = GetConstant(BinOp->getOperand(1)))
61 if (Constant *
C = GetConstant(BinOp->getOperand(0)))
66bool BinOpSameOpcodeHelper::InterchangeableInfo::trySet(
67 MaskType OpcodeInMaskForm, MaskType InterchangeableMask) {
68 if (Mask & InterchangeableMask) {
69 SeenBefore |= OpcodeInMaskForm;
70 Mask &= InterchangeableMask;
76unsigned BinOpSameOpcodeHelper::InterchangeableInfo::getOpcode()
const {
77 MaskType Candidate =
Mask & SeenBefore;
78 if (Candidate & MainOpBIT)
79 return I->getOpcode();
80 if (Candidate & ShlBIT)
81 return Instruction::Shl;
82 if (Candidate & AShrBIT)
83 return Instruction::AShr;
84 if (Candidate & MulBIT)
85 return Instruction::Mul;
86 if (Candidate & AddBIT)
87 return Instruction::Add;
88 if (Candidate & SubBIT)
89 return Instruction::Sub;
90 if (Candidate & FAddBIT)
91 return Instruction::FAdd;
92 if (Candidate & FSubBIT)
93 return Instruction::FSub;
94 if (Candidate & AndBIT)
95 return Instruction::And;
96 if (Candidate & OrBIT)
97 return Instruction::Or;
98 if (Candidate & XorBIT)
99 return Instruction::Xor;
103bool BinOpSameOpcodeHelper::InterchangeableInfo::hasCandidateOpcode(
104 unsigned Opcode)
const {
105 MaskType Candidate =
Mask & SeenBefore;
107 case Instruction::Shl:
108 return Candidate & ShlBIT;
109 case Instruction::AShr:
110 return Candidate & AShrBIT;
111 case Instruction::Mul:
112 return Candidate & MulBIT;
113 case Instruction::Add:
114 return Candidate & AddBIT;
115 case Instruction::Sub:
116 return Candidate & SubBIT;
117 case Instruction::And:
118 return Candidate & AndBIT;
119 case Instruction::Or:
120 return Candidate & OrBIT;
121 case Instruction::Xor:
122 return Candidate & XorBIT;
123 case Instruction::FAdd:
124 return Candidate & FAddBIT;
125 case Instruction::FSub:
126 return Candidate & FSubBIT;
127 case Instruction::LShr:
128 case Instruction::FMul:
129 case Instruction::SDiv:
130 case Instruction::UDiv:
131 case Instruction::FDiv:
132 case Instruction::SRem:
133 case Instruction::URem:
134 case Instruction::FRem:
143 const Instruction *To)
const {
145 unsigned FromOpcode =
I->getOpcode();
146 if (FromOpcode == ToOpcode)
149 auto [
C, Pos] = isBinOpWithConstant(
I);
150 Type *RHSType =
I->getOperand(Pos)->getType();
156 "Cannot convert the instruction.");
157 RHS = ConstantFP::get(RHSType, -CFP->getValueAPF());
160 const APInt &FromCIValue = CI->getValue();
161 unsigned FromCIValueBitWidth = FromCIValue.
getBitWidth();
162 switch (FromOpcode) {
163 case Instruction::Shl:
164 if (ToOpcode == Instruction::Add && FromCIValue.
isOne())
165 return {
I->getOperand(0),
I->getOperand(0)};
166 if (ToOpcode == Instruction::Mul) {
167 RHS = ConstantInt::get(RHSType,
171 assert(FromCIValue.
isZero() &&
"Cannot convert the instruction.");
176 case Instruction::Mul:
178 if (ToOpcode == Instruction::Shl) {
179 RHS = ConstantInt::get(
180 RHSType, APInt(FromCIValueBitWidth, FromCIValue.
logBase2()));
182 assert(FromCIValue.
isOne() &&
"Cannot convert the instruction.");
187 case Instruction::Add:
188 case Instruction::Sub:
189 if (FromCIValue.
isZero()) {
194 "Cannot convert the instruction.");
195 APInt NegatedVal = APInt(FromCIValue);
197 RHS = ConstantInt::get(RHSType, NegatedVal);
200 case Instruction::And:
206 assert(FromCIValue.
isZero() &&
"Cannot convert the instruction.");
221bool BinOpSameOpcodeHelper::isValidForAlternation(
const Instruction *
I)
const {
226bool BinOpSameOpcodeHelper::initializeAltOp(
const Instruction *
I) {
229 if (!isValidForAlternation(
I))
237 "BinOpSameOpcodeHelper only accepts BinaryOperator.");
238 unsigned Opcode =
I->getOpcode();
239 MaskType OpcodeInMaskForm;
243 case Instruction::Shl:
244 OpcodeInMaskForm = ShlBIT;
246 case Instruction::AShr:
247 OpcodeInMaskForm = AShrBIT;
249 case Instruction::Mul:
250 OpcodeInMaskForm = MulBIT;
252 case Instruction::Add:
253 OpcodeInMaskForm = AddBIT;
255 case Instruction::Sub:
256 OpcodeInMaskForm = SubBIT;
258 case Instruction::And:
259 OpcodeInMaskForm = AndBIT;
261 case Instruction::Or:
262 OpcodeInMaskForm = OrBIT;
264 case Instruction::Xor:
265 OpcodeInMaskForm = XorBIT;
267 case Instruction::FAdd:
268 OpcodeInMaskForm = FAddBIT;
270 case Instruction::FSub:
271 OpcodeInMaskForm = FSubBIT;
274 return MainOp.equal(Opcode) || (initializeAltOp(
I) && AltOp.equal(Opcode));
276 MaskType InterchangeableMask = OpcodeInMaskForm;
277 auto [
C, Pos] = isBinOpWithConstant(
I);
279 constexpr MaskType CanBeAll =
280 XorBIT | OrBIT | AndBIT | SubBIT | AddBIT | MulBIT | AShrBIT | ShlBIT;
281 const APInt &CIValue = CI->getValue();
283 case Instruction::Shl:
285 InterchangeableMask = CIValue.
isZero() ? CanBeAll : MulBIT | ShlBIT;
287 InterchangeableMask |= AddBIT;
289 case Instruction::Mul:
290 if (CIValue.
isOne()) {
291 InterchangeableMask = CanBeAll;
295 InterchangeableMask = MulBIT | ShlBIT;
297 case Instruction::Add:
298 case Instruction::Sub:
299 InterchangeableMask = CIValue.
isZero() ? CanBeAll : SubBIT | AddBIT;
301 case Instruction::And:
303 InterchangeableMask = CanBeAll;
305 case Instruction::Xor:
307 InterchangeableMask = XorBIT | OrBIT | SubBIT | AddBIT;
311 InterchangeableMask = CanBeAll;
314 }
else if (
C && Pos == 1) {
322 InterchangeableMask = FSubBIT | FAddBIT;
324 return MainOp.trySet(OpcodeInMaskForm, InterchangeableMask) ||
325 (initializeAltOp(
I) &&
326 AltOp.trySet(OpcodeInMaskForm, InterchangeableMask));
332static std::optional<std::pair<bool, APInt>>
334 const unsigned BW =
C.getBitWidth();
341 return std::make_pair(
false,
C);
343 return std::make_pair(
true,
C);
347 return std::make_pair(
false, Min);
349 return std::make_pair(
true,
C);
354 return std::make_pair(
false,
C);
356 return std::make_pair(
true, Max);
361 return std::make_pair(
true,
C);
363 return std::make_pair(
false, Max);
368 return std::make_pair(
true, Min);
370 return std::make_pair(
false,
C);
378CmpSamePredicateHelper::MaskType
380 MaskType M = getBit(Pred);
384 const auto &[IsComplement,
K] = *Family;
392 M |= IsComplement ? HiU : LoU;
394 M |= IsComplement ? LoU : HiU;
395 if (
K.isMinSignedValue())
396 M |= IsComplement ? HiS : LoS;
397 if (
K.isMaxSignedValue())
398 M |= IsComplement ? LoS : HiS;
402APInt CmpSamePredicateHelper::getFamilyConstant(
bool IsComplement,
425static std::optional<std::pair<CmpInst::Predicate, APInt>>
428 TI && TI->getType()->isIntOrIntVectorTy(1))
429 return std::make_pair(
435 return std::make_pair(CI->getPredicate(), *
C);
439CmpSamePredicateHelper::MaskType
440CmpSamePredicateHelper::getLaneMask(
const Instruction *
I) {
441 if (std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
443 MaskType M = getFormsMask(Cmp->first, Cmp->second);
448 return getBit(CI->getPredicate());
456 std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
460 std::optional<std::pair<bool, APInt>> Family =
462 return Family && Family->second.isZero();
467 SeenBefore |= getBit(CI->getPredicate());
468 Mask &= getLaneMask(
I);
474 MaskType Candidate = Mask & SeenBefore;
507 return ConstantInt::get(
I->getOperand(0)->getType(), 1);
509 std::optional<std::pair<bool, APInt>> Family =
511 assert(Family &&
"Expected a boundary family for a convertible compare.");
512 const auto &[IsComplement,
K] = *Family;
513 return ConstantInt::get(
I->getOperand(0)->getType(),
514 getFamilyConstant(IsComplement,
K, Pred));
519 if (
I->getOpcode() !=
Op->getOpcode())
526 IOp->getIntrinsicID()) !=
532 assert(MainOp &&
"MainOp cannot be nullptr.");
535 if (MainOp->getOpcode() == Instruction::Select &&
538 if (MainOp->getOpcode() == Instruction::ICmp &&
542 assert(AltOp &&
"AltOp cannot be nullptr.");
546 if (!
I->isBinaryOp() || !MainOp->isBinaryOp())
553 if (AltConverter.
add(
I) && AltConverter.
add(AltOp) &&
559 return Converter.hasAltOp() ? AltOp : MainOp;
563 constexpr std::array<unsigned, 8> MulDiv = {
564 Instruction::Mul, Instruction::FMul, Instruction::SDiv,
565 Instruction::UDiv, Instruction::FDiv, Instruction::SRem,
566 Instruction::URem, Instruction::FRem};
572 constexpr std::array<unsigned, 4> AddSub = {
573 Instruction::Add, Instruction::Sub, Instruction::FAdd, Instruction::FSub};
583 assert(
valid() &&
"InstructionsState is invalid.");
597 return C &&
C->getValue().getActiveBits() <=
604 if (
getOpcode() == Instruction::GetElementPtr)
606 GEP && (
GEP->getNumOperands() != 2 ||
607 GEP->getSourceElementType() !=
610 if (
I->getParent() != MainOp->getParent() &&
617 if (!
I->isBinaryOp() || !MainOp->isBinaryOp())
627 (
I->getOpcode() == Instruction::FMul ||
628 I->getOpcode() == Instruction::FAdd) &&
630 return is_contained(VL, Op);
637 (
I->getOpcode() == Instruction::FMul ||
638 I->getOpcode() == Instruction::FAdd) &&
643 bool HasFMulOrFAdd =
false;
651 HasFMulOrFAdd =
true;
653 return HasFMulOrFAdd;
657 assert(
valid() &&
"InstructionsState is invalid.");
663 auto CheckForTransformedOpcode = [](
const Instruction *RefOp,
666 case Instruction::Add:
667 switch (ExpandingOp->getOpcode()) {
668 case Instruction::Shl:
685 return CheckForTransformedOpcode(MainOp, ExpandingOp);
690 switch (
I->getOpcode()) {
691 case Instruction::Shl:
700 assert(
valid() &&
"InstructionsState is invalid.");
710 auto IsNonSchedulableCopyableElement = [
this](
Value *V) {
712 return !
I ||
isa<PHINode>(
I) ||
I->getParent() != MainOp->getParent() ||
717 !MainOp->comesBefore(
I));
720 return IsNonSchedulableCopyableElement(V);
739 if (Inst->getOpcode() == Opcode)
753 BaseOp0 == Op0 || BaseOp1 == Op1 ||
764 "Assessing comparisons of different types?");
774 return (BasePred == Pred &&
776 (BasePred == SwappedPred &&
793 (VL.
size() == 2 && InstCnt < 2))
808 unsigned AltOpcode = Opcode;
811 bool SwappedPredsCompatible = IsCmpOp && [&]() {
813 UniquePreds.
insert(BasePred);
814 UniqueNonSwappedPreds.
insert(BasePred);
815 for (
Value *V : VL) {
822 UniqueNonSwappedPreds.
insert(CurrentPred);
823 if (!UniquePreds.
contains(CurrentPred) &&
824 !UniquePreds.
contains(SwappedCurrentPred))
825 UniquePreds.
insert(CurrentPred);
830 return UniqueNonSwappedPreds.
size() > 2 && UniquePreds.
size() == 2;
836 InterchangeablePred =
848 bool AnyPoison = InstCnt != VL.
size();
858 unsigned InstOpcode =
I->getOpcode();
860 if (BinOpHelper.
add(
I))
865 Value *Op1 =
I->getOperand(0);
868 if (InstOpcode == Opcode || InstOpcode == AltOpcode)
870 if (Opcode == AltOpcode) {
873 "Cast isn't safe for alternation, logic needs to be updated!");
874 AltOpcode = InstOpcode;
881 Type *Ty0 = BaseInst->getOperand(0)->getType();
882 Type *Ty1 = Inst->getOperand(0)->getType();
884 assert(InstOpcode == Opcode &&
"Expected same CmpInst opcode.");
885 assert(InstOpcode == AltOpcode &&
886 "Alternate instructions are only supported by BinaryOperator "
894 if ((VL.
size() == 2 || SwappedPredsCompatible) &&
895 (BasePred == CurrentPred || BasePred == SwappedCurrentPred))
903 if (MainOp != AltOp) {
906 }
else if (BasePred != CurrentPred) {
909 "CmpInst isn't safe for alternation, logic needs to be updated!");
914 if (BasePred == CurrentPred || BasePred == SwappedCurrentPred ||
915 AltPred == CurrentPred || AltPred == SwappedCurrentPred)
930 }
else if (InstOpcode == Opcode) {
931 assert(InstOpcode == AltOpcode &&
932 "Alternate instructions are only supported by BinaryOperator and "
935 if (Gep->getNumOperands() != 2 ||
943 if (!LI->isSimple() || !BaseLI->isSimple())
953 if (
Call->hasOperandBundles() &&
955 !std::equal(
Call->op_begin() +
Call->getBundleOperandsStartIndex(),
956 Call->op_begin() +
Call->getBundleOperandsEndIndex(),
965 if (Mappings.
size() != BaseMappings.
size() ||
966 Mappings.
front().ISA != BaseMappings.
front().ISA ||
967 Mappings.
front().ScalarName != BaseMappings.
front().ScalarName ||
968 Mappings.
front().VectorName != BaseMappings.
front().VectorName ||
969 Mappings.
front().Shape.VF != BaseMappings.
front().Shape.VF ||
970 Mappings.
front().Shape.Parameters !=
971 BaseMappings.
front().Shape.Parameters)
985 assert(MainOp &&
"Cannot find MainOp with Opcode from BinOpHelper.");
987 assert(AltOp &&
"Cannot find AltOp with Opcode from BinOpHelper.");
1001 InterchangeablePred != BasePred) {
1006 return CI && CI->getPredicate() == InterchangeablePred;
1009 "Expected an instruction with the shared predicate.");
1013 "Incorrect implementation of allSameOpcode.");
1020 "Invalid InstructionsState.");
1024std::pair<Instruction *, SmallVector<Value *>>
1027 assert(SelectedOp &&
"Cannot convert the instruction.");
1028 if (
I->isBinaryOp()) {
1030 return std::make_pair(SelectedOp,
Converter.getOperand(SelectedOp));
1041 I, MainCI->getPredicate()))
1042 return std::make_pair(SelectedOp,
1053 assert(MainP != AltP &&
"Expected different main/alternate predicates.");
1062 assert((MainP ==
P || AltP ==
P || MainP == SwappedP || AltP == SwappedP) &&
1063 "CmpInst expected to match either main or alternate predicate or "
1065 return MainP !=
P && MainP != SwappedP;
1075 const unsigned NumLanes = VL.
size();
1087 if (!
I || !
I->hasOneUse() ||
I->getOpcode() != LaneOpcodes[Lane] ||
1098 if (GetChainLink(Lane, Columns[0][Lane]))
1100 Instruction *Link = GetChainLink(Lane, Columns[1][Lane]);
1103 std::swap(Columns[0][Lane], Columns[1][Lane]);
1107 return GetChainLink(Lane, Columns[0][Lane]) !=
nullptr;
1111 Instruction *Link = GetChainLink(Lane, Columns[0][Lane]);
1120 NewColumn[Lane] = Link->
getOperand(1 - RunningOp);
1121 Columns[0][Lane] = Link->
getOperand(RunningOp);
1123 Columns.
insert(std::next(Columns.
begin()), std::move(NewColumn));
1126 "Normalization guarantees at least one peeled level.");
1127 SubLanes.
resize(NumLanes);
1129 if (LaneOpcodes[Lane] == Instruction::Sub ||
1130 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)
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.
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....
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.