52std::pair<Constant *, unsigned>
53BinOpSameOpcodeHelper::isBinOpWithConstant(
const Instruction *
I) {
54 [[maybe_unused]]
unsigned Opcode =
I->getOpcode();
63 if (
Constant *
C = GetConstant(BinOp->getOperand(1)))
67 if (Constant *
C = GetConstant(BinOp->getOperand(0)))
72bool BinOpSameOpcodeHelper::InterchangeableInfo::trySet(
73 MaskType OpcodeInMaskForm, MaskType InterchangeableMask) {
74 if (Mask & InterchangeableMask) {
75 SeenBefore |= OpcodeInMaskForm;
76 Mask &= InterchangeableMask;
82unsigned BinOpSameOpcodeHelper::InterchangeableInfo::getOpcode()
const {
83 MaskType Candidate =
Mask & SeenBefore;
84 if (Candidate & MainOpBIT)
85 return I->getOpcode();
86 if (Candidate & ShlBIT)
87 return Instruction::Shl;
88 if (Candidate & AShrBIT)
89 return Instruction::AShr;
90 if (Candidate & MulBIT)
91 return Instruction::Mul;
92 if (Candidate & AddBIT)
93 return Instruction::Add;
94 if (Candidate & SubBIT)
95 return Instruction::Sub;
96 if (Candidate & FAddBIT)
97 return Instruction::FAdd;
98 if (Candidate & FSubBIT)
99 return Instruction::FSub;
100 if (Candidate & AndBIT)
101 return Instruction::And;
102 if (Candidate & OrBIT)
103 return Instruction::Or;
104 if (Candidate & XorBIT)
105 return Instruction::Xor;
109bool BinOpSameOpcodeHelper::InterchangeableInfo::hasCandidateOpcode(
110 unsigned Opcode)
const {
111 MaskType Candidate =
Mask & SeenBefore;
113 case Instruction::Shl:
114 return Candidate & ShlBIT;
115 case Instruction::AShr:
116 return Candidate & AShrBIT;
117 case Instruction::Mul:
118 return Candidate & MulBIT;
119 case Instruction::Add:
120 return Candidate & AddBIT;
121 case Instruction::Sub:
122 return Candidate & SubBIT;
123 case Instruction::And:
124 return Candidate & AndBIT;
125 case Instruction::Or:
126 return Candidate & OrBIT;
127 case Instruction::Xor:
128 return Candidate & XorBIT;
129 case Instruction::FAdd:
130 return Candidate & FAddBIT;
131 case Instruction::FSub:
132 return Candidate & FSubBIT;
133 case Instruction::LShr:
134 case Instruction::FMul:
135 case Instruction::SDiv:
136 case Instruction::UDiv:
137 case Instruction::FDiv:
138 case Instruction::SRem:
139 case Instruction::URem:
140 case Instruction::FRem:
149 const Instruction *To)
const {
151 unsigned FromOpcode =
I->getOpcode();
152 if (FromOpcode == ToOpcode)
155 auto [
C, Pos] = isBinOpWithConstant(
I);
156 Type *RHSType =
I->getOperand(Pos)->getType();
162 "Cannot convert the instruction.");
163 RHS = ConstantFP::get(RHSType, -CFP->getValueAPF());
166 const APInt &FromCIValue = CI->getValue();
167 unsigned FromCIValueBitWidth = FromCIValue.
getBitWidth();
168 switch (FromOpcode) {
169 case Instruction::Shl:
170 if (ToOpcode == Instruction::Add && FromCIValue.
isOne())
171 return {
I->getOperand(0),
I->getOperand(0)};
172 if (ToOpcode == Instruction::Mul) {
173 RHS = ConstantInt::get(RHSType,
177 assert(FromCIValue.
isZero() &&
"Cannot convert the instruction.");
182 case Instruction::Mul:
184 if (ToOpcode == Instruction::Shl) {
185 RHS = ConstantInt::get(
186 RHSType, APInt(FromCIValueBitWidth, FromCIValue.
logBase2()));
188 assert(FromCIValue.
isOne() &&
"Cannot convert the instruction.");
193 case Instruction::Add:
194 case Instruction::Sub:
195 if (FromCIValue.
isZero()) {
200 "Cannot convert the instruction.");
201 APInt NegatedVal = APInt(FromCIValue);
203 RHS = ConstantInt::get(RHSType, NegatedVal);
206 case Instruction::And:
212 assert(FromCIValue.
isZero() &&
"Cannot convert the instruction.");
227bool BinOpSameOpcodeHelper::isValidForAlternation(
const Instruction *
I)
const {
232bool BinOpSameOpcodeHelper::initializeAltOp(
const Instruction *
I) {
235 if (!isValidForAlternation(
I))
243 "BinOpSameOpcodeHelper only accepts BinaryOperator.");
244 unsigned Opcode =
I->getOpcode();
245 MaskType OpcodeInMaskForm;
249 case Instruction::Shl:
250 OpcodeInMaskForm = ShlBIT;
252 case Instruction::AShr:
253 OpcodeInMaskForm = AShrBIT;
255 case Instruction::Mul:
256 OpcodeInMaskForm = MulBIT;
258 case Instruction::Add:
259 OpcodeInMaskForm = AddBIT;
261 case Instruction::Sub:
262 OpcodeInMaskForm = SubBIT;
264 case Instruction::And:
265 OpcodeInMaskForm = AndBIT;
267 case Instruction::Or:
268 OpcodeInMaskForm = OrBIT;
270 case Instruction::Xor:
271 OpcodeInMaskForm = XorBIT;
273 case Instruction::FAdd:
274 OpcodeInMaskForm = FAddBIT;
276 case Instruction::FSub:
277 OpcodeInMaskForm = FSubBIT;
280 return MainOp.equal(Opcode) || (initializeAltOp(
I) && AltOp.equal(Opcode));
282 MaskType InterchangeableMask = OpcodeInMaskForm;
283 auto [
C, Pos] = isBinOpWithConstant(
I);
285 constexpr MaskType CanBeAll =
286 XorBIT | OrBIT | AndBIT | SubBIT | AddBIT | MulBIT | AShrBIT | ShlBIT;
287 const APInt &CIValue = CI->getValue();
289 case Instruction::Shl:
291 InterchangeableMask = CIValue.
isZero() ? CanBeAll : MulBIT | ShlBIT;
293 InterchangeableMask |= AddBIT;
295 case Instruction::Mul:
296 if (CIValue.
isOne()) {
297 InterchangeableMask = CanBeAll;
301 InterchangeableMask = MulBIT | ShlBIT;
303 case Instruction::Add:
304 case Instruction::Sub:
305 InterchangeableMask = CIValue.
isZero() ? CanBeAll : SubBIT | AddBIT;
307 case Instruction::And:
309 InterchangeableMask = CanBeAll;
311 case Instruction::Xor:
313 InterchangeableMask = XorBIT | OrBIT | SubBIT | AddBIT;
317 InterchangeableMask = CanBeAll;
320 }
else if (
C && Pos == 1) {
328 InterchangeableMask = FSubBIT | FAddBIT;
330 return MainOp.trySet(OpcodeInMaskForm, InterchangeableMask) ||
331 (initializeAltOp(
I) &&
332 AltOp.trySet(OpcodeInMaskForm, InterchangeableMask));
338static std::optional<std::pair<bool, APInt>>
340 const unsigned BW =
C.getBitWidth();
347 return std::make_pair(
false,
C);
349 return std::make_pair(
true,
C);
353 return std::make_pair(
false, Min);
355 return std::make_pair(
true,
C);
360 return std::make_pair(
false,
C);
362 return std::make_pair(
true, Max);
367 return std::make_pair(
true,
C);
369 return std::make_pair(
false, Max);
374 return std::make_pair(
true, Min);
376 return std::make_pair(
false,
C);
384CmpSamePredicateHelper::MaskType
386 MaskType M = getBit(Pred);
390 const auto &[IsComplement,
K] = *Family;
398 M |= IsComplement ? HiU : LoU;
400 M |= IsComplement ? LoU : HiU;
401 if (
K.isMinSignedValue())
402 M |= IsComplement ? HiS : LoS;
403 if (
K.isMaxSignedValue())
404 M |= IsComplement ? LoS : HiS;
408APInt CmpSamePredicateHelper::getFamilyConstant(
bool IsComplement,
431static std::optional<std::pair<CmpInst::Predicate, APInt>>
434 TI && TI->getType()->isIntOrIntVectorTy(1))
435 return std::make_pair(
441 return std::make_pair(CI->getPredicate(), *
C);
445CmpSamePredicateHelper::MaskType
446CmpSamePredicateHelper::getLaneMask(
const Value *V) {
448 V->getType()->isIntegerTy(1))
453 if (std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
455 MaskType M = getFormsMask(Cmp->first, Cmp->second);
460 return getBit(CI->getPredicate());
468 std::optional<std::pair<CmpInst::Predicate, APInt>> Cmp =
472 std::optional<std::pair<bool, APInt>> Family =
474 return Family && Family->second.isZero();
479 SeenBefore |= getBit(CI->getPredicate());
480 Mask &= getLaneMask(V);
486 MaskType Candidate = Mask & SeenBefore;
517 return ConstantInt::get(
I->getOperand(0)->getType(), 1);
519 std::optional<std::pair<bool, APInt>> Family =
521 assert(Family &&
"Expected a boundary family for a convertible compare.");
522 const auto &[IsComplement,
K] = *Family;
523 return ConstantInt::get(
I->getOperand(0)->getType(),
524 getFamilyConstant(IsComplement,
K, Pred));
532 "Expected an i1 constant lane.");
533 Type *Ty = Cmp->getOperand(0)->getType();
534 const unsigned BW = Ty->getIntegerBitWidth();
537 for (
auto [LHS, RHS] :
538 {std::make_pair(0, 0), std::make_pair(0, 1), std::make_pair(1, 0)})
541 return {ConstantInt::get(Ty, LHS), ConstantInt::get(Ty, RHS)};
552 if (
I->getOpcode() !=
Op->getOpcode())
559 IOp->getIntrinsicID()) !=
565 assert(MainOp &&
"MainOp cannot be nullptr.");
568 if (MainOp->getOpcode() == Instruction::Select &&
571 if (MainOp->getOpcode() == Instruction::ICmp &&
575 assert(AltOp &&
"AltOp cannot be nullptr.");
579 if (!
I->isBinaryOp() || !MainOp->isBinaryOp())
586 if (AltConverter.
add(
I) && AltConverter.
add(AltOp) &&
592 return Converter.hasAltOp() ? AltOp : MainOp;
596 constexpr std::array<unsigned, 8> MulDiv = {
597 Instruction::Mul, Instruction::FMul, Instruction::SDiv,
598 Instruction::UDiv, Instruction::FDiv, Instruction::SRem,
599 Instruction::URem, Instruction::FRem};
605 constexpr std::array<unsigned, 4> AddSub = {
606 Instruction::Add, Instruction::Sub, Instruction::FAdd, Instruction::FSub};
616 assert(
valid() &&
"InstructionsState is invalid.");
630 return C &&
C->getValue().getActiveBits() <=
641 if (
getOpcode() == Instruction::GetElementPtr)
643 GEP && (
GEP->getNumOperands() != 2 ||
644 GEP->getSourceElementType() !=
647 if (!IsRegion &&
I->getParent() != MainOp->getParent() &&
654 if (!
I->isBinaryOp() || !MainOp->isBinaryOp())
664 (
I->getOpcode() == Instruction::FMul ||
665 I->getOpcode() == Instruction::FAdd) &&
667 return is_contained(VL, Op);
674 (
I->getOpcode() == Instruction::FMul ||
675 I->getOpcode() == Instruction::FAdd) &&
680 bool HasFMulOrFAdd =
false;
688 HasFMulOrFAdd =
true;
690 return HasFMulOrFAdd;
694 assert(
valid() &&
"InstructionsState is invalid.");
700 auto CheckForTransformedOpcode = [](
const Instruction *RefOp,
703 case Instruction::Add:
704 switch (ExpandingOp->getOpcode()) {
705 case Instruction::Shl:
722 return CheckForTransformedOpcode(MainOp, ExpandingOp);
727 switch (
I->getOpcode()) {
728 case Instruction::Shl:
737 assert(
valid() &&
"InstructionsState is invalid.");
747 auto IsNonSchedulableCopyableElement = [
this](
Value *V) {
749 return !
I ||
isa<PHINode>(
I) ||
I->getParent() != MainOp->getParent() ||
754 !MainOp->comesBefore(
I));
757 return IsNonSchedulableCopyableElement(V);
776 if (Inst->getOpcode() == Opcode)
790 BaseOp0 == Op0 || BaseOp1 == Op1 ||
801 "Assessing comparisons of different types?");
811 return (BasePred == Pred &&
813 (BasePred == SwappedPred &&
830 (VL.
size() == 2 && InstCnt < 2))
845 unsigned AltOpcode = Opcode;
848 bool SwappedPredsCompatible = IsCmpOp && [&]() {
850 UniquePreds.
insert(BasePred);
851 UniqueNonSwappedPreds.
insert(BasePred);
852 for (
Value *V : VL) {
859 UniqueNonSwappedPreds.
insert(CurrentPred);
860 if (!UniquePreds.
contains(CurrentPred) &&
861 !UniquePreds.
contains(SwappedCurrentPred))
862 UniquePreds.
insert(CurrentPred);
867 return UniqueNonSwappedPreds.
size() > 2 && UniquePreds.
size() == 2;
873 InterchangeablePred =
885 bool AnyPoison = InstCnt != VL.
size();
895 unsigned InstOpcode =
I->getOpcode();
897 if (BinOpHelper.
add(
I))
902 Value *Op1 =
I->getOperand(0);
905 if (InstOpcode == Opcode || InstOpcode == AltOpcode)
907 if (Opcode == AltOpcode) {
910 "Cast isn't safe for alternation, logic needs to be updated!");
911 AltOpcode = InstOpcode;
918 Type *Ty0 = BaseInst->getOperand(0)->getType();
919 Type *Ty1 = Inst->getOperand(0)->getType();
921 assert(InstOpcode == Opcode &&
"Expected same CmpInst opcode.");
922 assert(InstOpcode == AltOpcode &&
923 "Alternate instructions are only supported by BinaryOperator "
931 if ((VL.
size() == 2 || SwappedPredsCompatible) &&
932 (BasePred == CurrentPred || BasePred == SwappedCurrentPred))
940 if (MainOp != AltOp) {
943 }
else if (BasePred != CurrentPred) {
946 "CmpInst isn't safe for alternation, logic needs to be updated!");
951 if (BasePred == CurrentPred || BasePred == SwappedCurrentPred ||
952 AltPred == CurrentPred || AltPred == SwappedCurrentPred)
967 }
else if (InstOpcode == Opcode) {
968 assert(InstOpcode == AltOpcode &&
969 "Alternate instructions are only supported by BinaryOperator and "
972 if (Gep->getNumOperands() != 2 ||
980 if (!LI->isSimple() || !BaseLI->isSimple())
990 if (
Call->hasOperandBundles() &&
992 !std::equal(
Call->op_begin() +
Call->getBundleOperandsStartIndex(),
993 Call->op_begin() +
Call->getBundleOperandsEndIndex(),
1002 if (Mappings.
size() != BaseMappings.
size() ||
1003 Mappings.
front().ISA != BaseMappings.
front().ISA ||
1004 Mappings.
front().ScalarName != BaseMappings.
front().ScalarName ||
1005 Mappings.
front().VectorName != BaseMappings.
front().VectorName ||
1006 Mappings.
front().Shape.VF != BaseMappings.
front().Shape.VF ||
1007 Mappings.
front().Shape.Parameters !=
1008 BaseMappings.
front().Shape.Parameters)
1022 assert(MainOp &&
"Cannot find MainOp with Opcode from BinOpHelper.");
1024 assert(AltOp &&
"Cannot find AltOp with Opcode from BinOpHelper.");
1038 InterchangeablePred != BasePred) {
1043 return CI && CI->getPredicate() == InterchangeablePred;
1046 "Expected an instruction with the shared predicate.");
1050 "Incorrect implementation of allSameOpcode.");
1057 "Invalid InstructionsState.");
1070 if (Blocks.
insert(BB).second &&
1074 return Blocks.
size() > 1;
1085 assert(Entry != BB &&
"Expected a block other than the region entry.");
1092 constexpr unsigned MaxBlocks = 64;
1095 while (!Worklist.
empty()) {
1097 if (Succ == BB || !Visited.
insert(Succ).second)
1099 if (Succ == Entry || Visited.
size() > MaxBlocks ||
1128 Blocks.
insert(
I->getParent());
1140 return I->getParent() == Entry;
1159std::pair<Instruction *, SmallVector<Value *>>
1162 assert(SelectedOp &&
"Cannot convert the instruction.");
1163 if (
I->isBinaryOp()) {
1165 return std::make_pair(SelectedOp,
Converter.getOperand(SelectedOp));
1176 I, MainCI->getPredicate()))
1177 return std::make_pair(SelectedOp,
1188 assert(MainP != AltP &&
"Expected different main/alternate predicates.");
1197 assert((MainP ==
P || AltP ==
P || MainP == SwappedP || AltP == SwappedP) &&
1198 "CmpInst expected to match either main or alternate predicate or "
1200 return MainP !=
P && MainP != SwappedP;
1210 const unsigned NumLanes = VL.
size();
1222 if (!
I || !
I->hasOneUse() ||
I->getOpcode() != LaneOpcodes[Lane] ||
1233 if (GetChainLink(Lane, Columns[0][Lane]))
1235 Instruction *Link = GetChainLink(Lane, Columns[1][Lane]);
1238 std::swap(Columns[0][Lane], Columns[1][Lane]);
1242 return GetChainLink(Lane, Columns[0][Lane]) !=
nullptr;
1246 Instruction *Link = GetChainLink(Lane, Columns[0][Lane]);
1255 NewColumn[Lane] = Link->
getOperand(1 - RunningOp);
1256 Columns[0][Lane] = Link->
getOperand(RunningOp);
1258 Columns.
insert(std::next(Columns.
begin()), std::move(NewColumn));
1261 "Normalization guarantees at least one peeled level.");
1262 SubLanes.
resize(NumLanes);
1264 if (LaneOpcodes[Lane] == Instruction::Sub ||
1265 LaneOpcodes[Lane] == Instruction::FSub)
1270std::pair<Instruction *, Instruction *>
1302 "Expected different main and alt instructions.");
1303 return std::make_pair(MainOp, AltOp);
1311 "Expected extractvalue instruction state.");
1317 for (
Value *V : VL) {
1319 Aggregates.push_back(VL0->getAggregateOperand());
1323 if (
IV->getIndices() != VL0Indices ||
1326 Value *Agg =
IV->getAggregateOperand();
1330 if (AggState && AggState.
getOpcode() == Instruction::Call &&
const TargetLowering & TLI
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...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
uint64_t IntrinsicInst * II
Scalar Replacement Of Aggregates
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file implements the C++20 <bit> header.
static const uint32_t IV[8]
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.
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
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.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
LLVM_ABI Instruction * findNearestCommonDominator(Instruction *I1, Instruction *I2) const
Find the nearest instruction I that dominates both I1 and I2, in the sense that a result produced bef...
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This instruction compares its operands according to the predicate given to the constructor.
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
bool isTerminator() const
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
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.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator insert(iterator I, T &&Elt)
void swap(SmallVectorImpl &RHS)
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
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.
const ParentTy * getParent() const
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 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...
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)
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...
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 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 allSameBlock(ArrayRef< Value * > VL)
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 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 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.
static bool isControlEquivalentToEntry(const BasicBlock *Entry, const BasicBlock *BB, const DominatorTree &DT, const LoopInfo &LI)
Checks if BB, dominated by Entry, is executed as often as Entry: every path from Entry passes BB befo...
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.
bool succ_empty(const Instruction *I)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
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 ...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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 any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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 > >
bool canVectorizeTy(Type *Ty)
Returns true if Ty is a valid vector element type, void, or an unpacked literal struct where all elem...
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.